Repository navigation
fix(cron): delete run history on every caller-requested removal - #19010
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Check: if someone removes a job while it is still running, the run's later record append re-creates the history file the new seam just deleted. [DESIGN-REVIEWED] 83bbe64 Description read[DESCRIPTION-READ] 563b7957cbd60d5a47a6222ab07051cbb7387cc1474c9b699261d5e947d15524 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 |
First Principles Review (Opus 5.5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The leak is justified on symmetry with the dashboard. Its premise, "nothing reads again", is wrong: the global History view reads the deleted index rows. It also leaves an async twin with zero callers. Not justified as shipped
What this change shipsInventory (5 items) — 3 justifiedIntent: removing a cron job from any surface also cleans up its run history. FIX.
[FIRST-PRINCIPLES-REVIEWED] 83bbe64 Description read[DESCRIPTION-READ] 46dfa0837380e9aa369a045fc0635d8b9a80996416bff32d15ba0ec9869d672c That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings that block the merge. FINDING — src/kiro_crew/cron.py:2365 — the service now runs [OPUS-REVIEWED] 83bbe64 |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
bc72597 to
3d405cf
Compare
3d405cf to
1d6c93f
Compare
|
Rebased onto main 098df01 with no change to the patch (the patch-id is the same). Line references in the description's frozen sections moved with main: |
Removing a cron job through the MCP cron_remove or cron_remove_all tool, the CLI, a chat command or the apps SDK left cron-history/<job id>.jsonl and the job's index rows behind. Only the two dashboard delete routes called delete_job_history, after the service had removed the job. CronService.remove_job, remove_job_async, remove_jobs and remove_jobs_sync delete the removed jobs' history themselves through one best-effort helper, which runs in a worker thread for the async variants. The dashboard routes drop their own call, so a dashboard delete still deletes once. Automated one-shot removals keep their history: the run path appends that run's record after the removal.
1d6c93f to
83bbe64
Compare
|
This PR moves run-history deletion out of the two dashboard delete routes and into CronService's removal seam (remove_job, remove_job_async, remove_job_if_async, remove_jobs, remove_jobs_sync) through a best-effort delete_history_of, so the MCP cron_remove/cron_remove_all tools, kirocrew cron remove, chat commands and the apps SDK delete history too. One-shot removals (one_shot_path set) and remove_jobs_by_owner keep their history. The code is correct as written: I checked every remove* caller in src, and the only automated one (the gateway Done removal at slack/gateway.py:3194) passes one_shot_path and is skipped. History failures are caught, so they never fail a completed removal or lose the audit row, and the dashboard now deletes exactly once. What decides the merge is a product question the First Principles lane raised and nobody answered: the leaked rows are not dead data, because get_all_history reads _index.jsonl for the global History view. So after this change, an agent calling cron_remove (or an app removing its own job) erases that job's past runs from the user's History, where today only a human dashboard delete does. Maintainer: should an agent- or app-initiated removal erase user-visible run history, or should only a human delete do that, with the disk growth handled by a retention sweep instead? If the answer is yes, also update docs/system-specs/modules/learn-cron-dashboard.md:3223, which still says the route purges history and that the audit lands before history cleanup (Opus lane finding). — crew-pr-reviewer (deep re-check) |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (8 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: every caller-requested cron removal deletes the job's run history in the store, not only the dashboard routes; automated one-shot removals keep it; tests added.
Problem / Motivation
Removing a cron job anywhere except the dashboard leaves its run history on disk.
cron-history/<job id>.jsonland the job's rows incron-history/_index.jsonlstay behind when one of these removes a job:cron_removetool (src/kiro_crew/mcp_cron.py:3677);cron_remove_alltool (src/kiro_crew/mcp_cron.py:3693), which removes every job the calling session owns throughremove_jobs_sync(:3715);kirocrew cron remove, throughremove_job(src/kiro_crew/cli_commands.py:2292,:2295);remove_jobs(src/kiro_crew/messaging/commands.py:961) andremove_job_async(:998);remove_job_async(src/kiro_crew/apps/cron_sdk.py:633).Only the two dashboard delete routes call
delete_job_history, after the service has removed the job (src/kiro_crew/dashboard/handlers/cron.py:1025at 2ada192 and:1091).git grep -n delete_job_history -- srcfinds no other caller.Goal: a removal that a caller asks for deletes the job's run history, whichever surface asked, and a dashboard delete still deletes it exactly once.
Why it matters
Each removed job leaves one file that nothing reads again and nothing deletes.
rotate_all(src/kiro_crew/cron_history.py:717) trims each file to the per-job cap but never deletes one, so the directory grows by one file per removed job for the life of the install. Agents create and remove jobs throughcron_removeroutinely, which is the path that leaks.Not a goal
delete_after_runconsume inCronService._merge_job_result, the gateway's Done removal (aremove_job_asynccall withone_shot_path="cron_gateway",src/kiro_crew/slack/gateway.py:3164) and the deferred drain (_drain_pending_removals_locked). They keep their history, as they do today. A delete there would not hold anyway. The run path consumes the job in_merge_job_result(src/kiro_crew/cron.py:3980). It appends that run's record afterwards (:4011), and the gateway's removal runs insideon_job, before both. That append writes the file again. Changing this needs a product answer first: should a one-shot that removed itself keep its last run record in History?remove_jobs_by_owner. An app's teardown (src/kiro_crew/apps/bridges.py:1908) and the SDK's remove-all (src/kiro_crew/apps/cron_sdk.py:763) remove every job an app owns. Whether an uninstalled app's run history stays is a decision for the app lifecycle, so it is left out of this change. Its synchronous sibling,remove_jobs_by_owner_sync, has no caller.What changed
The fix moves the delete out of the dashboard routes and into the service's removal seam. That is the one place every caller-requested removal passes through, so no surface can skip it.
CronHistoryStore.delete_job_history_sync(new,src/kiro_crew/cron_history.py) is the synchronous sibling ofdelete_job_history. It has the same enabled check, and anOSErrordegrades the store as before.CronService._delete_history_of(new,src/kiro_crew/cron.py) deletes the history of the removed ids. It is best-effort, the same as the audit: the jobs are already gone from the store, so a failure is logged and never fails the removal.CronService.remove_jobandremove_jobs_synccall the helper inline. Both are loop-less only: the store lock's guard refuses them on a running loop.remove_job_async,remove_jobsandremove_job_if_async(the dashboard card Undo's compare-and-delete, which main added in feat: let crewmates propose changes the user confirms as cards #18448) call it throughasyncio.to_thread. Each skips the helper when nothing was removed.remove_jobandremove_job_asyncalso skip it whenone_shot_pathis set.api_cron_deleteand the batch delete route (src/kiro_crew/dashboard/handlers/cron.py) drop their owndelete_job_historycall, so the dashboard deletes once.Backwards compatibility
Compatible: the dashboard's responses and status codes are unchanged. A failing history store logs a warning, which is what the batch route already did, and no longer turns a completed single delete into a 500. One-shot removals behave as before. One behaviour changes outside the dashboard: removing a job from the CLI (
kirocrew cron remove), the cron MCP server (cron_remove,cron_remove_all), a chat command or the apps SDK now deletes its run history too, which main kept; the dashboard already deleted it, so every caller-requested removal now does the same.Removes nothing: no endpoint, config key or public method is removed. The two routes stop calling
delete_job_historybecause the service makes that call.Tests
test/test_cron_remove_deletes_history.py(new):test_remove_job_deletes_the_historytest_remove_job_async_deletes_the_historytest_remove_job_if_async_deletes_the_history, the dashboard card Undo's compare-and-delete pathtest_control_a_refused_compare_and_delete_keeps_the_history, a control: a compare-and-delete with a stale expected revision returns"changed"and leaves the job, its history file and its index rows in placetest_cron_remove_tool_deletes_the_historytest_remove_jobs_deletes_the_historytest_cron_remove_all_tool_deletes_the_history, which drives the realcron_remove_alltool and checks that another session's job keeps its historytest_a_failed_history_delete_does_not_fail_the_removaltest_an_automated_one_shot_removal_keeps_the_historytest_control_the_dashboard_route_deletes_the_history_once, which drives the realapi_cron_deleteagainst a realCronServiceand counts deletes.The dashboard handler tests in
test/test_dashboard_cron_delete_handler.pyandtest/test_dashboard_cron_batch_delete_handler.pyare updated so the routes no longer delete history. Two tests are deleted, each replaced bytest_route_does_not_touch_the_history_storein the same file:test_dashboard_cron_delete_handler.py::test_audit_lands_before_history_cleanupexpected a history-store failure after the route's own delete to answer 500, with the service's audit already written. The route no longer calls the history store, so its replacement checks that a failing store gives 200 and is never called. On the service side,test_a_failed_history_delete_does_not_fail_the_removalchecks that a failing delete does not fail the removal. The audit still runs on that path because_delete_history_ofcatches every exception before_audit_requested_removalruns, buttest/test_cron_remove_deletes_history.pydoes not assert the audit.test_dashboard_cron_batch_delete_handler.py::test_history_cleanup_failure_still_counts_as_deletedexpected a history failure on one id to leave both ids reported as deleted and the refresh pushed. Its replacement checks the same response with a failing store that the route never calls. On the service side,_delete_history_ofcatches a failure per id, so the remaining ids are still deleted; no test covers a batch in which one id's delete fails.The two card-Undo tests
test/test_change_cards.py::test_schedule_card_undo_through_the_hook_refuses_a_delete_raced_by_another_tabandtest/test_change_cards_identity.py::test_crewmate_create_cron_undo_refuses_a_schedule_edited_in_the_windownow spy ondelete_job_history_sync, the call the service makes, instead of the asyncdelete_job_history, which nothing insrc/calls on this branch, so their refused-Undohistory_deletes == 0asserts still check something.Red, on origin/main 2e2bd06 with only the new test file copied in, 3 of 3 serial runs, each:
The three that pass on main are the two controls (the refused compare-and-delete and the dashboard route) and the one-shot test. With every change except the one to
remove_jobs_sync, the file gives 1 failed, 9 passed, in 3 of 3 runs: only the remove-all test fails, withcron_remove_all removed this session's jobs and left their history: [...].Green: the three changed test files give 27 passed in each of 3 runs, and with the two card-Undo files they give 263 passed in each of 3 runs. The new file plus every test file that names
remove_job,delete_job_history,cron_historyorcron_remove_all, withtest/test_change_cards.py(the compare-and-delete's own tests), 53 files includingtest/test_cli.pyandtest/test_change_cards_identity.py: 6915 passed, 35 skipped. mypy, flake8, isort, black,scripts/check_black_formatting.py,scripts/check_subprocess_encoding.py,scripts/docs-lint.shandscripts/check_comment_history.py(baseorigin/main) all pass.The rebase onto 098df01 moved the three lines the Not a goal section cites. On this branch the gateway's Done removal (
remove_job_async) starts atsrc/kiro_crew/slack/gateway.py:3194, the run path calls_merge_job_resultatsrc/kiro_crew/cron.py:4332, and it appends the run record (self._history.append) at:4368.Manual verification
None beyond the tests; the change has no UI. The reproducer above was also run three times serially on main, failing each time.
Related Issues
None found. No open issue or PR matches
delete_job_history, cron history orphans orremove_jobhistory. Two closed PRs matched the searches and are unrelated: #16979 and #10668 (history readers).Pattern harvest
Rule candidate: a side effect of removing a record (its history, its files) belongs in the service's removal seam, not in one caller's route; any surface that calls the seam directly otherwise skips it. Check with
git grepthat the side effect has exactly one caller and that it is the seam.Checklist
test/test_cli.pyremove_jobandremove_jobs_syncare loop-less only; the async variants useasyncio.to_thread)