Skip to content

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
TandemLLM:mainfrom
AgentSparko:feat/request-id-header
Open

AgentSparko wants to merge 1 commit into
TandemLLM:mainfrom
AgentSparko:feat/request-id-header

Conversation

@AgentSparko

@AgentSparko AgentSparko commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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's
request_id, the row a controller joins its own rows to. But on a stream the id reaches the
client 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:

X-Tandem-Request-Id: chatcmpl-<hex24>

The id is set on the handler the moment _complete makes it, and Handler.send_response —
the single write site every response passes through, beside the existing X-Tandem mode
header — emits it. That covers both completion entry points (/v1/chat/completions and
/v1/completions), streamed and non-streamed, including a stream opened early (S1): the
header leaves with the status line, not with the first frame. There is no /v1/messages or
other 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-Tandem has), so a response to anything that is not
a 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); a
non-completion response carries no such header.

python tests/test_app_loop.py    -> 31 passed (22 s, CPU, the random 4-layer model)

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.py skips here (its pair tests need a TandemApp checkout beside the
engine). 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server/api Server: the OpenAI API, tool calls, streaming, structured output

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant