Repository navigation
fix: resolve Pi selections against the host model catalog - #4710
Merged
Merged
Conversation
SawyerHood
pushed a commit
to stefanroex/bb
that referenced
this pull request
Oct 2, 2026
## Human comments ## What was wrong The Pi bridge keeps one `pi --mode rpc --no-session` catalog child per cwd. The child stays alive until it has gone `BB_PI_CATALOG_IDLE_MS` (5 minutes) without a fetch ([`catalog.ts`](https://github.com/get-bb/bb/blob/1b973d5584e10963018f4ae7d9c001e8ec09b99b/plugins/provider-pi/src/bridge/catalog.ts#L171-L241)). Pi answers `get_available_models` from `session.modelRuntime.getAvailableSnapshot()`, which it builds at startup, and its RPC protocol has no refresh command. While a child was alive, bb could not see models added to `models.json` or credentials added to `auth.json` until that child was replaced. [Root-cause report](https://get-bb.github.io/reports/issues/2289.html); additional evidence is in [this comment](get-bb#2289 (comment)). ## What changed - `plugins/provider-pi/src/bridge/bb-pi-extension.ts`: the embedded extension handles a new `refresh-models` bridge-channel request. It calls `ctx.modelRegistry.refresh({ allowNetwork: false })`, which reloads `models.json`, rebuilds providers, and reruns Pi's availability pass (re-reading `auth.json`). When the session context has no registry it returns `{ refreshed: false, reason: "unsupported" }`. A rejection comes back as the reply's `error`. - `plugins/provider-pi/src/bridge/catalog.ts`: - Each catalog child generation now correlates bridge-channel requests with their replies, using `catalog-<n>` IDs, a timeout, and rejection when the child exits. - Before every `get_available_models` except a generation's first, the catalog sends `refresh-models`. Concurrent reads share one in-flight refresh. - If the refresh is unsupported, rejects, or does not answer within 5 s, the child is killed, and the existing `PiRpcChildExitedError` retry in `fetchGeneration()` serves the list from a new child. - A generation's first read is never refreshed, since it serves the snapshot Pi just built. This also bounds the fallback to one respawn per read. - `probe()`, `touch()`, and the `catalog-model-scope` handshake are unchanged. - `plugins/provider-pi/src/bridge/fake-pi-rpc.mjs`: the fake now serves a boot-time snapshot, read from `FAKE_PI_MODELS_FILE` when set. Its extension context has a `modelRegistry.refresh` that reloads the snapshot and logs to `FAKE_PI_REFRESH_LOG`. New knobs: `FAKE_PI_NO_MODEL_REGISTRY=1` and `FAKE_PI_REFRESH_FAILURE=hang|reject`. Existing knobs are unchanged. There are no server, daemon wire, `HOST_DAEMON_PROTOCOL_VERSION`, CLI, environment-variable, or Pi version changes. This deviates from the report's proposal. Instead of fingerprinting `models.json`, the bridge asks Pi to reload. A fingerprint would miss credentials added to `auth.json`, which is the case in the follow-up evidence on the issue. Compatibility: `ModelRegistry.refresh` exists in Pi 0.84.0 (the declared minimum and the pinned devDependency) and in 1.0.0. The unsupported path covers a missing session context, or an older or custom build launched through `BB_PI_BRIDGE_COMMAND`. **Scope limit:** every bridge fetch is now fresh, but the server still memoizes the catalog for 10 minutes and serves stale data while it revalidates ([`FRESH_MS` / `evaluate()`](https://github.com/get-bb/bb/blob/1b973d5584e10963018f4ae7d9c001e8ec09b99b/apps/server/src/services/providers/provider-model-catalog-store.ts#L219-L247)). The model picker and `bb provider models pi` can therefore still lag by up to that window. That layer is a separate follow-up, and the design question for it is in [the issue comment](get-bb#2289 (comment)). `resolvePiModel()` reads the warm catalog through the same `rawModels()` path, so bridge-side model resolution sees new models right away. ## How you verified - New tests in `catalog.test.ts`. All five fail on `main` with the stale `[ 'fake-provider/fake-model' ]` list and pass with this change: - A model added after the child started is served without a respawn. The spawn counter stays at 1, and there is one `{"allowNetwork":false}` refresh. - Concurrent `listModels()` and `rawModels()` calls share one refresh. - With no model registry, the second read comes from a new child (spawn counter 2). - When the refresh hangs or rejects, the child is replaced and the first child has exited (2 cases). - The existing restart test (`FAKE_PI_SCOPE_BY_SPAWN` / `FAKE_PI_EXIT_AFTER_FIRST_AVAILABLE`) passes, unchanged. - `pnpm exec turbo run test --filter=bb-plugin-provider-pi`: 27 files, 170 tests passed. `turbo run typecheck` and `turbo run lint` (0 warnings, 0 errors) pass for the same filter. `git diff --check` is clean, and `oxfmt --check` is clean on the four changed files. - Real Pi, no bb server. I called `getPiCatalog()` with the real `pi` binary and an isolated `PI_CODING_AGENT_DIR`: read, add a model to `models.json`, read, write a `deepseek` key to `auth.json`, read. - `main`, Pi 1.0.0: `['probe/alpha']` on all three reads. - This branch, Pi 1.0.0: `['probe/alpha']` → `['probe/alpha', 'probe/beta']` → `['deepseek/deepseek-flash', 'deepseek/deepseek-v4-pro', 'probe/alpha', 'probe/beta']`, with the same `pi` PID throughout and 2–4 ms per read. - This branch, Pi 0.84.0: the same result (`deepseek/deepseek-v4-flash`, `deepseek/deepseek-v4-pro`), with the same PID. - The open get-bb#4710 also edits `fake-pi-rpc.mjs`. A test merge with it applies cleanly. Fixes get-bb#2289 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
🚨 SLOP COP 🚨 ·
new-issue-autopilotHuman comments
What was wrong
Pi model selections containing slashes were split into an assumed provider/ID pair before an exact catalog lookup. Pi could resolve the same input as a complete raw ID under another provider, and BB's strict startup verification then rejected the mismatch. Cold and warmed catalogs both reproduce this on trusted main. Reproduction and root-cause report.
What changed
The change stays within the existing Pi provider subsystem: 153 changed text lines (126 additions + 27 deletions), five files against
origin/mainata312ed2d632582c7f87585aa9eefc59169f17f8d. No dependency, lockfile, generated file, migration, stored-data, public wire/schema, authentication, authorization, permission, packaging, or release changes. No CLI flags or public SDK surface are added.How you verified
4e1d893fbd058354bcdc283eade2669fd9e7ac9d. Pi's pinned actual resolver also confirms the synthetic catalog interpretation offline.pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/bridge/bridge.model-resolution.test.tspasses all 14 regression cases.pnpm exec turbo run test typecheck lint --filter=bb-plugin-provider-pipasses: 178 tests passed, one Bun-only test skipped, typecheck passed, lint passed.git diff --checkpasses andgit diff --numstat origin/maincontains only text changes. Oxfmt passes four changed files; the two formatting discrepancies inbridge.tsare identical to untouched trusted main and are left unchanged.No live user runtime, account credentials, desktop instance, or remote model request was used. No linked PR was executed, and no existing open PR links to this issue at the final duplicate check.
Fixes #4704