Skip to content

fix(gateway): await cron exit watcher drain - #126963

Merged
steipete merged 3 commits into
mainfrom
fix/cron-exit-watcher-drain
Aug 21, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/cron-exit-watcher-drain

Conversation

@steipete

@steipete steipete commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • make CronExitWatchers.cancelAll() await every cancelled watcher lifecycle, including supervised child exit and terminal persistence
  • join that settlement from the gateway cron service's existing stopAndDrain() owner boundary
  • fence same-instance restarts so a pending predecessor drains and a later stop wins before watcher admission reopens
  • cover child-wait, terminal-persistence, and service-boundary drain behavior with deterministic regressions

Root cause

cancelAll() synchronously requested cancellation but returned while cancelled slots remained in settlingCancelledSlots. buildGatewayCronService.stopAndDrain() awaited active cron task runs and stream watchers only, so hot reload could start a replacement cron service while predecessor exit watchers were still settling.

The new boundary test fails on frozen base ab2bbd42dfafb1da9ecad901caa8d2d32e3cd251 with expected true to be false: the owner drain completed before the exit-watcher drain promise. It passes with this change.

Validation

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-core.config.ts src/gateway/cron-exit-watchers.test.ts — 17/17 passed
  • node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-server.config.ts src/gateway/server-cron.test.ts src/gateway/server-cron.drain.test.ts src/gateway/server-reload-handlers.test.ts src/gateway/server-cron-lazy.test.ts src/gateway/server-close.test.ts — 370/370 passed
  • watcher settlement stress — 25/25 iterations, 50 targeted test executions passed
  • gateway drain/restart cancellation stress — 10/10 iterations, 30 targeted test executions passed
  • node scripts/check-changed.mjs -- src/gateway/cron-exit-watchers.ts src/gateway/server-cron.ts src/gateway/cron-exit-watchers.test.ts src/gateway/server-cron.drain.test.ts — passed all production/test typechecks, lint, format, policy, dead-export, and import-cycle checks

Review status

  • authenticated repo autoreview of exact head 2dc5dd8cadd2eb8205c62715f480a6ab38d4073d: TruffleHog clean; patch is correct; confidence 0.94; findings []
  • separate read-only exact-head verifier: ACCEPT with no P0-P3 findings after two accepted lifecycle-interleaving findings were fixed and re-reviewed; confirmed 370/370 related tests and repeated stress

@clawsweeper

clawsweeper Bot commented Aug 21, 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 maintainer Maintainer-authored PR labels Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

@codex review exact head d173304 for Gateway cron exit-watcher lifecycle settlement and hot-reload predecessor/replacement overlap.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

To use Codex here, create a Codex account and connect to github.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 Aug 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 20, 2026, 11:46 PM ET / August 21, 2026, 03:46 UTC.

ClawSweeper review

What this changes

The PR makes Gateway cron shutdown wait for cancelled on-exit watcher lifecycles, including child exit and completion persistence, before restart or replacement scheduling proceeds.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open: this active maintainer-authored draft repairs a real Gateway shutdown gap, and source review found no patch defect. It still needs the stated exact-head Gateway validation before becoming ready to merge.

Priority: P2
Reviewed head: 2dc5dd8cadd2eb8205c62715f480a6ab38d4073d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a coherent owner-boundary repair and focused regression coverage, with exact-head runtime validation still to be refreshed before merge.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This is maintainer-authored Gateway reliability work, so the external-contributor proof gate does not apply; the PR body nevertheless records focused after-fix terminal validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is maintainer-authored Gateway reliability work, so the external-contributor proof gate does not apply; the PR body nevertheless records focused after-fix terminal validation.
Evidence reviewed 6 items Current-main gap: Current main still cancels exit watchers synchronously and does not await their lifecycle settlement, so the reported shutdown race remains unfixed there.
Owner-boundary repair: The PR gives each watcher a settlement promise and makes the cron service include that promise in its existing stop-and-drain barrier.
Boundary regression coverage: Tests hold child exit, terminal persistence, service drain, restart, and a later stop while settlement is pending.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-server.config.ts src/gateway/server-cron.drain.test.ts

Result: FAIL (failed) — step 1 run node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-server.config.ts src/gateway/server-cron.drain.test.ts: terminal command did not produce output within 20 seconds: "node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-server.config.ts src/gateway/server-cron.drain.test.ts"

node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-server.config.ts src/gateway/server-cron.drain.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126963-IaJPgT/target$ node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-server.config.ts src/
gateway/server-cron.drain.test.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126963-IaJPgT/target

node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-server.config.ts src/gateway/server-cron.drain.test.ts












































Assertions:

  • FAIL expect_output: server-cron.drain.test.ts

How this fits together

Gateway cron owns scheduled work and process watchers. A stop or reload cancels watcher children, drains their lifecycle work, and only then permits a replacement cron service to reconcile jobs.

