Skip to content

Build every thread action target from the thread id in one host resolver - #8087

Merged
ymichael merged 5 commits into
mainfrom
bb/one-thread-action-target-on-every-surface-git-st-thr_7zxi74ezuz
Nov 25, 2026
Merged

ymichael merged 5 commits into
mainfrom
bb/one-thread-action-target-on-every-surface-git-st-thr_7zxi74ezuz

Conversation

@ymichael

@ymichael ymichael commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Every surface that hosts thread actions built its own PluginThreadActionTarget, and they disagreed on environment. The thread header (ThreadDetailView) passed it only when a new thread could reuse it: environment ready, host active, path set. The sidebar, mobile recents, thread-list and Conductor passed any environment the thread had. So one action saw different targets in different menus. Live on main at phone width, for a thread whose worktree is still running its setup script (provisioning, path set), the header menu has no "New thread in environment" while the same thread's sidebar long-press menu offers it. thread-list (rows/threadActionTarget.ts) and Conductor (thread-target.ts) carried byte-identical copies of the mapper, and so do five community plugins. Separately, a thread action's useData received only ids. Git's Commit therefore called sdk.threads.get for every open thread, plus one subscription per thread, and fetched again on each environment change and reconnect, only to learn the environment the target already carried (audit a-thread F8b and F18's git item).

What changed

One resolver, on experimental_useThread's path. apps/app/src/lib/thread-actions/thread-action-target.tsx builds the target on #7955's thread-by-id resolution in thread-state.ts, not on a store of its own:

  • thread-state.ts now has one readThread resolution, used by both useThreadState and a new non-hook threadReadSource. It reads the held sidebar entry, otherwise the thread query, and keeps the last entry while a thread leaves the sidebar.
  • The target is that thread plus its environment's path. A held entry carries the path itself; a fetched thread reads the environment query.
  • For ids the sidebar doesn't hold, ThreadActionCollectors mounts a loader that calls useThreadState and useEnvironment. Those are the same queries the thread page uses, so the open thread adds no request.
  • Sidebar rows mount no query observers. There are no module-level caches; value-stable targets live in each snapshot source's closure.

The registry evaluates item, experimental_bulkItem and useData from that single resolution, so every surface gets the same target: the header, row menus and quick actions, the long-press drawer, selection menus, the pin/read/archive palette commands, mobile recents, and plugin lists.

SDK (0.6.202)

  • PluginThreadActionDataInput.experimental_threads: readonly PluginThreadActionTarget[]: the targets for threadIds, in the same order, leaving out threads not loaded yet.
  • experimental_useThreadActions(thread: { id: string }, options?), PluginThreadActionsMenuBaseProps.thread: { id: string }, and experimental_bulkThreads?: readonly { id: string }[]: bb reads only id. Existing callers that pass hand-built targets or PluginSidebarThreads still type-check.
  • PluginThreadActionTarget.environment now means "the thread's environment" on every surface: { id, path, status, hostLifecycle }, with path null while there is no checkout, or null when the thread has none or bb cannot read it. The JSDoc said "when a new thread can reuse it" but held something else on the sidebar.
  • The SDK test fake's TestThreadActionsResolver and TestThreadBulkActionsResolver now receive the { id } the plugin passed.

Callers

  • Core: ThreadDetailView (header, header menu, PaneThreadActionCommandHandler) and RootComposeMobileRecents pass the thread they hold. toThreadActionTarget and threadListEntryActionTarget are deleted.
  • thread-list: ThreadRow and the selection store pass SidebarThreads. rows/threadActionTarget.ts is deleted.
  • Conductor: WorkspaceTabs and WorkspaceSidebar pass the thread. thread-target.ts is deleted.
  • Git's Commit useData reads experimental_threads[].environment and no longer calls threads.get or subscribes per thread.
  • The engine floors for git, thread-list and conductor are now >=0.6.202.

