Skip to content

fix: allow Gateway restart after late sidecar cleanup - #197883

Merged
steipete merged 1 commit into
mainfrom
fix/2430-sidecar-restart
Nov 12, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/2430-sidecar-restart

Conversation

@steipete

@steipete steipete commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Gateway in-process restarts exiting instead of returning ready when a sidecar takes more than five seconds to stop but successfully finishes during the mandatory final join.

User Impact

A successfully cleaned-up Gateway can restart in the same process. Failed or still-pending sidecar cleanup continues to prevent resource release and restart.

Why This Change Was Made

The early sidecar stop recorded a permanent timeout error, even though the later required sidecar owner had successfully joined that same operation. The restart loop treated this obsolete error as proof that resources were still retained.

Use the existing mandatory final sidecar join as the settlement decision for the two sidecar steps it owns. Preserve cleanup order, the five-second diagnostic grace, fatal failures, and other optional cleanup refusal contracts. Production growth is 12 lines to name this existing ownership explicitly; no new state, cache, configuration, timeout, or supervisor fallback.

Evidence

  • The scheduled Matrix restart/replay scenario recorded SIGUSR2, a five-second sidecar warning, successful sidecar and mandatory final settlement at 7.288 seconds, then an erroneous retained-resource restart refusal and exit 0: run43258726252, QA job.
  • Regression uses the actual sidecar stop owner and final join. Both successful late-stop variants fail on the original source; all nine shutdown tests pass with this change, including late rejection and genuine optional retained work. Talk prelude and actual run-loop siblings passed 177/177.
  • Codex autoreview of the two-file local snapshot on d3ce53d was scoped-clean through P2, with no findings. The reviewed source bytes and relevant lifecycle owners remain unchanged at 8fb0cf7 after integrating fix(sessions): restore dependency checks for pending-input reads #197839.
  • Ran pnpm check:changed: three compiler stages initially refused external dependency links, and the export scan reproduced the old-main unused exports. A private frozen install resolved all three compiler stages; after integrating fix(sessions): restore dependency checks for pending-input reads #197839, production/full-tree/script export scans each report zero entries. All other selected changed-check stages passed in the original invocation.
  • Actual unmodified Matrix restart/replay proof passed in run 43299098210, QA profile 6/6 on inclusive head 7825ad2f2e3521fb095e14bfbbf3548b3723322d. The two repair files and six inspected sidecar/lifecycle/QA files match this PR head byte for byte. Artifact 13981856526 contains one passing observation with no retry, matching launch/source and observation hashes, both accepted pre/post-restart replies, and no replay. The unchanged scenario sends SIGUSR2 to the existing child with OPENCLAW_NO_RESPAWN=1; the job records no replacement spawn during the scenario.
  • Cleanup duration in that successful actual run is unmeasured: slim success artifacts and job output omit shutdown traces. There is no raw PID comparison or claim that the actual run crossed five seconds. The original real failure, exact-base controlled real-owner late-stop red/green, and actual same-process/replay/fresh-reply pass provide complementary evidence. No delay was injected into production.
  • Ordinary PR CI 43291949304 passed at exact 8fb0cf7a6d70a8bbb9ec583061cbe7943868e43a; ClawSweeper review on the same head has zero findings/open items.
  • Earlier local transport ancestry and remote native-preparation refusals happened before Gateway/payload startup (commandMs: 0 remotely); they remain setup-only evidence. The task-owned remote lease was cleaned up and its resource absence verified.

The timeout-leftover behavior dates to #185730 (9344233), before the last scheduled green. The initial slow sidecar’s cause remains unqualified; this change fixes the separately reproduced stale refusal after successful settlement. No flaky or infrastructure classification is inferred from a passing replay. Unit timings are not a controlled performance benchmark.

Let the mandatory final sidecar join own successful or failed settlement
when the early stop crosses its diagnostic grace. Preserve cleanup order,
required joins, fatal failures, and unjoined optional timeout refusal.

Exercise actual lifetime/post-ready stop owners across the grace and
prove successful release and failed-stop retention.
@clawsweeper

clawsweeper Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Nov 12, 2026
@steipete
steipete marked this pull request as ready for review November 12, 2026 19:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T19:38:51.092629Z 8fb0cf7 Draft marked ready
ℹ️ 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.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

Please review final head 8fb0cf7, including successful late sidecar settlement, failed-stop retention, and unchanged optional cleanup refusal. The PR body records completed local proof and the actual Matrix restart QA that remains mandatory before merge.

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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 Nov 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Let the mandatory final sidecar join determine whether slow but successful sidecar cleanup permits an in-process Gateway restart.

Example: A sidecar finishes stopping after 7.288 seconds, beyond the five-second diagnostic grace.

  • Before: The final join succeeds, but the earlier timeout remains recorded and the Gateway exits instead of restarting.
  • After: The warning remains diagnostic, and successful final settlement allows the restart to continue.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and source-correct, but the expressly required real Gateway restart proof remains outstanding.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: The Gateway exits during an in-process restart despite its slow sidecar cleanup ultimately succeeding.
Reason: The maintainer-authored repair restores the intended successful restart outcome while preserving refusal for failed or unfinished cleanup.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current shutdown error with a focused change that preserves failure retention and optional cleanup refusal; no actionable code defect was found.

Priority: P2
Reviewed head: 8fb0cf7a6d70a8bbb9ec583061cbe7943868e43a

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply the explicitly required exact-head isolated Matrix SIGUSR2 run showing cleanup beyond five seconds, successful final settlement, and a ready Gateway in the same process, with credentials and non-public endpoints redacted.
Agent review details

