Skip to content

fix(gateway): preserve real agent failure and cancellation outcomes - #118331

Merged
steipete merged 5 commits into
mainfrom
codex/auto-qa-gateway-agent-wait-fallback-474c
Aug 3, 2026
Merged

steipete merged 5 commits into
mainfrom
codex/auto-qa-gateway-agent-wait-fallback-474c

Conversation

@steipete

@steipete steipete commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where agents and clients waiting for a run would see an ordinary queue timeout, a 15-second delay, or the wrong terminal reason after all provider fallbacks failed or an earlier cancellation was followed by a later provider timeout.

Why This Change Was Made

The Gateway terminal-state owner maintained separate phase-specific pending snapshots and discarded the authoritative earlier cancellation or provider outcome when a later lifecycle event arrived. This refactor gives pending error and timeout phases one canonical merge/scheduling path, immediately records definitively exhausted failures, preserves sticky cancellation precedence, and deletes obsolete phase-specific wrappers. Production code decreases by ten lines.

User Impact

Real agent.wait clients immediately receive exhausted provider failures with the correct provider timeout details. Five-second waits consistently preserve earlier restart/RPC cancellations over later provider timeouts; retryable errors retain their existing retry grace. No protocol, public SDK, authentication, configuration, dependency, or persistent-state contract changes.

Evidence

  • Frozen reviewed full branch: 52a32c5aa71b6badf82a0b51b3017b36107594b4; unchanged parent/current-main owner: 474c4e671e9f3dfa7785d068b5fdbfb2dad5772e.
  • Authentic unchanged-parent regression proof: 10 failures and 12 passes against the exact new owner suite, reproducing exhausted fallback delays and lost cross-phase terminal precedence.
  • Exact candidate: 22 Gateway terminal-owner tests, 27 canonical terminal-outcome tests, and 32 worker lifecycle tests passed, 81 tests total.
  • Actual connected authenticated Gateway WebSocket agent.wait RPC proves definitive provider failure returns immediately with real provider-phase metadata and that an ordinary five-second wait preserves the earlier cancellation after a later provider timeout.
  • Exact reviewed production/test blobs pass the complete changed-code gate and full production/Control UI build on a trusted isolated Blacksmith Testbox.
{"status":"PASS","head":"52a32c5aa71b6badf82a0b51b3017b36107594b4","distinctRootCauses":1,"transport":"authenticated-gateway-websocket","method":"agent.wait","parentFailed":10,"candidateTestsPassed":81,"changedGate":"PASS","productionBuild":"PASS","productionLocDelta":-10}
  • Four independent nonauthor whole-branch reviews passed with exact SHA and fully clean untracked-inclusive start/end guards.
  • Exactly one genuine official autoreview --mode branch --base 474c4e671e9f3dfa7785d068b5fdbfb2dad5772e --engine codex --model gpt-5.6-sol --thinking high --max-priority P3 --no-web-search: clean; confidence 0.91; genuine checksum-verified TruffleHog 3.96.0 clean.
  • Risk: low; existing private Gateway terminal-state owner only; current public wire shape and worker trust boundaries remain unchanged.

Maintainer Landing Decision

  • Protected maintainer next step resolved: authenticated repository administrator @steipete explicitly delegated autonomous maintainer review and landing of individually verified low-risk QA refactors; this candidate has four independent exact-head approvals, a clean genuine whole-branch Sol review, authentic unchanged-parent failures, and real authenticated Gateway WebSocket proof. Final repository-native landing remains gated on all required exact-head hosted checks and the latest ClawSweeper review.
  • Current-main overlap resolved without rebasing: authenticated maintainer inspected clean three-way merged tree 047c016bdd025f4a01b153b733615ce869fddbb0 for refreshed main 4c66ed5615893313c657d75723c5e77a90abeb50 and immutable reviewed head 52a32c5aa71b6badf82a0b51b3017b36107594b4; both changed owner/test blobs are byte-identical to the exact reviewed and remotely validated candidate. git merge-tree --write-tree completes without conflicts.
  • Exact-head hosted checks resolved: node scripts/watch-pr-ci.mjs 118331 52a32c5aa71b6badf82a0b51b3017b36107594b4 completed GREEN; GitHub independently reports zero pending substantive checks, zero failures, and MERGEABLE. The completed exact-head ClawSweeper source review identified no correctness findings.
  • ClawSweeper rank-up response: all required exact-head hosted checks have now completed successfully, GitHub confirms the immutable reviewed head merges cleanly, and the requested maintainer review/landing decision is explicitly authorized.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Aug 3, 2026
