fix(pi-fff): non-blocking session_start warmup#599
Open
gustav-fff wants to merge 1 commit into
Open
Conversation
Schedule FileFinder.create + waitForScan via setTimeout(0) so Pi /new and /resume return immediately. A monotonic lifecycleId tagged on each session_start / session_shutdown lets a stale warmup detect that the session has been replaced and skip both ensureFinder and ctx.ui.notify. ensureFinder now returns the local handle so a shutdown mid-warmup can't hand back a destroyed/replaced finder. Closes #477
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #477
Root cause
packages/pi-fff/src/index.tssession_starthandler awaitedensureFinder()→finder.waitForScan(15000). Pi recreates the session runtime on/newand/resume, so the lifecycle hook blocked the UI until the FFF initial scan finished (up to 15s on large workspaces).Fix
ensureFinder(activeCwd)fromsession_startviasetTimeout(0)instead of awaiting it. The handler returns immediately; the warmup runs in the background.lifecycleId, bumped on everysession_startandsession_shutdown. The deferred warmup checks the captured id and bails out (noensureFinder, noctx.ui.notify) if the session has been replaced.ensureFinderreturns the localcreatedhandle instead of the mutablefinderglobal, so adestroyFinder()racing the warmup cannot hand back a destroyed/replaced instance to the caller.The native SDK already exposes
waitForScanas a non-blocking polling loop (packages/fff-node/src/finder.ts:477), so no SDK changes were needed — only the lifecycle hook.Steps to reproduce
Pre-fix, on
main:Expected: new session is interactive immediately.
Actual (pre-fix): UI hangs for up to 15s while
FileFinder.create+ initial scan runs insidesession_start. Same hang on/resumeafter picking a session.Post-fix:
/newand/resumereturn instantly. The firstffgrep/fffind/@-mention call awaits the same in-flightensureFinderpromise as before.How verified
bun test test/inpackages/pi-fff— all 17 tests pass (test helper updated to flush the deferred warmup before asserting).tsc --noEmitproduces only the pre-existing module-resolution errors (unchanged frommain).lifecycleId, andensureFinderreturns the local handle.Automated triage via Gustav. Honk-Honk 🪿