Skip to content

fix(gateway): avoid shutdown stalls with paired workers - #132877

Merged
steipete merged 3 commits into
mainfrom
codex/gateway-shutdown-node-completions
Aug 29, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/gateway-shutdown-node-completions

Conversation

@steipete

@steipete steipete commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #132819

What Problem This Solves

Fixes an issue where operators stopping or restarting a Gateway with paired workers could wait through node-command deadlines even though the node had already replied. Shutdown rejected the completion frames that its own maintenance and worker cleanup were waiting for.

Why This Change Was Made

The RPC router now lets an exact pending node owner execute its completion handler during restart without recursively requesting new root admission. The invocation-stream owner centralizes connection, deadline, and lifecycle checks for admission, progress, and result settlement. Private worker commands retain their existing live lifecycle predicate and recheck it after asynchronous handler dispatch; cleanup never mints a request root or revives a released one. Duplicate validation in the registry and stream handlers is removed.

New work remains fenced. Unrelated, replayed, disconnected, re-paired, expired, and owner-revoked replies cannot settle another invocation. Approval/question continuation policy remains suspension-only. No configuration, database schema, protocol version, or worker timeout changes.

Provenance: the suspension-only continuation path was introduced in #130003 (093166c, August 26), and worker environment-stop replies made the shutdown gap visible in #130733 (e4d602c, August 27). Both were authored and merged by @steipete. The focused reproduction is against current main at 10da9ac; this does not establish an older stable-release regression.

Production LOC: +68/-56 (net +12). The added capability is closure-bound completion for rootless private lifecycle cleanup; consolidating existing validation absorbs the rest of the repair. Tests and documentation are separate.

User Impact

Responsive paired workers can complete Gateway shutdown without waiting out their command budgets. Cleanup still targets the exact environment/session/owner epoch, and node-side physical teardown remains authoritative. The same private node transport serves device and cloud workers; remote-exec process ownership is unchanged.

Evidence

  • Before the production change, five continuation regression cases failed. The real Gateway/paired-node WebSocket test independently reproduced node.invoke.result unavailable during gateway restart while shutdown awaited its rootless environment-stop reply.
  • After the change, all 217 tests across eight focused files pass: restart signal/drain, suspension admission, invocation timeouts and streaming, node pairing/socket lifecycle, worker tunnel cleanup, and process admission.
  • The real-socket shutdown regression requires the cleanup acknowledgement and prompt Gateway close, without advancing command deadlines. It disconnects the node only during failure cleanup.
  • Independent Codex autoreview completed with no actionable findings at its default P0 threshold.
  • Fresh full build and all changed-scope checks completed successfully. Exact-head CI run33279493380 passed at4738d6cfe7cd12299a2a07ee1b346b4bc2167fd9, including the required openclaw/ci-gate.
  • Separate process-level proof used an isolated real Gateway, authenticated paired headless node, an active idle worker placement, and SIGTERM. No model inference or provider credentials were needed. Baseline main stayed running after 115.01 seconds, with repeated rejected node completion frames, until harness cleanup disconnected its node. With this patch, the Gateway exited normally in 0.466 seconds while the node remained connected. All owned processes and temporary state/credentials were cleaned up.

Sanitized process-probe results (same fixture and shutdown order):

baseline: active placement -> SIGTERM -> node.invoke.result unavailable during gateway restart
baseline: still running after 115.01s; node disconnect during failure cleanup allowed exit
fixed:    active placement -> SIGTERM -> exitCode=0, seconds=0.466, forced=false
fixed:    processesStopped=true, ephemeralCredentialsDeleted=true

The initial CI run found a return-style lint error in the new test helper (fixed; no runtime change) and an unrelated Codex child-startup diagnostic race, tracked separately in #132884. The latter is in unchanged code; no startup retry assertions or process inspection policy were relaxed here. The 15 tests in the two edited Gateway test files passed again after the lint correction. A subsequent UI shard passed all4,094 assertions but reported a deferred clipboard-focus callback after jsdom teardown. This PR includes a bounded test-only cleanup: drain that callback before restoring DOM mocks. Both clipboard/task-suggestion suites pass(12 tests); no UI production behavior or assertion changed.

Latest ClawSweeper review and rank-up moves read: its exact pending/lifecycle boundary is retained, and the +12 production lines are justified above. The maintainer-directed repair preserves that boundary. Required exact-head checks are green; both rank-up moves are satisfied and there are no outstanding review findings.

@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 29, 2026 22:27
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Aug 29, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Aug 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 6:55 PM ET / 22:55 UTC.

ClawSweeper review

What this changes

The PR lets authenticated paired-worker replies settle pending shutdown-cleanup commands during Gateway restart draining, adds lifecycle/socket regression coverage, and drains one deferred UI test callback before teardown.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No introduced correctness finding was identified. Keep this maintainer-labelled PR open for the normal maintainer merge decision after its exact-head checks complete.

Priority: P1
Reviewed head: 4738d6cfe7cd12299a2a07ee1b346b4bc2167fd9
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong real shutdown evidence, focused authority coverage, and a coherent owner-boundary repair support a high-quality review result.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed production owner is the pending node-invocation controller; the supplied terminal trace exercises an isolated real Gateway with an authenticated paired node and shows SIGTERM recovery from a 115.01-second baseline stall to a 0.466-second clean exit. The added real-socket shutdown test corroborates the same entrypoint and cleanup acknowledgement path.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed production owner is the pending node-invocation controller; the supplied terminal trace exercises an isolated real Gateway with an authenticated paired node and shows SIGTERM recovery from a 115.01-second baseline stall to a 0.466-second clean exit. The added real-socket shutdown test corroborates the same entrypoint and cleanup acknowledgement path.
Evidence reviewed 7 items Introduced continuation boundary: The introduced stream-controller path admits a rootless continuation only during restart drain and only after the pending invocation passes connection, deadline, and lifecycle-owner checks.
Final settlement recheck: Result handling calls the same pending-invocation validator immediately before removing and resolving the pending command, so an owner revoked while dispatch awaited cannot settle it.
Lifecycle caller contract: Worker retirement invokes the private environment-stop command with an authorization predicate bound to the retiring entry; the private transport composes it with current node/pairing/supervisor proof.
Findings None None.
Security None None.

