Repository navigation
fix(cron): park a cancelled delete_after_run one-shot - #25130
Conversation
A user cancel parked a plain one-shot "at" job but left a delete_after_run one, which is every one-shot the dashboard, the CLI and MCP create, to the failed-run auto-pause in _execute_with_timeout. That pause only reaches a run whose payload started. A cancel that lands earlier, in the fire-time gate or before the run task's first step, left the job enabled with its due time passed, so the next tick ran the job the user had just cancelled. Cancel now parks every one-shot. The store merge already parks any "at" job it is asked to, so nothing else changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Problem / Motivation edited at the author's request: it now walks through the user flow that leads to the bug (schedule a one-shot on the dashboard, Cancel it while its run waits in the fire-time gate, and the next tick runs it anyway). The Goal line, Why it matters and Not a goal are unchanged. |
|
Problem / Motivation corrected at the author's request: the user flow now starts where a one-shot is actually created (the agent's |
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS The one-condition change fixes the root cause: the cancel path stopped leaving the park to an auto-pause that only runs after the payload has started. Notes
[DESIGN-REVIEWED] 8786eb3 Description read[DESCRIPTION-READ] c40fd9b83df520b0698401bb34e9fd7375e98063cd7be5087300a70ce13b996a That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix is one condition removed at the point that causes the bug. It has a linked issue (#25128) and a test that fails on base. The one other site with this root cause, the reaper at What this change shipsInventory (4 items) — 4 justifiedIntent: a one-shot job the user cancels before its payload starts must never run. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 8786eb3 Description read[DESCRIPTION-READ] d40f4c998366d0a7d4d01ae2aac9bd796905e6a4223955548ac75c4103e6772b That sha256 names the PR description this verdict read. Recompute it with |
|
How this bug was found: a Lean counterexample The promise under test: once a user cancels a one-shot job, no scheduler tick dispatches it again. A Lean 4 model of the one-shot lifecycle (dispatch, fire-time gate, run, cancel, reap, store merge, each event one atomic step) states it as a theorem. For the current code it is false for /-- What a trace ends with: payloads started, dispatches, and whether the user cancelled. -/
def outcome (fixed : Bool) (dar : Bool) (es : List Ev) : Option (Nat × Nat × Bool) :=
(run fixed (init dar) es).map (fun t => (t.payloads, t.dispatches, t.userCancelled))
theorem bug_cancel_in_gate_runs_anyway : outcome false true cancelInGate = some (1, 2, true) := by
decide
The counterexample: /-- A user cancel that lands while the fire-time gate is awaited: `run_never_started` is set,
so the finally does not auto-pause, and cancel() does not park a delete_after_run job. The
next tick dispatches it again and its payload runs, after the user cancelled it. -/
def cancelInGate : List Ev :=
[tick, firstStep, enterExecute, cancelTake, cancelFinish, runFinally,
tick, firstStep, enterExecute, gatePass]
In the model, cancel's park decision is |
|
@bolichen97 thanks for the review. The only red check left is Internal Content Scan, and it has no verdict: its run was cancelled before the scan finished (https://github.com/kirodotdev/KiroCrew/actions/runs/40630087615). I have read-only access, so I can't re-run it. Could you re-run that job? PR Readiness should pick up the result on its next sweep. |
Problem / Motivation
Goal: A one-shot cron job the user cancels before its payload starts never runs, including the
delete_after_runone-shots the dashboard, the CLI and MCP create.A one-shot (
at) job withdelete_after_runruns anyway after a successful Cancel, when the cancel lands before its payload starts: while the run waits in the fire-time gate, or between the tick that dispatched it and the run task's first step. The job stays enabled with its due time passed, so the next tick dispatches it again and the payload runs. A plain one-shot cancelled at the same moment is parked and stays stopped.How a user runs into it:
cron_addtool (kirocrew cron add --atmakes the same kind). Every one-shot made this way isdelete_after_run: it is meant to remove itself after it runs.Why it matters
Cancel is how a user stops a one-shot they no longer want: a message to a channel, an agent turn with side effects. Here Cancel reports success and the action happens anyway, seconds later. Every one-shot the dashboard, the CLI and MCP create is
delete_after_run, so this is the common shape, not an edge setting.Not a goal
_force_reap): a reapeddelete_after_runone-shot whose run had already finished can still run twice. Open PR fix(cron): fence scheduled terminal settlement #9038 changes that settlement; this PR leaves it alone.user_pausedversusauto_pausedsemantics, and the cancel notification text.What changed (motivation → approach → change)
A cancelled one-shot is now parked whatever its
delete_after_runsetting, so the next tick does not run it.Symptom → cause.
cancel()incron_service/service/run_teardown.pyparked a one-shot only when it was notdelete_after_run, and left thedelete_after_runones to_execute_with_timeout's failed-run auto-pause. That pause runs only for a run whose payload started and failed. A cancel that lands earlier leaves the job enabled, andis_duetreats anatjob whose time has passed as due whateverlast_run_tssays.Change.
cancel()parks everyatjob._merge_terminal_state_lockedalready parks anyatjob it is asked to, so the one condition is the whole change: the job endsenabledfalse anduser_pausedtrue, the same park a cancelled plain one-shot gets today.The cron spec (
learn-cron-dashboard.md) states the same rule: a user cancel parks every one-shot, whatever itsdelete_after_runsetting.Backwards compatibility
Compatible: a cancelled
delete_after_runone-shot is kept and parked instead of left due; nothing that works today stops working.Removes nothing: the cancelled job is kept, parked the way a cancelled plain one-shot already is; no record, key, field or path is removed.
Tests
test_one_shot_cancelled_before_its_run_starts_does_not_run[False]and[True](test/test_cron_cancel.py): a cancel between the tick and the run task's first step. The next tick does not dispatch the job, its payload never runs, and a reloaded service finds it disabled anduser_paused.test_cancelled_one_shot_does_not_run_againsays why a mid-run cancel of adelete_after_runone-shot stays out of that test: the failed-run auto-pause races the cancel's store write, so its flags are not fixed.Proof: PROVEN test/test_cron_cancel.py::TestCancelledOneShotIsParked::test_one_shot_cancelled_before_its_run_starts_does_not_run[True] (head 8786eb3)
Determinism, on the two new node ids and the file they live in:
-n0: 20/20 green.test/test_cron_cancel.py(57 tests) at-n 4 --dist loadgroup --max-worker-restart=2: 10/10 green.scripts/local-gate.py: the related backend tests (477) and the related frontend set (410 files) pass.Manual verification
delete_after_runjobs and produced the event sequences that break it. The two deterministic ones were then reproduced on the realCronService, as below. The model is not part of this PR.CronServicewith adelete_after_runjob: a cancel while the run waits in the fire-time gate, and a cancel before the run task's first step, both left the job enabled, and the next tick dispatched it and ran its payload once more. Plain one-shots in the same scenarios stayed parked. The fire-time gate case takes the samecancel()branch the new test covers.Related Issues
Closes #25128
Sibling sweep
Swept: git grep -n "park_one_shot = " -- src/
Sibling: src/kiro_crew/cron_service/service/run_teardown.py:293 -- tracked in #9038
Pattern harvest
Not generalizable: one exclusion in one predicate, where the cancel path handed a required park to a pause whose precondition (the payload started) it cannot assume.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.