Skip to content

fix(gateway): prevent shutdown hangs during suspension - #138734

Merged
steipete merged 1 commit into
mainfrom
codex/postland-136146-deslop
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/postland-136146-deslop

Conversation

@steipete

@steipete steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators closing a suspended Gateway could wait until suspension expiry because background work queued by a reconnect or startup hook still held the connection lifetime open.

Related: #136146.

Why This Change Was Made

Pending independent admission now observes the owning connection scope's abort signal and removes its waiter on cancellation. The admission owner rechecks cancellation after resume; callbacks already admitted remain tracked until their original completion. Reconnect identity synchronization, restart-sentinel refresh, and gateway_start use the same cancellation boundary. Startup work still avoids lending its connection scope to long-lived services.

The follow-up also waits for child-process close before removing fixture directories, awaits asynchronous environment restoration, and limits the browser stdin-EOF assertion to platforms where graceful stdin closure precedes process termination. Process-death assertions remain cross-platform.

User Impact

Gateway shutdown no longer waits for a suspension lease to expire merely to retire queued background work. Work already running still drains normally. The suspension documentation records that behavior. No configuration, schema, protocol, or dependency changes.

Evidence

  • Reproduced pending-admission, reconnect, and both startup-tail failures before the runtime fix. The forced child-cleanup test also fails with the original kill-then-remove ordering.
  • Passed 223 affected tests across admission, WebSocket connect/suspension, startup, and real child-process shutdown; reran all 106 startup cases after the final lint correction.
  • Passed seven native Gateway startup/request lifetime cases and eight actual browser MCP subprocess cases on macOS. Earlier broader lifecycle verification passed 112 tests plus 25 focused scope/approval/question/cache cases.
  • Selected core, core-test, plugin-test, and root-test typechecks passed. Formatting, lint, dead-export scans, dependency/boundary guards, state-schema/store guards, sidecar loading, import cycles, and pairing/webhook checks passed. The initial lint run caught two promise-executor expressions in new tests; both were corrected and lint rerun successfully.
  • Fresh independent Codex autoreview: no actionable P0–P2 findings.

Production: +58/-37 (net +21); tests: +294/-17 (net +277); docs: +3. The production growth carries cancellation through the existing admission owner while sharing and replacing duplicated waiter registration; racing whole callbacks would incorrectly abandon admitted work.

Windows execution was not performed locally. This follow-up does not claim acceptance of #136146's separate protected-metadata audit gap.

Cancel pending reconnect and startup admission waits through the owning connection scope while retaining admitted work through completion. Share the admission wait lifecycle and cover abort/resume races.

Join child process closure before deleting fixture directories, await environment restoration, and align browser EOF proof with Windows process termination. Follow-up to #136146.
@steipete steipete self-assigned this Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes extensions: browser size: M maintainer Maintainer-authored PR labels Sep 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 8:53 PM ET / September 5, 2026, 00:53 UTC.

ClawSweeper review

What this changes

Cancels reconnect and startup work still queued behind Gateway suspension when shutdown begins, preserves completion tracking for running work, and corrects related test cleanup ordering.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still contains the shutdown-blocking admission wait, and this PR provides a focused repair with meaningful regression coverage. No introduced correctness defect was found.

Priority: P2
Reviewed head: f7d43ab4c2e936f325dca4b641122029d46fcb8a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with useful race and cleanup regressions, justified production growth, and no actionable correctness findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor-proof gate does not apply to this maintainer-authored internal lifecycle repair, and no material authority change triggers its exception. Inspected admission, reconnect, and startup tests cover the changed boundary; reported native runs are supplemental, not an independently inspected suspended-Gateway trace.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor-proof gate does not apply to this maintainer-authored internal lifecycle repair, and no material authority change triggers its exception. Inspected admission, reconnect, and startup tests cover the changed boundary; reported native runs are supplemental, not an independently inspected suspended-Gateway trace.
Evidence reviewed 10 items Pinned introduction boundary: The checkout and original PR head are f7d43ab, whose raw recorded parent is 49ae975. The reviewed delta is that parent-to-head patch, not base-branch endpoint drift. The recorded test merge has the exact pinned base followed by this head as parents.
Repair remains necessary on fetched main: Independent admission on fetched main registers a suspension waiter without accepting an AbortSignal. Closing the connection scope therefore cannot settle that queued operation until admission changes. The existing callback-completion join is retained by the proposed repair.
Canonical cancellation owner: The shared waiter races only admission against cancellation and removes its registration in finally. Independent admission rechecks cancellation after wakeup, while an admitted callback still completes before releasing its root. This reuses src/infra/abort-signal.ts rather than introducing a competing cancellation mechanism.
Findings None None.
Security None None.

How this fits together

The Gateway admission coordinator controls when reconnect-triggered and startup background work may begin. Its connection-lifetime owner must retire queued work during shutdown while retaining running operations until their dependencies can safely close.

