Skip to content

fix(gateway): let a supervisor keep stopped work from resuming at the next start - #201060

Merged
freeqaz merged 13 commits into
mainfrom
fix/gateway-restart-resume-scope
Nov 18, 2026
Merged

freeqaz merged 13 commits into
mainfrom
fix/gateway-restart-resume-scope

Conversation

@freeqaz

@freeqaz freeqaz commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A graceful Gateway shutdown marks the sessions that were working, and the next start resumes them with the hidden "The Gateway restarted while you were working" input. That is right for a restart, but a supervisor that stops a Gateway on purpose and later starts a new one has no way to say the interrupted work was stopped, not restarted. The stopped turn then runs again with no user message. In one managed deployment, an operator stopped an agent part-way through a long shell command; the next start resumed the turn and the agent ran the command again to completion.

User Impact

A supervisor can set OPENCLAW_GATEWAY_RESTART_RESUME_SCOPE to an opaque token of its choice. Work interrupted under one token resumes only when the next Gateway starts with the same token. When the supervisor starts the next Gateway with a different token, the interrupted turn does not run again, and a message that was queued behind it ends with the existing "The Gateway restarted before this message ran. Send it again." notice instead of running. Without the variable nothing changes.

Not covered: the scope applies to graceful-shutdown markers only. Crash recovery (a run left open by a crash or SIGKILL, and queued input replayed after a crash) does not consult it; that path has no marker to carry a scope, and recording one would mean a schema change. The docs say so.

The env-var budget goes from 461 to 462 for the new name (config/env-var-count-budget.txt).

Why This Change Was Made

  • Graceful shutdown stamps each restart marker with the current scope (resumeAfterRestart.scope), including the fallback marker written when shutdown cancels a run.
  • Startup resumes only markers stamped with the same scope. A marker from another scope, or an unscoped marker when a scope is set, is cleared without resuming, and the startup summary counts the session as scope-changed.
  • Queued input of that session then ends with restart-unrecoverable through the existing startup replay owner (continueSessionQueuedInputs) instead of being replayed, so it is visible to its sender and never runs after the work it was queued behind was ended.
  • The marker selection at startup (shutdown marker, parked yield, run orphaned in a crash window, legacy cycle) moves unchanged into resolveStartupRestartMarker next to restart store discovery, together with the scope check, so session-restart-resume.ts stays under the 700-line cap after this change. The run comparison with the startup snapshot stays in session-restart-resume.ts and is passed in, so the session-identity allowlist is unchanged.
  • The value is opaque: OpenClaw only compares it for equality. A supervisor picks when it changes, for example once per deployment, so a restart of the same deployment (rollout, node drain, self-restart) still resumes.

Evidence

Behavior checked: a graceful shutdown followed by a start under the same token resumes the interrupted run or turn; a start under a different token, or a token added or removed between the two, does not resume, clears the marker, and ends the queued message as restart-unrecoverable without a replay attempt; with no token on either side, behavior is unchanged.

  • src/gateway/session-restart-resume.test.ts: 29/29 pass, including 8 new scope cases (a live agent run and a live session turn, each with a queued message, through the real shutdown marker write and startup recovery).
  • Red on the base: with main's production code and the new test, the 6 scoped cases fail and the 2 unscoped cases pass.
  • Red without the queued-input ending: with only the endCause pass-through removed, the 4 out-of-scope cases fail because startup replays the queued message.
  • Sibling and consumer tests pass: session-restart-resume.{admission,upgrade,workspace,yield}.test.ts, session-restart-resume-custody.test.ts, queued-chat-inputs.metadata.test.ts, server-close.queued-inputs.test.ts (44/44).
  • Stored data: scope is an optional field on the existing marker, with no migration. Markers written before this change carry no scope and resume as before when no token is set (the unscoped cases above); session-restart-resume.upgrade.test.ts (prior-release serialized records) passes unchanged. A marker written without a token is not resumed by a Gateway that starts with one, as documented.
  • test/scripts/eager-import-closure.test.ts (PR wrapper inventory) and pnpm check:session-identity-ratchet pass.
  • pnpm tsgo:core and the core test typecheck shards, oxlint and oxfmt on the touched files, format:docs:check, docs:check-links, docs:check-mdx, and the test-lines ratchet (+120 of 400) pass.
  • pnpm check:env-var-count: 462 names, equal to the new budget; the 461 to 462 growth is reported as a warning in Actions and needs maintainer approval.