How this fits together

The Gateway sends private cleanup commands to paired worker nodes and receives progress or result frames on their sockets. During restart drain, an exact live pending invocation must be allowed to settle so cleanup and shutdown can finish, while unrelated work remains refused.

flowchart LR
  A[Gateway restart drain] --> B[Pending worker cleanup command]
  C[Paired worker result or progress] --> D[Invocation, connection, pairing, and owner checks]
  B --> D
  D --> E[Settle cleanup]
  E --> F[Gateway shutdown completes]
  D --> G[Reject stale or unrelated reply]
Loading

Decision needed

Question Recommendation
Should this protected Gateway shutdown repair be landed once its exact-head checks finish green? Land after green checks: Merge the reviewed head once GitHub reports its required exact-head checks as successful.

Why: The patch has no supported blocking finding, but the maintainer label requires explicit maintainer handling rather than automated closure or repair routing.

Before merge

  • Complete next step (P2) - No repair lane is needed because the reviewed patch has no actionable finding; the remaining action is normal maintainer merge handling after CI.
Agent review details

Security

None.

PR surface

Source +12, Tests +458, Docs +6. Total +476 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 68 56 +12
Tests 3 548 90 +458
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 622 146 +476

Review metrics

Metric Value Why it matters
Production versus test delta production +12, tests/support +458, docs +6 The net production growth is limited to a rootless private-cleanup settlement boundary while replacing duplicated validation; the larger increase is focused regression coverage.

Technical review

Best possible solution:

Preserve the single stream-controller settlement path and land it only once the remaining exact-head CI gates are green.

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

Yes: the source baseline excludes restart drain from node completion continuations, and the introduced socket regression exercises the paired-worker shutdown sequence. The PR body also supplies an isolated before/after SIGTERM trace.

Is this the best way to solve the issue?

Yes: centralizing identity and lifecycle validation at the pending-invocation owner repairs the denied completion without admitting a new request root or broadening node RPC access.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the pending node-invocation controller; the supplied terminal trace exercises an isolated real Gateway with an authenticated paired node and shows SIGTERM recovery from a 115.01-second baseline stall to a 0.466-second clean exit. The added real-socket shutdown test corroborates the same entrypoint and cleanup acknowledgement path.
  • 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:

  • P1: The repaired shutdown path can keep an operator's Gateway alive until a worker-command deadline despite an already available completion reply.
  • 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. Sufficient (terminal): The changed production owner is the pending node-invocation controller; the supplied terminal trace exercises an isolated real Gateway with an authenticated paired node and shows SIGTERM recovery from a 115.01-second baseline stall to a 0.466-second clean exit. The added real-socket shutdown test corroborates the same entrypoint and cleanup acknowledgement path.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the pending node-invocation controller; the supplied terminal trace exercises an isolated real Gateway with an authenticated paired node and shows SIGTERM recovery from a 115.01-second baseline stall to a 0.466-second clean exit. The added real-socket shutdown test corroborates the same entrypoint and cleanup acknowledgement path.

Evidence

What I checked:

  • Introduced continuation boundary: The introduced stream-controller path admits a rootless continuation only during restart drain and only after the pending invocation passes connection, deadline, and lifecycle-owner checks. (src/gateway/node-registry.invoke-stream.ts:256, 5593f49a7876)
  • Final settlement recheck: Result handling calls the same pending-invocation validator immediately before removing and resolving the pending command, so an owner revoked while dispatch awaited cannot settle it. (src/gateway/node-registry.invoke-stream.ts:123, 4738d6cfe7cd)
  • Lifecycle caller contract: Worker retirement invokes the private environment-stop command with an authorization predicate bound to the retiring entry; the private transport composes it with current node/pairing/supervisor proof. (src/gateway/worker-environments/node-worker-tunnel.ts:406, 4738d6cfe7cd)
  • Focused authority coverage: The introduced tests cover restart signal and drain, stale invocation/node/connection/pairing/owner identities, and revocation after an awaited handler; the socket test drives an idle paired-worker stop reply through Gateway shutdown. (src/gateway/server-methods.suspension-continuations.test.ts:454, 4738d6cfe7cd)
  • Baseline and patch provenance: The base implementation permitted node completion continuations only during suspension draining and required a captured root continuation; commit 5593f49 adds the restart/rootless path. (src/gateway/server-methods.ts:318, 5593f49a7876)
  • Real behavior evidence supplied: The PR body records an isolated real Gateway, authenticated paired node, active placement, and SIGTERM probe: baseline remained running after 115.01 seconds after rejected result frames, while this head exited normally in 0.466 seconds with the node connected. (4738d6cfe7cd)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-29T22:34:25.976Z sha 5593f49 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Aug 29, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Aug 29, 2026
@steipete
steipete merged commit 5b532a7 into main Aug 29, 2026
268 checks passed
@steipete
steipete deleted the codex/gateway-shutdown-node-completions branch August 29, 2026 23:01
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
)

* fix(gateway): avoid shutdown stalls with paired workers

* test(gateway): use consistent shutdown fixture returns

* test(ui): drain clipboard focus restoration before teardown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

[Bug]: Gateway shutdown rejects pending node completion replies during worker cleanup

1 participant