GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(app): reread a workspace file changed during its read by Hona · Pull Request #61818 · anomalyco/opencode

Conversation

@Hona

@Hona Hona commented Nov 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

A file that changes while the app reads it now shows the change. Workspace file content (packages/app/src/workspaces/files) moves from loose FileState flags, an inflight map, and a module-global LRU to one explicit state machine in content-machine.ts.

Bugs

  • Lost change during a read: load(a) starts read 1. a changes on disk, and the watcher calls load(a, { force: true }). That call joined read 1, so the tab kept the bytes from before the change until the next change. A forced load now sets rerun, and one more read starts when read 1 settles.
  • loaded together with error: a forced reload that failed (HTTP 500, disconnect) left loaded: true and error set, and the next plain load() returned early. A failed refresh is now ready with stale: true, and the next plain load reads again.
  • notFound together with loading: reloading a missing file kept notFound: true during the read. missing now goes to loading.
  • Shared content cache: the session route, the new-session route, and the components lab each mount a FileProvider, and they shared one LRU. A directory change in one provider reset the others' accounting, so their content could not be evicted. Also, protecting a path the cache did not hold ended the eviction pass early. Each provider now owns createFileContentCache().
  • Endless "Loading…" on media: the media HEAD probe skips the API request queue, so a wedged remote connection left it waiting forever. It now gives up after 60 s without a response, the same limit the queue applies to every API call (file.read included). Only the wait for the response is limited: a large file downloads for as long as it needs. Each read also has an AbortController that a directory change or unmount aborts.

Visual

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none">
  <style>
    .r1{animation:r1 4s linear infinite}
    .r2{animation:r2 4s linear infinite}
    .dot{animation:dot 4s steps(1) infinite}
    .old{animation:old 4s steps(1) infinite}
    .new{animation:new 4s steps(1) infinite}
    @keyframes r1{0%{width:0}35%,100%{width:96px}}
    @keyframes r2{0%,35%{width:0}70%,100%{width:96px}}
    @keyframes dot{0%,15%{opacity:0}15.01%,100%{opacity:1}}
    @keyframes old{0%,70%{opacity:.55}70.01%,100%{opacity:0}}
    @keyframes new{0%,70%{opacity:0}70.01%,100%{opacity:1}}
    @media (prefers-reduced-motion:reduce){.r1,.r2,.dot,.old,.new{animation:none}}
  </style>
  <g fill="currentColor">
    <text x="8" y="20" font-family="ui-monospace,monospace" font-size="9" opacity=".6">read 1</text>
    <rect x="48" y="13" width="96" height="6" opacity=".15"/>
    <rect class="r1" x="48" y="13" width="96" height="6" opacity=".5"/>
    <circle class="dot" cx="72" cy="8" r="3"/>
    <text x="78" y="10" font-family="ui-monospace,monospace" font-size="8" opacity=".6">change</text>
    <text x="8" y="40" font-family="ui-monospace,monospace" font-size="9" opacity=".6">read 2</text>
    <rect x="48" y="33" width="96" height="6" opacity=".15"/>
    <rect class="r2" x="48" y="33" width="96" height="6" opacity=".8"/>
    <rect x="156" y="8" width="76" height="56" fill="none" stroke="currentColor" stroke-opacity=".3"/>
    <rect class="old" x="164" y="18" width="48" height="5" opacity="0"/>
    <rect class="old" x="164" y="30" width="36" height="5" opacity="0"/>
    <rect class="new" x="164" y="18" width="56" height="5"/>
    <rect class="new" x="164" y="30" width="44" height="5"/>
    <rect class="new" x="164" y="42" width="30" height="5"/>
  </g>
</svg>
Before After

State

type FileEntryState =
  | { status: "loading"; attempt: number; silent: boolean; rerun: boolean }
  | { status: "ready"; content: FileContent; stale: boolean }
  | { status: "refreshing"; content: FileContent; attempt: number; silent: boolean; rerun: boolean }
  | { status: "missing"; error: string }
  | { status: "error"; error: string }

type FileContentState =
  | { status: "active"; directory: string; issued: number; files: Record<string, FileEntryState> }
  | { status: "disposed" }
stateDiagram-v2
  [*] --> loading: load
  missing --> loading: load
  error --> loading: load
  loading --> loading: forced load (rerun = true)
  refreshing --> refreshing: forced load (rerun = true)
  loading --> ready: succeeded
  refreshing --> ready: succeeded
  loading --> refreshing: succeeded, rerun
  refreshing --> refreshing: succeeded, rerun
  loading --> missing: missing
  refreshing --> missing: missing
  loading --> error: failed
  refreshing --> ready: failed (stale)
  ready --> refreshing: forced load, or plain load when stale
  ready --> [*]: evicted
  refreshing --> loading: evicted
Loading
  • issued only grows, also across directories, so a reply to a read from an earlier directory never matches a current attempt. scope.changed and disposed emit abort.all and cache.reset.
  • The driver in model.tsx runs effects (read, abort.all, settle, cache.*, toast) and owns the abort controllers and the promises load() returns. A server that sends no response arrives as load.failed; the machine has no clock. It writes only the entries that changed, so other files' readers stay quiet and content is never deep-merged.
  • FileState (what Files.get returns to plugins) is now a union per status. It stays assignable to the plugin SDK's FileState, so mounted-session.ts, the file viewer, review, and composer callers keep working without changes.

Deleted

  • FileState.loaded / loading / notFound as stored flags (now projected by selectFileState).
  • The inflight map, the scope() !== directory guards, ensure / setLoading / setLoaded / setLoadError.
  • The module-global lru and total, evictContentLru, resetFileContentLru, touchFileContent, hasFileContent, removeFileContentBytes.