Real-behaviour proof: isolated Gateway, real model, real stop and start

These runs used a Gateway built from this head (3cf718806fb, pnpm build, openclaw --version prints OpenClaw 2026.11.5 (3cf7188)) and the released [email protected] from npm, on a Linux x86-64 test machine. Each scenario had its own state directory. The Gateway listened on loopback with token auth and no channels. The agent's model was a real model served from a self-hosted model endpoint. Every turn below is a real model turn, and the exec calls are real tool calls that ran sleep. Nothing was scripted or mocked. The Gateway ran under systemd, and "graceful stop" means systemctl stop, which sends SIGTERM to the Gateway process. The driver was openclaw gateway call chat.send / chat.history from the same build, plus a read-only look at the agent database.

Each scenario followed the same steps:

  1. Send "Use the exec tool once, with awaitResults set to true, to run exactly this command: sleep 75; echo LONG-DONE-. After it finishes, reply with only the output line."
  2. While that exec call was running (about 20 s in), the same operator sent a second, plain message: "Reply with exactly QUEUED- and nothing else." chat.history lists it under pendingInputs with state queued.
  3. SIGTERM.
  4. Start again with the scenario's token, then read the startup log, chat.history and the database.
Marker written by Token at start Startup summary Interrupted turn Queued message
A this head, token a a resumed:1 continues: the agent sees the interrupted tool result, re-runs the command and answers replayed and answered (QUEUED-a3)
B this head, token a b resumed:0 skipped:1 scope-changed:1 does not run again; the transcript ends at the interrupted tool result not run: cancelled, endCause: restart-unrecoverable; a fresh message afterwards is answered
C this head, no token none resumed:1 continues replayed and answered
D1 v2026.11.5 (old marker format, no scope) none resumed:1 continues replayed and answered; settings and session intact
D2 v2026.11.5 (same state, copied) x resumed:0 skipped:1 scope-changed:1 does not run again not run: cancelled, restart-unrecoverable; settings and session intact, and the old session still chats

All of these match the description above and the docs. One thing worth knowing: a /followup <text> queued from the token-authenticated CLI is stored without a recovery source. It ends restart-unrecoverable even within the same scope ("Queued input has no original operator source; submit a new request."). That is existing behaviour for input without a recovery source, and this PR does not change it. The runs above use a plain message, which carries a recovery source (origin_source_json set).

A: same token (a then a)
# before stop (Gateway started with OPENCLAW_GATEWAY_RESTART_RESUME_SCOPE=a)
assistant (stop=toolUse): [toolCall exec {"command":"sleep 75; echo LONG-DONE-a3","awaitResults":true,"timeoutSeconds":180,...}]
pendingInputs: [{"state":"queued","message":{"role":"user","content":"Reply with exactly QUEUED-a3 and nothing else.",...}}]
db: pending state=queued end_cause=null origin_source=set

# SIGTERM
[restart-resume] shutdown restart resume: [{"agentId":"main","marked":1,"skipped":0,"reasons":{}}]
[gateway] chat pending input aborted: restart (cancelled)
[shutdown] completed cleanly in 2867ms
db: session status=killed resumeAfterRestart={"operatorSource":<gateway source of gateway-owner>,"scope":"a"}

# start with OPENCLAW_GATEWAY_RESTART_RESUME_SCOPE=a
[restart-resume] startup restart resume: [{"agentId":"main","resumed":1,"skipped":0,"reasons":{}}]

# chat.history after start
user: Use the exec tool once, with awaitResults set to true, to run exactly this command: sleep 75; echo LONG-DONE-a3. ...
assistant (stop=toolUse): [toolCall exec {"command":"sleep 75; echo LONG-DONE-a3",...}]
toolResult (exec): Tool call interrupted before a result was recorded; its outcome is unknown. ...
assistant (stop=toolUse): [toolCall exec {"command":"sleep 75; echo LONG-DONE-a3","title":"Repeat 75s sleep then echo",...}]
toolResult (exec): LONG-DONE-a3
assistant (stop=stop): LONG-DONE-a3
user: Reply with exactly QUEUED-a3 and nothing else.
assistant (stop=stop): QUEUED-a3
pendingInputs: {"items":[],"total":0,"queuedCount":0}
db: session status=done, no marker
B: changed token (a then b)
# before stop (token a): exec running, second message queued
pendingInputs: [{"state":"queued","message":{"content":"Reply with exactly QUEUED-b1 and nothing else.",...}}]

