Description
Note
Investigated by Claude Opus 5.5 in pi; written on behalf of the account owner.
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
My freeze on 0.1.9 was #22586, which #35460 fixed. On main, one fff call that waits on the same picker lock still runs on the JS thread: FileFinder.watch().
Area
apps/server
Steps to reproduce
Found by reading the code on main @ 6b7027b1f4. Not reproduced.
- Create a project's workspace index, for example by typing
@in the composer. - Make fff's watcher hold the picker write lock, for example by moving a large folder into the project.
index_new_directoryholdsshared_picker.write()while it stats and reads every file in that folder (background_watcher.rs#L844-L856). - Before the index has a watch subscription, type in the
@picker.searchandlistcalllistSymlinkEntries()→startSymlinkScan()→ensureWatching()→finder.watch()(WorkspaceSearchIndex.ts#L1036-L1045). Until a subscription exists, the scan result expires after 2 s (L1059-L1062), so each later read callswatch()again.
finder.watch() calls fff_watch_args synchronously: fff-node's ffiWatch uses callIntResult (ffi.ts#L1788-L1803). SharedFilePicker::watch then takes self.read() (shared.rs#L292-L307). The fff-node patch moves fff_scan_files, fff_get_scan_progress, the searches and fff_destroy to runInNewThread, but not fff_watch_args.
To check without the app, take the setup from #35460 (move a 200,000-file folder into an indexed folder) and call finder.watch(() => {}) instead of scanFiles().
Expected behavior
The server keeps answering while the watcher holds the lock, as it does for the paths fixed in #35460 and #36273.
Actual behavior
The JS thread blocks in fff_watch_args until the watcher releases the lock.
That can take minutes. On 0.1.9, through the refresh path that is now fixed, the watcher held the lock for 10.3 minutes:
- The project root was a folder that isn't a git repository, holding about 66 git worktrees, including 6 checkouts of a monorepo with about 615k files each.
WorkspaceSearchIndex.refreshtook 10.3 minutes. No other span ran in that time, and the desktop showed<host> is reconnecting · T3 Code on <host> did not answer.- A
sampleof the server showed the main thread waiting infff_scan_files→_pthread_cond_wait(2472 of 2472 samples). Meanwhilefff-watcher-ownwas inread,stat,openandcloseon files across one checkout. On macOS that thread only runsindex_new_directory(L117-L165).
Impact
Minor bug or occasional failure
It is rare, because it needs a busy watcher before the first subscription. When it happens, every client loses the server until the lock is released.
Version or commit
main @ 6b7027b1f4 for the code reading; desktop v0.1.9 for the measurements.
Environment
macOS 15.8.1, Apple Silicon. T3 Code (Beta) desktop 0.1.9, @ff-labs/fff-node 0.11.0.
Logs or stack traces
# server.trace.ndjson (0.1.9)
RunFinalizationService.finalize > RunFinalizationService.refresh > WorkspaceEntries.refresh > WorkspaceSearchIndex.refresh: 10.3 min
# sample, main thread (2472 of 2472 samples)
node::fs::AfterStat > [JS] > ffi-rs > fff_scan_files > _pthread_cond_wait
# sample, fff-watcher-own (2472 samples)
read 1362 · stat 641 · open 349 · close 82Workaround
Wait for the watcher to finish, or kill the backend. The desktop starts a new one.
Possible fix
Call fff_watch_args with runInNewThread, as the patch does for the other calls. Register the JS handler before events for the new watch id can arrive.
Related: #22586, #35460, #11306, #36273, dmtrKovalenko/fff#980.
Activity