Skip to content

fix(agents): resume Code Mode through gateway restarts - #116605

Merged
vincentkoc merged 2 commits into
mainfrom
fix-code-mode-restart-surface
Jul 31, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix-code-mode-restart-surface

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where an in-flight replay-safe Code Mode run could fail after a Gateway restart when reloaded configuration disabled Code Mode for new turns. Recovery either rejected the current Code Mode abort record or resumed the existing provider turn with the ordinary shell exec schema.

Why This Change Was Made

Restart recovery now recognizes the current exact Code Mode abort contract and carries a trusted internal fact that preserves the original exec/wait control surface for that one checkpoint-proven provider turn. The override is rejected unless it arrives from authenticated backend main-session restart recovery.

User Impact

Replay-safe Code Mode work can survive a Gateway restart without silently failing or receiving the wrong tool schema, while newly started turns still honor the reloaded Code Mode setting.

Evidence

  • Exact QA scenario gateway-restart-inflight-run: passed against the patched Gateway with mock OpenAI provider, real Gateway restart, config reload disabling Code Mode, and terminal RESTART-CODE-MODE-WAIT-OK reply.
  • node scripts/run-vitest.mjs src/agents/main-session-restart-recovery.test.ts: 148 passed.
  • node scripts/run-vitest.mjs src/agents/tool-surface-plan.test.ts: 13 passed.
  • node scripts/run-vitest.mjs src/gateway/server-methods/agent-request-preflight.test.ts: 17 passed.
  • Remote pnpm check:changed -- <18 changed files>: passed core/coreTests formatting, API/boundary guards, dead-code scan, core and core-test typechecks, lint, and architecture guards.
  • Autoreview: clean, no accepted/actionable findings; overall correctness 0.88.

@vincentkoc vincentkoc self-assigned this Jul 31, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review July 31, 2026 00:57
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Jul 31, 2026
@vincentkoc
vincentkoc force-pushed the fix-code-mode-restart-surface branch from 13a5059 to b1e5e86 Compare July 31, 2026 00:58
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 31, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Jul 31, 2026
@clawsweeper

clawsweeper Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 30, 2026, 9:07 PM ET / July 31, 2026, 01:07 UTC.

ClawSweeper review

What this changes

The PR adds a recovery-only Gateway flag that preserves Code Mode exec and wait controls while resuming a replay-safe in-flight run after a Gateway restart, without re-enabling Code Mode for new turns after configuration reload.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open for explicit maintainer review. The patch appears to narrowly preserve a checkpoint-proven Code Mode tool surface only for authenticated main-session restart recovery, and the provided QA evidence exercises a real Gateway restart; however, it changes a recovery-time Gateway protocol contract and session continuation behavior. Likely related people: vincentkoc is the current restart-recovery contributor (medium confidence).

Priority: P1
Reviewed head: e22401f53eeecf8893e2fc5b70ebef37f9123541

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a narrowly scoped authorization boundary, focused regression coverage, and a reported real restart scenario; maintainer confirmation remains appropriate for the recovery compatibility contract.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body reports an after-fix QA scenario using a real Gateway restart and an observed successful terminal reply after Code Mode was disabled by configuration reload.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body reports an after-fix QA scenario using a real Gateway restart and an observed successful terminal reply after Code Mode was disabled by configuration reload.
Evidence reviewed 5 items Recovery-only propagation: The PR carries forceCodeModeTools from main-session restart recovery through agent execution into the tool-surface planner, where it preserves Code Mode controls only for the reconstructed run.
Authenticated request boundary: The Gateway preflight rejects forceCodeModeTools unless the request comes from authenticated backend main-session restart recovery, preventing ordinary callers from selecting this internal tool surface.
Current abort contract coverage: The recovery policy recognizes the explicit Code Mode aborted wait result and marks the resumed turn to retain Code Mode controls; focused recovery tests cover that persisted transcript shape.
Findings None None.
Security None None.

How this fits together

Main-session restart recovery reads an interrupted run’s persisted transcript and checkpoint, then asks the Gateway to resume that provider turn. This change conveys a trusted recovery fact into the agent tool-surface planner so the resumed turn retains its original Code Mode controls while subsequent turns still use the reloaded configuration.

flowchart LR
  A[Interrupted Code Mode run] --> B[Persisted replay-safe checkpoint]
  B --> C[Gateway restart recovery]
  C --> D[Authenticated recovery request]
  D --> E[Tool-surface planner]
  E --> F[Code Mode exec and wait controls]
  F --> G[Resumed provider turn]
Loading

Before merge

  • Resolve merge risk (P1) - Merging changes the recovery-time Gateway request contract and the tool schema presented to a persisted session; maintainers should confirm that retaining Code Mode for the one checkpoint-proven turn is the intended upgrade behavior.
  • Resolve merge risk (P1) - The PR is member-authored and carries the protected maintainer label, so this workflow should not auto-close or autonomously land it despite the favorable patch and proof signals.
  • Complete next step (P2) - The protected maintainer label and member authorship require an explicit maintainer merge decision; there is no discrete mechanical repair finding for an automated worker.
Agent review details

Security

None.

PR surface

Source +54, Tests +148, Other +4. Total +206 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 15 71 17 +54
Tests 3 151 3 +148
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 4 0 +4
Total 19 226 20 +206

