Repository navigation
feat(api): session and route at request start, a replayable in-flight snapshot, rule hit counts - #197
Merged
Merged
Conversation
…ayable in-flight snapshot, rule hit counts
The desktop UI had to guess several things about running requests. Core
now says them:
- RequestStarted carries the session id the request is stored under
(`session`, replacing the `session_fp` fingerprint). The gateway assigns
it once, when the request starts (tw_gateway::session::Sessions); the
recorder stores the event's value instead of recomputing it.
- Phase one of routing is done before the start, so RequestStarted also
carries `route`, `rule`, `group` and `rewritten_by`. RequestRouted
carries the final record: `route`, `rule`, `group`, `rewritten_by`
(phase-two rewrites included) and `denied_by` (a phase-two rule that
denied the request; the denied hop is the last attempt). RoutingView,
the stored routing JSON, has the same fields, and is recorded from the
start event too, so a request that ends before routing finishes still
says which route and rule it went through.
- Requests a rule decided but that reached no upstream now leave a row:
denied by a rule (HTTP and WebSocket) or no chosen upstream can serve
them. They get a start, a RequestRouted with an empty chain, and a
failure. A phase-two denial now also emits RequestRouted.
- GET /in-flight returns InFlight { now_ms, requests: [{ id, events }] }:
core's clock and every event the bus has seen for each running request
(start, headers, routed, translated, guard records), in order, so a
late joiner can replay them through its normal reducer.
- RunningView (GET /live) gains elapsed_ms (core-computed, monotonic),
session, route, rule, group and upstream (the hop that served it).
- New GET /summary/routes: per route and per rule, requests matched,
decided, failed and last hit, from stored routing data. A request counts
under its deciding rule, every rule that rewrote it, and a phase-two
rule that denied it.
The engine's Decision and Outcome2::Proceed name the rules that added a
rewrite. The stored routing JSON changed shape, so the request store
SCHEMA is 20. CONTROL_API_VERSION is 21.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
fylorn
added a commit
that referenced
this pull request
Sep 25, 2026
v0.48.0 was published before the template landed, so its page holds only GitHub's generated list. release-notes/0.48.0.md summarizes it from #191-#198 so the page can be rewritten from the template: - upgrade notes: CONTROL_API_VERSION 21, so ThinkWatch Lite 2026.9.16 (core 0.47.0, protocol 20) does not connect to it and a server used with that app stays on 0.47.0; the request store's schema 20, which empties the request history on the first start (and again on the way back); the /in-flight shape, RequestStarted.session and the removed ChatgptUsage fields; - session and route on the start event, requests a rule decided without an upstream, the replayable /in-flight snapshot and the new /live fields, and /summary/routes (#197); - per-group unpriced and no-usage counts, and security log totals (#193); - the signed-in account on a ChatGPT account upstream (#195); - releases published from one job, the server guide and the crate metadata (#191), and the test port fix (#192). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fylorn
added a commit
that referenced
this pull request
Sep 25, 2026
v0.48.0 was published before the template landed, so its page holds only GitHub's generated list. release-notes/0.48.0.md summarizes it from #191-#198 so the page can be rewritten from the template: - upgrade notes: CONTROL_API_VERSION 21, so ThinkWatch Lite 2026.9.16 (core 0.47.0, protocol 20) does not connect to it and a server used with that app stays on 0.47.0; the request store's schema 20, which empties the request history on the first start (and again on the way back); the /in-flight shape, RequestStarted.session and the removed ChatgptUsage fields; - session and route on the start event, requests a rule decided without an upstream, the replayable /in-flight snapshot and the new /live fields, and /summary/routes (#197); - per-group unpriced and no-usage counts, and security log totals (#193); - the signed-in account on a ChatGPT account upstream (#195); - releases published from one job, the server guide and the crate metadata (#191), and the test port fix (#192). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fylorn
added a commit
that referenced
this pull request
Sep 25, 2026
…summary (#196) * ci(release): write the release page from a template, with an English summary #191 made the publish job write the release once, with GitHub's generated list of pull requests as its only text and the tag as its title. A release is now titled "ThinkWatch Core <version>", and its text has, in order: - an English summary from release-notes/<version>.md, when that file exists; - a table of the files for each platform; - the commands that install this version on a Linux server and switch an existing installation to it (install.sh --version, twcore upgrade --version --restart); - how to verify a download against its .sha256; - GitHub's generated list of pull requests. scripts/release_notes.py builds the text; the publish job fetches the generated list itself (releases/generate-notes) and hands the finished text to action-gh-release, which no longer generates anything. The "only once" rule from #191 stays: a release that already exists keeps its text. A rehearsal (workflow_dispatch) now writes the text into the run summary, using the version in Cargo.toml. scripts/release_notes_test.py checks that the table links exactly the files in release.yml's FILES list, that the install and upgrade options exist, and that every file in release-notes/ renders; the Linux CI job runs it before compiling. release-notes/0.47.0.md summarizes 0.47.0 from #183-#190; the live v0.47.0 release page now carries it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * release-notes: summarize 0.48.0 v0.48.0 was published before the template landed, so its page holds only GitHub's generated list. release-notes/0.48.0.md summarizes it from #191-#198 so the page can be rewritten from the template: - upgrade notes: CONTROL_API_VERSION 21, so ThinkWatch Lite 2026.9.16 (core 0.47.0, protocol 20) does not connect to it and a server used with that app stays on 0.47.0; the request store's schema 20, which empties the request history on the first start (and again on the way back); the /in-flight shape, RequestStarted.session and the removed ChatgptUsage fields; - session and route on the start event, requests a rule decided without an upstream, the replayable /in-flight snapshot and the new /live fields, and /summary/routes (#197); - per-group unpriced and no-usage counts, and security log totals (#193); - the signed-in account on a ChatGPT account upstream (#195); - releases published from one job, the server guide and the crate metadata (#191), and the test port fix (#192). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * release-notes(0.48.0): say where the key is kept without naming the keychain Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
The desktop UI's live views and routing map had to guess several facts about requests. Core now reports them.
Session at start
RequestStarted.sessionreplacessession_fp: it is the session id the request is stored under (requests.session,SessionView.id).tw_gateway::session::Sessions: same fingerprint and no more than 30 minutes since that conversation's previous request). The tracker lives inAppStateand survives config reloads; stale fingerprints are pruned. The recorder stores the event's value and no longer tracks sessions.Route and rule, from the start
RequestStartedcarriesroute,rule,groupandrewritten_by.RequestRoutedcarries the final record:route,rule,group,rewritten_by(phase-two rewrites included),denied_by(a phase-two rule that denied the request; the denied hop is the last attempt, with outcomeerror).RoutingView(stored routing JSON, request detail) has the same fields and is recorded from the start event too, so a request that ends before routing completes still says which route and rule it matched (empty attempts).Decision.rewritten_byandOutcome2::Proceed { set, rewritten_by }name the rules that added a rewrite.Requests a rule decided but no upstream received
Previously these produced no events and no row. Now they get
RequestStarted(emptyprovider),RequestRoutedwith an empty chain, andRequestFailed:deniedA phase-two denial now emits
RequestRoutedas well (it returned before the event). Such requests now count in/summaryrequests and failures, like guard denials already did. Requests that fail before a rule decides (auth, model admission, no rule matches) are still not recorded.In-flight snapshot and live view
GET /in-flightreturnsInFlight { now_ms, requests: [{ id, events }] }: core's clock plus every event the bus has seen for each running request, in order (start, headers, routed, translated, guard records; notQuotaSeen). A late joiner replays them through its normal reducer and computes elapsed time from core timestamps.RunningView(GET /live) addselapsed_ms(core's monotonic clock),session,route,rule,group,upstream(the attempt that served it, once routed).Rule hit counts
New read-only
GET /summary/routes(Window, default today) →Vec<RouteHits>: per routerequests,failed,last_ms, and per ruledecided,requests,failed,last_ms. A request counts under its deciding rule, every rule that rewrote it, and a phase-two rule that denied it (once each). Counted from the stored routing data, not from the current config; local answers are excluded.Compatibility
CONTROL_API_VERSIONstays 21 (bumped by feat(api): say who is signed in on a ChatGPT account upstream, read from its own token #195, not yet released); this change is documented under the same version.SCHEMAis 20 (the database is rebuilt, as in feat(api): closed sets are enums; attempt, model-list and probe reasons are coded #174).Tests
Unit tests for the session tracker, engine rewrite bookkeeping, bus snapshot and running view, recorder session/routing, and
route_hits; gateway integration tests (tests/routing_facts.rs,tests/ws.rs,tests/endings.rs) for session/route on events, rule denials, unservable choices, phase-two denial and rewrites; control-plane tests for/in-flight,/liveand an end-to-end/summary/routes(real gateway, recorder task). The smoke script hits/in-flight,/liveand/summary/routes.cargo fmt --all --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspace, thetsfeature checks andscripts/smoke.shpass locally.🤖 Generated with Claude Code