Skip to content

Every ending says which model the request was for - #81

Merged
fylorn merged 1 commit into
mainfrom
feat/end-events-carry-the-model
Sep 21, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/end-events-carry-the-model

Conversation

@fylorn

@fylorn fylorn commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

request_finished, request_failed and request_cancelled now carry model, the same string request_started has.

Why

A listener is not always there when a request starts. The desktop app subscribes while its window is open, and the overview's live chart only while the overview is showing, and usage arrives with the ending. With the model only on the start event, a request that began before anyone was listening and ended while someone was had its tokens and cost land on no model. The desktop app's live chart drew them as "Unknown model", a layer of their own, whenever the overview was opened in the middle of a task.

What changed

  • tw-api: model: String (#[serde(default)]) on the three end events, next to id.
  • tw-gateway: Ending::new takes the model; each ending (finished, failed, cancelled, and the ones reported from Drop) hands it on. HTTP requests pass the model from the request body; WebSocket sessions pass an empty string, as their start event does, because the upgrade request names no model.
  • tw-store: the recorder already has the model from the start event, so its match arms ignore the new field.

A field-only addition to the protocol, so the next tag is a patch.

Tests

  • ending.rs: a new unit test checks that all three endings carry the model, and the panic path is checked too.
  • tests/endings.rs: every HTTP scenario now also checks the ending's model against the one in the request body (finished, cancelled mid-stream, cancelled before headers, failed mid-stream, refused by every upstream, phase-two deny). On the WebSocket path it checks the model is empty rather than made up.
  • cargo fmt --check, cargo clippy --workspace --all-targets -D warnings, cargo test --workspace pass locally. Two oauth tests only pass with HTTP_PROXY unset, because a local proxy answers the deliberately unreachable address with a 503. That's this machine, not the change.

🤖 Generated with Claude Code

`request_finished`, `request_failed` and `request_cancelled` now carry
`model`, the same string `request_started` has.

A listener is not always there when a request starts. The desktop app
subscribes while its window is open, and the overview's live chart
only while the overview is showing, and usage arrives with the ending.
With the model only on the start event, a request that began before
anyone was listening and ended while someone was had its tokens and
cost land on no model: the live chart drew them as "Unknown model", a
layer of their own, whenever the overview was opened mid-task.

`Ending` takes the model when it is created and hands it to whichever
ending happens, including the one reported from `Drop`. WebSocket
sessions send an empty string, as their start event does, because the
upgrade request names no model. The recorder already has the model
from the start event and ignores the new field.

The endings integration tests check the model on every path, and on
the WebSocket path that it is empty rather than made up.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn force-pushed the feat/end-events-carry-the-model branch from 2285f66 to a07630e Compare September 21, 2026 12:52
@fylorn
fylorn merged commit 4d25572 into main Sep 21, 2026
1 check passed
@fylorn
fylorn deleted the feat/end-events-carry-the-model branch September 21, 2026 12:59
@fylorn fylorn mentioned this pull request Sep 21, 2026
fylorn added a commit that referenced this pull request Sep 21, 2026
`request_finished`, `request_failed` and `request_cancelled` now carry
`model` (#81), so a listener that joins mid-request still knows which
model an ending's usage belongs to. Additive; CONTROL_API_VERSION
unchanged.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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