Skip to content

feat(gateway): add cooperative host suspension#103618

Merged
steipete merged 15 commits into
mainfrom
codex/gateway-suspend-prepare
Jul 10, 2026
Merged

feat(gateway): add cooperative host suspension#103618
steipete merged 15 commits into
mainfrom
codex/gateway-suspend-prepare

Conversation

@steipete

@steipete steipete commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Partially addresses #86876.

What Problem This Solves

External hosting controllers had no atomic way to verify that a Gateway had stopped accepting new tracked user work and was idle before freezing or snapshotting its process.

A read-only preflight can race with a new RPC, session turn, cron tick, HTTP request, or detached persistence/delivery task. Restart draining is one-way, so it cannot safely represent an abandoned or reversible host snapshot operation.

Why This Change Was Made

This adds a host-neutral Gateway contract instead of a platform-specific API:

  • gateway.suspend.prepare
  • gateway.suspend.status
  • gateway.suspend.resume

prepare closes process-wide root, session, and command admission; pauses automatic cron scheduling; and synchronously inspects tracked active work. It returns ready only when the snapshot is idle. If work is active, it restores scheduling and admission before returning busy.

A ready lease lasts two minutes, can be renewed with the same stable requestId, auto-resumes on expiry, and requires the matching suspensionId for explicit resume. Scheduler-resume failures remain fail-closed and retryable. Restart signaling shares the same admission state, preventing a signal from racing a ready lease or reopening work during restart drain.

The generic fence lives in core. The Admin HTTP plugin exposes the same RPC methods as an alternate authenticated control path. The protocol change is additive and introduces no new config or environment variable.

This is complementary to the durable queue work in #51620 and #82572: the queue preserves accepted work, while this contract creates a bounded cooperative idle window for host snapshots.

User Impact

Host controllers can now coordinate a bounded idle window:

  1. Fence host-controlled ingress.
  2. Call gateway.suspend.prepare.
  3. Retry a busy result while leaving the process running.
  4. Freeze or snapshot before expiresAtMs after a ready result.
  5. Call gateway.suspend.resume after thaw or abandonment.

While prepared, new WebSocket handshakes are rejected; existing connections can call only suspension control methods; other RPCs return retryable UNAVAILABLE; automatic cron ticks remain paused; built-in HTTP user-work routes return 503; /healthz remains live; and /readyz reports not ready. A retained authenticated WebSocket or pre-enabled Admin HTTP RPC route is required for explicit resume.

This is a cooperative tracked-work fence, not general process quiescence. It does not persist incoming messages, stop third-party channel transports, fence external ingress, or prove arbitrary plugin/background work idle. The host remains responsible for fencing ingress and consistently freezing or snapshotting the full process tree and filesystem. If the control connection is lost, admission reopens when the lease expires.

Evidence

  • Exact final head e475996d946af6810c053f14a69684a6f9ebfb46; Git tree 35b61e79b5b2a8f1a535125081936ca4551afff0.
  • Source-blind AWS Crabbox run run_45c5519361af built that exact tree and passed the persistent WebSocket/Admin HTTP contract: baseline health/readiness, ready lease, retained status, prepared 200/503 probes, retryable unrelated-RPC refusal, fresh-WebSocket 503, mismatch preservation, matching resume, restored readiness, and idempotent repeat resume.
  • Exact-tree AWS Crabbox run run_5d1bf9ff69fa passed 159 focused protocol, Gateway, coordinator, cron, admission, detached agent/chat, and followup-drain tests across six Vitest shards.
  • Fresh high-reasoning autoreview found no actionable defect (patch is correct, confidence 0.88).
  • Final range-diff maps all 15 pre/post-rebase commits exactly; the detached-work patch-id is unchanged, current-main file overlap is zero, and merge-tree is clean.

Generated TypeBox protocol schemas, Swift client models, and the docs map are current. vgateway.quiesce is not introduced; the public API is the host-neutral gateway.suspend.* family.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes scripts Repository scripts agents Agent runtime and tooling extensions: admin-http-rpc size: XL maintainer Maintainer-authored PR labels Jul 10, 2026
@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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 10, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 10, 2026, 3:19 PM ET / 19:19 UTC.

Summary
Adds three cooperative Gateway suspension RPCs plus a reversible process-wide admission fence integrated with cron, restart, HTTP/WebSocket ingress, detached lifecycle work, Admin HTTP, protocol clients, and documentation.

Reproducibility: not applicable. This PR introduces a new lifecycle capability rather than reproducing an established current-main bug.

Review metrics: 3 noteworthy metrics.

  • Public lifecycle methods: 3 added. They establish a new operator wire contract over WebSocket and Admin HTTP.
  • Tracked blocker categories: 12 kinds. A ready result depends on complete accounting across queues, replies, runs, tasks, sessions, and persistence.
  • Configuration surface: 0 added, 0 changed, 0 removed. Upgrade risk is behavioral and operational rather than config-migration based.

