Repository navigation
Dedupe and briefly cache workspace status and pull-request reads (B7, B8) - #1886
Merged
SawyerHood merged 1 commit intoAug 19, 2026
Conversation
SawyerHood
force-pushed
the
bb/mobile-perf/workspace-status-and-pr-cache
branch
from
August 19, 2026 07:50
f5dda11 to
606a90e
Compare
SawyerHood
marked this pull request as ready for review
August 19, 2026 08:04
SawyerHood
force-pushed
the
bb/mobile-perf/workspace-status-and-pr-cache
branch
from
August 19, 2026 15:59
606a90e to
3306bb2
Compare
GET /environments/:id/status and GET /environments/:id/pull-request
forwarded every request to the host daemon, where each one spawns
4-5 git subprocesses (status) or a `gh pr view` (pull request). A
thread open, sidebar rows and a phone returning to the foreground all
ask for the same environment inside the same second, and the client
refetches status on every `work-status-changed` batch, so one editing
turn produced a stream of duplicate probes (240-344 ms each).
Add `WorkspaceReadCaches` on AppDeps: a per-environment in-flight
dedupe plus a short TTL cache (3 s for status, 10 s for pull request)
in front of both read routes. Overlapping reads share one daemon RPC;
repeated reads inside the TTL are served from memory; the response
shape is unchanged. Freshness follows the same daemon events the client
already refetches on: any environment change other than record-only
`metadata-changed` / `thread-storage-changed` (so `work-status-changed`,
`git-refs-changed`, `status-changed`, ...) drops the cached value and
detaches any in-flight probe for that environment, because a probe that
started before the change may have read the pre-change tree. Host
connect/disconnect drops that host's entries. The status probe itself
records the observed branch (`metadata-changed`), which is why that kind
is ignored. Cache keys include the workspace context and the merge-base
branch, so a re-provisioned environment or a different merge base never
reads a stale entry. Mutation routes keep probing directly.
Server-side mutations invalidate too, before they respond: the
environment action route (commit, squash merge, pull request
ready/draft/merge) drops both caches for its environment whether the
action succeeded or failed midway, and the host file write/mkdir/move/
remove routes drop the host's entries. The client refetches on mutation
success and the daemon watcher event for that write, if anyone is
subscribed, arrives asynchronously, usually after the response, so
without this the refetch read the pre-action tree ("untracked" right
after a commit that left it clean).
No server/daemon wire change.
Co-Authored-By: Claude <[email protected]>
SawyerHood
force-pushed
the
bb/mobile-perf/workspace-status-and-pr-cache
branch
from
August 19, 2026 16:13
3306bb2 to
3feb137
Compare
SawyerHood
added a commit
that referenced
this pull request
Aug 19, 2026
…n options by host (B6) (#1885) ## What was wrong Every execution-options read (each thread open, window focus, reconnect) sent a fresh `provider.list_models` RPC to the host, and the host spawned a provider CLI per request (measured 1-3 s). Nothing cached the answer on the server, daemon, or bridge. The request carried the environment's cwd although the Claude Code, Codex, and ACP bridges ignore it, so every environment probed separately. On the client, the follow-up composer keyed its query by `environmentId`, so each thread in a different environment on the same machine issued its own request. On mobile this put a CLI spawn on the critical path of every thread open. (Mobile perf sweep finding B6.) ## What changed - `apps/server`: `listProviderModelsMemoized` runs the probe through a new `createAsyncTtlMemo` (`services/lib/async-ttl-memo.ts`) held on `lifecycleDedupers.providerModelList` (10 min TTL, in-flight dedupe, failures never stored). The key is `[hostId, daemonSessionId, providerRegistrationRevision, command]`, so a daemon reconnect or a plugin reload re-probes at once. The probe bypasses the memo only while no daemon session is registered. - `packages/domain`: `providerModelCatalogDependsOnWorkspace(providerId)` states which first-party bridges read the workspace path (only Pi). The server sends `cwd` only for those; host-scoped catalogs share one memo entry across environments. - `apps/app`: component-local composers (`ThreadDetailPromptArea`, `EmbeddedThreadChat` via `PluginThreadChat`) receive the environment's host and `resolveThreadCreationProviderRouting` routes by `hostId` when the selected provider's catalog is host-scoped. Pi and unknown providers keep environment routing. - `plugins/provider-claude-code`: `model/list` goes through `createClaudeCodeBridgeModelListMemo` (2 min window plus in-flight dedupe; failures not kept) so bursts share one CLI spawn. ## How you verified - New tests: `apps/server/test/services/async-ttl-memo.test.ts` (TTL expiry, in-flight sharing, rejection not stored, clear); `apps/server/test/system/execution-options.test.ts` "model probe memo" block (one probe without cwd across two environments plus explicit host; Pi keeps cwd and keys per workspace; two concurrent readers share one held RPC; a failed probe is retried and a reconnected daemon session re-probes); `apps/app/src/hooks/useThreadCreationOptions.test.tsx` (claude-code component-local routes by host, pi routes by environment); `plugins/provider-claude-code/src/bridge/__tests__/model-list-memo.test.ts` (shared probe, window expiry, failure retry). Updated `provider-routing.test.ts` and `public-threads.defaults.test.ts` for the host-scoped Codex probe (no cwd, single probe). - `pnpm exec turbo run typecheck --force` for @bb/domain, @bb/server, @bb/app, bb-plugin-provider-claude-code: pass. `lint` for @bb/app: 0 errors, 147 warnings (same as baseline). Targeted vitest runs above: server 54/54, app 134/134, claude plugin 264/264. Full @bb/server suite: 1735 passed, 2 unrelated failures (file-mode umask assertion in internal-skill-trees, timeout in plugin-service under load). Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue). ## Stack context Layer 6 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins first, big rocks last). - Prerequisite (layer below): `bb/mobile-perf/thread-open-query-gating-review` (#1884). - Next layer: `bb/mobile-perf/workspace-status-and-pr-cache` (#1886). - Audit findings addressed: see title IDs. Review: approved-with-fixes; 1 review fix commit(s). - Reviewer notes / follow-ups: Minor (not fixed, low value): on plugin surfaces (PluginThreadChat) the environment is fetched separately from the thread, so the follow-up execution-options query can flip its key | Design note: host-scoped catalogs are reused for up to 10 min (server) + 2 min (Claude bridge) after an account/CLI change on the same daemon session; the curated Claude catalog is - Wire/contract: No schema or protocol change. HOST_DAEMON_PROTOCOL_VERSION not bumped (still 135). The only wire-visible difference: the server now omits the already-optional `cwd` field from `provider.list_models` for claude-code, codex, and acp-* providers (verified their bridges ignore it: Claude `model/list` params are `z.object({})`, Codex `handleModelList(id)` takes no params, ACP builds its list from the l > AGENT GENERATED: by Claude Code (claude-mangosteen-eap) --------- Co-authored-by: Claude <[email protected]>
SawyerHood
added a commit
that referenced
this pull request
Aug 19, 2026
…snippets (B25, B26) (#1887) ## What was wrong `searchThreadsWithPendingInteractionState` ran the full ranking pipeline twice per request, once for active and once for archived threads. Every token `MATCH` and the any-token hydration `MATCH` executed twice (2N+2 FTS scans for N tokens). The FTS5 table had no prefix index, so each `"tok"*` prefix query expanded against the full term list on every keystroke. The response carried up to three full message bodies per thread while the sidebar renders one truncated line (B25, B26 in the mobile perf sweep). ## What changed - New custom Drizzle migration `0101_thread_search_prefix_fts` recreates `thread_search_segments_fts` with `prefix = '2 3'`, rebuilds rows and triggers (same mechanism as 0040). Snapshot and journal regenerated with `drizzle-kit generate --custom`. - `packages/db/src/data/threads.ts`: one SQL statement ranks threads that contain every token, partitions `ROW_NUMBER`/`COUNT(*)` by archived state, keeps the top `limitPerGroup` per group, then joins the any-token `MATCH` once to pull the matching title segments plus the single best message segment per thread. Rows are split by group in JS. Total FTS scans: N+1. - Message matches are cut to a ~160-char snippet around the first highlight (40 chars of lead, word-boundary snapping bounded to 40 chars, surrogate-safe, "…" on each cut side). Highlight ranges are rebased onto the snippet. Titles stay whole so the sidebar can pair them with the display title. - Contract comment on `threadSearchMatchSchema.text` documents the snippet semantics. Response shape is unchanged; the client (`ThreadSearchResultRow`) already picks one message match and one title match. ## How you verified - `pnpm exec turbo run typecheck --filter=@bb/db --filter=@bb/server-contract --filter=@bb/server`: pass. - `pnpm exec turbo run test --filter=@bb/db`: 29 files, 396 tests pass (includes migration journal/snapshot chain checks and query-plan tests). - `pnpm exec turbo run test --filter=@bb/server -- test/public/public-thread-search.test.ts`: pass. - New/updated tests in `packages/db/test/data/thread-search.test.ts` (in-memory SQLite + migrate): one message match per thread; title + title_fallback + one message per thread; per-group limit and totals from one call with mixed active/archived; snippet bounds, ellipses, word-boundary lead, rebased ranges slice to the token; short text returned whole; long unbroken tail keeps hard cut; `sqlite_master` shows `prefix = '2 3'`. Migration backfill test now replays 0039/0040/0101. - `EXPLAIN QUERY PLAN` on the new statement: two `SCAN thread_search_segments_fts VIRTUAL TABLE INDEX` (single token), rowid PK lookups for segments, PK lookup for threads, automatic index for the limited-threads join. Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue). ## Stack context Layer 8 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins first, big rocks last). - Prerequisite (layer below): `bb/mobile-perf/workspace-status-and-pr-cache` (#1886). - Next layer: `bb/mobile-perf/timeline-delta-ring-and-output-cap` (#1888). - Audit findings addressed: see title IDs. Review: approved-with-fixes; 1 review fix commit(s). - Deliberately not done here: B25 optional `group=` query param: not added. It does not simplify the code (the partitioned scan already collapses the double MATCH) and would add contract, SD - Wire/contract: No server<->daemon wire changes (HOST_DAEMON_PROTOCOL_VERSION unchanged). Public API response shape for GET /threads/search is unchanged; semantics changed: `matches[].text` for message kinds is now a bounded snippet (with leading/trailing "…" when cut) and `highlightRanges` are offsets into that snippet; each thread returns at most one message match plus its title/title_fallback matches (previous > AGENT GENERATED: by Claude Code (claude-mangosteen-eap) --------- Co-authored-by: Claude <[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.
What was wrong
GET /environments/:id/statusandGET /environments/:id/pull-requestforwarded every request to the host daemon. Each status probe spawns 4-5 git subprocesses (measured 240-344 ms); each pull-request probe spawnsgh pr view. A thread open, sidebar rows and a phone returning to the foreground ask for the same environment inside the same second, and the client refetches status on everywork-status-changedbatch. One editing turn produced a stream of duplicate probes on the host (audit findings B7, B8).What changed
WorkspaceReadCaches(apps/server/src/services/environments/workspace-read-cache.ts) onAppDeps: a per-environment in-flight dedupe plus a short TTL cache, 3 s forworkspace.status, 10 s forworkspace.pull_request.metadata-changed/thread-storage-changeddrops the cached value and detaches any in-flight probe for that environment (a probe that started before the change may have read the pre-change tree). Host connect/disconnect drops that host's entries.metadata-changedis ignored because the status probe itself records the observed branch mid-flight.How you verified
apps/server/src/services/environments/workspace-read-cache.test.ts: in-flight sharing, TTL expiry with a fake clock, key separation, no caching of rejections, in-flight detachment on invalidation (late result does not overwrite), host-scoped invalidation, both caches dropped onwork-status-changed/git-refs-changed, kept acrossmetadata-changed/thread-storage-changed, dropped on host events.apps/server/test/environments/workspace-read-cache-routes.test.ts: two concurrent status GETs produce oneworkspace.statusdaemon command; a third GET is served without a daemon round trip;?mergeBaseBranch=is a separate probe;work-status-changedforces a fresh probe. Same for/pull-requestwithgit-refs-changed. These fail before the change (the third request blocks on an unanswered second daemon command).pnpm exec turbo run typecheck --filter=@bb/serverpasses; related suites (test/public,test/hosts,test/internal,test/environments,test/ai/commit-message.test.ts,src/services/environments) pass except one pre-existing umask-dependent assertion ininternal-skill-trees.test.ts(file mode 0664 vs 0644, unrelated).Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue).
Stack context
Layer 7 of 22 in the
bb/mobile-perf/*stack (bottom → top: quick wins first, big rocks last).bb/mobile-perf/list-models-cache(Memoize provider.list_models on the server and key follow-up execution options by host (B6) #1885).bb/mobile-perf/search-fts(Thread search: single partitioned FTS scan, prefix index and bounded snippets (B25, B26) #1887).gh pr createfrom a shell with no local ref change) can be up to 10 s stale; unsubscribed environments up to 3 s stale for status. Both are within wh | apps/server/src/routes/environments.ts has a pre-existing prettier drift (assertCanMarkPullRequestReady / assertCanConvertPullRequestToDraft) that predates this branch; not touchedworkspaceReadCaches(server-only).