Skip to content

fix(agents): run embedded gateway fallback on a fresh session after abnormal close - #110226

Merged
steipete merged 1 commit into
mainfrom
claude/fix-embedded-fallback-abnormal-close
Jul 17, 2026
Merged

steipete merged 1 commit into
mainfrom
claude/fix-embedded-fallback-abnormal-close

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

When the gateway is hard-killed (e.g. SIGKILL, WebSocket 1006 abnormal closure) while an openclaw agent turn is in flight, the CLI's embedded fallback re-ran the agent locally reusing the same explicit session key. Meanwhile the relaunched gateway's main-session-restart-recovery also resumes that same session — so two processes can drive one session concurrently across process boundaries (duplicate/conflicting transcript writes). The existing timeout fallback already used a distinct gateway-fallback-* session; the abnormal-close path did not.

Why This Change Was Made

Found during the R4 whole-system QA campaign (restart/recovery stress, live keys, isolated gateways). Repro: start a long agent turn, SIGKILL the gateway mid-turn → CLI logs EMBEDDED FALLBACK and enqueues lane=session:agent:main:<same-key> while the relaunched gateway logs resumed interrupted main session for the same key.

User Impact

After a gateway crash mid-turn, embedded fallback now always runs on a fresh gateway-fallback-* session (for both timeout and closed transport failures, with a fallbackReason recorded in result metadata), so it can never collide with gateway-side session recovery. Gateway recovery of the original session is unaffected.

Evidence

  • resolveGatewayAgentEmbeddedFallbackReason unifies both fallback triggers; GatewayTransportErrorKind is exactly "closed" | "timeout" (src/gateway/call.ts:120, constructed only at call.ts:846/:859), so the pair is exhaustive — no transport failure loses fallback.
  • Regression test: accepted turn followed by WebSocket 1006 proves fallback does not reuse the original explicit session key (src/commands/agent-via-gateway.test.ts). Focused suite: 74/74 pass.
  • Autoreview (codex gpt-5.6-sol, xhigh): clean — "patch is correct (0.91), no actionable findings". Net prod LOC −8.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Jul 17, 2026
@steipete steipete self-assigned this Jul 17, 2026
@steipete
steipete force-pushed the claude/fix-embedded-fallback-abnormal-close branch from 8d766f0 to e77967b Compare July 17, 2026 23:10
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 17, 2026, 7:14 PM ET / 23:14 UTC.

Summary
The branch makes embedded gateway fallback use a fresh gateway-fallback-* session after a closed or timed-out gateway transport error, records the reason in result metadata, and updates regression coverage.

PR surface: Source -6, Tests +24. Total +18 across 3 files.

Reproducibility: no. high-confidence live reproduction was inspectable in this review. The submitted test and description make the gateway-accepted-then-1006-close path source-reproducible, but no current-main runtime trace was available.

Review metrics: none identified.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Add redacted live gateway crash/restart output proving distinct fallback and recovered session keys.
  • Have an area maintainer confirm the intended session-continuity contract after an accepted turn loses transport.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Focused tests are reported, but no inspectable after-fix gateway crash/restart transcript, recording, live output, or redacted logs demonstrate the changed cross-process recovery behavior; add redacted runtime evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P2] The change deliberately separates fallback execution from the accepted session after a transport close; maintainers should confirm that result reporting and user expectations do not require the fallback turn to remain attached to the original explicit session.
  • [P1] The provided context lacks inspectable after-fix runtime evidence for the SIGKILL/WebSocket-1006 path, so test-only evidence does not yet demonstrate the cross-process recovery invariant in a real gateway setup.

Maintainer options:

  1. Prove the isolated-recovery contract (recommended)
    Capture a redacted SIGKILL or abnormal-close run proving the fallback session key differs from the gateway-recovered original session before merge.
  2. Accept the semantic change deliberately
    Merge only after a maintainer confirms that an abnormal close should abandon continuation of the explicit session in favor of isolated fallback execution.