flowchart LR
  A[Gateway stop or reload] --> B[Cron service]
  B --> C[Cancel exit watchers]
  C --> D[Wait for child exit and persistence]
  D --> E[Complete cron drain]
  E --> F[Start replacement scheduler]
Loading

Before merge

  • Resolve merge risk (P1) - All repository check runs shown for this draft are skipped; rerun the focused exact-head Gateway suites before marking it ready to merge.
  • Resolve merge risk (P1) - The repair adds 18 production lines in a shutdown path; that growth is justified by the explicit lifecycle barrier but carries availability blast radius if its ordering regresses.
  • Complete next step (P2) - This maintainer-authored implementation is already focused; the remaining action is normal exact-head validation and draft readiness, not an automated repair lane.
Agent review details

Security

None.

PR surface

Source +18, Tests +105. Total +123 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 29 11 +18
Tests 2 110 5 +105
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 139 16 +123

Review metrics

Metric Value Why it matters
Production versus test LOC production +18 net; tests +105 net The production increase implements one lifecycle settlement contract; the larger test delta covers its child, persistence, drain, restart, and cancellation interleavings.

Merge-risk options

Maintainer options:

  1. Refresh focused Gateway proof (recommended)
    Rerun the documented watcher and cron-drain suites against head 2dc5dd8 before taking the draft out of review.

Technical review

Best possible solution:

Retain one explicit exit-watcher settlement barrier at the cron-service shutdown owner, with restart admission behind that barrier and focused lifecycle regressions proving the order.

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

Yes—current main omits the exit-watcher await, and the PR supplies deterministic boundary tests for child exit, persistence, restart, and later-stop ordering; this read-only review did not execute them.

Is this the best way to solve the issue?

Yes—the existing cron stop-and-drain owner is the narrowest canonical place to join watcher settlement, matching the sibling stream-watcher shutdown barrier rather than adding a replacement-side workaround.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 579f9b8a8a5e.

Labels

Label justifications:

  • P2: This is a bounded Gateway reload/shutdown reliability repair with limited demonstrated blast radius.
  • merge-risk: 🚨 availability: Incorrect drain ordering could allow replacement cron scheduling while predecessor watcher processes or persistence are still live.
  • 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: This is maintainer-authored Gateway reliability work, so the external-contributor proof gate does not apply; the PR body nevertheless records focused after-fix terminal validation.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the recent Gateway cron shutdown and on-exit watcher history used by this repair. (role: recent lifecycle owner; confidence: high; commits: 3616fba951f7, 74f3af9735c2, 44a5c40e11ba; files: src/gateway/server-cron.ts, src/gateway/cron-exit-watchers.ts, src/gateway/server-cron.drain.test.ts)
  • Cameron Beeley: Introduced the on-exit cron schedule and its original Gateway watcher surface. (role: feature introducer; confidence: medium; commits: 68bfa42b9bfc; files: src/gateway/cron-exit-watchers.ts, src/gateway/server-cron.ts)

Rank-up moves

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

  • Rerun the reported focused Gateway watcher and drain commands against the current PR head, then mark the draft ready when the result is clean.

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-21T03:24:26.902Z sha 2dc5dd8 :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review August 21, 2026 06:08
@steipete
steipete merged commit 8720480 into main Aug 21, 2026
306 checks passed
@steipete
steipete deleted the fix/cron-exit-watcher-drain branch August 21, 2026 06:18

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 21, 2026
* origin/main: (107 commits)
  perf(test): speed up Agents page observation polling (#127063)
  fix(android): explicitly target notification intents (#127055)
  fix(agents): preserve literal Unicode-space paths (#126797)
  fix(agents): distinguish review routing from enforcement (#126216)
  fix(ui): associate steering work by target run (#126997)
  fix(ui): collapse completed pre-steer work
  fix(codex): preserve steering transcript order
  fix(gateway): retain Bonjour cleanup on startup failure (#127062)
  fix(release): require concrete validation retry groups (#127012)
  fix(file-transfer): expose directory page tokens (#127051)
  perf: trim setup detection worker imports (#127053)
  fix(onboard): make --auth-choice help match the accepted set (#127030)
  fix(gateway): await cron exit watcher drain (#126963)
  fix(telegram): preserve direct-topic self-history (#127050)
  fix: dismiss sidebar session menu tooltip (#127044)
  perf(test): speed up pairing access polling (#127047)
  perf(cli): remove ineffective dynamic imports (#127046)
  fix(gateway): recover credential-file accounts after secrets reload (#126999)
  fix(gateway): restore scheduler-owned Gateway context (#126640)
  fix(macos): keep first-run onboarding visible after Gateway changes (#127038)
  ...

# Conflicts:
#	.github/workflows/full-release-validation.yml
#	test/scripts/full-release-validation-at-sha.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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.

2 participants