Skip to content

fix: resolve Pi selections against the host model catalog - #4710

Merged
SawyerHood merged 1 commit into
mainfrom
slopcop/issue-4704
Oct 2, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
slopcop/issue-4704

Conversation

@bb-slop-cop

@bb-slop-cop bb-slop-cop Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · new-issue-autopilot

Human 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

  • Resolve exact canonical catalog references first, otherwise require one exact complete raw-ID match; reject ambiguity and missing models before launch.
  • Pass the resolved provider and raw model ID explicitly to Pi, retaining strict startup verification.
  • Add cold/warm bridge regression coverage for canonical multi-slash references, raw IDs, direct-route precedence, ambiguity, and missing selections.
  • Extend the existing RPC fixture for these selections, and warm/filter the catalog child in the existing transient-retry test so it continues to exercise an actual failed session and respawn.

The change stays within the existing Pi provider subsystem: 153 changed text lines (126 additions + 27 deletions), five files against origin/main at a312ed2d632582c7f87585aa9eefc59169f17f8d. 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

  • Before the production fix: the startup regression command failed only the cold/warm raw-ID cases (2 failed, 6 passed, 6 excluded), repeated by the same agent in a second clean checkout at report base 4e1d893fbd058354bcdc283eade2669fd9e7ac9d. Pi's pinned actual resolver also confirms the synthetic catalog interpretation offline.
  • Re-ran the two failing raw-ID cases on the latest trusted fix base, unchanged production code: both failed with the intended provider mismatch.
  • After the fix: pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/bridge/bridge.model-resolution.test.ts passes all 14 regression cases.
  • Existing transient-retry test passes after accounting for the catalog child, with a real failed session followed by its replacement.
  • pnpm exec turbo run test typecheck lint --filter=bb-plugin-provider-pi passes: 178 tests passed, one Bun-only test skipped, typecheck passed, lint passed.
  • git diff --check passes and git diff --numstat origin/main contains only text changes. Oxfmt passes four changed files; the two formatting discrepancies in bridge.ts are 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

AGENT GENERATED

@SawyerHood
SawyerHood merged commit b6aaf9f into main Oct 2, 2026
26 of 27 checks passed
@SawyerHood
SawyerHood deleted the slopcop/issue-4704 branch October 2, 2026 15:20
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]>
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.

Pi provider misparses slash-containing model IDs

1 participant