Skip to content

fix(files): Refresh re-reads the open file, and the agent's edits to it show - #300

Merged
thecodacus merged 2 commits into
mainfrom
fix/files-refresh-open-file
Oct 23, 2026
Merged

thecodacus merged 2 commits into
mainfrom
fix/files-refresh-open-file

Conversation

@thecodacus

@thecodacus thecodacus commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

What was seen

In a chat's Files panel, open a file, then let it change on disk. The panel keeps showing the old text. Clicking Refresh changes nothing either, so it looks broken.

Why

  • With a file open, the Refresh button still only listed the folder again (loadDir(dir)). The panel draws the file instead of the folder at that point, so the new listing was never shown. The file's text, its saved copy and the time it was read at were never read again.
  • The only live update is this chat's agent's read, write and edit calls (latestFileActivity → the activity effect in FilesPanel.tsx). That effect stopped early when the panel was not following, and also when there were unsaved changes. So the agent editing the open file showed nothing in either case.

The change

All of it is in extensions/files/src/FilesPanel.tsx.

  • Refresh reads the folder and the file that is open. It lists the folder again, as before, so that Back to the folder shows it as it is now. With a file open it also calls a new rereadFile. That reads the file again without blanking the view to "Loading…". The old text stays until the new text is here, and the view stays as it was (the source or the rendered page). Opening the file with loadFile would have reset that view. One exception, the same rule as opening a file: a page that becomes empty is shown as the source, because a blank page cannot be typed into. The icon spins while the folder or the file is read.
  • Unsaved changes are never replaced. If the file's mtime differs from the one the draft was made from, the existing "This file changed after you opened it." bar appears with Load the new version / Save mine anyway. That is the same choice a save conflict and a restored draft already give. If the mtime is the same, nothing happens. A read that fails while there are unsaved changes shows the same bar, as it does for a restored draft. With no unsaved changes, a failed read shows its error where the text was, as opening the file would.
  • A save makes a read that is still out not the answer. Refresh leaves the editor and Save usable while it reads, so a save can answer before the read does. Such a read found the file as it was before the save. Without this, its old text went on screen as saved, with the mtime from before the save: the next save was refused, and Save mine anyway would have written the old text over what was just saved. The save's answer now bumps fileAsk, the same way opening another file or going back does.
  • The agent's write or edit of the open file now goes through rereadFile too, whether or not the panel is following. With unsaved changes it shows the bar and keeps the draft. When following, this also means the open file is no longer reopened with "Loading…" in between. A read by the agent, or a change to a different file, works as before.
  • docs/guide/files.md now describes Refresh, how the agent's edits to the open file show up, and that the agent's write and edit tools are the only changes Files notices by itself.

No new UI text, so there are no new German strings.

Left for later

Files still does not refresh by itself for any change that is not the agent's write or edit tool: the agent's own shell commands (sed -i, a formatter, git checkout, a build), another chat, a terminal, another device, a cron job. That needs a server-side watch or a stat route and a stream to the panel. The docs extension's server half (watchDirs in extensions/docs/server.js: fs.watch plus a stream to the page) is a model for it. Until then, Refresh is how such a change shows. This is the first part of #292 ("No auto-refresh"), so this PR does not close the issue.

Tests

New browser specs in extensions/files/test/browser/refresh.spec.mts (11 tests). The mock takes the file's contents when a read arrives, as the server reads it then, so a read that is held answers with the file as it was before.

  • With a file open, Refresh shows the new text. While the read is held, the old text stays, "Loading…" never appears and the icon spins. Afterwards the next save is checked against the new mtime.
  • Refresh keeps the view: an empty file opened as the source stays the source after it gets text, a page stays a page, and a page that becomes empty is shown as the source.
  • With unsaved changes, Refresh keeps the draft and shows the bar only when the file changed. Load the new version and Save mine anyway (sent without an mtime) both work.
  • A Refresh read held across a successful save does not put the old text back. This is checked both with unsaved changes before the Refresh and with text typed and saved (Cmd+S) while the read was out. The next save is checked against the mtime the save gave.
  • A stale bar and an earlier save error go away once Refresh shows the file as it is now.
  • A failed read shows the bar when there are unsaved changes, and shows the error with no "Not saved" mark when there are none.
  • While not following, the agent's write updates the open file, and its edit with unsaved changes shows the bar.
  • The agent reading the open file, or writing a different file, does not re-read the open file.
  • While following, the agent's write updates the file without "Loading…" in between, and with unsaved changes it shows the bar.
  • In the folder view, Refresh still lists the folder again.
  • With a file open, Refresh lists the folder again too: after Back to the folder, a file added meanwhile is listed.