# SIGTERM
[restart-resume] shutdown restart resume: [{"agentId":"main","marked":1,"skipped":0,"reasons":{}}]
[shutdown] completed cleanly in 1157ms
db: session status=killed resumeAfterRestart={"operatorSource":<gateway source of gateway-owner>,"scope":"a"}
db: pending state=queued end_cause=null origin_source=set

# start with OPENCLAW_GATEWAY_RESTART_RESUME_SCOPE=b
[restart-resume] startup restart resume: [{"agentId":"main","resumed":0,"skipped":1,"reasons":{"scope-changed":1}}]

# chat.history after start (polled for about 8 minutes: no further model turn, the queued message never ran)
assistant (stop=toolUse): [toolCall exec {"command":"sleep 75; echo LONG-DONE-b1",...}]
toolResult (exec): Tool call interrupted before a result was recorded; its outcome is unknown. ...
pendingInputs: {"items":[{"state":"cancelled","endCause":"restart-unrecoverable",
  "message":{"role":"user","content":"Reply with exactly QUEUED-b1 and nothing else.",...},"runId":"b1-q"}],"total":1,"queuedCount":0}
db: session status=killed abortedLastRun=true, marker cleared
db: pending state=cancelled end_cause=restart-unrecoverable consumed=no origin_source=cleared

# endCause restart-unrecoverable is the existing chat notice "The Gateway restarted before this message ran. Send it again."
# (ui/src/i18n/locales/en-chat-system-notice.ts; the client here was the CLI, no browser was used)

# a fresh message afterwards
user: Reply with exactly FRESH-b1 and nothing else.
assistant (stop=stop): FRESH-b1
C: no token on either side (control)
# SIGTERM
[restart-resume] shutdown restart resume: [{"agentId":"main","marked":1,"skipped":0,"reasons":{}}]
db: session status=killed resumeAfterRestart={"operatorSource":<gateway source of gateway-owner>}   (no scope field)

# start without the variable
[restart-resume] startup restart resume: [{"agentId":"main","resumed":1,"skipped":0,"reasons":{}}]
toolResult (exec): Tool call interrupted before a result was recorded; its outcome is unknown. ...
assistant (stop=toolUse): [toolCall exec {"command":"sleep 75; echo LONG-DONE-c1",...}]
toolResult (exec): LONG-DONE-c1
assistant (stop=stop): LONG-DONE-c1
user: Reply with exactly QUEUED-c1 and nothing else.
assistant (stop=stop): QUEUED-c1
user: Reply with exactly FRESH-c1 and nothing else.
assistant (stop=stop): FRESH-c1
D: upgrade from v2026.11.5 (state and a mid-turn marker written by the release)
# released CLI and Gateway, no token
$ openclaw --version                                  -> OpenClaw 2026.11.5 (e13cf15)
$ openclaw config set agents.defaults.timeoutSeconds 1200
user: Remember the codeword ORCHID-7 for later in this conversation. Reply with exactly READY-D and nothing else.
assistant: READY-D
sessions.patch {"key":"agent:main:d","label":"upgrade-proof"}  -> ok
# long exec turn, second message queued, SIGTERM
[gateway] chat pending input aborted: restart (cancelled)
[shutdown] completed cleanly in 2468ms
db: marker written by the release = {"queuedInputIds":[...],"queuedInputSources":{...}}   (old format: no scope, no operatorSource)
db: pending state=queued (table without end_cause / origin_source_json columns)
# the state directory is copied for D2

# D1: this head on the same state, no token
OpenClaw 2026.11.5 (3cf7188)
[gateway] Agent main resume deferred: agent database unavailable (agent-database-inspection-pending)
[restart-resume] startup restart resume: [{"agentId":"main","resumed":1,"skipped":0,"reasons":{}}]
toolResult (exec): Tool call interrupted before a result was recorded; its outcome is unknown. ...
toolResult (exec): LONG-DONE-d
assistant: LONG-DONE-d
user: Reply with exactly QUEUED-d and nothing else.
assistant: QUEUED-d
$ openclaw config get agents.defaults.timeoutSeconds   -> 1200
db: label=upgrade-proof, same session id as before the upgrade
user: What codeword did I ask you to remember at the start of this conversation? Reply with only the codeword.
assistant: ORCHID-7

