-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix 'failure to apply changes' when Git diff views are open #1581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
## Bug Description Multi-file edit operations (`apply_diff` tool) would fail consistently when Git diff views were open in VSCode. The failure occurred before reaching the diff view opening code, indicating the issue was not with tab management as initially suspected. ## Root Cause The bug was caused by **environment context contamination** in `src/core/environment/getEnvironmentDetails.ts`. When Git diff views are open, the environment details gathering code was incorrectly processing non-text tabs: 1. **Improper type casting**: Line 68 used `(tab.input as vscode.TabInputText)?.uri?.fsPath` without filtering, casting all tab inputs as `TabInputText` regardless of their actual type 2. **Processing incompatible tab types**: Git diff tabs have input types like `TabInputTextDiff`, not `TabInputText` 3. **Malformed environment data**: This resulted in unexpected/malformed data being included in the environment context sent to the AI 4. **AI parsing interference**: The contaminated context affected how the AI parsed multi-file `apply_diff` requests, causing them to fail ## Fix Added proper tab type filtering before processing: ```typescript // Before (BROKEN) .map((tab) => (tab.input as vscode.TabInputText)?.uri?.fsPath) // After (FIXED) .filter((tab) => tab.input instanceof vscode.TabInputText) .map((tab) => (tab.input as vscode.TabInputText).uri.fsPath) ``` This matches the correct pattern already used in other parts of the codebase like `DiffViewProvider.ts` and `WorkspaceTracker.ts`. ## Impact - Multi-file edits now work reliably when Git diff views are open - Environment context data is properly filtered and type-safe - Consistent tab processing across the codebase Fixes: #712
🦋 Changeset detectedLatest commit: ae1a542 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughA patch was implemented to address failures when applying changes to files with open Git diff views in VSCode. The update filters VSCode tabs to process only valid text document tabs, preventing errors and ensuring changes can be applied regardless of open diff views. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Assessment against linked issues
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/core/environment/getEnvironmentDetails.ts (3)
24-29: Consider separating unrelated changes into a different PR.These imports for OpenRouter and Ollama handlers appear unrelated to the main bug fix described in the PR objectives. While they may be valid improvements, mixing them with the critical bug fix makes the PR harder to review and understand.
213-227: Unrelated model fetching logic mixed with bug fix.This OpenRouter/Ollama model fetching logic doesn't appear to be related to the Git diff tab filtering bug described in the PR objectives. Consider moving this to a separate PR focused on model handling improvements.
249-249: Unrelated mode handling change.This comment and logic change for non-existent modes doesn't relate to the main Git diff tab bug fix. While it may be a valid improvement, it should be in a separate PR for clarity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.changeset/lemon-grapes-bake.md(1 hunks)src/core/environment/getEnvironmentDetails.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/!(*kilocode*)/**/*.{ts,tsx,js,jsx,html,css,scss}
📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
**/!(*kilocode*)/**/*.{ts,tsx,js,jsx,html,css,scss}: For single line changes, add the comment '// kilocode_change' at the end of the line.
For multiple consecutive lines changed, wrap them with '// kilocode_change start' and '// kilocode_change end' comments.
Files:
src/core/environment/getEnvironmentDetails.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: storybook-playwright-snapshot
- GitHub Check: test-extension (ubuntu-latest)
- GitHub Check: test-webview (windows-latest)
- GitHub Check: test-extension (windows-latest)
- GitHub Check: test-webview (ubuntu-latest)
- GitHub Check: compile
🔇 Additional comments (2)
src/core/environment/getEnvironmentDetails.ts (1)
68-69: Excellent type-safe fix for Git diff tab handling.The filtering approach correctly prevents non-text tabs (like Git diff views) from being processed, which was the root cause of the multi-file edit failures. By filtering first and then casting, you eliminate the risk of undefined values contaminating the environment data.
.changeset/lemon-grapes-bake.md (1)
1-6: Clear and accurate changeset documentation.The changeset properly documents the Git diff view fix with appropriate patch-level versioning and a clear description that matches the core issue being resolved.
| .flatMap((group) => group.tabs) | ||
| .map((tab) => (tab.input as vscode.TabInputText)?.uri?.fsPath) | ||
| .filter((tab) => tab.input instanceof vscode.TabInputText) | ||
| .map((tab) => (tab.input as vscode.TabInputText).uri.fsPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kilocode_change?
Bug Description
apply_difftool would fail consistently when Git diff views were open in VSCode.Root Cause
The bug was caused by environment context contamination in
src/core/environment/getEnvironmentDetails.ts. When Git diff views are open, the environment details gathering code was incorrectly processing non-text tabs:(tab.input as vscode.TabInputText)?.uri?.fsPathwithout filtering, casting all tab inputs asTabInputTextregardless of their actual typeTabInputTextDiff, notTabInputTextapply_diffrequests, causing them to failFix
Added proper tab type filtering before processing:
This matches the correct pattern already used in other parts of the codebase like
DiffViewProvider.tsandWorkspaceTracker.ts.Impact
Fixes: #712
Roo PR: RooCodeInc/Roo-Code#6350