Skip to content

fix: graceful Gateway shutdown outlives its stop deadline - #188188

Merged
steipete merged 2 commits into
mainfrom
codex/graceful-stop-exits
Oct 30, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/graceful-stop-exits

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes graceful Gateway stops that leave a completed Linux service-child owner alive, keep session-admission cleanup pending after cancellation, or let watchdog worker startup extend the native shutdown deadline.

User Impact

Process-owned shutdown bounds session resource settlement to five seconds after marker persistence and cancellation, and retires a certified, fully drained native child. Embedded hosts still join actual cleanup before reusing resources. Uncertified descendants or incomplete channels remain retained and use the existing process-exit safety net.

Why This Change Was Made

Session admission settlement joins captured producers, operation owners, interrupted effects, and terminal persistence; an abort signal is only the start of that cleanup. The run-shutdown owner now bounds its process-exit receipt and uses the existing close-step warning/retention path, preserving databases for late cleanup.

The Linux host previously excluded every subreaper from retained-child retirement, even after a descendant-extinction certificate and all channel EOFs. Reuse the existing direct-child retirement path for that completed owner, including ordinary graceful closure. No native PGID signaling is introduced.

The watchdog was armed with the correct shutdown budget but started its relative timer only after worker bootstrap. Pass an absolute monotonic deadline and check its existing cancellation queue immediately before killing. A delayed bootstrap now consumes the budget, and an already-queued cancellation still wins. The historical bootstrap delay was not measured, so this proves a deadline-accounting defect rather than attributing the recorded incident conclusively.

Evidence

Candidate: e0e9ee29edf3d24766beb8524975cffbed60b425, base c32556b0cea7f63b33db0ac393affd71ecb0015b.

  • Admission regression: red on base (1 failed / 4 passed); fixed close/resource consumers 116 passed. The new case keeps real SQLite available through late cleanup while the admission close step settles after grace.
  • Native retirement regression: red on base (1 failed / 35 passed); fixed 36 passed, including missing-certificate refusal, all EOFs, observed direct-child exit, and zero native PGID probes.
  • Final watchdog process fixture: red on original production (another 1,004 ms after delayed bootstrap versus <500 ms); green with the fix. It also joins delayed cancellation and kills a real blocked-main process. Signal/liveness consumer suites: 11 passed before the final queue-read correction; final watchdog regression passed afterward.
  • Exact-head pnpm test:e2e:gateway test/gateway-restart-resume.e2e.test.ts test/gateway-restart-handoff.e2e.test.ts --maxWorkers=1: 2 passed / 1 Linux-only skipped on macOS. SIGTERM markers+abort 24.6 ms, shutdown 381 ms; managed restart shutdown 359 ms. Linux Testbox queued and was stopped; Linux handoff remains a specific proof gap for CI/coordinator.
  • pnpm tsgo:core, all 29 core test typecheck graphs, final owning CLI test graph, targeted oxlint/oxfmt, both line-count ratchets, and git diff --check: pass. No cap/baseline changes. Whole diff: production +26, tests −11, docs +6 lines.
  • Applied pr-simplify: reused existing shutdown, retirement, and cancellation owners; removed duplicate close tracking and test scaffolding. Final local Codex autoreview of the entire base-to-candidate snapshot: complete/scoped-clean at P0/P1, no actionable findings. The committed candidate has the same reviewed bytes.

No live deployment, schema, configuration option, dependency, version, or changelog change. CI observation and merge belong to the coordinator; this PR does not enable auto-merge.

Bound process-owned session admission settlement after restart markers and cancellation while preserving embedded-host joins and retained database ownership. Retire the direct Linux subreaper child once its descendant certificate and channel EOFs prove only the native owner remains.
Capture a monotonic deadline before creating the native watchdog worker. Observe queued cancellation at the kill effect so an already-cancelled watchdog cannot kill after delayed startup. Prove both paths through real worker bootstrap delays and native process exit.
@clawsweeper

clawsweeper Bot commented Oct 30, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T08:29:43.791124Z e0e9ee2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: M labels Oct 30, 2026
@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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR bounds process-owned session cleanup, retires fully drained Linux child owners, and includes worker startup in the shutdown watchdog deadline.

