fix: prevent file corruption from focus switching during active editing #8841
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.
This PR attempts to address Issue #8840 by implementing activity detection to prevent file corruption when the agent switches focus while the developer is actively typing.
Problem
When Roo Code's agent automatically switches focus to edit files while the developer is actively typing in another file, the developer's keystrokes can corrupt the newly opened file, leading to frustrating situations where code gets accidentally inserted into the wrong file.
Solution
This implementation adds an activity detection mechanism that:
Key Changes
New ActivityDetector utility (
src/utils/activity-detector.ts):Integration in file editing tools:
PREVENT_FOCUS_DISRUPTION experiment enabled by default:
src/shared/experiments.tssaveDirectlyinstead of showing diff views, avoiding focus disruptionTesting
Future Enhancements
The issue author suggested an "ideal" solution of implementing a pair programming mode with independent cursors. While this PR doesn't implement that advanced feature, it effectively solves the immediate problem of file corruption from focus switching.
Review Confidence
The implementation review showed HIGH confidence (92%) with all requirements successfully addressed.
Fixes #8840
Feedback and guidance are welcome!
Important
Introduces
ActivityDetectorto delay file operations during user activity, integrated into file editing tools, withPREVENT_FOCUS_DISRUPTIONenabled by default.ActivityDetectorinactivity-detector.tsto track user activity and delay file operations until inactivity.applyDiffToolLegacy,insertContentTool,searchAndReplaceTool, andwriteToFileToolto prevent file corruption.PREVENT_FOCUS_DISRUPTIONexperiment enabled by default inexperiments.ts.ActivityDetectorinactivity-detector.test.ts.insertContentTool.spec.tsandwriteToFileTool.spec.tsto mock experiments and activity detection.experiments-preventFocusDisruption.spec.tsto reflect default enabled state.This description was created by
for 2430e8c. You can customize this summary. It will automatically update as commits are pushed.