Visible changes. One rule now decides where "New thread in environment" shows: the environment has a checkout, is ready or still provisioning, and its machine is active. Core's action reads it from the target, and the thread page's own button uses the same condition.

  • Compact header menu: now offers it while the environment provisions, as the sidebar row already did. The new thread is created in that environment and waits on "Preparing workspace".
  • Sidebar long-press, mobile recents and header: no longer offer it when setup failed or the machine is being removed or gone. Before, the sidebar offered it there, and it ended in "Failed to create thread / Workspace setup failed." or "Machine removal has begun; wait for a replacement machine".
  • Thread page composer button: now also shows while the environment provisions (it required "ready").

To give every surface that state without extra requests, PluginThreadActionTarget.environment gains status and hostLifecycle. Sidebar entries get them from the server: ThreadListEntry gains environmentStatus and environmentHostLifecycle, joined from the environment and its host in the thread list query. An environment status-changed event (host lifecycle changes also send it) now refreshes the sidebar threads in that environment. A thread outside the sidebar reads them from the environment query, as before.

Git's Commit is not visible in any of these states. Its status RPC answers "Workspace is still starting.", "Workspace setup failed." or "Workspace status unavailable.", so the action hides from its own data.

Docs

  • docs/api_to_audit.md: a "One target" paragraph naming the core callers, experimental_threads, and an updated audit item 1.
  • Plugin Guide: PluginThreadActionDataInput.experimental_threads in surfaces.ts.
  • bb-plugin-authoring: frontend-registration.md and frontend-sidebar-navigation.md say to pass the thread and read experimental_threads.

Community callers (not edited). All still compile. Their mappers are now unnecessary, and their thread actions see the host-resolved target:

  • nosenss/bb-plugin-attention-sidebar (components/thread-row.tsx toActionTarget)
  • grishaster80/bb-plugin-focus-sidebar (app.tsx actionTarget)
  • nikushiks/bb-plugin-top-tabs
  • tobi/bb-bots-sidebar (lib/thread-action-target.ts)
  • OXI-717/oxi-thread-list (rows/threadActionTarget.ts and its selection store). Its ThreadRow.test resolver reads target fields from the object it passes, so it needs a lookup by id once it moves to SDK 0.6.202.
  • useData users notpritam/bb-plugin-inbox, yusuf8834/bb-git-history and jgnagy/bb-plugin-madmax are unaffected (the field is additive).

How you verified

Live repro, pnpm start:worktree. The fixture is a git project whose .bb-env-setup.sh sleeps, which keeps a worktree environment provisioning with its path set.

  • Main, 390×844 touch: the header menu for that thread lists Copy link, Pin, … with no "New thread in environment". The sidebar row's long-press menu for the same thread lists Copy link, New thread in environment, Pin, ….
  • Branch: both menus list "New thread in environment" while the environment provisions and for a ready checkout. For a failed setup, neither menu lists it. After killing a provisioning thread's setup script, the already-open mobile recents row's long-press menu dropped it without a reload.
  • Creating a worktree thread: the environment status-changed events arrived in the same batch as metadata-changed events, which already refresh the sidebar, so the new refresh added no sidebar-bootstrap fetch of its own.
  • Branch, desktop: the right-click row menu is unchanged. A shift-click selection gives "Actions for 3 threads" with Pin, Mark unread, Notifications, Move to section, Archive 3 threads, Delete 3 threads, Clear selection. Commit appears in the header for a dirty workspace with showCommitButton on.

Git requests. Script: open a thread, then click 5 more sidebar rows, and attribute each GET /api/v1/threads/:id by its request initiator stack.

  • Main: 6 such GETs, all from the bb--git bundle (one per opened thread).
  • Branch: 0, both with showCommitButton off and on. Total API requests for the walk fell from 152 to 141.

Sidebar render cost. sidebar.bench.test.tsx with 3000 threads and the real thread-list plugin, alternating main and branch under taskpolicy -a.

  • Quietest pair (host load average about 32): mount 571 ms main vs 479 ms branch; status patch 37 vs 34 ms; pin 62 vs 59 ms.
  • Query observers: 15 on both (0.19 per row), so sidebar rows mount no loaders.

Tests

  • ThreadActionsMenu.test.tsx "thread action target": every menu surface (desktop dropdown, desktop context menu, compact drawer, compact long press), header entries, a two-thread selection and both placements' useData receive the same target, resolved from an id. A thread outside the sidebar resolves through the thread and environment queries.
  • ThreadActionsMenu.test.tsx on both compact surfaces: New thread in environment shows for ready and provisioning environments on an active machine, and hides for failed setup and for machines being removed or gone.
  • thread-runtime-display.test.ts: list entries carry the environment's status and the host's lifecycle, and follow both when they change.
  • realtime-cache-effects.test.ts: an environment status-changed event invalidates the sidebar when it holds a thread in that environment.
  • ThreadDetailView.contract.test.tsx: header actions get the thread's environment while it provisions. On main that target's environment is null, so the test fails there.
  • commit-action.test.tsx: Commit appears from experimental_threads, with threads.get rejecting and never called.
  • Existing app tests now hold threads in the sidebar store through holdSidebarThreads (active threads in navigation, archived ones in the archive list), as the app does.

Commands

  • pnpm exec turbo run typecheck lint --filter=@bb/app --filter=@get-bb/plugin-sdk --filter=bb-plugin-bb--git --filter=bb-plugin-thread-list --filter=bb-plugin-conductor --filter=bb-plugin-push-notifications --filter=bb-plugin-plugin-api-docs --filter=bb-plugin-bb-guide: green.
  • turbo run test: green for the same packages.
    • plugin-sdk passed 448/448 when run alone. Its two timeouts (shared-declaration-emit, kill-processes) and one plugin-api-docs timeout (mobile-guide) happened only while other suites ran in parallel.
    • @bb/app passed 7453 tests with 3 failures, in composer-contract, PromptBoxInternal and exclusive-pick-first-paint. All 313 tests in those files pass when the three run alone.
    • ThreadDetailSecondaryContent.test.tsx fails 7/8 when run directly with npx vitest on both this branch and origin/main, and passes under turbo.

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael
ymichael force-pushed the bb/one-thread-action-target-on-every-surface-git-st-thr_7zxi74ezuz branch 5 times, most recently from 17833bd to 71fb9ff Compare November 24, 2026 23:18
ymichael and others added 5 commits November 24, 2026 15:57
Each surface that hosted thread actions built its own PluginThreadActionTarget:
the thread header passed the environment only when a new thread could reuse
it, while the sidebar, mobile recents, thread-list and Conductor passed any
environment, so one action saw different targets in different menus. The
thread-list and Conductor plugins carried byte-identical mappers, and git's
Commit useData fetched every open thread with threads.get to learn its
environment.

The host now builds the target from the thread id on experimental_useThread's
resolution (thread-state.ts readThread, shared by useThreadState and the new
non-hook threadReadSource) plus the environment's path. Menus,
experimental_useThreadActions and experimental_bulkThreads take { id } and read
only the id; item, bulkItem and the new
PluginThreadActionDataInput.experimental_threads all read that one
resolution. Git reads environments from experimental_threads. The mappers in
thread-list and Conductor are gone. Plugin SDK 0.6.192.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…thread

The thread action target now carries the environment's setup status and its
machine's lifecycle, so core's New thread in environment hides for a failed
setup or a machine being removed instead of ending in an error toast. Held
sidebar entries get both from the server's thread list entry (joined from the
environment and its host), and an environment status change refreshes the
sidebar threads in it. The thread page's own button uses the same rule, which
now includes environments that are still provisioning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/one-thread-action-target-on-every-surface-git-st-thr_7zxi74ezuz branch from dd0e260 to 2eb0274 Compare November 24, 2026 23:58
@ymichael
ymichael merged commit 3c42fdb into main Nov 25, 2026
55 checks passed
@ymichael
ymichael deleted the bb/one-thread-action-target-on-every-surface-git-st-thr_7zxi74ezuz branch November 25, 2026 00:12
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.

1 participant