Next step before merge

  • [P1] A protected maintainer-labeled PR with a session-ownership decision and missing real behavior proof should remain in human review rather than enter an automated repair lane.

Maintainer decision needed

  • Question: Should the maintainer accept the new closed-transport fallback contract that intentionally runs the CLI retry outside the accepted explicit session?
  • Rationale: The protected label and session-state behavior require confirmation that preserving the original session exclusively for gateway recovery is the intended user-facing recovery model.
  • Likely owner: steipete — The PR author and assignee is the only concrete routing signal supplied for this recovery behavior.
  • Options:
    • Accept isolated fallback (recommended): Confirm that abnormal-close fallback must always use a new session, then request real crash/restart proof before merge.
    • Preserve original-session fallback: If a fallback must continue the accepted session, define a single-owner recovery protocol instead of allowing concurrent gateway and embedded execution.

Security
Cleared: The supplied diff is limited to fallback-session selection, metadata typing, and tests; it adds no dependency, permission, secret, workflow, or code-execution surface.

Review details

Best possible solution:

Retain the fresh-session fallback boundary, then add redacted real gateway crash/restart evidence showing the original session is recovered only by the gateway while the CLI fallback runs under a distinct session key.

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

No high-confidence live reproduction was inspectable in this review. The submitted test and description make the gateway-accepted-then-1006-close path source-reproducible, but no current-main runtime trace was available.

Is this the best way to solve the issue?

Unclear. Using a fresh fallback session matches the stated goal of preventing concurrent writers, but a maintainer must confirm the resulting recovery/session-continuity contract and see real crash-path evidence.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P2: This addresses a real but crash-dependent session-concurrency failure with bounded impact rather than an always-on core outage.
  • add merge-risk: 🚨 session-state: The patch changes which persisted session owns fallback work after an accepted gateway turn closes abnormally.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Focused tests are reported, but no inspectable after-fix gateway crash/restart transcript, recording, live output, or redacted logs demonstrate the changed cross-process recovery behavior; add redacted runtime evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: This addresses a real but crash-dependent session-concurrency failure with bounded impact rather than an always-on core outage.
  • merge-risk: 🚨 session-state: The patch changes which persisted session owns fallback work after an accepted gateway turn closes abnormally.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Focused tests are reported, but no inspectable after-fix gateway crash/restart transcript, recording, live output, or redacted logs demonstrate the changed cross-process recovery behavior; add redacted runtime evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source -6, Tests +24. Total +18 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 32 38 -6
Tests 1 38 14 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 70 52 +18

What I checked:

  • Submitted fallback change: The submitted diff replaces the timeout-only fallback helpers with shared fallback-session helpers and maps closed transports to gateway_closed, so both specified transport failures receive fresh fallback sessions. (src/commands/agent-via-gateway.ts:308, e77967baf76d)
  • Regression coverage: The PR test changes model an accepted gateway turn followed by a WebSocket 1006 close and assert that the embedded fallback uses a distinct session and reports gateway_closed. (src/commands/agent-via-gateway.test.ts:1659, e77967baf76d)
  • Protected maintainer routing: The supplied GitHub timeline shows the maintainer label and assignment, so conservative cleanup policy requires explicit human handling rather than automated closure or repair dispatch.
  • Proof gap: The PR body reports focused test results and an autoreview, but the supplied discussion contains no inspectable redacted runtime transcript, logs, recording, or artifact showing the abnormal-close recovery path after this change. (e77967baf76d)

Likely related people:

  • steipete: The supplied PR metadata identifies this person as the author of the focused gateway-fallback change and as the assignee; checkout history could not be inspected in this read-only environment to establish broader ownership. (role: recent area contributor; confidence: low; commits: e77967baf76d; files: src/commands/agent-via-gateway.ts, src/commands/agent-via-gateway.test.ts, src/agents/command/types.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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 a428765 into main Jul 17, 2026
144 of 150 checks passed
@steipete
steipete deleted the claude/fix-embedded-fallback-abnormal-close branch July 17, 2026 23:18
@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

agents Agent runtime and tooling commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant