Skip to content

feat(api): state the app can read instead of waiting for an event it may have missed - #102

Merged
fylorn merged 1 commit into
mainfrom
feat/live-state
Sep 22, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/live-state

Conversation

@fylorn

@fylorn fylorn commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

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:

  • a subscriber that fell behind lost events with a log line on core's side only, so a request whose ending was dropped stayed "in progress" in the app forever;
  • /quota served 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);
  • whether an upstream rejects its credential, or a proxy is down, only existed as a change event, so a page opened afterwards could not show it;
  • opening a request that is still running returned "There is no request N", because rows are written when a request ends.

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.
  • Quota reset times are moments: QuotaWindow.resets_at_ms and QuotaExhausted.resets_at_ms replace reset_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.
  • The overview carries the current state: ProviderView.auth_rejected (the 401 or 403 the upstream answered) and ProxyView.unreachable (ProxyFault: the failed step, why, and when it was checked). The gateway keeps the status and the last check result it already computed for AuthChanged / 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_flight says so. Once the request ends, the same call returns the stored row.
  • Control API version 8: a UI written for 7 reads reset_in_secs and would show no countdown.

The desktop app follows in its own PRs after the release.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace (run locally with HTTP_PROXY/HTTPS_PROXY unset)
  • 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 gets EventsDropped with the right count, then the events that were kept; a running request opens with in_flight, its status, route and request body, and becomes the stored row when it ends; an unknown id is still 404; the overview reports auth_rejected: 401 after a real 401 and unreachable with an l1.* 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's resets_at_ms is 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

…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>
@fylorn
fylorn merged commit 131ab7c into main Sep 22, 2026
1 check passed
@fylorn
fylorn deleted the feat/live-state branch September 22, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant