Repository navigation
fix(gateway): report timed-out HTTP agent runs as failures - #133275
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 7:52 AM ET / 11:52 UTC. ClawSweeper reviewWhat this changesThe PR makes the OpenAI-compatible Chat Completions and Responses HTTP endpoints use the agent command’s recorded terminal outcome for JSON and streaming success/failure responses, with matching documentation and regression coverage. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessThis focused maintainer-authored fix remains necessary: current main still uses the legacy metadata classifier, while the PR consistently reads the command owner’s recorded terminal outcome. No blocking correctness or security finding was identified; leave the linked issue open until this PR merges. Priority: P1 Review scores
Verification
How this fits togetherGateway HTTP endpoints invoke an agent command and translate its result into OpenAI-compatible JSON or Server-Sent Events. The command owner records the final terminal outcome after delivery and cleanup, and the two HTTP surfaces use that fact to choose their client-facing terminal response. flowchart LR
Client[HTTP client] --> Gateway[Gateway HTTP endpoint]
Gateway --> Command[Agent command]
Command --> Outcome[Recorded terminal outcome]
Outcome --> Decision[Success or failure decision]
Decision --> Json[JSON response]
Decision --> Stream[SSE terminal event]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -9, Tests +68, Docs +4. Total +63 across 7 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one canonical terminal-outcome decision at the agent-command owner and have both OpenAI-compatible HTTP projections consume it, preserving existing generic error envelopes and already-emitted streaming content. Do we have a high-confidence way to reproduce the issue? Yes, at source level: the linked report supplies a concrete compiled-Gateway scenario, and current main still applies the legacy metadata-only failure test at the affected HTTP decision points. This read-only review did not execute that scenario locally. Is this the best way to solve the issue? Yes. The command completion paths already own timeout and cancellation precedence and record a completed/failed carrier; consuming that fact in both HTTP projections removes the duplicated, incomplete metadata inference. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against eeec0d4b2a0c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Closes #133274
What Problem This Solves
Fixes an issue where callers of the OpenAI-compatible Chat Completions and Responses endpoints receive successful completion when the whole-agent run budget expires. Streaming callers can receive partial text followed by success without seeing the timeout.
Why This Change Was Made
Both command return paths already record the final run outcome after delivery and cleanup. All four HTTP projections now read that fact instead of inferring failure from optional
meta.errororstopReason: "error"fields. This deletes the duplicate classifier; timeout and cancellation precedence, retry policy, existing error envelopes, and disconnect handling remain unchanged.Both SSE endpoints already wait for the returned command result before finalizing, so no additional timing state is needed. Adding timeout-string matching or another HTTP-specific classifier would duplicate the existing owner policy.
Production LOC: +8/-17 (net −9). Tests: +94/-26 (net +68). Docs: +4/-0.
User Impact
Expired agent runs report an error through JSON or a failed streaming terminal instead of presenting an incomplete answer as successful. Already-delivered partial content remains delivered; successful and genuinely recovered runs keep their normal completion behavior. No public configuration, protocol, auth, or persistence changes.
Evidence
Candidate head:
9a6d534b62362a76f5bcc05424181645e8545341.Actual baseline proof used the canonical compiled Gateway CLI, maintained isolated instance helper, real agent command/runtime, a deterministic localhost Responses provider, and official OpenAI SDK 7.5.0. With an existing 3-second agent budget and 30-second provider deadline:
finish_reason: "stop"stop, no SDK error[DONE]; no success finishstatus: "completed"response.completedresponse.failedand[DONE]Normal success passed. A genuine recovery control made exactly two provider requests and logged the agent's retry before returning one successful completion. Ordinary provider-request timeouts already reported errors correctly. Each stream closed once with one terminal and one
[DONE].Six new regression cases failed on unchanged production for the expected JSON/SSE success misclassification; 14 existing controls passed. After the repair, all 156 Chat and Responses tests pass, including private-error redaction, partial output, completed error-marked payloads, stream finalization, client disconnects and client-tool siblings. The fresh structured autoreview is clean for its explicitly limited P0 scope. A separate all-priority Codex review and independent source/runtime verification found no actionable issues on the exact candidate.
The canonical candidate build passed in 225.62 seconds. All six actual compiled after-proof requests passed: the four repaired paths above, normal Responses success, and genuine OpenAI-provider recovery requiring exactly two provider requests plus the runtime retry log. Three isolated Gateway instances were cleaned up; all 28 guarded runtime/helper source hashes and all three build stamps matched the candidate.
{"head":"9a6d534b62362a76f5bcc05424181645e8545341","actual_gateway_cli_sdk":{"passed":6,"failed":0,"budget_failures_reported":4,"success_controls":2,"recovered_provider_attempts":2,"one_terminal_and_done_per_stream":true,"cleanup":true}}The canonical seven-path changed gate passed in 426.51 seconds with unchanged source hashes and a clean checkout. Exact-head hosted CI passed; its actual checkout merge contains the reviewed candidate and implementation base. Native CI/Testbox prepare and merge gates passed. Landed as a8c8c82708361d2f859f820562ae1b00cf162e93; remote main and all seven reviewed/landed file blobs were verified, and native cleanup completed. No external provider/model request, external Codex runtime, or released-binary reproduction is claimed; the recorded terminal fact is source-traced, not a runtime spy in the compiled proof.
The baseline is
0320297d7a1573c08cfaab781f93bd57dc4a694b; all 29 implicated source/test/docs/provider paths were verified identical on implementation base4306140e0b8824fc8e41f19bdf1ef119e37247d9. Direct dependency inspection covered the installed SDK error/final-response behavior and upstream Codex retry-versus-terminal status contracts. No upstream Codex defect or protocol change is asserted.Maintainer Review Disposition
The August 30 ClawSweeper review on the exact candidate found no actionable correctness or security issue and judged the canonical outcome reader the best fix. Its remaining SDK-source limitation is resolved by direct inspection of the installed SDK 7.5.0 SSE parser (
src/core/streaming.ts:45–123) and Responses accumulator/final-result handling (src/lib/responses/ResponseStream.ts:205–218,289–301), plus the six actual compiled Gateway/SDK cases above. The implementation preserves ordered partial output and the existing error/failed-response contracts.The generated stored-data-model warning is not applicable:
src/gateway/openai-compat-errors.tsonly loses the optional-metadata classifier and its import. No embedding, persisted data, schema, or migration code changes. The existing command fact is an in-process symbol property and is unchanged. There is no separate Rank-up moves list in that review; its normal CI/merge next step is tracked by the pending gates above. No rereview is requested for this unchanged head.