Repository navigation
Conversation
ashhart
added a commit
that referenced
this pull request
Nov 16, 2026
…oed and in the request's log lines
A client could not tie a reply, or the server's log lines for it, to its own
trace, and a streaming client had no cancel handle until its first event.
Each reply head, an SSE stream's included, now carries X-Request-Id after
Date.
A request with exactly one X-Request-Id of 1 to 128 printable ASCII
characters and no space gets it back, and every [tensorfold] line its thread
writes while it handles that request, the access line first, ends with
request_id=ID. Any other value, an empty one or a repeated header is
ignored, never refused. The reply then carries the server's own id: the one
POST /v1/requests/{id}/cancel takes, named where openai.runNamed makes it,
so chat completions, completions and Responses replies carry the chatcmpl-,
cmpl- or resp_ id their body has, and /v1/messages its chat completion's
chatcmpl- id. A request that names none gets a new req_ id of 32 hex
digits; ids.fill makes it into the connection's own buffer. Bodies are
unchanged.
The golden normalizer drops a server-made X-Request-Id as it drops Date, so
every existing golden compares as before; a new request-id group pins the
echo (on a 401, a 400, a 404 and a stream) and the values that are not
echoed. request_id_test.zig covers the echo and log lines on a connection,
the fresh id, the keep-alive reset, and over sockets the id each route
carries. The Ollama keep-alive test now looks for a 501 status line, since a
random id can hold those digits.
…sponses would prefill, generating nothing
OpenAI's input-token count for a Responses request answered "unknown path".
POST /v1/responses/input_tokens (and /responses/input_tokens) now takes the
same body and answers {"object": "response.input_tokens", "input_tokens": N}.
The body goes through the route's own reader, scope check and translation
(responses.request, split out of responses.post), the turn's logprobs check
(responses.unofferedLogprobs, split out of responses.turn), then
openai_prepare.prepare: the run's own plan and chat.prepare, as the Responses
WebSocket warmup already counts its prompt. So N is the rendered prompt the
run prefills, with instructions, tools, items, a stored parent's
conversation and image tokens, and a body /v1/responses refuses gets the same
status and error. The request gate, admission and key scopes are the
Responses route's; inference keys reach it, read keys do not.
A count is not written to TENSORFOLD_REQUEST_LOG: prepare takes the run's
skip_request_log flag, and the warmup passes false as before. Two modes
rewrite a prompt during the run with text not yet written, so a request
they would take is refused by name: --compact-at past its threshold, using
compact.zig's own over and wanted, and a --cortheon turn, using
cortheon.takes, the check begin made before it starts one.
Golden cases on a server of their own count five Responses corpus bodies
(each equal to that case's usage.input_tokens), refuse its sixteen refusal
bodies with byte-identical replies, and count a stored parent's continuation
as its run prefills it. responses_count_test.zig checks counts against the
prompts a recording engine is given, the refusals and scope rules, both mode
refusals and the request log. All fail on main and pass here.
…for the 600-line cap
ashhart
force-pushed
the
lead/responses-input-tokens
branch
from
November 22, 2026 04:59
2093c65 to
4c3ef0f
Compare
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.
OpenAI's Responses API has
POST /v1/responses/input_tokens, which counts the input tokens a request would use without generating. On TensorFold the path answered 404 "unknown path". This serves it with the exact count the run would prefill.What this changes
The route:
POST /v1/responses/input_tokens(and/responses/input_tokens) takes the same body asPOST /v1/responses:model,input,instructions,tools,previous_response_idand so on. It answers{"object": "response.input_tokens", "input_tokens": N}and generates nothing.How N is computed: the body goes through the Responses route's own reader, scope check, translation and logprobs check, now shared. Then it goes through
openai_prepare.prepare, the run's own render and checks, which the WebSocket warmup already uses. So N is the exact prompt length/v1/responseswould prefill for the same body.usage.input_tokens(26, 26, 162, 38, 77).Refusals: a body
/v1/responsesrefuses gets the same status and error. All 16 refusal cases are byte-identical to the Responses route's. A streamed body's refusal comes back as a JSON reply.Two modes can't be counted, and say so: they rewrite the prompt during the run with text that doesn't exist yet. A request either one would take gets a 400 naming the flag:
--compact-atpast its threshold, where the model writes the compaction note;--cortheonturn, which adds its program, tools and research.cortheon.begin's checks moved intocortheon.takes, so both callers use the same checks, with no behaviour change.Keys, scopes, admission and the request gate: the Responses route's. Counts are not written to
TENSORFOLD_REQUEST_LOG.Issue: n/a. This came from the 16 Nov check of competitor gap docs against main (llama.cpp serves it; the
/v1/responsesdocs here listed it as missing); no issue or PR covered it.Stacked on: server: every reply carries X-Request-Id, a client's own valid id echoed and in the request's log lines #3536 (
X-Request-Id), which stacks on server: GET /v1/models/{id} returns one served model's entry, and an unknown id is a 404 model_not_found #3535 (GET /v1/models/{id}). This PR addsece2df75d6. The three PRs touch the security-case list, the key-scope docs row androot.zig, and the stack resolves those once.atc overlap --json: to run after review.golden/cases.json, which is generated, also changes in the code-infill draft server: /v1/completions takes suffix, a fill-in-the-middle prompt from the tokenizer's own FIM tokens #3528; whichever lands second rerunsfreeze_cases.py.Checks on this head
responses.zigis exactly 600 lines.tools/pr_check.py: 0 errors, 2 advisory warnings (the inherited0.0.0.0in the regenerated security-case list, and the PR number).zig build test-server-cpu1494/1503 (9 skipped);zig build test-golden344/357 equal with 0 unexpected (the 13 are main's existing known list), and security 80/80;zig build test-model-discovery-host test-key-scopes-host76/76.zig fmt --check,git diff --check: clean.Receipt
n/a: a counting route that renders the prompt and generates nothing. Host checks are above.
Checklist
The title and description match the head commit.
New tests fail before the change, pass after it, and skip cleanly without their dependency.
Comments and docstrings are one line. No measurements or history in the source.
No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
Synthena (Ash's Agent)