Repository navigation
feat(api): state the app can read instead of waiting for an event it may have missed - #102
Merged
Merged
Conversation
…may have missed
The desktop app keeps its screens current from the event stream, but it
often joins late: a window opens, a page mounts, the stream drops events.
Several states could only be learned from an event it may have missed.
- A subscriber that falls behind is told. Core used to drop its oldest
events with only a log line on its own side. It now sends that
subscriber EventsDropped { count }, so it can resync from /in-flight,
the history and the overview. The marker goes only to the subscriber
that lagged and never onto the bus.
- Quota reset times are moments. QuotaWindow and QuotaExhausted carry
resets_at_ms instead of reset_in_secs. The seconds were true when the
response arrived, and /quota kept serving them unchanged, so every
countdown built on them stood still. A numeric reset header may also be
a Unix timestamp in seconds, which used to be read as a countdown of
some fifty years. Windows last at most a week and any recent timestamp
is above a billion, so the two are told apart by size.
- The overview carries the current credential and proxy state:
ProviderView.auth_rejected (the 401 or 403 the upstream answered) and
ProxyView.unreachable (the failed step, why, and when it was checked).
AuthChanged and ProxyChanged only report changes, so a page opened
afterwards could not tell.
- GET /request/{id} answers for a request still running. A row is
written when its request ends, and the request people open is often
the long one still streaming; they used to get "There is no request N".
The recorder now builds the row it has so far (identity, upstream, the
status once headers arrive, the route once it is decided), the request
body is already stored, and the detail says in_flight.
Control API version 8: a UI written for 7 reads reset_in_secs and would
show no countdown.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Sep 22, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The desktop app keeps its screens current from the event stream, but it often joins late: a window opens, a page mounts, the stream drops events. An audit of every live-updating screen found states the app could only learn from an event it may have missed, and one number that never moves:
/quotaserved the reset time as the seconds left when the response arrived, so every countdown built on it stood still (the Upstreams page polled it every 30 s and got the same number each time; the menu bar has the same problem);What changed
EventsDropped { count }is sent to a subscriber that falls behind, in place of the old silent drop. Only that subscriber gets it; it never goes on the bus. The SSE encoding is split from the event stream so the stream itself is testable.QuotaWindow.resets_at_msandQuotaExhausted.resets_at_msreplacereset_in_secs, computed when the headers are read (and when the ChatGPT usage answer arrives). A numeric reset header that is a Unix timestamp in seconds is no longer read as a countdown of fifty years: windows last at most a week, timestamps are above a billion.ProviderView.auth_rejected(the 401 or 403 the upstream answered) andProxyView.unreachable(ProxyFault: the failed step, why, and when it was checked). The gateway keeps the status and the last check result it already computed forAuthChanged/ProxyChanged.GET /request/{id}answers for a request still running: the recorder builds the row it has so far (identity, upstream, status once headers arrive, the route once decided); the request body is already stored;RequestDetail.in_flightsays so. Once the request ends, the same call returns the stored row.reset_in_secsand would show no countdown.The desktop app follows in its own PRs after the release.
Test plan
cargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspace(run locally withHTTP_PROXY/HTTPS_PROXYunset)scripts/smoke.sh: 51 passed, 0 failed, 1 over target (memory 35 MB against the 30 MB target, below the 40 MB regression line)New or extended tests:
tw-control: a lagging subscriber getsEventsDroppedwith the right count, then the events that were kept; a running request opens within_flight, its status, route and request body, and becomes the stored row when it ends; an unknown id is still 404; the overview reportsauth_rejected: 401after a real 401 andunreachablewith anl1.*reason after a proxy check fails.tw-gateway: the auth and proxy notice tests also check the current state while rejected/unreachable and after recovery; a quota'sresets_at_msis the moment the response arrived plus the upstream's seconds, and stays that moment; the quota parser takes RFC 3339, relative seconds and Unix timestamps, and drops moments already past.🤖 Generated with Claude Code