Skip to content

fix(gateway): report timed-out HTTP agent runs as failures - #133275

Merged
steipete merged 1 commit into
mainfrom
codex/qa-20260830-http-terminal-outcome
Aug 30, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa-20260830-http-terminal-outcome

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

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.error or stopReason: "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:

Surface Before After
Chat JSON HTTP 200, timeout prose, finish_reason: "stop" HTTP 500 / SDK error
Chat SSE after partial output Partial answer then stop, no SDK error Partial answer retained, then one SDK error and [DONE]; no success finish
Responses JSON HTTP 200, status: "completed" HTTP 500 / SDK error
Responses SSE after partial output Partial answer then response.completed Partial answer retained, then one response.failed and [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 base 4306140e0b8824fc8e41f19bdf1ef119e37247d9. 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.ts only 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.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 30, 2026
@steipete
steipete marked this pull request as ready for review August 30, 2026 11:39
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 7:52 AM ET / 11:52 UTC.

ClawSweeper review

What this changes

The 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 provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This 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
Reviewed head: 9a6d534b62362a76f5bcc05424181645e8545341

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative production fix consumes the established owner result across both equivalent HTTP surfaces with useful boundary regression coverage.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository-state author association is MEMBER, so the external-contributor proof gate does not apply; the PR body nevertheless supplies a detailed compiled Gateway and official-SDK after-fix run for the changed HTTP terminal behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository-state author association is MEMBER, so the external-contributor proof gate does not apply; the PR body nevertheless supplies a detailed compiled Gateway and official-SDK after-fix run for the changed HTTP terminal behavior.
Evidence reviewed 7 items Current main still has the defect: The current-main comparison reverses this PR’s changes: it removes the terminal-outcome reader and restores the legacy metadata-only classifier at the JSON and streaming decision points.
Canonical outcome producer: The embedded-command completion path records failed when its canonical terminal classification is not success, after delivery and deferred cleanup complete.
Sibling command path matches: The ACP command completion path independently records completed or failed from the same canonical terminal-outcome classification.
Findings None None.
Security None None.

How this fits together

Gateway 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]
Loading

Before merge

  • Resolve merge risk (P1) - The installed OpenAI SDK source was unavailable in this read-only worktree, so independent parser-contract inspection is a reviewer limitation; the PR’s supplied compiled-Gateway evidence is the available client-behavior evidence.
  • Complete next step (P2) - No repair dispatch is appropriate: this is an active maintainer-authored candidate fix, and the remaining work is normal exact-head CI and merge handling.
Agent review details

Security

None.

PR surface

Source -9, Tests +68, Docs +4. Total +63 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 8 17 -9
Tests 2 94 26 +68
Docs 2 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 106 43 +63

Review metrics

Metric Value Why it matters
Production versus regression coverage production −9 net, tests +68 net, docs +4 The fix removes the duplicate metadata classifier while adding boundary coverage for both JSON and streaming API families.

Stored data model

Persistent data-model change detected: vector/embedding metadata: src/gateway/openai-compat-errors.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    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.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best 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.

Labels

Label changes:

  • add P1: Expired agent runs can otherwise be reported as successful completions, including after partial streamed output.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-state author association is MEMBER, so the external-contributor proof gate does not apply; the PR body nevertheless supplies a detailed compiled Gateway and official-SDK after-fix run for the changed HTTP terminal behavior.

Label justifications:

  • P1: Expired agent runs can otherwise be reported as successful completions, including after partial streamed output.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-state author association is MEMBER, so the external-contributor proof gate does not apply; the PR body nevertheless supplies a detailed compiled Gateway and official-SDK after-fix run for the changed HTTP terminal behavior.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit a8c8c82 into main Aug 30, 2026
334 checks passed
@steipete
steipete deleted the codex/qa-20260830-http-terminal-outcome branch August 30, 2026 12:00
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenAI-compatible HTTP reports success when the agent run budget expires

1 participant