# D2: this head on the copied state, OPENCLAW_GATEWAY_RESTART_RESUME_SCOPE=x
[restart-resume] startup restart resume: [{"agentId":"main","resumed":0,"skipped":1,"reasons":{"scope-changed":1}}]
toolResult (exec): Tool call interrupted before a result was recorded; its outcome is unknown. ...   (no further turn)
pendingInputs: [{"state":"cancelled","endCause":"restart-unrecoverable","message":{"content":"Reply with exactly QUEUED-d and nothing else.",...}}]
db: marker cleared; pending state=cancelled end_cause=restart-unrecoverable
$ openclaw config get agents.defaults.timeoutSeconds   -> 1200
db: label=upgrade-proof, same session id
user: What codeword did I ask you to remember at the start of this conversation? Reply with only the codeword.
assistant: ORCHID-7

A marker written by v2026.11.5 has no scope. Without a token it resumes, and its queued input replays, as before. When the first start after the upgrade sets a token, the marker counts as another scope's: the turn does not continue and its queued input ends restart-unrecoverable. This matches the docs line "When a token is set, a marker without one counts as another scope's".

Output above is trimmed to the relevant lines. Session keys are shortened (the message tags a3, b1, c1 and d are the real ones), and host, path and model-endpoint details are removed.

…eration

A graceful shutdown marks running sessions and the next start resumes
them. A supervisor that stops a deployment on purpose (an operator stop)
and later starts a new one cannot tell the next Gateway that the
interrupted work was stopped, so the stopped turn runs again with a
synthetic resume message.

Add OPENCLAW_GATEWAY_RESTART_RESUME_SCOPE. Shutdown stamps restart
markers with the current scope; startup resumes only markers written
under the same scope. A marker from another scope, or an unscoped
marker when a scope is set, is cleared and its queued inputs are settled
like a crash's orphans. Without the variable nothing changes.
…after clearing it

The worker withdrawal keeps inputs listed in the session's current marker, so
the orphaned-input settlement that ran before the marker was cleared left them
queued. Settle them once the marker is gone, and drop the discovery filter that
could not reach them.
…pe helper

Keeps session-restart-resume.ts within the max-lines budget: the helper returns the
pending-input target of an out-of-scope marker, and the existing orphaned-input
settlement cancels its queued inputs after the marker is cleared.
…esume-scope

Main (#200533) moved accepted queued input out of the restart marker into
its own durable row and replays queued rows at startup after root resume,
removing the marker's queuedInputIds and the orphaned-input interrupt.

Conflict resolution:
- types.ts: keep main's marker shape (operatorSource only) plus `scope`.
- session-run-lifecycle-projection.ts, session-restart-resume.ts: stamp
  main's marker shape with createRestartResumeMarker.
- An out-of-scope marker is still cleared without resuming. Its session's
  queued rows now end with `restart-unrecoverable` through the same
  startup replay owner (new `endCause` option of
  continueSessionQueuedInputs) instead of being replayed, so the sender
  sees that the Gateway restarted before the message ran.
- The scope helper drops the pending-input target helper and exposes
  isRestartResumeMarkerOutOfScope.
- The scope table test now expects the slimmer marker and checks that
  in-scope startup replays the queued row while out-of-scope startup
  ends it without a replay attempt.
…sor token

The scope covers shutdown markers only; crash recovery of unmarked runs
and of queued input does not consult it. Queued input behind an
out-of-scope marker ends without running.
…store discovery

Merging main left session-restart-resume.ts at 720 counted lines, over the
700-line cap. The marker selection (shutdown marker, parked yield, run
orphaned in a crash window, legacy cycle) and its scope check move into
resolveStartupRestartMarker; behavior is unchanged.
…ope helpers module-private

The production unused-export scan flagged the env name and resolver, which
only the test imported.
@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

…nventory

session-run-lifecycle-projection.ts, which the trusted-anchor PR wrapper
extracts, now imports it (test/scripts/eager-import-closure.test.ts).
…listed module

The session-identity ratchet allows no identity comparisons in the restart discovery module.
Compare the selected run with the startup snapshot in session-restart-resume.ts, as on main,
and pass the result to resolveStartupRestartMarker.
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Adds an optional supervisor token that prevents graceful restart continuation and queued-message replay when the token changes.

Example: A Gateway stops during sleep 75; echo LONG-DONE-b1 under token a and starts under token b.

  • Before: Startup resumes the interrupted turn and replays its queued message.
  • After: Startup skips continuation, clears the marker, and records the queued message as restart-unrecoverable; fresh messages still work.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused implementation with shipped-entry-point and stable-upgrade evidence, no open findings, and applicable proof across the latest merge.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Public terminal traces exercise the changed shutdown/startup owners through an isolated Linux Gateway, real model and exec tool: matching tokens continue, changed tokens suppress continuation and queued replay, and ordinary fresh input succeeds; the relevant production code is unchanged since the proven head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: A supervisor's intentional Gateway stop can be followed by automatic continuation that repeats interrupted work without a fresh user message.
Reason: The concrete operational scenario warrants a narrow opt-in control; supplied maintainer-authorship facts establish direction, including the documented exclusion of crash recovery.

Merge readiness

✅ Ready for maintainer review

This PR provides useful supervisor control over graceful restart recovery, with no concrete introduced defect found; current-head CI remains pending.

Priority: P2
Reviewed head: c10305eb539d60336c320263ae507d0bac8f3cef

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway shutdown records live sessions in persisted restart markers; startup consumes those markers and durable queued inputs through the existing recovery and authorization owners.

flowchart TD
  A[Supervisor token] --> B[Shutdown marker writers]
  B --> C[Persisted session marker]
  C --> D[Startup scope comparison]
  D --> E[Normal authorized continuation]
  D --> F[Clear mismatched marker]
  F --> G[Record queued input ending]
Loading

Technical review

Best possible solution:

Retain the optional scope on the existing restart marker and settle mismatched queued inputs through the existing pending-input owner.

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

Current-main source consumes graceful shutdown markers without a supervisor token comparison, so an intentional process stop followed by startup enters ordinary continuation; the PR supplies live before/after recovery traces, but this review ran no target code.

Is this the best way to solve the issue?

The change addresses the documented graceful-stop scenario at the existing recovery boundary, shares marker creation between both writers, and reuses queued-input settlement without adding a competing recovery owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 76d63b8aaf45.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ea3eb71 adds src/gateway/session-restart-resume.ts:558 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ea3eb71a0263; files: src/gateway/session-restart-resume.ts)
  • Ayaan Zaidi: Raw commit 703c82d adds src/gateway/queued-chat-inputs.ts:74 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 703c82d20c5c; files: src/gateway/queued-chat-inputs.ts)
  • Josh Avant: Raw commit 67a327f adds src/gateway/queued-chat-inputs.ts:69 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 67a327fc1a32; files: src/gateway/queued-chat-inputs.ts)

