Skip to content

Audit: Audit the repository: Tell me what can we do better in this rep… - #14

Closed
cloudly-9566c1[bot] wants to merge 1 commit into
mainfrom
agent/thread-171900fc
Closed

cloudly-9566c1[bot] wants to merge 1 commit into
mainfrom
agent/thread-171900fc

Conversation

@cloudly-9566c1

@cloudly-9566c1 cloudly-9566c1 Bot commented Nov 4, 2026

Copy link
Copy Markdown

Opened by Cloudly for run 6d5489b1-7128-4590-ac43-3f22b3e9c65d (native-codex).

Task

Fix this finding

  1. Concurrent workers can claim two turns from one thread (apps/worker/src/claim.ts:9)
    The NOT EXISTS check prevents a turn from being claimed when a running/finalizing turn is visible in the statement snapshot. With two workers claiming concurrently, both statements can begin before either update commits: worker 1 locks the first queued row, and worker 2 skips that locked row and can lock a second queued row for the same thread. Its snapshot cannot see worker 1's uncommitted status change, so both are returned as running. This breaks the stated sequential-turn behavior and lets both runs mutate the same branch and persistent agent home. Serialize claims by thread (for example, lock the Thread row before choosing a run, or use an equivalent transactional/advisory lock), and add a test that races two claimRun calls for queued turns in one thread.

1. **Concurrent workers can claim two turns from one thread** (`apps/worker/src/claim.ts:9`)
   The NOT EXISTS check prevents a turn from being claimed when a running/finalizing turn is visible in the statement snapshot. With two workers claiming concurrently, both statements can begin before either update commits: worker 1 locks the first queued row, and worker 2 skips that locked row and can lock a second queued row for the same thread. Its snapshot cannot see worker 1's uncommitted status change, so both are returned as running. This breaks the stated sequential-turn behavior and lets both runs mutate the same branch and persistent agent home. Serialize claims by thread (for example, lock the Thread row before choosing a run, or use an equivalent transactional/advisory lock), and add a test that races two claimRun calls for queued turns in one thread.
@AymanKhan9 AymanKhan9 closed this Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant