Repository navigation
fix(cron): prevent stale outcomes after same-millisecond restarts - #127003
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 3:53 AM ET / 07:53 UTC. ClawSweeper reviewWhat this changesThe PR makes cron task rows and restart recovery use the durable receipt UUID as the primary run identity, while retaining a manual public run ID as a suffix. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readinessThe patch correctly binds restart recovery to the durable receipt and covers the same-millisecond and legacy ambiguity cases; no actionable defect was found. It should remain open for protected maintainer review; likely related person: steipete (high confidence). Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherCron admission creates a receipt and task-ledger row for each job execution. Gateway restart recovery reads those records to restore a completed outcome or record an interrupted one. flowchart LR
A[Cron job] --> B[Run admission]
B --> C[Durable receipt]
B --> D[Task ledger row]
C --> E[Restart recovery]
D --> E
E --> F[Job history and status]
Decision needed
Why: The alternative is silently attributing an older successful task row to a different receipt; choosing that upgrade policy is maintainer-owned. Before merge
Agent review detailsSecurityNone. PR surfaceSource +30, Tests +134. Total +164 across 6 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the durable receipt as the sole recovery owner, preserve manual public IDs only as suffixes, and report historically ambiguous pre-upgrade rows as interrupted. Do we have a high-confidence way to reproduce the issue? Yes—current main’s timestamp/prefix task lookup and the PR’s same-millisecond regression scenario provide a high-confidence source-level reproduction path. Is this the best way to solve the issue? Yes—the durable receipt is the owner-native record, so threading it through task creation and recovery is narrower and safer than ranking timestamp-matched rows. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 378e45a6052d. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
f8368ec to
06f1322
Compare
06f1322 to
084bf31
Compare
Preserve receipt-less legacy matching, but fail closed when an active receipt has only an ambiguous pre-upgrade task identity. Amp-Thread-ID: https://ampcode.com/threads/T-01a0220e-6236-745d-8b14-759d26595b12
084bf31 to
743bf7e
Compare
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
Preserve receipt-less legacy matching, but fail closed when an active receipt has only an ambiguous pre-upgrade task identity. Amp-Thread-ID: https://ampcode.com/threads/T-01a0220e-6236-745d-8b14-759d26595b12 Co-authored-by: Amp <[email protected]>
What Problem This Solves
Fixes an issue where a cron run interrupted by a Gateway restart could be reported as successful when another run for the same job began in the same millisecond and had already finalized its task row.
Why This Change Was Made
Cron receipts already provide the durable execution owner, but task identity and restart lookup still accepted any same-job/same-start candidate. Receipt-backed task IDs now put the receipt UUID first (
cron:<job>:<startedAt>:<receiptId>[:<publicRunId>]), and receipt-backed recovery accepts only that exact owner-native prefix. Receipt-less legacy recovery keeps its existing broad matching.Pre-upgrade caller-ID-only and reservation-keyed task rows do not encode receipt ownership. When one is paired with an active receipt, the states “this receipt finalized before crashing” and “an earlier receipt finalized, then a same-millisecond receipt crashed” are durably indistinguishable. The approved compatibility policy is fail closed: report that rare ambiguous upgrade-window state as interrupted rather than guess and silently attribute stale success. No schema, protocol, or version change is required.
Provenance: broad execution-start recovery came from #114820 (
6ca7c6488ed9), while durable receipts came from #122948 (d3308e2cfd9d); composing timestamp-level task lookup with receipt-level ownership exposed this gap.User Impact
Current runs and unambiguous receipt-backed recovery preserve the exact finalized outcome. Genuinely ambiguous pre-upgrade in-flight manual runs are conservatively reported as interrupted after restart instead of potentially showing another run’s success.
Production LOC: +44/-14 (net +30) | Tests: +159/-25 (net +134)
Evidence
lastRunStatus: "ok"; manual identity/fallback regressions could not find a receipt-prefixed terminal row (4/4 failures).node scripts/check-changed.mjs: passed, including core/test typechecks, type-aware lint, formatting, dead exports, import cycles, schema, database-first, and dependency guards.pnpm build: passed on the exact published head.a09b58d8-c729-4dd7-b2d2-a48d5a7d403fand exact receipt-keyed task row, was abruptly SIGKILLed, then recovered after supervised Gateway restart with the receiptinterrupted, the taskfailed,running_at_mscleared, and the job/history markederror; no provider, model, channel, or inherited credentials were used.Published head:
743bf7e4f95bc20d518ddd360c3c9da9e75642e9Tested parent/main cutoff:
3a759c85c5862b4d95c6d873b3e33c544ee14827Live base tip at publication:
378e45a6052d0ae840e9998e5f1bb61cc211f69dHead tree:
c6f4731a4efeb7dfb942010a714abc84059c1f0c