Skip to content

fix(core): pick up new files in file search without a restart - #54643

Closed
Hona wants to merge 1 commit into
anomalyco:devfrom
Hona:fresh-file-search
Closed

Hona wants to merge 1 commit into
anomalyco:devfrom
Hona:fresh-file-search

Conversation

@Hona

@Hona Hona commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Fixes #32747 (and its duplicates #38065, #37103).

Problem

  • ripgrepLayer (Windows default, non-VCS directories) rescanned at most every 10 s and never waited for the rescan, so the query that started it still got the old index.
  • fffLayer (git repos on Linux/macOS) relied only on fff's watcher. On WSL /mnt/*, 9p, SMB, and NFS mounts, the watcher reports isWatcherReady: true but never delivers changes. New files never appeared until a restart.

Fix

Both backends now follow one rule: rescan at most every 2 s, and the query that starts a rescan waits up to 250 ms for it.

// packages/core/src/filesystem/search.ts
const REFRESH_INTERVAL = Duration.toMillis("2 seconds") // was 10 s
const FRESH_WAIT = Duration.toMillis("250 millis")
sequenceDiagram
  participant P as @ picker
  participant S as FileSystemSearch
  participant I as index (ripgrep walk / fff)
  P->>S: find("plan"), index older than 2 s
  S->>I: rescan (ripgrep.find / picker.scanFiles())
  S-->>S: wait ≤ 250 ms
  I-->>S: fresh index swaps in atomically
  S->>P: results include plan.md
Loading
  • ripgrep: the query that starts a rescan waits for it. If the scan is slow or fails, the query answers from the previous index, and later queries get the new one once it swaps in.
  • fff: calls scanFiles() on the same interval instead of relying on its watcher, which misses every change on drvfs/9p while scanFiles() finds them. Queries also wait for the initial scan, which otherwise served a partial index right after boot.
  • Cost: at most one rescan every 2 s while queries arrive, and nothing while idle (30k files on NTFS: ~40 ms for fff, ~130 ms for ripgrep).

Before / after

Live GET /api/fs/find probes against a server built from this branch and from dev. Each yellow line marks when the new file was written.

Before After
  • Bottom group: a Windows server running fff on a project inside WSL (\\wsl.localhost\…). This has the same 9p watcher blindness as WSL /mnt.

Copilot AI balanced review requested due to automatic review settings October 11, 2026 23:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 reached their quota limit.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me. I checked it with a live test against real ripgrep and fff layers on a temp directory. On the base branch, a file created before a 2 s pause was still missing from ripgrep results. With this PR it shows up on the next query, and fff no longer returns [] on its first query. I couldn't test the WSL/9p watcher-blind case here. The search tests pass and packages/core type-checks.

The public API is unchanged (Fff.Picker is internal).

One inline note: on slow mounts, fff's cold-start wait is capped at 250 ms.

Related: #46417

const scanned = result.value.scanFiles()
if (!scanned.ok) yield* Effect.logWarning("failed to rescan fff index", { error: scanned.error })
}
// Rescans swap in atomically, but the initial scan exposes a partial index until it completes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This wait is capped at next.wait (≤ 250 ms). So on the slow mounts this PR targets, an initial fff scan that takes longer than that still serves a partial (often empty) index for the first queries. The ripgrep layer instead waits fully while !initialized. If the description's "no partial results on fff cold start" is meant to hold, should the first scan be awaited without the cap, like ripgrep does (e.g. track an initialized flag here too)?

The ripgrep index rescanned at most every 10 s and never waited for the rescan; fff trusted its watcher, which never reports changes on WSL /mnt, 9p, and network mounts. Both now rescan at most every 2 s, and the query that starts a rescan waits up to 250 ms for it. Fixes anomalyco#32747.
@Hona
Hona force-pushed the fresh-file-search branch from ca31785 to c78123a Compare October 12, 2026 00:06
@Hona Hona changed the title fix(core): revalidate file search index per search session fix(core): pick up new files in file search without a restart Oct 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@ file mentions do not include files created after startup

2 participants