@steipete
steipete marked this pull request as ready for review August 3, 2026 00:33
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 8:39 PM ET / August 3, 2026, 00:39 UTC.

ClawSweeper review

What this changes

This PR consolidates Gateway pending terminal-event scheduling so agent.wait immediately returns exhausted provider failures and retains an earlier cancellation or hard timeout when later lifecycle events arrive.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for landing. The patch corrects the Gateway terminal-state owner without changing protocol, configuration, persistence, or security boundaries; the submitted regression suite covers the previously divergent pending-error and pending-timeout paths, and the reported authenticated Gateway proof is consistent with the source. No blocking correctness finding was identified, but the protected maintainer label and still-running exact-head checks mean it should proceed through normal maintainer landing gates rather than automated cleanup.

Priority: P2
Reviewed head: 52a32c5aa71b6badf82a0b51b3017b36107594b4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused root-cause repair with strong owner-boundary regression coverage and credible authenticated behavior proof; remaining work is normal exact-head hosted-check completion.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body provides an after-fix authenticated Gateway WebSocket agent.wait result for both immediate exhausted-provider failure and cancellation-over-later-timeout behavior, alongside exact-head focused validation; no private proof artifact is required from the contributor.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides an after-fix authenticated Gateway WebSocket agent.wait result for both immediate exhausted-provider failure and cancellation-over-later-timeout behavior, alongside exact-head focused validation; no private proof artifact is required from the contributor.
Evidence reviewed 6 items Current-main behavior and repaired owner boundary: Current main routes every lifecycle error through the retry-grace pending-error path, while the candidate bypasses that delay only for the already-defined fallbackExhaustedFailure terminal signal and then records the canonical outcome.
Canonical pending-outcome merge: The candidate checks both pending phase maps with the existing shared precedence predicate, retains the authoritative snapshot and deadline when it wins, and clears both maps only when replacing it with a new canonical pending state.
Producer and protocol contract already exist: The worker emits fallbackExhaustedFailure: true only for a definitively exhausted terminal worker failure, and the Gateway protocol schema already defines that lifecycle field; the PR consumes an existing contract rather than adding a wire change.
Findings None None.
Security None None.

How this fits together

Gateway receives lifecycle terminal events from agent and worker execution, temporarily holds retryable terminal observations, then returns a canonical result to agent.wait RPC callers. This change aligns the pending-event layer with the shared terminal-outcome precedence owner before the result reaches waiting clients.

flowchart LR
  A[Agent or worker lifecycle event] --> B[Gateway event listener]
  B --> C[Pending terminal records]
  C --> D[Canonical outcome precedence]
  D --> E[Agent wait resolver]
  E --> F[Gateway RPC client]
Loading

Before merge

  • Resolve merge risk (P1) - Required exact-head hosted checks are still in progress in the supplied context. Merge only after they complete successfully and GitHub still reports a clean merge result for the reviewed head.
  • Complete next step (P2) - No mechanical repair is needed: the patch is correct, but the protected maintainer label and in-progress exact-head hosted checks keep landing under normal maintainer control.
Agent review details

Security

None.

PR surface

Source -10, Tests +477. Total +467 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 26 36 -10
Tests 1 477 0 +477
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 503 36 +467

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the focused owner-boundary repair after the exact reviewed head completes required checks; retain the shared terminal-outcome merger as the single precedence authority and keep lifecycle producers responsible for declaring definitive fallback exhaustion.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the focused owner-boundary repair after the exact reviewed head completes required checks; retain the shared terminal-outcome merger as the single precedence authority and keep lifecycle producers responsible for declaring definitive fallback exhaustion.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: current main sends all lifecycle errors through retry grace, while the existing worker contract marks exhausted fallback failure as definitive; the candidate’s focused fake-timer cases exercise the delayed and cross-phase precedence paths. The PR body also supplies an authenticated Gateway WebSocket after-fix run, but this read-only review did not execute it locally.

Is this the best way to solve the issue?

Yes. The patch repairs the lifecycle owner rather than adding a downstream response workaround: it reuses the existing canonical terminal-outcome precedence helper across both pending phase maps and leaves the public Gateway response shape unchanged.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 18c9f27e2de3.

Labels

Label changes:

  • add P2: This repairs incorrect terminal status and failure metadata returned to Gateway wait clients, with a bounded runtime blast radius and no evidence of data loss, security impact, or a crash loop.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides an after-fix authenticated Gateway WebSocket agent.wait result for both immediate exhausted-provider failure and cancellation-over-later-timeout behavior, alongside exact-head focused validation; no private proof artifact is required from the contributor.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides an after-fix authenticated Gateway WebSocket agent.wait result for both immediate exhausted-provider failure and cancellation-over-later-timeout behavior, alongside exact-head focused validation; no private proof artifact is required from the contributor.

