Build token timeline from returned token ids #1085
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.63) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.63 · 274 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.336
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.063
Real PR Conversation Timeline
1 comments
"Review active on #1085"
general
weight: 0.35
rishabhsinha17
Part of #917
The token timeline of a streamed response is built by re-tokenizing the text of each chunk. Tokens the server's tool parser swallows never reach the client as text, so they are missing from the timeline. The client/server count check on tool turns runs with a tolerance for that reason.
With
api.return_token_ids: truethe client sendsreturn_token_idsand builds the timeline from the ids each chunk carries. Every generated token gets an arrival time, swallowed ones included. The count check on those responses is exact, tool turns included. A response that carries no ids falls back to the re-tokenized timeline.output_lenis unchanged.Changes:
Add
api.return_token_ids, default false. Streaming chat and completion only. Other APIs and unary are rejected at config load.Send
return_token_idsin the request body when the flag is on.Record one arrival time per returned token id in the SSE parser.
Use the id timeline for
output_token_timesin the chat, completion and replay graph session paths when ids came back. Mark the response withtoken_ids_returned.Skip re-tokenizing and the tool-turn tolerance in the count check when ids came back.
Add
requests_with_token_idsto the summary, so a zero mismatch count says which check produced it.Document the flag in
docs/config.mdanddocs/metrics.md.Other changes:
The fake OpenAI server in the integration tests can stream tool calls, chunks with no text, and token ids.
test_openai_client.pysetsreturn_token_ids = False. AMagicMockattribute is truthy, which sent the field on the embeddings and rerank round trips.vLLM puts the ids of the whole prompt on the first chunk when the field is set. The first chunk grows with prompt length.
pdm run validate,pdm run testandpdm run check:covran clean.e2e/tests/test_vllm_cpu_token_ids.pyran clean against vLLM v0.33.0 on CPU for chat and completion. Its tool-call case ran clean against the same release serving Qwen/Qwen3-0.6B with the hermes tool parser. That case needs a tool-capable server, so it skips in CI.This PR was written in part with the assistance of generative AI.