Repository navigation
fix(cron): consume resume drain failures instead of crashing the gateway - #172273
wangmiao0668000666 wants to merge 1 commit into
Conversation
|
Codex review: needs real behavior proof before merge. What this changesThis PR catches failed cron queue drains during scheduling resume and logs the failure. Example: A Gateway resumes scheduling with a queued cron request while its state database reports “cron state database is damaged.”
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 1 item remains This PR fixes a concrete rejection-handling gap still present on main, and no introduced correctness defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherGateway suspension handlers resume CronService scheduling, which asks the worker-owned durable queue to activate pending runs. flowchart TD
A[Gateway resume request] --> B[Suspension coordinator]
B --> C[CronService resume]
C --> D[Worker queue drain]
D --> E[Pending cron launches]
D --> F[Failure warning]
Technical reviewBest possible solution: Keep rejection containment at the resume boundary and retain one focused regression through the Gateway handlers. Do we have a high-confidence way to reproduce the issue? Source establishes the path from scheduling resume through a rejecting worker drain to the fatal process handler; contributor-reported regression controls support it, but this review ran no target code. Is this the best way to solve the issue? Observing the background promise at its caller is the smallest appropriate repair and follows the existing queue-wake contract without changing database recovery policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1a86e3e08fe8. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +2, Tests +237. Total +239 across 3 files. Added test files: 1. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 14, 2026, 12:38 PM ET / 16:38 UTC (Revision 2). |
resumeScheduling() fired drainCronRunQueue() without a catch, so a failed drain (store busy, a just-restarted worker, a damaged state database) escaped as a process-level unhandled rejection. Transient store errors are already classified non-fatal by the rejection handler, but a non-transient drain failure reaches the process-exit path. The wake path already guards the same call the same way. Co-Authored-By: Claude Code <[email protected]>
3ea3d7d to
a899b53
Compare
|
@clawsweeper re-review Revision 2 addresses the R1 findings:
Verification (server):
|
|
🦞👀 Re-review progress:
|
|
Closing after the round limit. The patch itself is sound — ClawSweeper rates patch quality 🐚 platinum hermit with zero findings, and the defect is real and still present on current main ( Producing that requires a packaged build plus a heavy orchestration (saturating the queue so a drained row exists, then forcing a non-transient worker/store failure during resume). Three review rounds narrowed the gap to proof-only, but that evidence was not reachable in this environment within the round budget. The branch Thanks to ClawSweeper for the careful reviews. |
What Problem This Solves
resumeScheduling()(src/cron/service/ops-lifecycle.ts:73) fireddrainCronRunQueue(state)as a floating promise with no rejection handler. When that drain fails non-transiently (for example a damaged shared-state database), the rejection escapes to the process-levelunhandledRejectionhandler, which treats it as fatal and exits the Gateway.Scope note: transient store failures such as
SQLITE_BUSY/SQLITE_CANTOPENare already classified non-fatal bysrc/infra/unhandled-rejections.ts:288-309(isTransientUnhandledRejectionError). The crash path this PR closes is the non-transient one; the reproducer below uses exactly such a failure.The same call is already guarded on the wake path (
src/cron/service/run-queue-wake.ts:42-45), which catches the identical rejection and logscron: queue drain delayed. The resume path was missing that guard.User Impact
Why This Change Was Made
One line: attach the same
.catchthe wake path already uses. No behavior change on the success path, no new config, no API surface.Evidence
Signal path — full chain (source verified)
src/gateway/server-methods/suspend.tsresumeScheduling: () => context.cron.resumeScheduling()src/infra/gateway-suspend-coordinator.tsentry.resumeScheduling()after a held suspensionsrc/cron/service.tsCronService.resumeScheduling()src/cron/service/ops-lifecycle.tsvoid drainCronRunQueue(state)— no.catchsrc/cron/service/run-queue.tslockedsrc/cron/service/run-queue-wake.tsvoid drain().catch(… "cron: queue drain delayed")Gateway suspend/resume proof (new test)
src/gateway/server-cron-suspend-drain.test.tsdrives the real Gateway suspension handlers (gateway.suspend.prepare→gateway.suspend.resume) through the real coordinator with a realCronServiceand its state worker: 8 concurrency-blocking runs occupy the queue, a 9th request stays queued, the shared-state database is latched as damaged, then the suspension resumes. It asserts the Gateway logscron: queue drain delayed, records nounhandledRejection, and still answersgateway.suspend.statusafterwards.Control-red (guard reverted on the same tree): the test fails — the warning is never logged and the rejection escapes instead of being observed.
Cron regression test
src/cron/service.run-queue.test.ts→ "consumes a resume-scheduling drain failure instead of tripping the fatal unhandled-rejection path" (no fixed sleeps; it waits on the observed drain completion).Control-red: reverting the one-line guard makes this test fail with
[ Error { "message": "cron state database is damaged" } ]where[]is expected.Lint / format
Related precedent: #169525 fixed the sibling unhandled-rejection path for recovered cron jobs.
🤖 Generated with Claude Code