flowchart TD
  A[Operator reconnect or startup] --> B[Gateway lifetime owner]
  B --> C{Admission open?}
  C -->|No| D[Wait for resume or shutdown]
  D -->|Resume| C
  D -->|Shutdown| E[Remove waiter and settle]
  C -->|Yes| F[Run callback through completion]
  E --> G[Finish Gateway cleanup]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +21, Tests +277, Docs +3. Total +301 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 4 58 37 +21
Tests 7 294 17 +277
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 355 54 +301

Review metrics

Metric Value Why it matters
Production versus test growth Production +58/-37, net +21; tests +294/-17, net +277; docs +3 Production growth carries cancellation through the existing owner and replaces duplicate waiter registration; test growth protects cancellation races and cleanup ordering.

Technical review

Best possible solution:

Keep cancellation inside the shared admission waiter while retaining admitted callbacks through completion; the small signal-plumbing increase preserves that ownership distinction without racing running work.

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

Yes, from source: suspend admission, queue reconnect sync or a startup tail, then close the Gateway; current main's waiter cannot observe the owner's abort. Focused regression cases encode this ordering, but this read-only review did not execute them.

Is this the best way to solve the issue?

Yes: extending the existing admission owner is preferable to reopening suspension during shutdown or racing entire callbacks, either of which would weaken the established completion boundary.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: Repairs a bounded shutdown hang when suspension parks reconnect or startup background work, without evidence of a widespread runtime outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor-proof gate does not apply to this maintainer-authored internal lifecycle repair, and no material authority change triggers its exception. Inspected admission, reconnect, and startup tests cover the changed boundary; reported native runs are supplemental, not an independently inspected suspended-Gateway trace.

Label justifications:

  • P2: Repairs a bounded shutdown hang when suspension parks reconnect or startup background work, without evidence of a widespread runtime outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor-proof gate does not apply to this maintainer-authored internal lifecycle repair, and no material authority change triggers its exception. Inspected admission, reconnect, and startup tests cover the changed boundary; reported native runs are supplemental, not an independently inspected suspended-Gateway trace.

Evidence

What I checked:

  • Pinned introduction boundary: The checkout and original PR head are f7d43ab, whose raw recorded parent is 49ae975. The reviewed delta is that parent-to-head patch, not base-branch endpoint drift. The recorded test merge has the exact pinned base followed by this head as parents. (f7d43ab4c2e9)
  • Repair remains necessary on fetched main: Independent admission on fetched main registers a suspension waiter without accepting an AbortSignal. Closing the connection scope therefore cannot settle that queued operation until admission changes. The existing callback-completion join is retained by the proposed repair. (src/process/gateway-work-admission.ts:411, 4d132d8cbd47)
  • Canonical cancellation owner: The shared waiter races only admission against cancellation and removes its registration in finally. Independent admission rechecks cancellation after wakeup, while an admitted callback still completes before releasing its root. This reuses src/infra/abort-signal.ts rather than introducing a competing cancellation mechanism. (src/process/gateway-work-admission.ts:379, f7d43ab4c2e9)
  • Caller and shutdown-boundary coverage: The WebSocket detached-work wrapper passes its Gateway connection owner's signal. Startup tracking passes the same signal explicitly to sentinel refresh and gateway_start without lending its AsyncLocalStorage scope to long-lived services. AsyncWorkScope.beginClose aborts that signal; drain retains pending original operations. Existing node snapshots and identity/avatar tails share the WebSocket wrapper. (src/gateway/server/ws-connection/message-handler.ts:167, f7d43ab4c2e9)
  • Focused regression and sibling coverage: New admission cases cover cancellation before admission, during suspension, during resume, and after execution begins. WebSocket tests cover reconnect sync on resume versus shutdown; startup tests separately cover parked sentinel and gateway_start work. Existing tests retain restart-fence behavior, original-operation joins, and independent Gateway scopes. Tests were inspected, not executed in this review. (src/process/gateway-work-admission.test.ts:592, f7d43ab4c2e9)
  • Ancillary cleanup changes match their owners: The process fixture registers close before readiness and joins child closure before deleting directories. The restored-requester fixture now awaits the asynchronous restoreEnv contract. The browser assertion adjustment matches existing Windows cleanup ordering: chrome-mcp-process.ts terminates the tracked tree before calling the native transport close, while process-death assertions remain cross-platform. (src/cli/gateway-cli/run-loop.direct-stop-active-work.process.test.ts:19, f7d43ab4c2e9)

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.

@steipete
steipete merged commit 7975054 into main Sep 5, 2026
187 checks passed
@steipete
steipete deleted the codex/postland-136146-deslop branch September 5, 2026 00:58
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
Cancel pending reconnect and startup admission waits through the owning connection scope while retaining admitted work through completion. Share the admission wait lifecycle and cover abort/resume races.

Join child process closure before deleting fixture directories, await environment restoration, and align browser EOF proof with Windows process termination. Follow-up to openclaw#136146.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation extensions: browser gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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