Stored data model
Persistent data-model change detected: serialized state: src/auto-reply/reply/session-hooks-context.test.ts, serialized state: src/auto-reply/reply/session-updates.lifecycle.test.ts, serialized state: src/auto-reply/reply/session-updates.ts, serialized state: src/auto-reply/reply/session.ts, serialized state: src/gateway/session-reset-service.ts, serialized state: src/sessions/session-lifecycle-admission.test.ts, and 9 more. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until stronger real behavior proof is added.

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

Rank-up moves:

  • [P1] Add redacted exact-head live transcripts for both suspension control paths.
  • Obtain explicit Gateway owner approval for the public lifecycle contract.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The linked workflows are cancelled and target older SHAs; add redacted exact-head terminal or live output for both WebSocket and Admin HTTP paths, then update the PR body to trigger a fresh ClawSweeper review.

Risk before merge

  • [P1] A missed detached state-changing path could allow a false-ready snapshot, while an incorrectly retained root or failed scheduler recovery could prolong Gateway unavailability.
  • [P1] Prepared suspension intentionally rejects new connections and ordinary RPC/HTTP work; operators need a retained authenticated control path or must wait for lease expiry.
  • [P1] The three public RPCs and their fail-closed semantics can become long-term host-controller and plugin compatibility obligations.

Maintainer options:

  1. Add exact-head operational proof (recommended)
    Provide redacted current-head output covering busy and ready prepare, ordinary RPC rejection, health/readiness probes, mismatched and matching resume, expiry, WebSocket, and Admin HTTP.
  2. Narrow the public commitment
    Remove or defer the RPC exposure while retaining internal safety primitives if maintainers are not ready to own the compatibility contract.
  3. Pause the draft
    Defer the XL lifecycle change if its availability semantics and ongoing audit burden are not accepted.

Next step before merge

  • [P1] The remaining blockers are contributor-supplied exact-head proof and maintainer product acceptance, not a narrow automated code repair.

Maintainer decision needed

  • Question: Should OpenClaw support gateway.suspend.prepare, gateway.suspend.status, and gateway.suspend.resume with these reversible process-wide admission semantics as a public Gateway lifecycle contract?
  • Rationale: The API deliberately changes service availability and creates a durable operator-facing compatibility commitment; correctness review cannot decide that product boundary.
  • Likely owner: steipete — Current-main history most strongly connects Peter to the affected safe-restart, Gateway lifecycle, and protocol surfaces.
  • Options:
    • Adopt after exact-head proof (recommended): Accept the public contract once both authenticated transports and all recovery states are demonstrated on the reviewed SHA.
    • Keep the primitives internal: Retain generic admission and coordinator code while deferring public RPC exposure to a separately approved API design.
    • Defer cooperative suspension: Pause the branch until host snapshot lifecycle support is an explicit product priority.

Security
Cleared: No dependency, workflow, package-resolution, secret, or permission expansion concern was found; the suspension methods retain explicit authenticated operator scopes and control-plane policy.

Review details

Best possible solution:

Keep one canonical core admission/coordinator path, but merge only after redacted exact-head live transcripts prove both WebSocket and Admin HTTP flows and the Gateway owner explicitly accepts the cooperative—not total-process—quiescence contract.

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

Not applicable: this PR introduces a new lifecycle capability rather than reproducing an established current-main bug.

Is this the best way to solve the issue?

Yes, provisionally: an atomic core fence is the narrowest way to prevent races that an observational plugin cannot close, and one canonical coordinator is preferable to platform-specific snapshot hooks; exact-head proof and product acceptance remain required.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add feature: ✨ showcase: ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. An atomic, bounded idle lease could unlock safe host snapshots and reversible scale-down coordination without embedding platform-specific hosting policy in core.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P2: This is a broad, normal-priority Gateway lifecycle feature rather than an urgent user regression.
  • merge-risk: 🚨 compatibility: The new public RPC names and result semantics can become stable host-controller and plugin dependencies.
  • merge-risk: 🚨 availability: Admission and scheduler-recovery behavior can reject normal traffic or keep the Gateway unavailable.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • feature: ✨ showcase: ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. An atomic, bounded idle lease could unlock safe host snapshots and reversible scale-down coordination without embedding platform-specific hosting policy in core.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The linked workflows are cancelled and target older SHAs; add redacted exact-head terminal or live output for both WebSocket and Admin HTTP paths, then update the PR body to trigger a fresh ClawSweeper review.
Evidence reviewed

What I checked:

