Repository navigation
Refresh Pi's model registry before serving the catalog - #4727
Conversation
The bridge keeps one `pi --mode rpc` child per cwd for up to five idle
minutes, and Pi answers `get_available_models` from a snapshot it builds
at startup. Models or credentials added while the child was alive stayed
invisible until the child was replaced.
Before every catalog read after a generation's first, ask the bb
extension inside Pi to call `ctx.modelRegistry.refresh({ allowNetwork:
false })` over the bridge channel. Concurrent reads share one refresh.
When the registry is missing, the refresh rejects, or it does not answer
within five seconds, kill the child and let the existing exit retry serve
the list from a newly started one.
Refs get-bb#2289
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks @dandaka for the PR. This repo needs approval before a PR. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ) and explain what you want to open a PR for and why. A maintainer then adds you to the allow list. This PR now closes on its own. Reopen it or open a new one after approval. |
## Human comments ## What was wrong @dandaka's PR #4727 was closed by the contributor gate because the account was absent from the approved contributor list. ## What changed Add `dandaka` to `.github/APPROVED_CONTRIBUTORS` so they can open pull requests. This grants PR approval only. ## How you verified Verified the canonical GitHub login, confirmed it was absent from main, checked that the diff adds only this login, and confirmed it appears exactly once case-insensitively. `git diff --check` passed. CI and SlopCop are skipped for this data-only change. > AGENT GENERATED
SawyerHood
left a comment
There was a problem hiding this comment.
Reviewed commit e0838a7. No blocking findings.
The refresh uses the same ModelRuntime that serves get_available_models in the supported Pi 0.84.0 dependency. Reply correlation, shared in-flight refresh, and bounded child-replacement retry cover the changed behavior. The tests load the actual embedded extension and exercise freshness and unsupported, rejected, and timed-out refresh paths.
Independent verification:
pnpm exec turbo run test typecheck lint --filter=bb-plugin-provider-pipassed: 169 tests passed, one Bun runtime test skipped; typecheck and lint passed.- Real Pi 0.84.0 with an isolated PI_CODING_AGENT_DIR: adding and removing models in models.json and adding a placeholder provider key in auth.json were reflected by successive reads through the same catalog object.
git diff --checkpassed.
The server's existing 10-minute catalog cache remains a documented scope limitation: this fixes bridge freshness, while model-picker freshness still needs the separate follow-up described in the PR. I did not verify Pi 1.0.0 independently.
AGENT GENERATED
Human comments
What was wrong
The Pi bridge keeps one
pi --mode rpc --no-sessioncatalog child per cwd. The child stays alive until it has goneBB_PI_CATALOG_IDLE_MS(5 minutes) without a fetch (catalog.ts). Pi answersget_available_modelsfromsession.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 tomodels.jsonor credentials added toauth.jsonuntil that child was replaced. Root-cause report; additional evidence is in this comment.What changed
plugins/provider-pi/src/bridge/bb-pi-extension.ts: the embedded extension handles a newrefresh-modelsbridge-channel request. It callsctx.modelRegistry.refresh({ allowNetwork: false }), which reloadsmodels.json, rebuilds providers, and reruns Pi's availability pass (re-readingauth.json). When the session context has no registry it returns{ refreshed: false, reason: "unsupported" }. A rejection comes back as the reply'serror.plugins/provider-pi/src/bridge/catalog.ts:catalog-<n>IDs, a timeout, and rejection when the child exits.get_available_modelsexcept a generation's first, the catalog sendsrefresh-models. Concurrent reads share one in-flight refresh.PiRpcChildExitedErrorretry infetchGeneration()serves the list from a new child.probe(),touch(), and thecatalog-model-scopehandshake are unchanged.plugins/provider-pi/src/bridge/fake-pi-rpc.mjs: the fake now serves a boot-time snapshot, read fromFAKE_PI_MODELS_FILEwhen set. Its extension context has amodelRegistry.refreshthat reloads the snapshot and logs toFAKE_PI_REFRESH_LOG. New knobs:FAKE_PI_NO_MODEL_REGISTRY=1andFAKE_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 toauth.json, which is the case in the follow-up evidence on the issue.Compatibility:
ModelRegistry.refreshexists 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 throughBB_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()). The model picker andbb provider models pican 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.resolvePiModel()reads the warm catalog through the samerawModels()path, so bridge-side model resolution sees new models right away.How you verified
catalog.test.ts. All five fail onmainwith the stale[ 'fake-provider/fake-model' ]list and pass with this change:{"allowNetwork":false}refresh.listModels()andrawModels()calls share one refresh.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 typecheckandturbo run lint(0 warnings, 0 errors) pass for the same filter.git diff --checkis clean, andoxfmt --checkis clean on the four changed files.getPiCatalog()with the realpibinary and an isolatedPI_CODING_AGENT_DIR: read, add a model tomodels.json, read, write adeepseekkey toauth.json, read.main, Pi 1.0.0:['probe/alpha']on all three reads.['probe/alpha']→['probe/alpha', 'probe/beta']→['deepseek/deepseek-flash', 'deepseek/deepseek-v4-pro', 'probe/alpha', 'probe/beta'], with the samepiPID throughout and 2–4 ms per read.deepseek/deepseek-v4-flash,deepseek/deepseek-v4-pro), with the same PID.fake-pi-rpc.mjs. A test merge with it applies cleanly.Fixes #2289
🤖 Generated with Claude Code