Dual-write phase and lease in task status transitions (B2 Phase 1 step 3/5)

This commit is contained in:
ZacharyZhang-NY committed 2026-04-20 12:55:53 -04:00
1 parent 8cb227f455
commit 2656684392
4 files changed
+100 -1

No files matched your search

+11
View File
@@ -136,6 +136,17 @@ export function buildTaskCrudMethods(
"UPDATE tasks SET checkout_run_id = NULL, execution_locked_at = NULL, updated_at = ? WHERE id = ? AND checkout_run_id = ?",
)
.run(ts, run.taskId, run.id);
// B2 Phase 1 step 3/5 — dual-write: cascade to the shadow
// lease row so a task-delete does not leave an orphan lease
// behind. The FK on `task_leases.task_id` would also cascade
// via the DELETE at the end of this transaction; we clear
// here explicitly so the intermediate state (task still
// present, lease already gone) matches what `releaseTaskLock`
// would have done if the delete had gone through the normal
// lifecycle path.
getDb()
.prepare("DELETE FROM task_leases WHERE task_id = ? AND run_id = ?")
.run(run.taskId, run.id);
if (run.workspaceId) {
getDb()
.prepare(