fix: stabilize remote compaction streams#699
Merged
Merged
Conversation
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
Fixes intermittent Codex session interruptions that appeared in request audits as successful
200 / Stream / 0 Tokensrequests.These requests are Codex Remote Compaction V2 calls sent through
POST /v1/responseswith a terminalcompaction_trigger. Codex requires exactly onecompactionoutput item followed byresponse.completed; a stream ending before that point must not be treated as successful.Root cause
The gateway previously had several gaps around compaction and streaming responses:
compaction_triggerrequests were classified as ordinary Responses requests.response.completedpayload.200 / Stream / 0 Tokens.Changes
Codex compaction
compaction_triggeritems in/v1/responses.compactionaudit operation.Stream integrity
Added protocol-aware terminal-event validation:
response.completed[DONE]message_stopimage_generation.completedStreams are now classified as:
upstream_stream_incompleteupstream_stream_interruptedupstream_stream_errorstream_interruptedfor downstream/client write failuresTransport-level incomplete or interrupted upstream streams temporarily cool the selected account so the client can retry against another account. Semantic failure events do not cool the account because they may be request-specific.
The gateway does not replay a stream after partial output, avoiding duplicated text or tool calls.
Audit and migration
compactionto the audit domain and frontend API contract.request_audits.operationCHECK constraint for SQLite and PostgreSQL.Compatibility
Test plan
go test ./... -count=1go vet ./...go build ./cmd/grok2apipnpm lintpnpm buildgit diff --checkgo test -race \ ./internal/transport/http/inference \ ./internal/infra/provider/cli \ ./internal/application/gateway \ ./internal/infra/persistence/relational