fix(db): move active runs query into deleteTask transaction (P1-12 TOCTOU)

This commit is contained in:
ZacharyZhang-NY committed 2026-04-16 22:49:22 -04:00
1 parent 9874d825b6
commit 2eb6cb2c06
1 file changed
+9 -9
+9 -9
View File
@@ -116,16 +116,16 @@ export function buildTaskCrudMethods(
},
deleteTask(id: string, companyId: string): void {
const activeTaskRuns = readAll<{
id: string;
taskId: string;
workspaceId: string | null;
}>(
"select id, task_id as taskId, workspace_id as workspaceId from runs where task_id = ? and company_id = ? and status in ('queued', 'running')",
id,
companyId,
);
transaction(() => {
const activeTaskRuns = getDb()
.prepare(
"select id, task_id as taskId, workspace_id as workspaceId from runs where task_id = ? and company_id = ? and status in ('queued', 'running')",
)
.all(id, companyId) as Array<{
id: string;
taskId: string;
workspaceId: string | null;
}>;
for (const run of activeTaskRuns) {
const ts = nowIso();
getDb()