Skip to content

chore(gateway): guard admitted cron work during shutdown - #158080

Merged
roboclaw-bot merged 1 commit into
mainfrom
fix/gateway-queued-heartbeat-shutdown-20260925
Sep 25, 2026
Merged

roboclaw-bot merged 1 commit into
mainfrom
fix/gateway-queued-heartbeat-shutdown-20260925

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Existing shutdown coverage can miss an early return from the real cron drain while admitted work is still running.

User Impact

No user-visible or production change. This is now a test-only supplement to @steipete’s landed heartbeat-first fix, 24babfe9. Main’s shutdown ordering and all existing tests remain unchanged; the earlier competing production hunk is removed.

Why This Change Was Made

Main’s queued-heartbeat regression supplies a cron drain callback. This additional test exercises the real Gateway cron.stopAndDrain owner with an admitted isolated sibling. It checks that queued heartbeat settlement does not allow shared state to retire before the sibling’s actual core finishes, and that shared state closes exactly once afterward.

It reuses the existing close fixture, with no Gateway/server boot, new production seam, retry, sleep, worker policy or deadline. The unchanged 10-second drain budget is not claimed to provide indefinite protection.

Contributor credit: requested by and co-authored with @vincentkoc. The production ordering fix was independently landed by @steipete.

Work sessions

Evidence

  • Distinct negative control: changing only the real cron join’s timeout argument to zero leaves main’s existing queued test passing, but this supplement fails because Gateway close returns before the admitted sibling finishes. The heartbeat-settlement assertion passes first; this is not a test timeout. The disposable mutation was restored and hash-verified.
  • Positive: final supplement 1/1 passed, 30 ms test body, 27.407 s wrapper wall; main’s queued test plus seven affected siblings 152/152 passed, 37.451 s wrapper wall. Wrapper time includes native-worker preparation.
  • Runtime/compiler/tests/checks ran in rootless Podman with network disabled, private PID namespace and task-only HOME/state, on Node 24.19.0 / pnpm 12.4.2. No operator credentials, host services, sockets or ports were exposed.
  • Applicable changed-file gates completed: 19 initial checks passed; the sole missing pinned Knip cache was prepared separately through the public registry, then all three canonical dead-export scans passed offline in 63.184 s. Type-aware lint passed with zero warnings/errors. No skip flag or network-enabled check fallback was used.
  • Independent P0–P2 review found and corrected the missing eventual-retirement assertion and failure-sensitive global cleanup. Final review is scoped-clean.
  • The original queued-waiter negative remains applicable by verified owner-blob identity; main differs in the landed shutdown order. No duplicate old-order replay was counted.

Hosted qualification: ready-event CI 36145105507 passed (44 jobs: 23 successful, 21 skipped). The actual regression passed 1/1 in 35 ms; Vitest 39.76 s, test step 43 s, job 83 s, including 19.031 s worker preparation. Completed exact-head ClawSweeper review found no actionable issues or before-merge items. Required CI/dependency/sensitive-review gates passed.

Historical qualification limit: Prior checks and the partially completed updater proof belong to superseded production candidate 46d5943, not this test-only revision. Its larger updater cell was safety-stopped; it is not being relabeled green or repeated. No claim that RoboClaw’s alternative production ordering landed, or that full-main CI has recovered.


View the OpenClaw team session

@clawsweeper

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

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 25, 2026 10:49
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Sep 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 10:16 AM ET / 14:16 UTC (Revision 5).

ClawSweeper review

What this changes

Adds a Gateway shutdown test that checks queued heartbeat settlement and keeps shared state open until an admitted cron job core finishes.

Merge readiness

✅ Ready for maintainer review

Keep open. Main has the heartbeat-first shutdown fix, but its existing regression uses a supplied cron drain callback. This branch adds distinct coverage for the real drain, and the competing production-order change identified in the prior review is absent.

Priority: P2
Reviewed head: 49c998bc9b515c9545b9a70f53a8357bd53a0e22

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary regression with a reported negative control and no identified patch defect earns a normal good rating.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The supplied repository state identifies a member-authored bot PR, so the external-contributor proof gate does not apply. The branch changes only a test; its reported isolated run and negative control support the test's distinct production-owner coverage, while the earlier updater run belongs to a superseded head. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a member-authored bot PR, so the external-contributor proof gate does not apply. The branch changes only a test; its reported isolated run and negative control support the test's distinct production-owner coverage, while the earlier updater run belongs to a superseded head. No stored-data contract changes.
Evidence reviewed 7 items Introduced test: The pinned introduced diff adds only this test. It calls Gateway close with a real built cron service, holds a sibling core open, and checks that shared state retires after the drain.
Current shutdown order: Current main stops the heartbeat runner before calling cron stopAndDrain; the checkout and fetched-main production files are identical.
Real cron drain: The Gateway cron service aborts active task runs and waits for their settlement within its existing drain budget.
Findings None None.
Security None None.

