Repository navigation
Recover threads from unavailable models - #835
Merged
SawyerHood merged 2 commits intoJul 21, 2026
Merged
SawyerHood merged 2 commits into
SawyerHood merged 2 commits into
Conversation
SawyerHood
deleted the
bb/bb-75-recover-threads-stuck-on-an-unavailable-mo-thr_kbpabss4gp
branch
July 21, 2026 15:24
SawyerHood
added a commit
that referenced
this pull request
Jul 23, 2026
## Summary - always offer BB's curated, version-pinned Claude models and make account-scoped discovery purely additive, so a narrow probe result can never strand the model picker - preload the picker from the last catalog this account reported, so it is populated instantly instead of waiting ~2-3s on a CLI process spawn, and a selection made during that window does not snap back - substitute the curated rows server-side when the probe fails transiently - remove Mythos from the curated catalog - bump `HOST_DAEMON_PROTOCOL_VERSION` because `provider.list_models` semantics changed ## Problem Claude's model probe spawns a CLI process on the host. Measured on this branch: `provider.list_models` takes 2.1-2.6s and `/api/v1/system/execution-options` 2.2-2.3s. Until it returned, the picker was empty. A probe that reported a narrow list could strand it entirely. #835 had made the catalog `curated ∩ discovered` to fix Mythos being offered to accounts that could not run it. That fixed phantoms but left the picker fully dependent on a slow, failable probe. ## Approach **Catalog rule inverted.** `buildClaudeCodeModels` now emits `CLAUDE_CODE_ACTIVE_CATALOG` unconditionally and appends only discovered ids BB has no curated entry for. Selected-only rows stay discovery-gated — they exist to label a selection the user already has, so there is nothing to keep stable. Mythos is deleted outright; the discovered-passthrough path already surfaces it with Anthropic's own label for entitled accounts. **Catalog moved to `@bb/agent-providers`**, since the daemon (filtering), server (fallback), and app (preload) all need the same rows. `DEFAULT_CLAUDE_CODE_MODEL` and the xhigh reasoning ladder are single-sourced there too. **Preload.** `useSystemExecutionOptions` sets react-query `placeholderData` for `claude-code` from the last catalog the account reported, cached in localStorage keyed by host/environment. Because those ids match what the fresh probe returns, a pick during the preload window survives. Curated rows are the cold-cache path only. **Failure fallback.** The server substitutes the curated rows in `loadSystemProviderModels`'s catch, gated to `timeout`/`failed` — not `missing_executable`/`auth_required`, which the app routes to an install/auth prompt where offering models would only defer the failure to submit time. **The invariant that keeps this safe.** A provisional catalog must never look authoritative. Recovery is now gated on `modelCatalogIsUnverified`, covering both a load error and placeholder data, so neither can retire a stored selection — only a successful probe can. Caching is likewise gated on `modelLoadError === null`, so the failure fallback cannot later masquerade as the account's real models. ## Trade-off Deliberate and reviewer-visible: a curated row can name a model an account cannot run — an entitlement it lacks, or a CLI older than Fable 5's v2.1.170 requirement. Verified live on this account, whose probe does not report `claude-opus-4-7[1m]` yet is now offered it. That failure surfaces from Claude Code at turn time rather than as a clean 400 from BB, because absence from the list is no longer evidence of unavailability. In exchange the picker is always usable. Both sites carry comments saying so. ## Protocol bump `provider.list_models` results change meaning from "account-verified" to "curated ∪ discovered". An enrolled daemon on the old build would keep returning a discovery-filtered list, so the bump is what forces it to update. The contract test pins 65 and records why. ## Validation Verified against a live dev instance — the curated four are present including `claude-opus-4-7[1m]` (not reported by this account's probe), plus additive `claude-haiku-4-5-20251001` and `claude-horchata-eap[1m]`. - `@bb/app` 2077/2077 - `@bb/agent-runtime` 795/795 - `@bb/agent-providers` 9/9, `@bb/host-daemon-contract` 50/50 - `@bb/server` 1253/1255 — both failures pre-existing and environment-dependent: a umask-sensitive skill-tree fixture (asserts 0644, local umask 0002 creates 0664) and `plugin-update.test.ts`, which passes 13/13 in isolation - `turbo run build typecheck lint` passes on all five affected packages `model-list.test.ts`'s old *"returns an empty catalog when the provider reports no models"* asserted exactly the behavior this PR removes; it is rewritten as *"still offers the curated catalog when the provider reports no models"* so the suite guards the new contract instead of losing the coverage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 30, 2026
## Human comments ## What was wrong The GitHub plugin's `issue` and `pr` mention providers run `mentionItems` on every debounced `@` or `#` keystroke (https://github.com/get-bb/bb/blob/2a21dd56f69cb1b72d78f97d51e8d4d72f09fe2e/plugins/github/server.ts#L1579-L1587). `mentionItems` called `listCachedItems({ kind, query, state: "open" })` and then `.slice(0, 8)`. That query is `SELECT * FROM items ... ORDER BY updated_at DESC` and has no `LIMIT` (https://github.com/get-bb/bb/blob/2a21dd56f69cb1b72d78f97d51e8d4d72f09fe2e/plugins/github/server.ts#L762-L801), and the table has no index besides its primary key `(repo, kind, number)`. So SQLite read every cached row, also closed rows and 3.5 KB bodies. It sorted all matches in a temporary B-tree (`SCAN items | USE TEMP B-TREE FOR ORDER BY`). The plugin then parsed labels and assignees for each match and kept 8. The sync keeps up to 230 rows per tracked repository. One keystroke cost 5.65 ms at 10 repositories and 33.58 ms at 40. This work runs synchronously in the server process. I measured the real `search` path before changing anything (see the table below). ## What changed - `plugins/github/server.ts`: a new storage migration adds `CREATE INDEX items_kind_state_updated_number ON items (kind, state, updated_at, number)`, and listings order by `updated_at DESC, number DESC`. SQLite runs the mention query as `SEARCH items USING INDEX items_kind_state_updated_number (kind=? AND state=?)`. It walks the open rows of one kind newest first and does no sort. The `number` tie-breaker keeps rows with equal `updated_at` in a fixed order; without it the index walk reversed their previous order (seen on a real cache: `#835` listed 8355 before 8354 on main, 8354 first with an `updated_at`-only index). - `listCachedItems` takes an optional `limit` and binds it as `LIMIT ?`. `mentionItems` passes `limit: 8` instead of slicing, so the walk stops after 8 matches. The `bb github issues`, `bb github prs` and `listItems` RPC listings pass no limit and return the same rows as before. The new index can change only their plan, not their result. - No wire, CLI, RPC or protocol changes. Deviation from the issue's first idea (`LIMIT 8` and only `repo, number, title`): neither change alone removes the scan. The body is in the same page as the row, so the query must read every row page to find the newest 8. Measured at 40 repositories: `LIMIT 8` alone is 11-16 ms, and three columns with `LIMIT 8` is about 9 ms. With the index and `LIMIT 8`, only the 8 result rows are read. Then `SELECT *` of 8 rows costs nothing measurable, so the mention path keeps the one shared query and does not get a second column-specific copy of it. ## How you verified New test in `plugins/github/server.batching.test.ts`: "answers a mention search with the newest 8 open matches through the index". It syncs 10 matching open issues (shuffled `updatedAt`, two sharing one), a closed issue and an open pull request through the fake GraphQL response. The test then checks that the issue provider returns exactly the 8 newest issues in order, and that SQLite plans the statement of the search as an index search with no scan and no temporary B-tree. - On origin/main (unfixed), it fails: ``` AssertionError: expected [ 'SCAN items', …(1) ] to deeply equal [ StringMatching{…} ] - StringMatching /^SEARCH items USING INDEX /, + "SCAN items", + "USE TEMP B-TREE FOR ORDER BY", ``` - With `LIMIT 8` and no index, it fails on the same plan assertion. - With the index and no `LIMIT`, it fails: `expected [ { id: 'acme/one#9', …(2) }, …(8) ] to deeply equal [ { id: 'acme/one#9', …(2) }, …(7) ]` (9 results). - With the fix, it passes. Measurements: a temporary Vitest file (not committed) loads the real plugin with `createFakePluginHost`. Like the host, it uses a file-backed SQLite database with the default page cache. The file inserts 230 rows per repository (100 open and 50 closed issues, 50 open and 30 merged pull requests, 3.5 KB bodies) and times both providers' `search` calls for one keystroke. Each value is the median of 200 runs after 20 warm-up runs. | Repos (rows) | Query | Before | After | |---|---|---|---| | 1 (230) | `""` | 0.38 ms | 0.11 ms | | 1 (230) | `"a"` | 0.33 ms | 0.09 ms | | 1 (230) | `"zzz"` (no match) | 0.09 ms | 0.12 ms | | 10 (2,300) | `""` | 5.65 ms | 0.07 ms | | 10 (2,300) | `"a"` | 3.74 ms | 0.11 ms | | 10 (2,300) | `"fix"` | 0.80 ms | 0.12 ms | | 10 (2,300) | `"zzz"` (no match) | 0.43 ms | 0.41 ms | | 40 (9,200) | `""` | 33.58 ms | 0.06 ms | | 40 (9,200) | `"a"` | 32.34 ms | 0.07 ms | | 40 (9,200) | `"fix"` | 18.35 ms | 0.10 ms | | 40 (9,200) | `"item 17"` (matches only in older rows) | 16.76 ms | 7.31 ms | | 40 (9,200) | `"zzz"` (no match) | 16.02 ms | 6.95 ms | The walk stops at the eighth match. A query with fewer than 8 matches, or with matches only in older rows, still reads most open rows of that kind. It no longer reads closed rows or the other kind, and it does not sort, so it is still about 2x faster than before. Commands: ``` pnpm exec turbo run typecheck test lint lint:type-aware --continue --concurrency=6 --filter=bb-plugin-github ``` All 11 tasks pass (44 tests). `lint` reports 3 warnings in `plugins/github/app.tsx` (`react(immutability)`, two `react(set-state-in-effect)`), which are on origin/main and not in this change. Fixes #8218 > AGENT GENERATED --------- Co-authored-by: Michael Yong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
scowalt
pushed a commit
to scowalt/bb
that referenced
this pull request
Dec 1, 2026
…b#8219) ## Human comments ## What was wrong The GitHub plugin's `issue` and `pr` mention providers run `mentionItems` on every debounced `@` or `#` keystroke (https://github.com/get-bb/bb/blob/e9e0493838b52b1276625f32730c26fb908ea159/plugins/github/server.ts#L1579-L1587). `mentionItems` called `listCachedItems({ kind, query, state: "open" })` and then `.slice(0, 8)`. That query is `SELECT * FROM items ... ORDER BY updated_at DESC` and has no `LIMIT` (https://github.com/get-bb/bb/blob/e9e0493838b52b1276625f32730c26fb908ea159/plugins/github/server.ts#L762-L801), and the table has no index besides its primary key `(repo, kind, number)`. So SQLite read every cached row, also closed rows and 3.5 KB bodies. It sorted all matches in a temporary B-tree (`SCAN items | USE TEMP B-TREE FOR ORDER BY`). The plugin then parsed labels and assignees for each match and kept 8. The sync keeps up to 230 rows per tracked repository. One keystroke cost 5.65 ms at 10 repositories and 33.58 ms at 40. This work runs synchronously in the server process. I measured the real `search` path before changing anything (see the table below). ## What changed - `plugins/github/server.ts`: a new storage migration adds `CREATE INDEX items_kind_state_updated_number ON items (kind, state, updated_at, number)`, and listings order by `updated_at DESC, number DESC`. SQLite runs the mention query as `SEARCH items USING INDEX items_kind_state_updated_number (kind=? AND state=?)`. It walks the open rows of one kind newest first and does no sort. The `number` tie-breaker keeps rows with equal `updated_at` in a fixed order; without it the index walk reversed their previous order (seen on a real cache: `get-bb#835` listed 8355 before 8354 on main, 8354 first with an `updated_at`-only index). - `listCachedItems` takes an optional `limit` and binds it as `LIMIT ?`. `mentionItems` passes `limit: 8` instead of slicing, so the walk stops after 8 matches. The `bb github issues`, `bb github prs` and `listItems` RPC listings pass no limit and return the same rows as before. The new index can change only their plan, not their result. - No wire, CLI, RPC or protocol changes. Deviation from the issue's first idea (`LIMIT 8` and only `repo, number, title`): neither change alone removes the scan. The body is in the same page as the row, so the query must read every row page to find the newest 8. Measured at 40 repositories: `LIMIT 8` alone is 11-16 ms, and three columns with `LIMIT 8` is about 9 ms. With the index and `LIMIT 8`, only the 8 result rows are read. Then `SELECT *` of 8 rows costs nothing measurable, so the mention path keeps the one shared query and does not get a second column-specific copy of it. ## How you verified New test in `plugins/github/server.batching.test.ts`: "answers a mention search with the newest 8 open matches through the index". It syncs 10 matching open issues (shuffled `updatedAt`, two sharing one), a closed issue and an open pull request through the fake GraphQL response. The test then checks that the issue provider returns exactly the 8 newest issues in order, and that SQLite plans the statement of the search as an index search with no scan and no temporary B-tree. - On origin/main (unfixed), it fails: ``` AssertionError: expected [ 'SCAN items', …(1) ] to deeply equal [ StringMatching{…} ] - StringMatching /^SEARCH items USING INDEX /, + "SCAN items", + "USE TEMP B-TREE FOR ORDER BY", ``` - With `LIMIT 8` and no index, it fails on the same plan assertion. - With the index and no `LIMIT`, it fails: `expected [ { id: 'acme/one#9', …(2) }, …(8) ] to deeply equal [ { id: 'acme/one#9', …(2) }, …(7) ]` (9 results). - With the fix, it passes. Measurements: a temporary Vitest file (not committed) loads the real plugin with `createFakePluginHost`. Like the host, it uses a file-backed SQLite database with the default page cache. The file inserts 230 rows per repository (100 open and 50 closed issues, 50 open and 30 merged pull requests, 3.5 KB bodies) and times both providers' `search` calls for one keystroke. Each value is the median of 200 runs after 20 warm-up runs. | Repos (rows) | Query | Before | After | |---|---|---|---| | 1 (230) | `""` | 0.38 ms | 0.11 ms | | 1 (230) | `"a"` | 0.33 ms | 0.09 ms | | 1 (230) | `"zzz"` (no match) | 0.09 ms | 0.12 ms | | 10 (2,300) | `""` | 5.65 ms | 0.07 ms | | 10 (2,300) | `"a"` | 3.74 ms | 0.11 ms | | 10 (2,300) | `"fix"` | 0.80 ms | 0.12 ms | | 10 (2,300) | `"zzz"` (no match) | 0.43 ms | 0.41 ms | | 40 (9,200) | `""` | 33.58 ms | 0.06 ms | | 40 (9,200) | `"a"` | 32.34 ms | 0.07 ms | | 40 (9,200) | `"fix"` | 18.35 ms | 0.10 ms | | 40 (9,200) | `"item 17"` (matches only in older rows) | 16.76 ms | 7.31 ms | | 40 (9,200) | `"zzz"` (no match) | 16.02 ms | 6.95 ms | The walk stops at the eighth match. A query with fewer than 8 matches, or with matches only in older rows, still reads most open rows of that kind. It no longer reads closed rows or the other kind, and it does not sort, so it is still about 2x faster than before. Commands: ``` pnpm exec turbo run typecheck test lint lint:type-aware --continue --concurrency=6 --filter=bb-plugin-github ``` All 11 tasks pass (44 tests). `lint` reports 3 warnings in `plugins/github/app.tsx` (`react(immutability)`, two `react(set-state-in-effect)`), which are on origin/main and not in this change. Fixes get-bb#8218 > AGENT GENERATED --------- Co-authored-by: Michael Yong <[email protected]> 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.
Summary
provider.list_modelssemantics changedRoot cause
BB had replaced Claude's SDK model probe with a static active catalog. That catalog included
claude-mythos-5for “Project Glasswing access,” so Mythos appeared for accounts whose authoritative SDK catalog did not contain it. A live SDK probe reproduced that mismatch: the account reported Fable, Opus, Sonnet, and Haiku, but not Mythos.After Mythos was submitted,
client/turn/requested.execution.model(or a stickythreads.model_override) persisted it. On the next render the app saw that the id was missing and displayed the catalog default, but because the user had not touched the fallback,executionInputSources.modelwas omitted. The server therefore discarded the displayed Opus value and resumed with the stale Mythos id. This explains the issue screenshot showing Opus in the composer while every provider error still namedclaude-mythos-5.The fix treats a missing model as definitive only after successful discovery. That fallback is sent explicitly, and a stale sticky override is replaced only after live-catalog validation. Discovery failures stay retryable (
503 model_catalog_unavailable); a successfully loaded catalog that lacks the requested replacement returns400 invalid_request.Validation
pnpm exec turbo run test --filter=@bb/agent-runtime --force -- src/claude-code/model-list.test.ts src/claude-code/bridge/__tests__/bridge.test.ts(61 passed)pnpm exec turbo run test --filter=@bb/app --force -- src/hooks/useThreadCreationOptions.test.tsx(8 passed)pnpm exec turbo run test --filter=@bb/server --force -- test/services/threads/thread-model-recovery.test.ts test/services/threads/thread-execution-override.test.ts test/public/public-threads.execution-override.test.ts(14 passed)@bb/appsuite (1,853 passed)@bb/agent-runtime(39 files),@bb/host-daemon(41 files), and@bb/host-daemon-contract(3 files) suites passed@bb/agent-runtime,@bb/app,@bb/server,@bb/host-daemon, and@bb/host-daemon-contract@bb/serversuite: 1,194/1,196 passed; unrelated failures were an umask-sensitive skill-tree fixture mode assertion (expected 0644, environment created 0664; reproduced alone) and a host-management timeout that passed on isolated rerunCloses #832