How this fits together

The Gateway shutdown coordinator runs ordered cleanup steps, joins sidecar owners, and reports cleanup outcomes to the CLI loop that decides whether the runtime can restart.

flowchart TD
  A[Restart request] --> B[Ordered Gateway shutdown]
  B --> C[Sidecar stop owners]
  C --> D[Five second grace warning]
  D --> E[Mandatory final sidecar join]
  E --> F[Gateway resource close]
  F --> G[CLI restart decision]
Loading

Technical review

Best possible solution:

Keep final settlement with the existing sidecar owners and treat only their successfully joined early timeouts as diagnostic.

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

Current-main source deterministically preserves the timeout leftover after successful final settlement; the PR reports matching regression and scheduled QA failures, but this read-only review ran no target code.

Is this the best way to solve the issue?

The patch corrects outcome classification at the existing coordinator without weakening required joins, changing cleanup order, or introducing a competing cleanup owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0001c18108e9.

Provenance checked

  • Bounded sidecar cleanup and retained-runtime refusal changes intended behavior with a stated reason (9344233: Bound process-owned cleanup and prevent unsafe reuse when resources remain retained.)
  • Required joins preserve accepted-write lifetime keeps the original intent (4e55843: Diagnostic grace must not release Gateway state admission while accepted persistence is still running.)
  • Final resource retirement after slow settlement keeps the original intent (e32051e: Keep final cleanup joins mandatory so late finalizers can settle before database retirement.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Focused introduced change: Only the lifetime and post-ready sidecar steps are exempted from permanent timeout leftovers; required joins, rejection handling, and other optional cleanup remain intact. (src/gateway/server-shutdown.ts:194, 8fb0cf7a6d70)
  • Production ownership matches the exemption: The lifecycle coordinator joins both exact sidecar owners with Promise.allSettled and propagates failure; each owner preserves rejected handles and rejects final settlement while cleanup remains incomplete. (src/gateway/server-lifecycle.ts:511, 8fb0cf7a6d70)
  • Distinct regression coverage: The added cases exercise successful and rejected late stops through the real stop owner for both affected steps; existing optional and fatal cases now use an unrelated plugin-hook step to retain their original contract. (src/gateway/server-shutdown.test.ts:23, 8fb0cf7a6d70)
  • Current main retains the defect: Fetched main still unconditionally records the early optional timeout even though its mandatory final sidecar join can later succeed. (src/gateway/server-shutdown.ts:186, 0001c18108e9)
  • Original cleanup intent: refactor: resume running sessions after graceful restarts #185730 established bounded cleanup and prohibited restarting a runtime with genuinely retained resources; this PR preserves that restriction while correcting stale timeout classification. (src/gateway/server-shutdown.ts, 9344233e7a66)
  • Recorded proof and explicit pending gate: The PR body and author discussion report red-before/green-after regression results and explicitly require actual Matrix restart QA before merge. The linked scheduled QA job failed in its smoke scenario; its downloadable logs redirected to a host blocked by the review environment, so their detailed trace was not independently inspected. (8fb0cf7a6d70)

PR surface

Source +12, Tests +55. Total +67 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 15 3 +12
Tests 1 56 1 +55
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 71 4 +67

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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A slow but successful sidecar stop can incorrectly terminate an in-process restart; the trigger is limited to cleanup exceeding its grace.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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.

  • Complete the recorded Matrix restart proof on the reviewed head.

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 November 12, 2026, 2:42 PM ET / 19:42 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Actual Matrix restart/replay proof now passes in QA job 131465840212 at inclusive head 7825ad2f2e3521fb095e14bfbbf3548b3723322d. The two repair files plus six inspected owner/QA files match PR head 8fb0cf7 exactly. Artifact 13981856526 records one passing observation, no retry, verified source/receipt hashes, both replies and no replay. The unchanged SIGUSR2/NO_RESPAWN child path and absence of a replacement spawn during the scenario establish same-process continuity.

The successful run does not retain shutdown timing or raw PID traces, so it does not demonstrate a measured >5-second cleanup. That causal boundary is covered separately by the original real failure and exact-base real-owner late-success/late-rejection regression. No production delay was injected. The PR body now records this distinction and the completed actual-flow proof; exact-head ordinary CI and ClawSweeper remain green with zero open findings.

@steipete
steipete merged commit 4fe2693 into main Nov 12, 2026
218 of 219 checks passed
@steipete
steipete deleted the fix/2430-sidecar-restart branch November 12, 2026 20:42
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 13, 2026
Let the mandatory final sidecar join own successful or failed settlement
when the early stop crosses its diagnostic grace. Preserve cleanup order,
required joins, fatal failures, and unjoined optional timeout refusal.

Exercise actual lifetime/post-ready stop owners across the grace and
prove successful release and failed-stop retention.
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
Let the mandatory final sidecar join own successful or failed settlement
when the early stop crosses its diagnostic grace. Preserve cleanup order,
required joins, fatal failures, and unjoined optional timeout refusal.

Exercise actual lifetime/post-ready stop owners across the grace and
prove successful release and failed-stop retention.

(cherry picked from commit 4fe2693)
Source-x: 4fe2693
Backport scope: src/gateway/server-shutdown.ts mark only the two sidecar steps joinedByLateSidecarCleanup and leave their final outcome to existing required late join; preserve genuine failed stops/optional leftovers and dependency order.
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit a2ca45f2fcb49f98b00768aa92909aef100f1c28)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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