Skip to content

ADFA-5260 | Fix edit_file to save edited file via saveFile - #79

Open
jatezzz wants to merge 1 commit into
mainfrom
fix/ADFA-5260-file-targeted-save
Open

ADFA-5260 | Fix edit_file to save edited file via saveFile#79
jatezzz wants to merge 1 commit into
mainfrom
fix/ADFA-5260-file-targeted-save

Conversation

@jatezzz

@jatezzz jatezzz commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Description

This PR updates EditorBufferApplier to persist the specific file it modifies, preventing a severe code loss and desynchronization issue. Previously, the applier would call openFile (which merely posted a tab switch) followed immediately by saveCurrentFile(). This race condition caused the IDE to force-save whichever tab the user was actively looking at, leaving the agent's target file dirty on disk while falsely reporting a successful save to the model.

To fix this, we:

  • Removed all calls to openFile and saveCurrentFile in EditorBufferApplier.
  • Replaced them with a direct, file-targeted saveFile(file) call executed off the main thread.
  • Added handling for SecurityException during the save process, so a denied filesystem write gracefully reports saved=false to the model without throwing an escaping exception that would abort the agent's turn.
  • Created EditorBufferApplierTest and migrated EditFileHandlerTest to verify unfocused file scenarios, save success/failure states, and to guarantee tab focus is never stolen.

Details

Logic-related changes. Please review the newly added EditorBufferApplierTest suite which includes strict negative verifications to lock in the regression fix (ensuring openFile and saveCurrentFile are never invoked).

Before

Screen_Recording_20260824_161034_Code.on.the.Go.mp4

After

Screen_Recording_20260824_161341_Code.on.the.Go.mp4

Ticket

ADFA-5260
Parent: ADFA-5215

Observation

The plugin version in AndroidManifest.xml has been bumped to 26.35. The tests confirm the requirements for regression test REG-TOOL-EDIT-006, ensuring that agent edits to unfocused files keep the user's currently focused unsaved changes strictly untouched.

This PR depends on appdevforall/CodeOnTheGo#1750

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

EditorBufferApplier persisted its edit by focusing the target tab and calling saveCurrentFile(). Both are fire-and-forget: openFile() only posts the tab switch, so saveCurrentFile() read the previous tab index and saved whatever the user was looking at - force-saving their in-progress work while the target file stayed dirty and unchanged on disk. It returned true either way, so the model was told "saved" and later builds compiled the stale copy.

Use the host's new file-targeted IdeEditorService.saveFile(File) instead. The buffer read and the replaceRange still share one main-thread block; the save moves to ioDispatcher, because saveFile blocks until the bytes are on disk and the write itself runs on main. openFile is gone from this path entirely - the agent no longer takes the user's focus to persist a file.

saveFile throws on a permission miss rather than returning false, so the call is wrapped: an exception escaping here would abort the whole agent turn over an edit that already landed in the buffer. Swallowing it into saved=false yields "applied, left unsaved", which is true and actionable.

New EditorBufferApplierTest covers the unfocused-file case with negative verifications on openFile/saveCurrentFile - the lock against reintroducing the focus dependency - plus save success, failure, throwing, and the two refusal paths. EditFileHandlerTest moves off the removed stubs.

Requires the host release that ships saveFile (26.35); min_ide_version bumped, though the host records rather than enforces it.
@jatezzz
jatezzz force-pushed the fix/ADFA-5260-file-targeted-save branch from e46ab31 to 229cdbd Compare August 27, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants