fix(db): make task row state authoritative

This commit is contained in:
ZacharyZhang-NY committed 2026-04-22 16:24:57 -04:00
1 parent ebcc15c68d
commit 775598ef4c
16 files changed
+75 -924

No files matched your search

-11
View File
@@ -207,11 +207,6 @@ export function buildRunMethods(
getDb()
.prepare("UPDATE tasks SET checkout_run_id = NULL, execution_locked_at = NULL, updated_at = ? WHERE id = ? AND checkout_run_id = ?")
.run(ts, run.taskId, input.runId);
// B2 Phase 1 step 3/5 — dual-write: release the shadow lease
// for this run at the same instant the legacy lock is cleared.
getDb()
.prepare("DELETE FROM task_leases WHERE task_id = ? AND run_id = ?")
.run(run.taskId, input.runId);
if (runNeverStarted) {
// Roll the task back to `todo` when no *other* live run claims
// it. Invariant: `task.status = 'in_progress'` ⇒ a queued or
@@ -223,7 +218,6 @@ export function buildRunMethods(
// NOT EXISTS clause is the canonical "no live owner" check.
getDb()
.prepare(
// eslint-disable-next-line no-restricted-syntax -- B2 Phase 1 grandfathered: finishRun's "runNeverStarted" rollback; trigger mirrors status→phase, shadow lease already dropped above
`UPDATE tasks
SET status = 'todo',
checkout_run_id = NULL,
@@ -276,11 +270,6 @@ export function buildRunMethods(
getDb()
.prepare("UPDATE tasks SET checkout_run_id = NULL, execution_locked_at = NULL, updated_at = ? WHERE id = ? AND checkout_run_id = ?")
.run(ts, taskId, runId);
// B2 Phase 1 step 3/5 — dual-write: drop the shadow lease when
// the legacy cancellation clears checkout_run_id.
getDb()
.prepare("DELETE FROM task_leases WHERE task_id = ? AND run_id = ?")
.run(taskId, runId);
}
if (workspaceId) {
getDb()