Skip to content

Resolve provider env without a thread for bb model listing - #70

Merged
OXI-717 merged 1 commit into
OXI-717:mainfrom
ymichael:fix/null-thread-provider-env
Oct 20, 2026
Merged

OXI-717 merged 1 commit into
OXI-717:mainfrom
ymichael:fix/null-thread-provider-env

Conversation

@ymichael

Copy link
Copy Markdown
Contributor

Hi! I'm one of the bb maintainers. get-bb/bb#5767 changes bb.providers.experimental_contributeEnv: bb now also calls resolvers when it lists a provider's models, so the model picker shows the models the pool can serve rather than only the machine's own login. For those calls the context has threadId: null and projectId: null. (ExperimentalPluginProviderEnvContext becomes string | null for both in @get-bb/plugin-sdk 0.6.57.)

What breaks without this

In account-pool-balanced, every resolver passes context.threadId to hubTokens.forThread, which parses it as a string. The Claude resolver also passes it to routing.recordRouted, which builds routed:<threadId> with the same check. With a null thread they throw. bb logs the error and drops the plugin's env for that listing, so Codex, Claude Code, Cursor, Kimi, Devin and the OpenAI-compatible providers list models from the machine's own login, which is the bug get-bb/bb#5767 fixes for the bundled Account Pooler.

Change

  • isThreadBypassed(context): a null thread is never bypassed.
  • scopedHubToken(context): with a null thread it uses hubTokens.forProject(hostId, projectId), which returns the host token when the project is null. Otherwise it uses forThread as before.
  • The Claude resolver records the routed thread only when there is one.

Thread sessions and turns behave exactly as before.

Verification

  • New test resolves pooled env without a thread for bb model listing. It resolves Claude Code env with a null thread and project, then sends /v1/messages through the hub with the returned token and gets a 200. It fails without the change.
  • npx tsc --noEmit, npx vitest run src/server.test.ts (218/218) and bb plugin build . in plugins/account-pool-balanced.

The test casts the null context, because SDK types before 0.6.57 still declare both fields as strings.

AGENT GENERATED

🤖 Generated with Claude Code

bb now resolves contributed provider environment with a null thread and project
when it lists a provider's models, so the model picker matches what pooled
threads can use. hubTokens.forThread and the routed-thread key both require a
thread, so every resolver threw and bb dropped the pool env for model listing.
Without a thread, resolvers skip the bypass check and routed-thread record and
use the host-scoped token.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael added a commit to get-bb/bb that referenced this pull request Oct 19, 2026
)

## Human comments

## What was wrong

The model catalog sent `provider.list_models` without the environment
plugins contribute through `bb.providers.experimental_contributeEnv`.
Those resolvers ran only for thread sessions and turns. With the Account
Pooler routing Codex, the bridge's model-list `codex app-server`
therefore started with the machine's own Codex login instead of the
pool. On a machine without its own login, or with a smaller plan, the
picker showed only that account's models. For example, GPT-6-Astra and
the Sol models were missing even though pooled threads could use them.

## What changed

- **Server** (`provider-model-catalog-store.ts`): catalog reads and
prewarm resolve contributed provider env with `{ threadId: null,
projectId: null, hostId }` and send it on `provider.list_models`. The
env names and values are part of the catalog fingerprint, so a route or
token change discards the stored list.
- **Wire**: `provider.list_models` gains a required `contributedEnv`;
`HOST_DAEMON_PROTOCOL_VERSION` 242 → 243. The daemon passes it to
`runtime.listModels`. The runtime expands it like a session's env
(`serverPath` → `BB_SERVER_URL` + path) through a shared
`resolveContributedEnvironment`, and sends the result as `envVars` on
the bridge `model/list` request. That bridge param is optional, so
existing bridges ignore it.
- **Codex bridge**: the cached model-list app-server is keyed on the
pool base URL and auth token. It relaunches when they change, and
discards a launch that loses a race with a newer route.
- **Plugin SDK** (0.6.56 → 0.6.57):
`ExperimentalPluginProviderEnvContext.threadId` and `projectId` are now
`string | null`, with `null` meaning "no thread", e.g. model catalog
listing. This is a breaking change to an `experimental_` API.
- **Account Pooler**: with a `null` thread it still returns the pooled
env, but skips the thread bypass check, the `retry-route:` key and
`recordRouted`.
- **Docs**: `docs/provider-plugin-api.md`, `docs/api_to_audit.md`, and
the bb-plugin-authoring `providers.md` reference.