PR surface

Source +90, Tests +113, Docs +13, Other +2. Total +218 across 11 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 126 36 +90
Tests 1 113 0 +113
Docs 2 28 15 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 2 3 1 +2
Total 11 270 52 +218

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
New operator control 1 optional environment variable OPENCLAW_GATEWAY_RESTART_RESUME_SCOPE adds explicit supervisor control while preserving behavior when unset.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Useful control for managed Gateway lifecycles with a concrete repeated-command scenario and limited impact on default installations.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-18T07:32:05.576Z sha 49872b4 :: blocked before merge. :: [P2] Include the scope module in the trusted wrapper inventory | [P2] Keep the extracted identity comparison within the ratchet contract
  • reviewed 2026-11-18T08:30:47.331Z sha 3cf7188 :: blocked before merge. :: none
  • reviewed 2026-11-18T09:34:11.713Z sha 3cf7188 :: needs maintainer review before merge. :: none

Reviewed November 18, 2026, 5:01 AM ET / 10:01 UTC (Revision 4).

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Nov 18, 2026
@freeqaz

freeqaz commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 18, 2026
@freeqaz

freeqaz commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Nov 18, 2026
@freeqaz

freeqaz commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Nov 18, 2026
@freeqaz
freeqaz merged commit 2769799 into main Nov 18, 2026
138 checks passed
@freeqaz
freeqaz deleted the fix/gateway-restart-resume-scope branch November 18, 2026 10:21
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 18, 2026
Staging route 1 for openclaw#129388 (staging only; no PR ref move).
Upstream main b894fe5 (fetched 2026-11-18T19:00Z),
merge base 9122a49 (the chain's own absorb). 42 conflicted paths, all resolved
here; rerere replayed none.

Agent schema: upstream 703c82d (openclaw#200533) owns 43 (pending-input endings) and 44 is
free in this tree, so continuation's recipient authority moves 43 -> 44:
- SQLite owner runs upstream's 43 step, then the idempotent authority step;
- PostgreSQL ladder: 42 tool usage, 43 endings (from V42), 44 authority (from V43);
- backup scopes 43 session_pending_inputs (upstream), 44 session_recipient_authority;
- port descriptor pin 44, historical 27-43; witness admits upstream's 43;
- the fleet bridge classifies 38-43; it admits only upstream's own 43 there, so the
  never-deployed chain 43 (upstream 42 + authority) is refused before any write;
- jump-14 42 (the fleet on ab5a30e) now runs upstream's 42 and 43, then authority;
- package schemaVersions.agent 44; agent-schema-history doc rows 42/43/44 and the
  authority section (the chain had left it at 42).

One owner where upstream now owns a fork extraction:
- session-restart-resume: upstream's resolveStartupRestartMarker (openclaw#201060) replaces
  the fork's session-restart-resume-marker.ts (deleted); the fork's tombstone early
  return stays ahead of upstream's interrupted-settle check.
- user-turn-transcript: upstream's applyUserTurnReplacementText replaces the fork's
  byte-identical applyPersistedUserTurnReplacementText (deleted).
- migration witness: upstream's agentSchemaVersions (+43) replaces the fork's
  AGENT_WITNESS_SCHEMA_VERSIONS.
- session-event delivery: the fork's #1447 cron failure-copy withholding moves into
  upstream's createSessionEventReplyDelivery; session-event-handoff equals upstream.

Other resolutions keep both sides (import unions checked against real uses; upstream
openclaw#200533 marker shape `{}`, end causes, lifecycleRestartScope; fork restart tombstones
and operator recovery). attempt.cwd-split.test.ts follows upstream's deletion
(openclaw#198916); its one fork case moves to attempt.continuation-tools.test.ts.
Generated outputs regenerated (config docs, gateway validators, postgres schema,
worker inventory). Compile follow-through: compactionTarget.storePath (openclaw#200714) and
two fork test cleanups pass upstream's new finishPendingInput end cause.

Refs: openclaw#129388

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
… next start (openclaw#201060)

* fix(gateway): scope restart resume to the supervisor's deployment generation

A graceful shutdown marks running sessions and the next start resumes
them. A supervisor that stops a deployment on purpose (an operator stop)
and later starts a new one cannot tell the next Gateway that the
interrupted work was stopped, so the stopped turn runs again with a
synthetic resume message.

Add OPENCLAW_GATEWAY_RESTART_RESUME_SCOPE. Shutdown stamps restart
markers with the current scope; startup resumes only markers written
under the same scope. A marker from another scope, or an unscoped
marker when a scope is set, is cleared and its queued inputs are settled
like a crash's orphans. Without the variable nothing changes.

* docs(gateway): document the restart resume scope and record its env name in the budget

* test(gateway): settle out-of-scope queued input across a real process boundary; format

* fix(gateway): cancel queued inputs of an out-of-scope restart marker after clearing it

The worker withdrawal keeps inputs listed in the session's current marker, so
the orphaned-input settlement that ran before the marker was cleared left them
queued. Settle them once the marker is gone, and drop the discovery filter that
could not reach them.

* refactor(gateway): resolve the out-of-scope restart target in the scope helper

Keeps session-restart-resume.ts within the max-lines budget: the helper returns the
pending-input target of an out-of-scope marker, and the existing orphaned-input
settlement cancels its queued inputs after the marker is cleared.

* docs(gateway): describe the restart resume scope as an opaque supervisor token

The scope covers shutdown markers only; crash recovery of unmarked runs
and of queued input does not consult it. Queued input behind an
out-of-scope marker ends without running.

* refactor(gateway): select the startup restart marker next to restart store discovery

Merging main left session-restart-resume.ts at 720 counted lines, over the
700-line cap. The marker selection (shutdown marker, parked yield, run
orphaned in a crash window, legacy cycle) and its scope check move into
resolveStartupRestartMarker; behavior is unchanged.

* test(gateway): stub the restart resume scope with vi.stubEnv; keep scope helpers module-private

The production unused-export scan flagged the env name and resolver, which
only the test imported.

* style(sessions): format the restart resume scope resolver

* fix(scripts): add the restart resume scope module to the PR wrapper inventory

session-run-lifecycle-projection.ts, which the trusted-anchor PR wrapper
extracts, now imports it (test/scripts/eager-import-closure.test.ts).

* fix(gateway): keep the run comparison of restart startup in its allowlisted module

The session-identity ratchet allows no identity comparisons in the restart discovery module.
Compare the selected run with the startup snapshot in session-restart-resume.ts, as on main,
and pass the result to resolveStartupRestartMarker.
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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts 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