Repository navigation
refactor(gateway): schedule durable session delivery retries - #159275
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 26, 2026, 8:25 PM ET / September 27, 2026, 00:25 UTC. ClawSweeper reviewWhat this changesRoutes delayed session recovery and durable delivery retries through the shared Gateway scheduler, with tests for clock changes and stale reads. Merge readiness⛔ Blocked before merge - 3 items remain Current main still uses private session-delivery timers, so this PR remains useful. The scheduler cutover has focused test coverage, but the required isolated Gateway restart-delivery proof is not yet shown. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway stores pending session deliveries in SQLite. Startup recovery and retry scheduling read those rows, then pass eligible entries to the existing delivery and settlement path. flowchart LR
A[Pending SQLite rows] --> B[Startup recovery]
B --> C[Gateway scheduler]
C --> D[Reload current row]
D --> E{Retry eligible?}
E -->|Yes| F[Deliver and settle]
E -->|No| C
Before merge
Agent review detailsSecurityNone. PR surfaceSource +11, Tests +113. Total +124 across 4 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Use the shared Gateway scheduler for wake timing while SQLite retains claim, retry, and settlement authority, with restart recovery verified for the original non-main session. Do we have a high-confidence way to reproduce the issue? Not applicable: this is an internal scheduling refactor, not a reported defect. Current main's private-timer path is visible in source. Is this the best way to solve the issue? Yes: the existing scheduler's merged earliest-deadline mode provides a narrow timing owner while the queue retains delivery decisions; the Gateway recovery composition still needs proof. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ea2a69fe6891. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
What Problem This Solves
Session-delivery retries currently own native timers separately from the Gateway scheduler. Move the pending-row retries, failed-scan retry, and delayed startup recovery onto the kernel scheduler, with a required dependency throughout the production constructor path.
The queue remains authoritative for claim deadlines, retry eligibility, settlement and persistence. A pending read uses the scheduler's approved earliest-deadline mode, keeping an earlier elapsed wake even if the wall clock moves backward or a stale claimed-row read finishes later. Active drains still coalesce duplicate requests, retry unchanged pending rows no faster than the existing retry floor, and join admitted reads and settlement writes on shutdown. There is one scheduler instance per Gateway process; required dependencies enforce injection through these paths.
Delete the native timer handles, their unref/clear plumbing and the leaf's duplicate earliest-deadline bookkeeping. Tests use the shared injected scheduler clock, including real-store backward-clock and delayed stale-read regressions.
User Impact and Update Behavior
Update behavior: existing rows, claim and retry timestamps, external delivery behavior, configuration and ports retain their contracts. Boot recovery reads the existing owning store; no new persisted schedule or migration is added. The deliberate timing change is that wall-clock forward jumps can shorten a retry wake, while a backward correction cannot postpone an earlier elapsed wake. Every wake reloads the owning row and checks current wall-time eligibility before delivery. No storage schema, config or SDK contract changes.
Scope and Stack
LOC: production +97/-86/net +11; tests +224/-111/net +113; docs +0/-0/net 0. The 518 changed lines include the complete typed constructor cutover and replacement of the original timer-driven tests; splitting these would leave dead code or two timing owners.
Stack: follows earliest-deadline contract #159260. The preceding media maintenance #159126 is merged; system-job retries #159129 are independent. Next: update watcher, update campaign, diagnostic/CLI/SDK, auth pruning, MCP preparation/cutover, then final docs and live proof. Earlier stack links are in the predecessor bodies.
Evidence
Proof: provider
blacksmith-testbox, leasetbx_01m3fqja9r983kwbphpb3v3g5g, run 36270738491. Afterpnpm install --frozen-lockfile, each file ran withpnpm test <file> --maxWorkers=1:src/infra/session-delivery-queue-runtime.test.ts: 21 cases passed, 31.429 s wall.src/infra/session-delivery-queue.recovery.test.ts: 22 passed, 17.073 s.src/gateway/server-runtime-services.test.ts: 37 passed, 10.370 s.All 80 cases passed in 58.872 s. The two negative controls restored wall-only timing and replace semantics respectively: each failed its intended delivered-once assertion (zero deliveries), in 18.167 s and 18.293 s. Candidate source was restored and verified. Exact proof tree
e08176b6a808af51bade9afedd893d2c49c20865; publication preserves all four reviewed/proved files byte-for-byte on fresh main, including the landed scheduler prerequisite. Required GitHub ci-gate replaces a separate check-changed invocation for this stack.Review: deslop removed the redundant dueAt state and pre-schedule cancellation; Full-diff Codex P2 review and the subsequent one-line assertion delta review are both scoped-clean, with no accepted/actionable findings. Final stack proof will exercise an isolated Gateway, cron, SIGSTOP/SIGCONT, durable restart and budgeted SIGTERM against merged main.
Remote failure record: the first earliest-mode owner run passed 20 of 21 cases. The forward-clock test required nextWakeAtMs to equal now, while earliest mode correctly retained an already-overdue deadline. Only that assertion now checks due <= now; the zero host delay, delivered-once and empty-queue checks remain. Both new clock/stale-read regressions passed on that first run. The corrected 21-case suite and all 59 sibling cases passed in the proof above.