fix: stop spinner on failed file edits and add re-anchor experiment (#12032)#12033
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: stop spinner on failed file edits and add re-anchor experiment (#12032)#12033roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
…12032) Part 1 - UI Bug Fix: - ApplyDiffTool: Add finalizePartialToolAskIfNeeded to close partial ask messages on error paths, preventing stuck spinners - ApplyDiffTool: Always show diff_error on first failure (was >= 2) - ApplyDiffTool: Set didToolFailInCurrentTurn on diff apply failure - EditFileTool: Always show diff_error on first failure (was >= 2) Part 2 - Re-anchor Before Edit Experiment: - Add reAnchorBeforeEdit experiment type to packages/types - Add RE_ANCHOR_BEFORE_EDIT to shared experiments config (default off) - When enabled, adds system prompt guideline instructing the model to re-read a file before every edit to reduce hallucination-based failures - Add English localization keys for settings UI - Settings UI auto-renders via existing ExperimentalSettings component
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.
Summary
This PR attempts to address Issue #12032. Feedback and guidance are welcome.
Part 1: Fix spinner stuck on failed file edits (UI bug)
Problem: When a file edit tool (e.g.,
apply_diff) fails due to LLM hallucination, the loading spinner at the top of the UI keeps spinning indefinitely. This happens becausehandlePartial()creates a partialaskmessage during streaming, but when the edit fails inexecute(), no code finalizes (closes) that partial ask message.Fix:
finalizePartialToolAskIfNeeded()helper (matching the pattern already inEditFileTool) that closes any outstanding partial ask message on error paths. AddeddidSendPartialToolAskandpartialToolAskRelPathtracking properties, set inhandlePartial().diff_errormessage on every failure (previously only shown on 2nd consecutive failure), giving immediate visual feedback.didToolFailInCurrentTurn = trueon diff apply failure for consistency.diff_errormessage on every failure (previously only shown on 2nd consecutive failure).Part 2: Re-anchor before edit experiment
Problem: LLMs hallucinate file contents when editing, especially for longer files or after many conversation turns. The issue author reports this can be architecturally solved in 80%+ of cases by requiring a re-read step before every edit.
Solution: Added a new experimental setting
reAnchorBeforeEditthat, when enabled, adds a system prompt guideline instructing the model to always re-read a file (usingread_file) immediately before editing it. This uses more tokens but significantly reduces hallucination-based edit failures.Changes:
packages/types/src/experiment.ts: AddedreAnchorBeforeEditto experiment IDs and schemasrc/shared/experiments.ts: AddedRE_ANCHOR_BEFORE_EDITconfig (default: off)src/core/prompts/sections/tool-use-guidelines.ts: Accepts experiments config, adds re-anchoring instruction when enabledsrc/core/prompts/system.ts: Passes experiments togetToolUseGuidelinesSection()webview-ui/src/i18n/locales/en/settings.json: Added localization keysExperimentalSettingscomponentTests
editFileTool.spec.tsto reflect thatdiff_erroris now shown on every failureexperiments.spec.tswith new experiment teststool-use-guidelines.spec.tsto verify re-anchor guideline behaviorAll existing and new tests pass. Lint and type checks pass.
Interactively review PR in Roo Code Cloud