Repository navigation
SRV-733: a completion response carries the answer's id on its headers at stream open, in X-Tandem-Request-Id - #178
Open
AgentSparko wants to merge 1 commit into
Open
AgentSparko wants to merge 1 commit into
AgentSparko wants to merge 1 commit into
Conversation
… at stream open, in X-Tandem-Request-Id
This branch has not been deployed
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.
Completion responses carry the answer's id at stream open (
X-Tandem-Request-Id)The problem
The engine makes the answer's own id (
chatcmpl-<hex24>) when it accepts the request(
server/app.py,_complete) — SRV-733 documented that this id is the engine ledger row'srequest_id, the row a controller joins its own rows to. But on a stream the id reaches theclient only with the first SSE frame, which leaves after prefill. The TandemApp controller in
front of the engine therefore cannot join its prefill-phase rows — the ones the Live view
shows while the answer is still prefilling — to the engine's live rows until the answer has
already begun.
This is the engine side of the cross-repo pairing with TandemApp's PR "Live view: the
controller carries its engines' live figures": the controller's live view wants to show the
engine's own in-flight figures beside its own prefill rows, and the join key is this id.
The change
Every response to a completion request now carries the id on its headers, written when the
response opens — before any generated token:
The id is set on the handler the moment
_completemakes it, andHandler.send_response—the single write site every response passes through, beside the existing
X-Tandemmodeheader — emits it. That covers both completion entry points (
/v1/chat/completionsand/v1/completions), streamed and non-streamed, including a stream opened early (S1): theheader leaves with the status line, not with the first frame. There is no
/v1/messagesorother anthropic-compat completion entry point in this repository — the two paths above are
the whole completion surface, and both share the one id machinery. The handler resets the id
per request (the same keep-alive reset
X-Tandemhas), so a response to anything that is nota completion — health, dashboard, a refusal answered before
_complete— carries no id.Tests
tests/test_app_loop.py::test_the_completion_response_carries_the_answer_id_at_stream_open:on both entry points, streamed and non-streamed, the header is present exactly once and
equals the id in the first SSE frame's body (streamed) / the body's
id(non-streamed); anon-completion response carries no such header.
The narrowest neighbouring suites over the HTTP surface touched also pass:
test_auth.py(25),test_compat.py(17),test_body_limits.py(4),test_base_plain.py(6).
test_gpu_health.pyskips here (its pair tests need a TandemApp checkout beside theengine). The full suite was not run (it is heavy; the change is three write sites and one
header line).
Verified by test; live proof deferred to the TandemApp controller test which consumes the
header (this box's engine serves the owner's chat and is not restarted for a contribution).
Backward compatibility
Additive only: one response header on completion responses, no status, body, or timing
change. Clients that ignore unknown headers — every SDK we serve — see nothing different.
Pairs with the controller PR: TandemLLM/TandemApp#1 — it consumes this header to join prefill-phase rows and works unchanged with engines that do not send it. The two land together.