Review metrics

Metric Value Why it matters
Recovery protocol surface 1 optional Gateway parameter added The new parameter crosses persisted recovery, Gateway preflight, TypeScript runtime, and generated Swift protocol surfaces, so its scope and authorization boundary matter before merge.

Stored data model

Persistent data-model change detected: serialized state: src/agents/main-session-restart-recovery.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Confirm and merge the narrow recovery contract (recommended)
    Confirm that a checkpoint-proven resumed provider turn may retain its original Code Mode controls after configuration reload while every newly started turn continues to honor current configuration.
  2. Pause for a broader recovery-contract review
    Pause the PR if maintainers want restart recovery flags to remain entirely internal to a different Gateway contract rather than adding this optional protocol field.

Technical review

Best possible solution:

Retain the recovery-only override, with the authenticated preflight boundary and focused restart tests, then have a maintainer confirm the intended compatibility contract before merge.

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

Yes, source-reproducible: the submitted recovery policy and focused tests define the persisted aborted wait transcript that triggers the wrong resumed tool surface, and the PR reports a real Gateway-restart QA run for it.

Is this the best way to solve the issue?

Yes: preserving the original Code Mode surface only for an authenticated, checkpoint-proven recovery turn is narrower than changing the reloaded Code Mode default or adding a user-facing configuration exception.

AGENTS.md: unclear because the file could not be read completely.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports an after-fix QA scenario using a real Gateway restart and an observed successful terminal reply after Code Mode was disabled by configuration reload.

Label justifications:

  • P1: An interrupted replay-safe Code Mode run can otherwise fail or resume with an incompatible tool surface after Gateway restart.
  • merge-risk: 🚨 compatibility: The PR adds an optional Gateway protocol field and intentionally distinguishes resumed persisted turns from newly started turns after configuration reload.
  • merge-risk: 🚨 session-state: The field is derived from restart checkpoint state and controls the tool surface used to continue that persisted session.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body reports an after-fix QA scenario using a real Gateway restart and an observed successful terminal reply after Code Mode was disabled by configuration reload.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports an after-fix QA scenario using a real Gateway restart and an observed successful terminal reply after Code Mode was disabled by configuration reload.

Evidence

What I checked:

  • Recovery-only propagation: The PR carries forceCodeModeTools from main-session restart recovery through agent execution into the tool-surface planner, where it preserves Code Mode controls only for the reconstructed run. (src/agents/main-session-restart-recovery-store.ts:558, e22401f53eee)
  • Authenticated request boundary: The Gateway preflight rejects forceCodeModeTools unless the request comes from authenticated backend main-session restart recovery, preventing ordinary callers from selecting this internal tool surface. (src/gateway/server-methods/agent-request-preflight.ts:235, e22401f53eee)
  • Current abort contract coverage: The recovery policy recognizes the explicit Code Mode aborted wait result and marks the resumed turn to retain Code Mode controls; focused recovery tests cover that persisted transcript shape. (src/agents/main-session-restart-recovery-resume-policy.ts:315, e22401f53eee)
  • Real restart proof: The PR body reports the gateway-restart-inflight-run QA scenario with a real Gateway restart, configuration reload disabling Code Mode, and an observed terminal RESTART-CODE-MODE-WAIT-OK reply; the supplied check state also marks Real behavior proof successful. (e22401f53eee)
  • Protocol client alignment: The Gateway protocol schema and generated Swift AgentParams model both include the new optional recovery field, avoiding a visible schema/client mismatch in the submitted diff. (packages/gateway-protocol/src/schema/agent.ts:335, e22401f53eee)

Likely related people:

  • vincentkoc: Authored the main restart-recovery implementation commit and the follow-up generated protocol update in this PR. (role: current restart-recovery contributor; confidence: medium; commits: b1e5e8624f93, e22401f53eee; files: src/agents/main-session-restart-recovery-resume-policy.ts, src/gateway/server-methods/agent-request-preflight.ts, packages/gateway-protocol/src/schema/agent.ts)

Rank-up moves

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

  • Confirm the intended persisted-session versus newly started-turn behavior before merge.

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.

@vincentkoc
vincentkoc merged commit 32036c4 into main Jul 31, 2026
123 checks passed
@vincentkoc
vincentkoc deleted the fix-code-mode-restart-surface branch July 31, 2026 01:22
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 31, 2026
…e2e-integration-20260730

* origin/main:
  fix(agents): resume Code Mode through gateway restarts (#116605)
  fix(ci): restore beta release harnesses (#116596)
vincentkoc added a commit that referenced this pull request Jul 31, 2026
* origin/main:
  fix(ai): prevent websocket cache clobber on concurrent acquire (#116216)
  test(ui): settle custodian mobile layout assertions (#116613)
  fix(agents): resume Code Mode through gateway restarts (#116605)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 31, 2026
* fix(agents): preserve Code Mode restart recovery

* chore(protocol): regenerate Swift agent params
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 31, 2026
* origin/main:
  fix(ai): prevent websocket cache clobber on concurrent acquire (openclaw#116216)
  test(ui): settle custodian mobile layout assertions (openclaw#116613)
  fix(agents): resume Code Mode through gateway restarts (openclaw#116605)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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