Repository navigation
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
Closed
cloudly-9566c1[bot] wants to merge 1 commit into
cloudly-9566c1[bot] wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Opened by Cloudly for run
6d5489b1-7128-4590-ac43-3f22b3e9c65d(native-codex).Task
Fix this finding
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.