Repository navigation
Keep the Pi model list alive when an extension is broken - #1148
SawyerHood merged 2 commits into
Conversation
Issue #1086 asks to port primeExtensions() to the production Pi bridge so extension providers appear in the stock Pi provider. That port already landed in #1080: the bridge builds its model runtime through createConfiguredPiServices(), and Pi 0.84.0 flushes the pending provider registrations inside createAgentSessionServices(). A disposable priming session is not necessary. An end-to-end test against the built bridge with the real pi-commandcode-provider extension returns its 51 models. The same test found two defects that still produce the symptom in the issue. A broken extension emptied the whole picker. collectServiceErrors() throws on any extension load error, and getPiModelRuntime() passed that on, so model/list answered with an error. The user lost every model on the machine, built-in providers included, because of one bad third-party extension. Split the service builder: loadConfiguredPiServices() reports the problems and createConfiguredPiServices() still throws. Model listing now writes the problems to stderr and lists what loaded. Thread start still fails loudly, so a run never uses a partial configuration in silence. An extension model without input types crashed the list. An extension registers its models from plain JavaScript, so Pi's required `input` can be missing at runtime, and the spread threw. One malformed model hid every other provider. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🚨 SLOP COP 🚨 · I am the SlopCop. I am reviewing this pull request for security, code quality, architecture, performance, tests, and product behavior. I will post one final review after the parallel checks finish. |
| for (const configError of configErrors) { | ||
| process.stderr.write(`pi bridge: ${configError}\n`); | ||
| } | ||
| return services.modelRuntime; |
There was a problem hiding this comment.
🚨 slopcop/review — P2: Do not cache a partial runtime after configuration errors
loadConfiguredPiServices() now resolves with configErrors. The promise therefore stays in modelRuntimePromises.
If the user fixes the extension, later model/list calls still use the partial runtime. The repaired provider stays absent until the long-lived bridge restarts.
Delete this cache entry when configuration errors exist. Add a test where the first load has an error and the next load returns the repaired runtime.
There was a problem hiding this comment.
Fixed in 493bb91. getPiModelRuntime() now deletes the memo when configErrors is non-empty, so the next call reloads.
Verified end to end against the built bb-pi-bridge.mjs, repairing the extension without restarting the bridge process:
1. broken extension present: commandcode-fake: 2
2. after repair, same process: commandcode-fake: 2, repaired: 1
Added two tests: one where the first load reports an error and the next returns the repaired runtime, and one asserting a clean load still memoizes.
| // An extension registers its models from plain JavaScript, so Pi's | ||
| // required `input` can still be missing at runtime. Reading it blindly | ||
| // threw and failed the whole list, which hid every other provider too. | ||
| input: Array.isArray(model.input) ? [...model.input] : [], |
There was a problem hiding this comment.
🚨 slopcop/review — P2: Validate each model before the list builder uses it
This guard handles a missing input value, but Pi can also return a JavaScript extension model without an id. buildPiAvailableModels() then calls id.endsWith() and drops the complete model list.
Skip each malformed model at this boundary. Add a test with one model without an identifier and one valid model.
There was a problem hiding this comment.
Fixed in 493bb91. You are right that id is equally extension-supplied, and I confirmed the failure: isModelAlias() calls id.endsWith() and throws, which fails the whole list.
Replaced the single-field guard with boundary validation. toPiCatalogModel() now drops any model missing a usable id, name, or provider, defaults input, and writes the skip to stderr. Added a test with one model without an identifier alongside a valid one.
SawyerHood
left a comment
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
ELI5
The model list is like a toy shelf. One broken toy no longer hides all the good toys.
Two problems remain. A repaired toy stays hidden until the room restarts. A toy without a name tag can still hide the shelf.
Findings
- P2 — A partial runtime stays cached. When an extension fails, the bridge caches the partial runtime for that workspace. A later extension repair does not restore its models until the long-lived bridge restarts.
- P2 — One malformed model can still drop the complete list. The new guard handles a missing
inputvalue. A JavaScript extension model without anidstill causesbuildPiAvailableModels()to throw.
I left inline comments with a test case for each problem.
Other checks
I found no security problem. Project trust still controls extension load, and thread start still uses the strict configuration path.
I found no performance regression. Clean workspaces keep the same one-time service load, and the new array check has a constant cost.
The tolerant loader and strict wrapper form a clear architecture. I found no duplicate error collector or duplicate fallback logic.
Validation
- The exact head SHA passed the
@bb/agent-runtimeTurbo type check. - All 823
@bb/agent-runtimetests passed. git diff --checkpassed.- All applicable GitHub checks passed.
- I did not run a browser test. This host-local Pi configuration path has no direct browser route.
This review uses comments only. It does not approve the pull request or request changes.
Do not keep a partial model runtime in the cache. The bridge is long-lived, so a memoized runtime built from a broken configuration hid a repaired extension until the process restarted. Drop the memo when the load reports configuration errors and reload on the next call. Validate each Pi model at the boundary instead of guarding one field. An extension registers its models from plain JavaScript, so `id`, `name`, and `provider` can be missing too. A model without an id reached `isModelAlias()`, which called `id.endsWith()` and failed the whole list. Skip the incomplete model and report it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Fixes #1123. ## Summary - resolve an ambiguous bare Pi model through its sole authenticated provider - keep explicit provider selections authoritative - retain the ambiguity error when zero or multiple matching providers have authentication - bump the host daemon protocol to update enrolled daemons before the model meaning changes ## Tests - `pnpm exec turbo run test typecheck --filter=@bb/host-daemon-contract --filter=@bb/agent-runtime --force` - 879 tests passed after rebasing on #1148 - both package typechecks passed ## Risk The behavior changes only for bare model IDs with multiple catalog matches and exactly one authenticated provider. Explicit provider-prefixed IDs remain unchanged.
## Summary - Verify that the `primeExtensions()` port asked for in get-bb#1086 already landed in get-bb#1080, end to end against the built bridge. - Stop one broken Pi extension from emptying the whole model picker. - Stop an extension model without `input` types from failing the whole model list. ## Why get-bb#1086 asks to port `primeExtensions()` to the production Pi bridge so extension providers such as `commandcode` appear in the stock Pi provider. That port already landed in get-bb#1080 (`8d7bf6124`). The bridge builds its model runtime through `createConfiguredPiServices()`, and Pi 0.84.0 flushes `pendingProviderRegistrations` inside `createAgentSessionServices()`. A disposable priming session is not necessary. I confirmed this with the real extension from the issue, not a mock: `[email protected]` installed from npm, driven by a real `model/list` JSON-RPC request to the built `dist/bb-pi-bridge.mjs`. It returns **51 CommandCode models**. That test found two defects that still produce the exact symptom in the issue. ### 1. A broken extension emptied the whole picker `collectServiceErrors()` throws on any extension load error, and `getPiModelRuntime()` passed that on, so `model/list` answered with a JSON-RPC error. The user lost every model on the machine, built-in providers included, because of one bad third-party extension. Repro before this change, with a working extension and a broken one installed together: ``` Error: Failed to load Pi extension "/tmp/pi-broken/ext/broken.ts": Cannot find module '@not-installed/nope' ``` The fix splits the service builder. `loadConfiguredPiServices()` reports the problems, and `createConfiguredPiServices()` still throws. Model listing writes the problems to stderr and lists what loaded. Thread start still fails loudly, so a run never uses a partial configuration in silence. After, through the shipped bundle: ``` pi bridge: Failed to load Pi extension "/tmp/pi-broken/ext/broken.ts": ... TOTAL 2 commandcode-fake: 2 ``` ### 2. An extension model without `input` crashed the list `input: [...model.input]` threw `TypeError: model.input is not iterable`. Pi types `input` as required, but an extension registers its models from plain JavaScript and Pi does not validate them. One malformed model hid every other provider. ## Impact A user with a broken or outdated Pi extension keeps a working model picker and gets the reason on stderr, instead of an empty picker with no explanation. ## Note on model counts Extension models appear only when the provider has credentials. With `COMMANDCODE_API_KEY` unset, `getAvailable()` filters CommandCode out and the count returns to 0. That is correct Pi behavior, not a BB defect, but it may explain part of what the reporter saw. `HOST_DAEMON_PROTOCOL_VERSION` is unchanged: this is internal to the bridge process and the `model/list` result shape is the same. ## Validation - 823 `@bb/agent-runtime` tests, including 3 new regression tests - 482 `@bb/host-daemon` tests - `pnpm exec turbo run typecheck --filter=@bb/agent-runtime --filter=@bb/host-daemon` - ESLint on `packages/agent-runtime/src/pi` - All three scenarios driven over JSON-RPC against the built `bb-pi-bridge.mjs`, not only against source Fixes get-bb#1086 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Fixes get-bb#1123. ## Summary - resolve an ambiguous bare Pi model through its sole authenticated provider - keep explicit provider selections authoritative - retain the ambiguity error when zero or multiple matching providers have authentication - bump the host daemon protocol to update enrolled daemons before the model meaning changes ## Tests - `pnpm exec turbo run test typecheck --filter=@bb/host-daemon-contract --filter=@bb/agent-runtime --force` - 879 tests passed after rebasing on get-bb#1148 - both package typechecks passed ## Risk The behavior changes only for bare model IDs with multiple catalog matches and exactly one authenticated provider. Explicit provider-prefixed IDs remain unchanged.
Summary
primeExtensions()port asked for in Port primeExtensions() to production Pi bridge so commandcode/extension models appear in stock Pi provider #1086 already landed in Load user Pi configuration in the bundled runtime #1080, end to end against the built bridge.inputtypes from failing the whole model list.Why
#1086 asks to port
primeExtensions()to the production Pi bridge so extension providers such ascommandcodeappear in the stock Pi provider.That port already landed in #1080 (
8d7bf6124). The bridge builds its model runtime throughcreateConfiguredPiServices(), and Pi 0.84.0 flushespendingProviderRegistrationsinsidecreateAgentSessionServices(). A disposable priming session is not necessary.I confirmed this with the real extension from the issue, not a mock:
[email protected]installed from npm, driven by a realmodel/listJSON-RPC request to the builtdist/bb-pi-bridge.mjs. It returns 51 CommandCode models.That test found two defects that still produce the exact symptom in the issue.
1. A broken extension emptied the whole picker
collectServiceErrors()throws on any extension load error, andgetPiModelRuntime()passed that on, somodel/listanswered with a JSON-RPC error. The user lost every model on the machine, built-in providers included, because of one bad third-party extension.Repro before this change, with a working extension and a broken one installed together:
The fix splits the service builder.
loadConfiguredPiServices()reports the problems, andcreateConfiguredPiServices()still throws. Model listing writes the problems to stderr and lists what loaded. Thread start still fails loudly, so a run never uses a partial configuration in silence.After, through the shipped bundle:
2. An extension model without
inputcrashed the listinput: [...model.input]threwTypeError: model.input is not iterable. Pi typesinputas required, but an extension registers its models from plain JavaScript and Pi does not validate them. One malformed model hid every other provider.Impact
A user with a broken or outdated Pi extension keeps a working model picker and gets the reason on stderr, instead of an empty picker with no explanation.
Note on model counts
Extension models appear only when the provider has credentials. With
COMMANDCODE_API_KEYunset,getAvailable()filters CommandCode out and the count returns to 0. That is correct Pi behavior, not a BB defect, but it may explain part of what the reporter saw.HOST_DAEMON_PROTOCOL_VERSIONis unchanged: this is internal to the bridge process and themodel/listresult shape is the same.Validation
@bb/agent-runtimetests, including 3 new regression tests@bb/host-daemontestspnpm exec turbo run typecheck --filter=@bb/agent-runtime --filter=@bb/host-daemonpackages/agent-runtime/src/pibb-pi-bridge.mjs, not only against sourceFixes #1086
🤖 Generated with Claude Code