Skip to content

Commit 49b57c6

Browse files
authored
fix(db): scope artifact upload row lock (#146)
## Summary - lock only the active `v2_agent_runs` row while validating artifact-upload ownership - keep project, thread, and user joins read-only under their least-privilege grants - preserve the transaction fence against a concurrent run completion ## Why PostgreSQL applies an unqualified `FOR UPDATE` to every relation in a joined query. The agent role intentionally cannot update projects, so generated media reached persistence and then failed before its upload intent could be committed. `FOR UPDATE OF v2_agent_runs` matches the intended concurrency boundary and the clean baseline ACLs. ## Verification - `pnpm exec biome check packages/db/src/artifact-upload-intents.ts` - `pnpm turbo lint` - `pnpm turbo typecheck --filter=@cheatcode/db --filter=@cheatcode/agent-worker` - `pnpm turbo build --filter=@cheatcode/agent-worker` - `pnpm db:migrate -- --dry-run`
1 parent c27a649 commit 49b57c6

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

packages/db/src/artifact-upload-intents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ function lockActiveUploadOwnership(
289289
isNull(users.deletionFence),
290290
),
291291
)
292-
.for("update")
292+
.for("update", { of: agentRuns })
293293
.limit(1)
294294
.then((rows) => rows[0]);
295295
}

0 commit comments

Comments
 (0)