How this fits together

The Gateway coordinates heartbeat wakes and scheduled cron jobs during restart. Shutdown settles queued wakes, drains admitted cron work, and then retires shared state.

flowchart LR
  A[Restart request] --> B[Gateway shutdown]
  B --> C[Heartbeat wake queue]
  C --> D[Cron stop and drain]
  E[Admitted job core] --> D
  D --> F[Shared state retirement]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +160. Total +160 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 160 0 +160
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 160 0 +160

Review metrics

Metric Value Why it matters
Reported test cost 30 ms test body; 27.407 s wrapper wall The PR reports that the fake-time shutdown scenario is cheap to execute, while native-worker preparation dominates its wrapper time.

Technical review

Best possible solution:

Retain main's heartbeat-first shutdown order and add the focused real-cron regression at the Gateway close boundary.

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

Yes, for the coverage gap: current source shows that main's test supplies a drain callback while production cron joins active runs. The contributor reports a distinguishing negative control; I did not independently execute it.

Is this the best way to solve the issue?

Yes. The test exercises the existing close and cron owners without adding a production seam or changing the landed shutdown order.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 supplied repository state identifies a member-authored bot PR, so the external-contributor proof gate does not apply. The branch changes only a test; its reported isolated run and negative control support the test's distinct production-owner coverage, while the earlier updater run belongs to a superseded head. No stored-data contract changes.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 availability: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The test protects a bounded Gateway restart reliability invariant without changing production behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 supplied repository state identifies a member-authored bot PR, so the external-contributor proof gate does not apply. The branch changes only a test; its reported isolated run and negative control support the test's distinct production-owner coverage, while the earlier updater run belongs to a superseded head. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • roboclaw-bot: 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 (4 earlier review cycles)
  • reviewed 2026-09-25T10:56:07.471Z sha 46d5943 :: blocked before merge. :: none
  • reviewed 2026-09-25T11:37:35.147Z sha 46d5943 :: blocked before merge. :: none
  • reviewed 2026-09-25T13:04:57.283Z sha 46d5943 :: blocked before merge. :: none
  • reviewed 2026-09-25T13:36:56.732Z sha 46d5943 :: blocked before merge. :: [P1] Remove the competing shutdown order before rebasing

@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

New same-head lifecycle evidence for 46d594317b6967b2e7b642e9cf64a4767008c827. Please reassess the published-driver × candidate requirement against the completed first-hop boundary below, alongside the existing real queued-owner regression. The larger selected cell did not pass; its safety stop and unfinished assertions are explicit below.

Completed published-driver update/restart

Executed the unchanged legacy-operator-state × auto-auth harness from Tooling 36def8be398b15248fb7fc05d51617fa40f7aae6 in secretless rootless Podman, using its actual canonical selective mounts, private PID/network namespaces, and synthetic service manager controlling real Gateway processes. Node 24.19.0 / npm 11.17.0. No live Team Gateway or operator state was mounted or changed.

Observation Verified result
Published driver [email protected], commit eb377ac59e6c9fd6c7705028034812becf00271b; 10,824 installed immutable entries matched its published tarball
Actual updater process PID 4245 exited 0, JSON status: ok, 209.271 s; all 13 update steps exited 0; restart source baseline-update
Installed candidate Exact commit 46d594317b6967b2e7b642e9cf64a4767008c827; 10,977 installed immutable entries matched the verified candidate tarball
Same-version identity Both packages are 2026.9.6, but commit, buildId and payload changed; this was not the later already-current no-op
Actual Gateway replacement Child PID 3863 → 11074; supervisors 3849 → 11066. These are container-namespace PIDs, not host PIDs
Candidate service verification New buildId, serviceRunning: true, readyz: true, settled: true, pluginErrors: []
Public endpoint observations /healthz HTTP 200; /readyz HTTP 200; authenticated operator.read RPC returned the candidate buildId
Additional completed phases Migration, first-hop cron ownership, state/config survival, plugin recovery and a synthetic chat turn
Shutdown after safety stop Candidate active-work drain settled; clean shutdown 407 ms, actual child exit 0; custody retired to zero and all task containers removed

