Skip to content

fix(pi-fff): fall back to transient finder when LMDB env already open (#760) - #763

Closed
gustav-fff wants to merge 1 commit into
mainfrom
triage-bot/issue-760
Closed

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

Conversation

@gustav-fff

Copy link
Copy Markdown
Collaborator

Closes #760

Root cause

heed 0.22 keeps a process-global OPENED_ENV registry (env_open_options.rs:405-422); opening the same canonical LMDB path twice in one process returns Error::EnvAlreadyOpened. pi-fff's main finder always opens the fixed ~/.pi/agent/fff/{frecency,history} (packages/pi-fff/src/index.ts:313-321), so an in-process subagent (createAgentSession) that loads the extension a second time hits this on FileFinder.create(). #700 fixed only aux finders, not the main finder.

Fix

When ensureFinder gets EnvAlreadyOpened from FileFinder.create(), retry once without frecencyDbPath/historyDbPath — a transient finder without persistent scoring, exactly like aux finders (#700). packages/pi-fff/src/index.ts.

Steps to reproduce

Rust layer (proves the engine-level cause), add to crates/fff-core/src/dbs/frecency.rs tests and run cargo test -p fff-search:

#[test]
fn repro_760() {
    let dir = std::env::temp_dir().join("fff_repro_760");
    let _ = std::fs::remove_dir_all(&dir);
    assert!(FrecencyTracker::open(dir.to_str().unwrap()).is_ok());   // first open
    let b = FrecencyTracker::open(dir.to_str().unwrap());            // second open, same process
    if let Err(e) = &b { eprintln!("{e}"); }
    assert!(b.is_ok());                                             // FAILS on pre-fix main
}

Pre-fix actual output:

SECOND OPEN ERROR: Failed to open frecency database env: environment already open in this program; close it to be able to open it again with different options

Expected: second open succeeds (or the caller degrades gracefully). In pi-fff this surfaces as FFF init failed: ...environment already open... on subagent start.

How verified

bun test test/     # packages/pi-fff -> 56 pass, 0 fail (adds a fallback test)

The new test falls back to a transient finder when the LMDB env is already open forces create() to return EnvAlreadyOpened once and asserts the retry drops the DB paths and session_start does not error.

Automated triage via Gustav. Honk-Honk 🪿

…#760)

In-process subagents (createAgentSession) load the extension a second time
in the same process. heed opens an LMDB env at most once per path per
process, so reopening the shared frecency/history DBs fails with
EnvAlreadyOpened. Retry the main finder without persistent scoring, matching
the aux-finder precedent (#700).

Closes #760
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.

[Bug]: Pi extension breaks with in-process subagents

2 participants