Skip to content

fix(pi-fff): isomorphic bun/node SDK lazy-load#669

Open
gustav-fff wants to merge 1 commit into
mainfrom
triage-bot/issue-668
Open

fix(pi-fff): isomorphic bun/node SDK lazy-load#669
gustav-fff wants to merge 1 commit into
mainfrom
triage-bot/issue-668

Conversation

@gustav-fff

@gustav-fff gustav-fff commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Closes #668

Root cause

packages/pi-fff/src/index.ts:21 had a top-level import { FileFinder } from "@ff-labs/fff-node". @ff-labs/fff-node pulls ffi-rs and the optional per-platform native binary packages (@ff-labs/fff-bin-*) into its module graph. oh-my-pi statically resolves every extension import to validate the extension; the optional native package for a foreign platform is not on disk, so validation fails even though the runtime install would be fine.

Reporter also flagged that pi runs under both bun and node — but pi-fff only ever loaded the node SDK, so bun hosts paid the ffi-rs cost instead of using @ff-labs/fff-bun which shares the same FileFinderApi.

Fix

  • Drop the static FileFinder value import; keep @ff-labs/fff-node for type-only imports (erased at compile time, invisible to the static validator).
  • New detectRuntime() checks globalThis.Bun and process.versions.bun.
  • New loadSdk() does a variable-name await import(pkg) for the runtime-appropriate SDK, with a fallback to the other one. Variable-name import defeats static resolvers.
  • Result cached in sdkPromise so a single load survives concurrent tool calls.
  • ensureFinder() now await loadSdk() before FileFinder.create(...); the existing in-flight-promise guard from pi-fff: parallel ffgrep calls can hang indefinitely due to unsynchronized ensureFinder singleton #403 still serializes creation.
  • package.json: add @ff-labs/fff-bun as an optional peer dependency so bun-hosted pi pulls it in without forcing node-hosted pi to install it.

Both SDKs implement the identical FileFinderApi (packages/shared/fff-api.ts:528), so the call sites don't change.

Steps to reproduce

git checkout main
cd packages/pi-fff
bun install
# The static import chain is visible to any resolver that walks it:
node -e "console.log(require.resolve('@ff-labs/fff-node'))"
# oh-my-pi's static validator follows @ff-labs/fff-node -> ffi-rs -> optional native binary,
# which is missing for platforms other than the host and aborts validation.

Expected: extension loads under oh-my-pi.
Actual: validator errors on the unresolved optional native package.

How verified

  • cd packages/pi-fff && bun run typecheck — clean.
  • bun test test/ — 18/18 pass (added mock for @ff-labs/fff-bun alongside @ff-labs/fff-node since bun-hosted tests now prefer the bun SDK).
  • bun run format — no changes.

Not verified end-to-end against a real oh-my-pi install — that would need the pi validator in the loop. @dmtrKovalenko please smoke-test under omp before releasing.

Automated triage via Gustav. Honk-Honk 🪿

@gustav-fff

Copy link
Copy Markdown
Collaborator Author

[triage-bot] CI note: Spell Check with Typos fails on crates/fff-core/src/bigram_query.rs:202 (simpliestsimplest). Pre-existing on main — same failure on the latest main run: https://github.com/dmtrKovalenko/fff/actions/runs/29052646755. Unrelated to this diff.

Honk-Honk 🪿

Detect bun vs node at runtime and dynamically import the matching SDK
(@ff-labs/fff-bun on bun, @ff-labs/fff-node on node) via a variable
package name so oh-my-pi's static extension validator does not chase
ffi-rs' optional native binaries through the module graph.

Closes #668
@dmtrKovalenko dmtrKovalenko force-pushed the triage-bot/issue-668 branch from a265a46 to fbdf9f8 Compare July 10, 2026 00:10
@gustav-fff gustav-fff changed the title fix: lazy-load @ff-labs/fff-node in pi-fff (#668) fix(pi-fff): isomorphic bun/node SDK lazy-load Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Suggestion]: statically link imports

1 participant