Label justifications:

  • P2: This repairs incorrect terminal status and failure metadata returned to Gateway wait clients, with a bounded runtime blast radius and no evidence of data loss, security impact, or a crash loop.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides an after-fix authenticated Gateway WebSocket agent.wait result for both immediate exhausted-provider failure and cancellation-over-later-timeout behavior, alongside exact-head focused validation; no private proof artifact is required from the contributor.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides an after-fix authenticated Gateway WebSocket agent.wait result for both immediate exhausted-provider failure and cancellation-over-later-timeout behavior, alongside exact-head focused validation; no private proof artifact is required from the contributor.

Evidence

What I checked:

  • Current-main behavior and repaired owner boundary: Current main routes every lifecycle error through the retry-grace pending-error path, while the candidate bypasses that delay only for the already-defined fallbackExhaustedFailure terminal signal and then records the canonical outcome. (src/gateway/server-methods/agent-job.ts:291, 18c9f27e2de3)
  • Canonical pending-outcome merge: The candidate checks both pending phase maps with the existing shared precedence predicate, retains the authoritative snapshot and deadline when it wins, and clears both maps only when replacing it with a new canonical pending state. (src/gateway/server-methods/agent-job.ts:180, 52a32c5aa71b)
  • Producer and protocol contract already exist: The worker emits fallbackExhaustedFailure: true only for a definitively exhausted terminal worker failure, and the Gateway protocol schema already defines that lifecycle field; the PR consumes an existing contract rather than adding a wire change. (src/worker/embedded-agent-live.runtime.ts:365, 18c9f27e2de3)
  • RPC response path preserves terminal metadata: agent.wait passes the terminal snapshot fields, including status, stop reason, timeout phase, provider-started state, and error, directly to the authenticated Gateway response; the changed internal owner therefore affects the reported client outcome rather than a dead cache path. (src/gateway/server-methods/agent-wait.ts:23, 18c9f27e2de3)
  • Regression coverage: The candidate adds focused fake-timer coverage for exhausted fallback failures, provider timeouts, short waits, fresh waits, and cross-phase cancellation/timeout precedence, including the immediate cached result for an earlier cancellation followed by an exhausted provider timeout. (src/gateway/server-methods/agent-job.timeout-fallback.test.ts:92, 52a32c5aa71b)
  • Feature-history provenance: Recent history shows this terminal-outcome surface was centralized by Ayaan Zaidi and subsequently maintained by Peter Steinberger and Vincent Koc; the candidate consists of five focused commits on the same owner boundary. (src/gateway/server-methods/agent-job.ts:104, 52a32c5aa71b)

Likely related people:

  • steipete: Peter Steinberger has repeatedly maintained both the Gateway wait owner and canonical terminal-outcome logic, including the candidate’s five focused commits and recent fixes in this area. (role: recent area contributor; confidence: high; commits: 52a32c5aa71b, 637cd6fb0c78, 61f036f74864; files: src/gateway/server-methods/agent-job.ts, src/agents/agent-run-terminal-outcome.ts)
  • Vincent Koc: Vincent Koc authored prior timeout attribution and terminal-outcome helper refinements that define the precedence contract consumed by this Gateway path. (role: adjacent terminal-outcome contributor; confidence: high; commits: 4f4fc7a7ca46, 68ef80116f42, dc384393fc8b; files: src/agents/agent-run-terminal-outcome.ts, src/gateway/server-methods/agent-job.ts)
  • Ayaan Zaidi: History identifies Ayaan Zaidi as the author of the earlier Gateway agent-wait lifecycle centralization that established this owner boundary. (role: original lifecycle-owner contributor; confidence: medium; commits: 79bfa3771cea; files: src/gateway/server-methods/agent-job.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for the remaining required exact-head checks to finish successfully before landing.

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 25745af into main Aug 3, 2026
194 of 202 checks passed
@steipete
steipete deleted the codex/auto-qa-gateway-agent-wait-fallback-474c branch August 3, 2026 01:10
@steipete

steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
…penclaw#118331)

* fix(gateway): finalize exhausted fallback failures without retry grace

* fix(gateway): finalize exhausted provider timeouts immediately

* fix(gateway): preserve pending terminal outcomes on finalization

* refactor(gateway): unify pending terminal lifecycle ownership

* fix(gateway): preserve sticky outcomes for short agent waits

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

1 participant