Source/package bindings:

published tarball sha256: 1a7355691bc0e605222ba818f1f72c1787253c78dfeb0df6be2086ec73b71e63
candidate tarball sha256: 4e31dd54c47ed0b553af63f2fa995711dad9f6016dacf63a37a8e1e8d1cad783
registry manifest sha256: 194e5abf5a52585dd4b417964f8e69ec5e362540a35679a50d89d8d8eb4c09b1
candidate buildId: 2026.9.6-46d594317b69-2026-09-25T11-50-01.444Z

Safety stop and proof limits

@vincentkoc — the canonical fixture mocked chat routing but left memory embeddings at a real OpenAI endpoint. Unexpected embeddings requests used an invalid synthetic fixture credential and received HTTP 401; retrospective baseline logs showed the same behavior. No production credential was available. The owned run was stopped immediately on discovery, with no retry or policy workaround. Further runtime execution is paused pending a hermetic fixture.

The harness/container exited 143 during the later no-op assertion, after the first-hop updater had already succeeded. No-op completion, final Doctor checks and rollback restoration remain unproven; only backup creation was verified. Generic clean shutdown and cron ownership migration/survival are observed, not a separate queued-heartbeat or explicit cron-close runtime oracle. The exact-candidate 17 ms CI regression remains the separate proof that queued heartbeat settlement unblocks the drain while admitted sibling work stays joined. Do not count the aggregate cell as green or infer a missing oracle.

Sanitized receipts, exact commands, payload inventories, custody and cleanup evidence are retained in the verification work session. This comment records the narrow passing boundary and the remaining gaps; no merge or full-main recovery is claimed.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@roboclaw-bot
roboclaw-bot marked this pull request as draft September 25, 2026 13:30
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Current-main reconciliation: I verified that @steipete’s 24babfe94446197e4d9dd35dac8a14556943d7f5 is on main and already repairs queued heartbeat settlement with heartbeat-first shutdown. I am retaining that landed ordering, not replacing it with this branch’s alternative.

The competing production hunk in this PR will not land. I am checking only whether the existing regression adds distinct coverage: real Gateway cron stopAndDrain, an already-admitted sibling core, and shared-state retirement staying joined. Main’s new queued-wake test uses a supplied drain callback, so those additional ownership checks may still be useful. Production source remains byte-identical to main in the reconciliation checkout.

This PR is draft while that explicitly test-only scope is qualified. Any rewritten head will require its own normal CI/review. The earlier CI and published-updater receipt belong to the original 46d5943 candidate and are not being relabeled as proof of a rewritten head. The updater harness remains paused after the disclosed embeddings safety stop; this reconciliation permits only isolated, network-disabled unit verification—not another updater run.

No merge or full-main recovery is claimed.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 25, 2026
Retain main heartbeat-first ordering from 24babfe. Add distinct real stop-and-drain coverage proving a queued heartbeat settles while an admitted sibling remains joined before shared state retirement; assert eventual retirement and unconditional fixture cleanup.

Co-authored-by: vincentkoc <[email protected]>
@roboclaw-bot roboclaw-bot changed the title fix(gateway): prevent restart stalls on queued heartbeat work chore(gateway): guard admitted cron work during shutdown Sep 25, 2026
@roboclaw-bot
roboclaw-bot force-pushed the fix/gateway-queued-heartbeat-shutdown-20260925 branch from 46d5943 to 49c998b Compare September 25, 2026 14:03
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 25, 2026 14:04
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 25, 2026
@roboclaw-bot
roboclaw-bot merged commit 4d4c1b9 into main Sep 25, 2026
189 of 192 checks passed
@roboclaw-bot
roboclaw-bot deleted the fix/gateway-queued-heartbeat-shutdown-20260925 branch September 25, 2026 14:25
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
…8080)

Keep main’s heartbeat-first shutdown unchanged and cover the real Gateway cron stop-and-drain owner with queued heartbeat work plus an admitted isolated sibling. Assert shared state remains available until the sibling actually finishes, retires exactly once afterward, and fixture cleanup restores admission even after failure.

The targeted case, 152 affected sibling tests, applicable changed-file gates, independent P0–P2 review, and exact-head hosted CI passed. This is test-only coverage, not a replacement production ordering.

Co-authored-by: vincentkoc <[email protected]>
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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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