Example: A watchdog has a 1,000 ms budget and its worker takes 1,000 ms to bootstrap.

  • Before: The worker starts another 1,000 ms timer after bootstrap.
  • After: The worker observes the elapsed deadline and checks queued cancellation before terminating the process.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation has no actionable finding, but its Linux-specific behavior lacks completed production-boundary evidence.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence covers real watchdog processes and macOS Gateway restart tests, while Linux retirement is supported by mocked certificate tests rather than a completed Linux handoff.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Graceful Gateway stops can retain completed child owners or unfinished session cleanup and exceed their intended shutdown deadline.
Reason: The maintainer-authored repair follows the recorded bounded-shutdown direction without adding configuration, public APIs, or a competing lifecycle subsystem.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses shutdown defects still present on current main, and the reviewed diff introduces no concrete correctness finding.

Priority: P2
Reviewed head: e0e9ee29edf3d24766beb8524975cffbed60b425

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied macOS Gateway runs do not exercise certified Linux child retirement, and no completed Linux handoff trace is supplied.
Agent review details

How this fits together

The Gateway shutdown path records restart markers, cancels session work, and closes resources; the process supervisor joins child extinction, while an independent worker enforces the process exit deadline.

flowchart TD
  A[Stop or restart request] --> B[Gateway shutdown owner]
  B --> C[Persist markers and cancel sessions]
  C --> D[Bound cleanup and retain dependencies]
  B --> E[Join certified child retirement]
  A --> F[Independent deadline watchdog]
  D --> G[Process exit]
  E --> G
  F --> G
Loading

Technical review

Best possible solution:

Keep shutdown deadlines with the existing lifecycle owners while retaining dependencies for unfinished cleanup and refusing unsafe runtime reuse.

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

Current main starts the watchdog delay after worker bootstrap and excludes Linux subreapers from retained-child retirement; the author also reports base-red regressions, which this read-only review did not rerun.

Is this the best way to solve the issue?

The patch is a focused repair using existing shutdown, retirement, and cancellation owners; every production hunk serves the stated problem, and no smaller complete alternative was established.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4c6ae7f801f5.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +26, Tests -11, Docs +6. Total +21 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 51 25 +26
Tests 3 89 100 -11
Docs 1 8 2 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 148 127 +21

Review metrics

Metric Value Why it matters
Production versus test growth Production +51/−25 (net +26); tests +89/−100 (net −11) The small production increase adds deadline accounting and certified retirement through existing owners, while regression coverage extends existing fixtures.

Labels

Label changes:

  • add P2: This is a focused shutdown reliability repair; the source establishes deadline and cleanup defects without demonstrating an emergency outage.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This is a focused shutdown reliability repair; the source establishes deadline and cleanup defects without demonstrating an emergency outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Publish a redacted Linux trace showing certified child retirement, observed child exit, and bounded Gateway handoff through the real process owner.

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.

Reviewed October 30, 2026, 4:43 AM ET / 08:43 UTC.

@steipete
steipete merged commit a4062ee into main Oct 30, 2026
140 of 143 checks passed
@steipete
steipete deleted the codex/graceful-stop-exits branch October 30, 2026 09:01
RomneyDa added a commit that referenced this pull request Oct 31, 2026
Adapt the service-child retirement portion of main PR #188188 for the release branch so a native Linux subreaper receipt can retire the retained relay without a stale process-group probe.

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…r systemd SIGKILL (openclaw#188188)

On Team (2026-10-30 05:05Z), the restart redesign resumed every running root correctly, but the process never exited on its own. systemd SIGKILLed it at 90 s:
- restart.close.session-admissions stayed pending for 85 s;
- a service-child relay (linux-subreaper) missed its cleanup deadline;
- the native hard-exit watchdog did not beat systemd.

Fixes:
- The session-admission join waited for full producer, operation, effect and terminal-persistence settlement. It now has a 5 s process-owned bound and keeps databases open for late cleanup.
- Service-child relay retirement: once descendant extinction is certified and channel closure is complete, it uses the existing direct-child retirement path.
- The hard-exit watchdog started its relative timer after worker bootstrap, which could exceed systemd's margin. It now consumes an absolute monotonic deadline and checks queued cancellation before killing.

Proof at exact head e0e9ee2:
- Regressions for all three are red on base and green here. Close/resource suites (116), the service-child relay suite (36) and the hard-exit process test (incl. delayed cancellation and blocked-main SIGKILL) pass.
- The restart acceptance and handoff e2e pass: markers and abort in 24.6 ms, SIGTERM exit in 381 ms.
- Exact-head CI: 65 jobs succeeded, zero failed.

Gap: Linux handoff proof (Testbox queued). Uncertified owners still rely on the watchdog. Production +26 LOC.
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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