Likely related people:

  • steipete: Current-main blame and concentrated history connect Peter to safe restart activity inspection, Gateway lifecycle, and protocol behavior central to this PR. (role: feature owner and recent area contributor; confidence: high; commits: e43f225c814d, 5aea34ad8c21; files: src/infra/restart-coordinator.ts, src/infra/restart.ts, src/process/command-queue.ts)
  • vincentkoc: Area shortlog shows repeated current-main contributions across the sampled Gateway, restart, and protocol surfaces relevant to owner review. (role: recent adjacent contributor; confidence: medium; commits: e085fa1a3ffd; files: src/infra/restart.ts, src/infra/restart-coordinator.ts, packages/gateway-protocol/src/index.ts)
  • xingzhou: The latest merged work identified in prior review context touched command queue and restart coordination, providing useful review context for the admission changes. (role: recent adjacent contributor; confidence: low; commits: 4d004e2054ba; files: src/process/command-queue.ts, src/infra/restart.ts, src/infra/restart-coordinator.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.
Review history (2 earlier review cycles)
  • reviewed 2026-07-10T12:08:52.340Z sha f915754 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-10T18:05:10.291Z sha 0309c02 :: needs real behavior proof before merge. :: none

@steipete steipete self-assigned this Jul 10, 2026
@steipete
steipete force-pushed the codex/gateway-suspend-prepare branch 3 times, most recently from 296414e to 0309c02 Compare July 10, 2026 17:39
@steipete
steipete force-pushed the codex/gateway-suspend-prepare branch from c18474c to e475996 Compare July 10, 2026 18:49
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. feature: ✨ showcase ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer proof complete for exact head e475996d946af6810c053f14a69684a6f9ebfb46 (tree 35b61e79b5b2a8f1a535125081936ca4551afff0).

Review fixes now included:

  • transactional cron re-arm and explicit fail-closed scheduler recovery;
  • stale AsyncLocalStorage descendants rejected after root retirement;
  • detached agent and chat.send dispatch retain their request root through cleanup;
  • followup/collect drains own an independent root across debounce and retries;
  • clearing a debouncing queue aborts the timer and releases its root immediately;
  • dispatch-error lifecycle projection stays tracked when restart drain overlaps.

Exact proof:

  • corepack pnpm test packages/gateway-protocol/src/gateway-suspend.test.ts src/gateway/server-methods/suspend.test.ts src/gateway/server-methods.suspension-admission.test.ts src/infra/gateway-suspend-coordinator.test.ts src/cron/service.every-jobs-fire.test.ts src/process/gateway-work-admission.test.ts src/gateway/server.agent.gateway-server-agent-a.test.ts src/gateway/server.chat.gateway-server-chat.test.ts src/auto-reply/reply/queue.drain-restart.test.ts
  • corepack pnpm build plus source-blind persistent WebSocket/Admin HTTP validation: AWS Crabbox run_45c5519361af
    • baseline /healthz and /readyz 200;
    • idle prepare ready, activeCount: 0, no blockers;
    • while prepared: health 200, readiness 503, unrelated RPC retryable UNAVAILABLE, fresh WebSocket 503;
    • mismatched resume 400 and lease preserved;
    • matching resume 200/resumed: true, readiness restored;
    • repeated resume resumed: false, ordinary RPC recovered.
  • Fresh high-reasoning autoreview: no actionable findings (patch is correct, confidence 0.88).
  • Final range-diff: all 15 commits preserved exactly; current-main overlap zero; merge-tree clean.

Known scope boundary: this is a cooperative tracked-work fence, not third-party channel shutdown or an OS/process-tree snapshot adapter. #86876 remains open for those broader controller/plugin concerns.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete
steipete marked this pull request as ready for review July 10, 2026 19:24
@steipete
steipete requested a review from a team as a code owner July 10, 2026 19:24
@steipete
steipete merged commit 1bcc4c5 into main Jul 10, 2026
116 of 120 checks passed
@steipete
steipete deleted the codex/gateway-suspend-prepare branch July 10, 2026 19:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 11, 2026
* feat(gateway): add cooperative suspension preparation

* style: satisfy suspension lint checks

* test(gateway): reset work admission between shared suites

* fix(gateway): reject upgrades during suspension

* fix(gateway): preserve admitted work during suspension

* test(gateway): isolate suspension and restart state

* fix(gateway): close suspension false-ready gaps

* refactor(protocol): slim suspension declaration graph

* refactor(plugin-sdk): sever protocol registry edges

* fix(gateway): preserve admitted restart follow-ups

* fix(gateway): make suspension recovery fail closed

* fix(protocol): keep validation formatter re-export only

* test(gateway): simplify deferred fixture type

* style(gateway): clarify suspension entry name

* fix(gateway): retain detached work admission
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 cli CLI command changes docs Improvements or additions to documentation extensions: admin-http-rpc feature: ✨ showcase ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL 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