Results:

  • npx playwright test extensions/files/test/browser extensions/git/test/browser/chat.spec.mts: 44 passed.
  • The two specs added in the second commit (the save race, and Back after Refresh) both fail against the first commit's FilesPanel.tsx.
  • Against origin/main's FilesPanel.tsx, the first commit's new specs gave 8 failed and 1 passed (the folder-view guard).
  • Mutation check on the first commit: 16 mutations of the change, each killed by at least one spec. They covered: Refresh only listing the folder; Refresh using loadFile; no dirty branch; asking without comparing the mtime; the activity line removed; reads counted as changes; any file counted; the empty-page rule removed; the bar or the save error not cleared; a failed read with unsaved changes kept silent; the draft not reset; no spinner; the spinner never stopping; the folder view's Refresh doing nothing; a failed read always asking.
  • node --import tsx --test extensions/files/test/*.test.mts: 21 passed.
  • npm run build in extensions/files (build plus tsc --noEmit) is clean, and npm run check:boundaries passes.

Part of #292

Note for merging: the first commit's message still ends with the keyword line that closes the issue, and that cannot change without a force-push. Squash-merge and take that line out of the squash message. A merge commit would keep it and close the issue.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • File Management
    • Refresh now rereads the open file, replacing its displayed content when there are no unsaved edits. If edits are present and the file has changed, you can resolve the save conflict without losing your draft.
    • Agent writes and edits update the open file whether or not the panel is following the agent.
    • Refresh reloads the folder listing when no file is open. Changes made outside the chat are not detected automatically.
  • Documentation
    • Updated the Files guide to explain refresh behavior and handling of unsaved edits.

…it show

With a file open, Refresh listed the folder again, which is not drawn
while the file is, so it did nothing anyone could see: the text, the
saved copy and the time it was read at stayed as they were. And the
agent's write or edit of the file that is open showed only while the
panel was following and had no unsaved changes.

- Refresh acts on what is on screen. With a file open it reads the file
  again where it is (rereadFile): the text stays until the new text is
  here, with no "Loading…" between, and the view it is shown in, the
  page or the source, is kept; emptied, it is the source, as an empty
  file opens. Unsaved changes are never replaced: if the file changed
  under them, the bar about a changed file asks, as a save does. The
  icon turns while the file is read, as it does for the folder, which
  Refresh still lists again when no file is open.
- A write or edit by this chat's agent of the file that is open gets the
  same, whether the panel follows or not; following, it is no longer
  opened anew with "Loading…" between, and an edit in the way is asked
  about instead of left with an old copy.
- The guide says what Refresh does, and that a change made outside the
  chat is not noticed by itself.

Closes #292

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 34 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cfd01494-76e0-4aa2-b292-7e5853b9dbb0
📥 Commits

Reviewing files that changed from the base of the PR and between 2dacb68 and 5ef61f9.

📒 Files selected for processing: 3
  • docs/guide/files.md
  • extensions/files/src/FilesPanel.tsx
  • extensions/files/test/browser/refresh.spec.mts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 77f71805-a3ef-4b09-b12e-4357e6ef000b
📥 Commits

Reviewing files that changed from the base of the PR and between 2286642 and 2dacb68.

📒 Files selected for processing: 3
  • docs/guide/files.md
  • extensions/files/src/FilesPanel.tsx
  • extensions/files/test/browser/refresh.spec.mts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

📝 Walkthrough

Refresh now rereads an open file or reloads the folder listing. Agent writes and edits to the open file trigger a reread, while unsaved edits remain available for the existing conflict choice.

Changes: Files panel refresh

Layer / File(s) Summary
Open-file reread and refresh
extensions/files/src/FilesPanel.tsx, extensions/files/test/browser/refresh.spec.mts, docs/guide/files.md
Refresh rereads the open file, ignores stale responses, and preserves unsaved edits when the file changes or the read fails. When no file is open, Refresh reloads the folder listing. Browser tests cover refreshed content, view mode, conflicts, and read failures. The guide describes this behavior and states that external changes are not detected automatically.
Agent-triggered file rereads
extensions/files/src/FilesPanel.tsx, extensions/files/test/browser/refresh.spec.mts, docs/guide/files.md
Writes and edits to the open file trigger a reread regardless of follow mode. Browser tests cover agent activity with following enabled and disabled, including unsaved edits. The guide documents these updates.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 2dacb

The changed Refresh and agent-update paths have no identified merge-blocking issue. The existing same-mtime save limitation is not introduced or worsened by this change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Linked Issues check Warning Issue #292 directly requires automatic detection of external changes to the open file. The PR implements Refresh rereads and rereads triggered by this chat's agent activity, but the PR description sta… Implement and test automatic detection for external changes to the open file. Reload silently when there are no unsaved edits. Show the existing changed-file notice when unsaved edits exist. Preserve the implemented Refresh behavior.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and specifically summarizes the main changes: Refresh rereads the open file, and agent edits appear in the Files panel.
Out of Scope Changes check Passed The changed Files panel behavior, browser tests, and guide updates all support issue #292 or document its explicit limitation. Agent write/edit rereads address the panel's file-update path, and folder…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 …
Full details: Out of Scope Changes check

Explanation

The changed Files panel behavior, browser tests, and guide updates all support issue #292 or document its explicit limitation. Agent write/edit rereads address the panel's file-update path, and folder Refresh preserves the issue's requested folder behavior. No unrelated change is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

Full details: Linked Issues check

Explanation

Issue #292 directly requires automatic detection of external changes to the open file. The PR implements Refresh rereads and rereads triggered by this chat's agent activity, but the PR description states that changes from another chat, a terminal, another device, or a cron job remain undetected. The issue's automatic-update browser criterion is therefore unmet.

Resolution

Implement and test automatic detection for external changes to the open file. Reload silently when there are no unsaved edits. Show the existing changed-file notice when unsaved edits exist. Preserve the implemented Refresh behavior.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…lists the folder too

- A read of the open file asked before a save answered (Refresh, or the
  agent's change) found the file as it was before the save. Answered after
  it, there were no unsaved changes any more, so its old text went on screen
  as saved, with the time from before: the next save was refused, and "Save
  mine anyway" would have written the old text over the saved one. The
  save's answer now makes such a read not the answer, as opening another
  file does.
- With a file open, Refresh read only the file, so Back showed the folder as
  it was when the file was opened. It lists the folder again as well, as it
  did before, and as the agent's activity does.
- The guide says which changes Files notices by itself: only the agent's
  write and edit tools. Its shell commands are not noticed either.

Part of #292

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thecodacus
thecodacus merged commit 09f886b into main Oct 23, 2026
5 checks passed
@thecodacus thecodacus mentioned this pull request Oct 23, 2026
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.

1 participant