Deviations from the design

  • Rerun instead of abort and restart: a forced load during a read queues one more read rather than aborting the current read. Aborting would starve a file that changes faster than it reads (an open log file stuck on "Loading…"). The first read's content shows, then the follow-up read replaces it. A failed or missing result with a rerun pending reads again without a toast.
  • No machine timeout: the design's 30 s load.timed-out covered the whole download and cut off large files on slow connections. The transport's 60 s limit applies only to the wait for a response (request-queue.ts), and headStreamedFile gives the media HEAD the same limit.
  • No selectFileTracked selector; the watcher checks whether an entry exists.

Product calls

  • A media HEAD that gets no response shows "Request failed" (an existing string) and toasts unless the load was silent.
  • The newest read and the visible tab are protected from eviction; before, only the newest read was.
  • An evicted file loses its entry, so the watcher no longer rereads evicted files that no tab shows.
  • Off the hot path (file loads only), so no benchmark.

Added by the opencode bot (AI-generated).

Related: #52941

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Hona
Hona requested a review from Brendonovich as a code owner November 4, 2026 22:38
Copilot AI balanced review requested due to automatic review settings November 4, 2026 22:38
Copilot AI reviewed Nov 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
opencodejr[bot]
opencodejr Bot reviewed Nov 4, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

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.

The fix works. I copied the new Playwright test onto the base, where it fails: the tab keeps showing "before change". With this PR it passes, and so do the other 29 tests in review.spec.ts. The unit tests in workspaces/files pass, and tsc -b is clean.

Public API: unchanged. FileState is app-internal. It is now a union keyed on status, and it still has the loaded, loading, notFound, content and error fields that plugin callers read.

The state machine follows the State Machines section of packages/app/AGENTS.md. It uses attempt ids to drop stale results, every read ends in a state, a driver owns the abort controllers and timers, and a disposed event handles cleanup. Each FileProvider owning its own cache also fixes the shared-LRU problem. One inline comment about the new read timeout.

Related: #52941

Before

After

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/app/src/workspaces/files/content-machine.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Hona
Hona force-pushed the file-content-machine branch from fb264e7 to 84e3ee8 Compare November 4, 2026 22:59
opencodejr[bot]
opencodejr Bot reviewed Nov 4, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

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.

This push rebases onto newer dev. The changes to packages/app are the same as in the commit I reviewed before. On the new head, the unit tests in workspaces/files and the new e2e test pass. tsc -b reports one error, in session/composer/region.tsx (pinned), and dev has the same error, so it doesn't come from this change. Public API: unchanged. My earlier point about the 30 s read timeout is not addressed yet, so that thread stays open. Nothing new to add.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Hona
fix(app): reread a workspace file changed during its read
8a76132
Model workspace file content as an explicit state machine (content-machine.ts). A forced reload during a read now queues one more read instead of joining the stale one, a failed refresh keeps its content without an error, a reload of a missing file no longer reports it missing, reads time out, and each file provider owns its content cache.
@Hona
Hona force-pushed the file-content-machine branch from 84e3ee8 to 8a76132 Compare November 4, 2026 23:21
opencodejr[bot]
opencodejr Bot reviewed Nov 4, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

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.

This push rebases onto newer dev, and the changes to packages/app are unchanged. On the new head, the unit tests in workspaces/files, tsc -b and the new e2e test all pass. Public API: unchanged. My earlier point about the 30 s read timeout is not addressed yet, so that thread stays open. Nothing new to add.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Hona
fix(app): bound only the wait for a file read's response, not its dow…
2120030
…nload

The 30 s whole-read timeout cut off large files over slow connections. The API's request queue already bounds every
call's wait for headers (60 s) and lets the body stream; the media HEAD, which skips the queue, now gets the same bound.
opencodejr[bot]
opencodejr Bot reviewed Nov 4, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

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.

My earlier point is addressed. File reads no longer have their own 30 s limit on the whole download. They now rely on the request queue's 60 s limit, which only covers the wait for the server's response, and the media HEAD gets the same limit through headStreamedFile. On the new head, the workspaces/files unit tests pass, including the new headStreamedFile tests. tsc -b is clean, and all of review.spec.ts passes (30/30), including the test for a file changed during its read. Public API: unchanged. Nothing new to raise.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Hona
Hona merged commit c777f9a into dev Nov 5, 2026
22 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@Hona
Hona deleted the file-content-machine branch November 5, 2026 00:10
cramelolo291-bot added a commit to cramelolo291-bot/opencode that referenced this pull request Nov 5, 2026
@cramelolo291-bot
Merge pull request #1 from anomalyco/dev
1a5b9d3
fix(app): reread a workspace file changed during its read (anomalyco#61818)
This was referenced Nov 5, 2026
app: file tab stays on older content when a file changes again during a refresh #61982
Closed
fix(app): reread a file that changes again during a read #61983
Closed
@Karanvir1729 Karanvir1729 mentioned this pull request Nov 5, 2026
fix(gui-plugins): reread a file when the file browser opens it #61961
Open
3 of 6 tasks
Karanvir1729 added a commit to Karanvir1729/opencode that referenced this pull request Nov 5, 2026
@Karanvir1729
fix(gui-plugins): read a file once on its first open from the file br…
c39c252
…owser

Selecting the new tab loads the file, and since anomalyco#61818 a forced load during
a read asks for one more read. Forcing after the tab opened read every newly
opened file twice. Force first, so the tab's load joins that read.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@opencodejr opencodejr[bot] opencodejr[bot] left review comments
@Brendonovich Brendonovich Awaiting requested review from Brendonovich

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Hona
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.