Repository navigation
Report how many requests are still being served - #23
Merged
Merged
Conversation
`Status` gains `in_flight`: requests from the moment they enter the data plane until the last byte of the response has gone out, or the client has left. Queued requests count; streams still producing output count. The desktop app needs this to update without breaking anyone's work. Installing a new version restarts the gateway, and a restart cuts every stream that has not finished — a Claude Code task mid-response loses its output and has to start that request again. Waiting for this number to reach zero turns the restart into a gap between requests. It cannot be counted until the handler returns. For a streaming response the handler returns before the first byte is sent, so a six-minute task would count as finished before it had started producing anything. The pass travels with the response body instead, and is returned when the body is dropped: when the stream completes, and also when a client walks away and hyper discards the body — which is the path a hand-written decrement would miss, leaving a count that never reaches zero. The WebSocket path moves its pass into the upgraded connection's task, so a Codex session counts for as long as the connection is open. Both failure modes were checked against the tests: counting until the handler returns fails the streaming and client-disconnect tests; not moving the pass into the upgrade fails the WebSocket test. Version 0.1.1, for the release the desktop app will pin. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thanks for the PR. One thing before review: this targets
No need to close and reopen: click Edit next to the PR title and change the base branch to See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract. |
This was referenced Sep 16, 2026
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.
What this changes
tw_api::Statusgainsin_flight: the number of requests currently beingserved, from entering the data plane until the last byte of the response has
been sent or the client has gone. Queued requests and streams still producing
output both count.
Workspace version 0.1.1.
Why
The desktop app is getting one-press automatic updates. Installing a new
version restarts the gateway, and a restart cuts every stream that has not
finished: a Claude Code task in the middle of a response loses that output and
has to send the request again. With this number the app can wait for it to
reach zero and restart in the gap between two requests instead.
It cannot be counted until the handler returns. For a streaming response
the handler returns before the first byte goes out, so a six-minute task would
count as finished before it had produced anything. The pass
(
tw_gateway::live::Pass) travels with the response body and is returned whenthe body is dropped. That covers a completed stream, and also a client walking
away mid-stream, when hyper discards the body and none of the code after the
stream loop runs — the path a hand-written decrement would miss, leaving a count
that never gets back to zero.
WebSocket upgrades move the pass into the upgraded connection's task, so a
Codex session counts for as long as its connection is open.
How it was checked
crates/tw-gateway/tests/live.rsruns a real gateway in front of a fakeupstream that sends one SSE frame and then stalls:
Each test was also run against the broken version it guards against. Holding
the pass only until the handler returns fails the streaming and disconnect
tests ("流还没结束,它就不该被当成已经结束"); not moving it into the upgrade
fails the WebSocket test ("计数停在 0,等的是 1").
Gates:
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspace(1,128 passed),./scripts/smoke.sh(46 passed).Found along the way, not fixed here
A client that disconnects mid-stream never produces
RequestFinishedorRequestFailed, because the tail of the stream block never runs. The recorderkeeps such a request in memory and never writes it, so the tokens the upstream
already billed for it go unrecorded. That deserves its own change.
🤖 Generated with Claude Code