**Marketplace impact.** I searched all 414 community marketplace entries
(316 git repos and 13 npm packages, default branches). 7 plugins call
`experimental_contributeEnv`. None crash, because when a resolver
throws, bb logs it and skips that plugin's env.
- `OXI-717/account-pool-balanced` throws in `hubTokens.forThread`, which
requires a string thread, so its Codex catalog still lists local-login
models and logs an error per read. It needs the same null-thread guard
as the bundled pooler: OXI-717/bb-plugins#70.
- `grrowl/bb-github-app-auth` returns nothing and logs project-lookup
warnings.
- Magpie (`vaayne/agent-kit`) falls back to its global routing setting,
so it gets the fix.
- The other four ignore the thread or no-op.

## How you verified

- New tests:
  - runtime: model list expands contributed env against `BB_SERVER_URL`
- catalog store: contributed env reaches `provider.list_models` and a
change invalidates the stored list
- Account Pooler: a null-thread resolve returns pooled env and writes no
thread state
- Codex bridge: the model-list app-server relaunches with the new token
(verified through the fake app-server's launch log)
- `pnpm exec turbo run typecheck lint --filter='...[origin/main]'`:
142/142 tasks passed.
- `turbo run test` for agent-runtime, host-daemon-contract, host-daemon,
server, provider-bridge-protocol, plugin-sdk, account-pool and
provider-codex all passed, except one timing assertion in
`builtin-plugins.test.ts` (builtin hot-reload), which passed when re-run
alone.
- Manual: ran `pnpm start:worktree` inside a pooled bb thread
(parent-proxy mode; this machine has no Codex login). `bb provider
models codex` against main listed 3 models (gpt-6-luna, gpt-5.6-terra,
gpt-5.6-luna). Against this branch it listed 8, including gpt-6-astra,
gpt-6.1-sol and gpt-6-sol, all with the `fast` tier.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
@OXI-717

OXI-717 commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Claimed by the delivery session for independent acceptance of the exact HEAD, focused scope/token regression checks and delivery decision.

@OXI-717 OXI-717 added the wip Claimed for review or acceptance label Oct 20, 2026
@OXI-717

OXI-717 commented Oct 20, 2026

Copy link
Copy Markdown
Owner

VERDICT: PASS
SHA: 03b0bc7
REVIEWER: native BB independent acceptance
SCOPE: bounded provider environment and scope-token compatibility

The provider-env resolver accepts the null thread/project model-catalog context using the existing project/host token store. Thread contexts retain their per-thread token and bypass checks. A null catalog context does not create a routed:null record. No model dispatch gate or transport policy is relaxed.

Independently ran 218 server tests, typecheck and plugin build successfully on this exact HEAD. Re-ran the new catalog regression against the original server source: RED; the submitted source is GREEN. Existing project/thread token, per-thread bypass and network-policy regressions remain green. GitHub CI is required before merging. No live state changed during review. Memory retrieval for the change class completed successfully with no matching cards.

The cloud review bot has not supplied a receipt for this fork PR; acceptance relies on this independent review and the exact-head CI, without claiming a bot PASS. This is the documented stuck-review limitation for this delivery, not a waiver of any reported finding.

@OXI-717
OXI-717 merged commit dff1693 into OXI-717:main Oct 20, 2026
14 checks passed
@OXI-717 OXI-717 removed the wip Claimed for review or acceptance label Oct 20, 2026
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.

2 participants