fix: prevent race conditions when applying multiple diffs in parallel#9490
fix: prevent race conditions when applying multiple diffs in parallel#9490uinstinct wants to merge 7 commits intocontinuedev:mainfrom
Conversation
Learn moreAll Green is an AI agent that automatically: ✅ Addresses code review comments ✅ Fixes failing CI checks ✅ Resolves merge conflicts |
1 similar comment
Learn moreAll Green is an AI agent that automatically: ✅ Addresses code review comments ✅ Fixes failing CI checks ✅ Resolves merge conflicts |
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="gui/src/redux/thunks/handleApplyStateUpdate.ts">
<violation number="1" location="gui/src/redux/thunks/handleApplyStateUpdate.ts:172">
P1: Concurrent apply thunks can deadlock: the wait loop counts the current not-started apply state, so two simultaneous calls both wait forever and never call applyToFile.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
RomneyDa
left a comment
There was a problem hiding this comment.
Is there a more deterministic approach we could take to queuing these diffs?
My concern is that 1000 ms is kind of long so in the case a diff stopped streaming just after it checks (1000 ms till next check) and then someone starts clicking around it would suddenly start streaming and feel glitchy?
True. It need not be 1000 ms. I added that as an approximate - but most diffs resolve faster. Will put 100 ms instead. |
There was a problem hiding this comment.
@uinstinct I think we should consider more predictable routes to applying the diffs in order, there are other issues with this approach e.g. selectApplyStatesInProgress could potentially detect some stale apply states which were ignored in a previous session etc and then it would never apply the diff
Let's avoid polling if possible and implement some kind of predictable queue.
- for both reading and writing to the file when applying to it
implemented a new method to rely on getting the filepath's editor without opening activeTextEditor |
There was a problem hiding this comment.
1 issue found across 5 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="extensions/vscode/src/diff/vertical/manager.ts">
<violation number="1" location="extensions/vscode/src/diff/vertical/manager.ts:308">
P2: instantApplyDiff now assumes `filepath` is already a URI string; passing a filesystem path breaks handler creation and map lookups because `Uri.parse` and `fileUriToCodeLens` keys won’t match the editor’s file:// URI.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
RomneyDa
left a comment
There was a problem hiding this comment.
@uinstinct tested, this works pretty nice!
I found some minor issues which are already problems but I think make sense to fix now
- multi edit doesn't count as an "action" when called in parallel because we auto accept tool call and go to diffs
-
The
cmd/ctrl + shift + enteronly ever works for the first diff when multiple are created in parallel. Interesting bug -
When calling multi edit in parallel with other tools, if it's first and you accept the diff it moves cursor to the editor so can't use keyboard shortcuts with proceeding tool calls and unexpectedly e.g. adds a new line in the file. Users will then likely hit cmd + z which then cancels the apply and messes up the sequence
-
Once ^ is fixed let's update the tool prompts to clarify that they can now be called in parallel with other tools
fixed!
created #10183 for this |
this is happening because accepting the diff requires cmd+shift+enter key combination instead of cmd+enter for accepting tool calls. should we change this to cmd+enter for accepting diffs? |


Description
Wait for the previous edit tool to create its diff in the IDE before the next edit tool.
This caused race conditions because the code required the text editor to be active for the diff to be streamed into the proper file.
resolves CON-5048
AI Code Review
@continue-reviewChecklist
Screen recording or screenshot
before.mp4
after.mp4
Tests
[ What tests were added or updated to ensure the changes work as expected? ]
Continue Tasks
Powered by Continue
Summary by cubic
Prevent race conditions when multiple edit tools apply diffs at the same time by targeting the correct file editor. Each diff now streams to the right file without relying on the active editor.
Written for commit e36e9c3. Summary will update on new commits.