Repository navigation
refactor: share the codex stream's line, usage and tool call helpers - #61
Merged
Merged
Conversation
bketelsen
approved these changes
Nov 11, 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.
Summary
The codex provider's stream translation (
internal/inference/responses.go) and the usage tap (internal/inference/usage.go) repeat small pieces of logic. This PR moves each into 1 helper:sseJSON: the parse of an SSEdata:line that holds a JSON object, whicheventsandusageTap.sseLineeach did on their own.chatUsage: the chat completionusageobject (prompt_tokens,completion_tokens,total_tokens), built inchatCompletionand in the chunker's last usage chunk.chatToolCall: the chat completion tool call, built inchatCompletionand in the chunker'sresponse.output_item.donepath (the chunker adds itsindex).answerParts: a finished response's text and function calls, with the fallback toresponse.output.chatCompletionand the chunker's "no deltas came" path both use it, so that path no longer builds a whole chat completion and digs the message out of it with type assertions.No change in behavior: the same chat completion, chunks,
[DONE]line, error chunk and recorded usage for the same provider stream. Every function name, signature and JSON field that other code uses stays the same.Left out on purpose:
internal/inference/{config,server,codex,copilot}.go(risk paths) andcmpString, whichcodex.gouses.Risk tier
Risk tier: 1 — a refactor with no change in behavior.
internal/inference/responses.goandinternal/inference/usage.goare not in.github/risk-paths.json; no listed path is touched.Verification
7d33cca) addsinternal/inference/stream_test.go: 22 characterization tests ofevents, the usage tap,chatCompletionand the chunker (text deltas, function calls, an answer with no deltas from the items or fromresponse.output, the usage chunk, a completed event with no response, failures,[DONE]). Chunks are compared by value, becauseencoding/json/v2does not sort map keys. On the base code:go test -count=1 ./internal/inference/→ok(0.552s).1a936fd) is the refactor; it does not change the new test file or any other test.make checkgreen (host): on the base74a31e4, exit 0; on the head1a936fd, exit 0.Cross-review
openai/gpt-6.1-sol; primary coderdeepseek/deepseek-flash, with a small edit byanthropic/claude-opus-5-5.74a31e4856b5e44da4567c53307cb83cf1354bf1, head1a936fd75c2dae165f88d598306f87f86d07cf69; 1 pass, all 3 changed files, withcodex.goread for context.[DONE]and recorded tokens stay the same.