fix: cascade-delete TaskRun records when removing a ScheduledTask#2669
fix: cascade-delete TaskRun records when removing a ScheduledTask#2669soumojit-D48 wants to merge 2 commits into
Conversation
Greptile code reviewThis repo uses Greptile for automated review. Before merge, aim for Confidence Score: 5/5 with zero unresolved review threads — see CONTRIBUTING.md. Run a review — add a PR comment with: Give it ~5-10 minutes (sometimes longer) for results, then fix feedback and re-trigger until you reach Confidence Score: 5/5. Optional: automate with the greploop skill. |
Greptile SummaryThis PR fixes orphaned
Confidence Score: 5/5Safe to merge — the cascade delete is correctly scoped, best-effort, and covered by integration tests. The implementation is straightforward: No files require special attention; Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant store.py as store.remove_task()
participant JSON as JSON Store (FileLock)
participant claim_store.py as claim_store.delete_runs()
participant SQLite as SQLite (scheduler.db)
Caller->>store.py: remove_task(task_id)
store.py->>JSON: acquire lock → filter out task → _save_raw()
JSON-->>store.py: written (lock released)
store.py->>claim_store.py: delete_runs(task_id, db_path)
claim_store.py->>SQLite: path.exists()?
alt DB exists
SQLite-->>claim_store.py: True
claim_store.py->>SQLite: "DELETE FROM task_runs WHERE task_id = ?"
SQLite-->>claim_store.py: rowcount
claim_store.py-->>store.py: deleted N rows
store.py->>store.py: "log.info (if N > 0)"
else DB absent
SQLite-->>claim_store.py: False
claim_store.py-->>store.py: 0 (no-op)
end
store.py-->>Caller: True
Reviews (2): Last reviewed commit: "fix: use shared DB filename constant, mo..." | Re-trigger Greptile |
|
@greptile-apps review again |
|
@muddlebee Hi pls check this PP and let me know. Thank u!! |
Fixes #2668
Describe the changes you have made in this PR -
remove_task()was only deleting theScheduledTaskfrom the JSON store but leaving orphanedTaskRunrecords in the SQLite claim store. Addeddelete_runs()toclaim_store.pyand wired it intoremove_task()so run history is cleaned up when a task is deleted.Changes:
app/scheduler/claim_store.py— addeddelete_runs(task_id, db_path)that deletes allTaskRunrows for a given taskapp/scheduler/store.py—remove_task()now callsdelete_runs()after removing the task from JSON; best-effort, logs warning on failure, return value unchangedtests/scheduler/test_claim_store.py— 4 new tests fordelete_runs(scoped delete, idempotent, empty DB, multi-run)tests/scheduler/test_store.py— 2 new tests for cascade (deletes runs, doesn't affect other tasks)Demo/Screenshot for feature changes and bug fixes -
$ pytest tests/scheduler/test_claim_store.py tests/scheduler/test_store.py -v ======================= 27 passed in 1.38s ========================Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
Explain your implementation approach:
The
TaskRunrecords live in a separate SQLite DB (scheduler.db) with atask_idreference to the parentScheduledTask. When the parent is deleted, those records become inaccessible orphans.Two changes:
delete_runs()— a focused SQL DELETE scoped bytask_id. Returns rowcount, no-ops if DB doesn't exist, idempotent.remove_task()— derives the SQLite path from the JSON store's directory and callsdelete_runs()after the JSON write succeeds. Wrapped intry/exceptso a DB failure doesn't revert the JSON deletion — orphaned runs are acceptable (waste space) but a stuck task is not.Checklist before requesting a review
Note: Please check Allow edits from maintainers if you would like us to assist in the PR.