Skip to content

feat(api): route stats say where their history starts; the ChatGPT login result names the account - #200

Merged
fylorn merged 1 commit into
mainfrom
feat/route-stats-coverage
Sep 25, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/route-stats-coverage

Conversation

@fylorn

@fylorn fylorn commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Two facts the desktop UI had to fill in on its own. Core now reports them.

Route stats say where their history starts

GET /summary/routes returned a bare RouteHits[]. The counts only see requests that are still in the store, so after a fresh install, after the store is rebuilt on an upgrade (v0.48.0 did, SCHEMA 19 → 20), or with retention.row_days shorter than the window, the routing page labelled a few hours of data as "7 days" and flagged rules as never matched in 7 days.

The endpoint now returns RouteStats:

type RouteStats = {
  covered_since_ms: number | null; // always present
  routes: Array<RouteHits>;        // the previous array, unchanged
};
  • covered_since_ms = max(from, oldest stored request's at_ms). The oldest request counts whether it was routed or answered locally: either way the store was recording by then.
  • It equals from when the whole window is covered, and is later than from when the history starts inside the window. Before it, "no hits" means "not known".
  • It is null when no moment of the window is covered: no stored request at all, or the oldest one is at or after the window's end (an empty window too).
  • When set, from <= covered_since_ms < to.
  • One SELECT MIN(at_ms) on the at_ms index; nothing new is stored, so the request store SCHEMA stays 20 (no history wipe).

The ChatGPT login result names the account

ChatgptLoginStatus (GET / DELETE /chatgpt/login/{id}) drops plan and carries account?: AccountView ({ email?, plan? }), the same block as OAuthView.account, read from the same token: the access token the sign-in just saved to the config. The login result and the upstream row cannot name different accounts, and the login completion page no longer needs an extra Overview read. It is present for done when the token names at least one of the two. The id_token is still read, for the account id only. LoginFinished is unchanged (like the Z.ai sign-in, the event reports the outcome and the status carries the account).

Compatibility

  • CONTROL_API_VERSION 21 → 22, documented with the previous entries.
  • No message codes added or changed. No events changed.

Tests

  • Store: empty store (null, serialized as null rather than omitted), history shorter than the window (a local-answer row counts; pruning moves the start), history longer than the window (with and without requests inside it), a window before the history began, the exclusive end, an empty window.
  • Control plane: end-to-end /summary/routes on a fresh store (start = the first request, not from), and a store with no history yet ({"covered_since_ms": null, "routes": []}).
  • ChatGPT: the login result's account for browser, device and repeated sign-ins, equal to the upstream view's; a new test where the id_token carries only the account id shows the account comes from the access token (fails if read from the id_token). Pending and failed statuses carry no account.
  • TypeScript export: covered_since_ms: number | null, account?: AccountView, no plan on the login status.
  • scripts/smoke.sh reads the new shape and checks covered_since_ms.

cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace, the ts feature checks (clippy, tests, export + tsc --strict) and scripts/smoke.sh pass locally.

🤖 Generated with Claude Code

…gin result names the account

GET /summary/routes now returns RouteStats { covered_since_ms, routes }
instead of a bare RouteHits array. The counts only see requests that are
still in the store: on a fresh install, after the store is rebuilt on an
upgrade, or when rows are kept for fewer days than the window, the oldest
stored request is later than the window's start, and "no hits" before it
means "not known", not "never matched". covered_since_ms is the later of
the window's start and the oldest stored request (any request, routed or
answered locally); it is null when no moment of the window is covered (no
stored request at all, or the oldest one is at or after the window's
end). When set it lies inside the window: from <= covered_since_ms < to.
The field is always present, so a client has to handle null.

ChatgptLoginStatus drops `plan` and carries `account` (AccountView: email
and plan), the same block as OAuthView.account and read from the same
token: the access token the sign-in just saved to the config. The login
result and the upstream row cannot name different accounts, and the
login completion page no longer needs an Overview read. The id_token is
still read for the account id only. LoginFinished is unchanged.

CONTROL_API_VERSION is 22. No message codes changed; the request store
SCHEMA stays 20.

Tests: store-level coverage for an empty store, history shorter than the
window (including after pruning), history longer than the window, and a
window before the history began; an end-to-end /summary/routes with a
fresh store and with no history yet; the login result's account for
browser, device and repeated sign-ins, equal to the upstream view's, and
taken from the access token when the id_token carries only the account
id. The TypeScript export and the smoke script follow the new shapes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn force-pushed the feat/route-stats-coverage branch from aa58167 to 51cb2df Compare September 25, 2026 07:24
@fylorn
fylorn merged commit ab43211 into main Sep 25, 2026
4 checks passed
@fylorn
fylorn deleted the feat/route-stats-coverage branch September 25, 2026 07:34
@fylorn fylorn mentioned this pull request Sep 25, 2026
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