fix(pi-fff): cache sdk import across reloads to avoid /reload hang - #758
Merged
dmtrKovalenko merged 1 commit intoAug 9, 2026
Merged
Conversation
Pi reloads extension modules with jiti moduleCache:false, so loadSdk() re-executes a dynamic import of the fff-bun module graph on every /reload. The fff-bun graph top-level awaits a type:file import of the native .so, which never resolves when re-imported inside the Bun-compiled pi binary, leaving the reload screen stuck forever (pi awaits session_start handlers without a timeout). Cache the first import on globalThis so reloads reuse it. Closes dmtrKovalenko#757
dmtrKovalenko
approved these changes
Aug 9, 2026
abhijit-s
pushed a commit
to abhijit-s/fff
that referenced
this pull request
Aug 10, 2026
Upstream (6 commits): rescan throttling for giant folders (dmtrKovalenko#751), configurable $HOME scanning (dmtrKovalenko#743/dmtrKovalenko#749), Lua-level fs-root/home guard (dmtrKovalenko#745/dmtrKovalenko#748), pi-fff SDK import cache (dmtrKovalenko#758), release 0.10.3. Conflict resolution: - Cargo.toml/Cargo.lock (all crates): keep fork's 0.17.2 version scheme over upstream's 0.10.3; preserve fff-mcp's fff-ipc/dirs/libc deps and upstream's new rescan-stats feature. - Makefile: union of fork's daemon/install targets and upstream's test-rescan/rescan-probe targets. - install-mcp.sh: keep fork's removal of the pinned-release SHA block (delivery is via Homebrew tap + apt, not pinned GitHub tarballs). - background_watcher.rs: adopt upstream's throttled try_trigger_full_rescan mechanism wholesale, keeping only the fork's per-root user_gi ignore filter; drop the obsolete need_full_rescan boolean.
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 #757
Root cause
Pi reloads extension modules with
jitimoduleCache: false, soloadSdk()inpackages/pi-fff/src/sdk.tsre-executes a dynamicimport("@ff-labs/fff-bun")on every/reload. The fff-bun module graph top-level awaits atype: "file"import of the nativelibfff_c.so(packages/fff-bun/src/embedded.ts), which never resolves when re-imported inside the Bun-compiled pi binary. Since pi awaits allsession_starthandlers without a timeout, the reload screen sticks on "Reloading keybindings..." forever (CPU ≈ 0).The first import at startup resolves fine (~20ms); plain
bunre-imports also work — the hang is specific to the pi Bun binary + jiti combination.Fix
Cache the first import on
globalThisso reloads reuse the resolved module instead of re-importing:Verification
Reproduced in an isolated env (copied agent dir +
PI_CODING_AGENT_DIR, PTY driver):/reloadstuck >60s, no "Reloaded keybindings" line, process at ~0% CPU./reloadcalls all succeed in ~2s with the full 28-package user settings.Note: #599 (non-blocking session_start warmup) would mask the UI hang, but the background import would still hang and break subsequent fff tool calls, which
awaitthe same in-flightsdkPromise. This import-level fix is complementary.