Repository navigation
Conversation
ymichael
marked this pull request as ready for review
October 23, 2026 01:27
ymichael
force-pushed
the
bb/smarter-github-pr-refresh-in-the-pr-status-plugi-thr_sxr6xeiwun
branch
from
October 23, 2026 02:47
2c60da1 to
d387d8c
Compare
Branch discovery now resolves the base repository the way gh does (gh-resolved remote, then upstream, github, origin; GH_REPO overrides) and matches only same-repository PRs unless the branch is pushed to another owner, skipping settled PRs on the default branch. Servers without merge queues are retried without isInMergeQueue. The pullRequests read keeps main's one-row-per-environment shape and storage keeps only each environment's current link. CLI and plugin reads after a restart wait for overdue data, cached reads skip the environment and machine lookups, and the public PR row no longer carries headRefOid. Co-Authored-By: Claude Opus 5.5 <[email protected]>
One timer now drives every watched check. Active PRs keep their 30 second cadence; other open PRs recheck every 5 minutes. When the timer fires, every check at least halfway to its due time joins, so rounds align and their reads share GraphQL batches. App reads reuse a missing-PR result for 5 minutes; CLI and RPC reads keep the 10 second cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PERSISTENCE_ENABLED turns the saved snapshots off in one line, and bumping PERSISTENCE_VERSION discards rows saved by older code. The version lives in SQLite's user_version, so the schema does not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/smarter-github-pr-refresh-in-the-pr-status-plugi-thr_sxr6xeiwun
branch
October 23, 2026 18:49
ymichael
added a commit
that referenced
this pull request
Oct 23, 2026
#6143 hid cached PR status in core's PR hook when the GitHub PR Status plugin is disabled. That hook now lives in the plugin, which only renders while enabled, so the check moves to the retired sidebar shim, core's one remaining reader, with #6143's test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Oct 23, 2026
…PR Status plugin (#6023) ## Human comments ## What was wrong Git and GitHub pull request status were still core UI. The composer's context banner hard-wired its parent-thread, changed-files and pull request rows. The Info tab drew the Pull request row from core, using PR data owned by the bundled GitHub PR Status plugin (#6125). There was no slot through which core and plugins could add context beside a thread's composer. ## What changed - **`app.slots.experimental_threadContextSegment`** (SDK 0.6.75): segments share the context row above an existing thread's composer. - A registration takes separate `summary`, `action?` and `details?` components, like composer customizations take separate lists. The host mounts each in its own crash boundary: `summary` in the row, `action` at the row's end, `details` below the row. - `group` then `order` place segments, as for Info rows and thread actions. `experimental_THREAD_CONTEXT_SEGMENT_GROUPS` names only core's groups, `thread` (`1_thread`) and `git` (`3_git`); the PR plugin uses its own `2_pullRequest`. - Props give `threadId`, `projectId`, `environment`, the visible `segments` as `{ key, pluginId }` (`key` is `<pluginId>/<id>` with core as `bb--core`, the shape thread action keys use), and a shared one-open-at-a-time disclosure. - `useVisible` runs in plugin scope per thread. - The banner is drawn above `ComposerBox`, so it shows under every composer plugin. - **Core uses the same path.** The parent thread (including read-only history) and changed files (with the merge-base action) register through `definePluginApp` and the collector, and render through the same host as plugins. Core segments render without a plugin crash boundary, as core Info rows do, so their DOM is unchanged. - **Active child threads are their own core row** (`ThreadChildThreadsBanner`) above the context row, like the todo and workflow cards, with their own open state. They are not a segment, so the slot has no card placement that would overlap composer `banners`. - **GitHub PR Status plugin gets an app entry** (`plugins/github-pr-status/app.tsx`, `ui/`): - the pull request segment: status pill, label rules, Mark ready and the merge split button with Convert to draft, the remembered merge method under the same localStorage key, and the same toast copy; - the Info tab's Pull request row, through #6117's `experimental_threadInfoRow`; - the display helpers, status pill, next-step label, favicon and the keyed read hook, moved from core with their tests. Core has no pull request UI or PR imports left. The one exception is the retired `experimental_useSidebarThreadPullRequest` runtime member for old marketplace plugins. - **`environment` on slot props.** It is `{ id } | null` on the new slot and on `ExperimentalThreadInfoProps`. - On both, it is null when the thread has no environment, its host is not active, or the environment is not a usable checkout. - On the segment slot only, it is also null when "Show Git changes and Commit button" is off. That keeps main's behaviour, where the PR hides with changed files and the Info row does not. - **No extra PR reads after the move.** - The plugin hook refetches only when an environment starts showing, not for each extra view, so opening Info adds no read. - `WebSocketManager` sends its final unsubscribe a microtask later and cancels it when the same target resubscribes in that task. Without this, a thread switch on the same environment dropped the plugin read subscription and restarted the server's watch, which can run `gh`. - `BannerActionSlot` and the banner action buttons moved to `@bb/shared-ui/prompt-banner-actions`, so the plugin draws the same controls. - **One toast path for core and plugins.** The `toast` plugins import from `sonner` is now a facade over core's `appToast` (`apps/app/src/lib/notifications/plugin-toast.ts`), replacing the recording wrapper. - `toast()`, `message`, `info`, `success`, `warning`, `error`, `loading`, `dismiss` and `promise` render and record exactly like core's toasts. - `custom`, `getHistory` and `getToasts` pass through. - A toast whose `action` or `cancel` is a plain React node (sonner allows it; no bundled plugin uses it) falls back to sonner. - Every plugin's toasts change appearance to match core's, which is intended. - **The retired `experimental_useSidebarThreadPullRequest` member keeps main's refresh.** It uses main's hook, kept in core as `useRetiredSidebarEnvironmentPullRequest` with main's tests: a cached row refetches on mount, and a stale row on page show. - Core's copy and the plugin's copy of that hook announce every refetch they start with a `window` event (`PULL_REQUESTS_REFETCH_EVENT` in the plugin contract) and mark those rows loaded. - A stale-row refetch rechecks staleness right before it runs, so a row that already has a fetch in flight, or was refreshed within its staleness window, is not read twice. SDK refetch behaviour is unchanged. - **Docs:** - a `docs/api_to_audit.md` entry; the Info entry and the live-reads and retired-member text updated; - the Banners Guide card's symbols, bullets and fixture, with anatomy anchors; - `frontend-registration.md` and `frontend-api-index.md`; - the PR stories moved to the plugin and added to Ladle. No database, daemon wire or CLI changes. Rebased onto #6143. Its "hide cached PR status when the plugin is disabled" check in core's PR hook moved with that hook's last core caller, the retired sidebar shim (`retired-sidebar-pull-request.ts`), with #6143's test; the plugin's own hook only renders while the plugin is enabled. The keyed read stays one PR per environment, so the segment and Info row need no change. **Deviations from main** - While core's commit or push runs, the PR buttons are no longer disabled; the plugin cannot see core's git actions. The replacement Michael asked for is to pass the displayed head to `gh pr merge --match-head-commit`. That needs `headRefOid` on the PR, which #6143 adds, so it lands on top of #6143. - A crash in the PR segment removes only that segment, or its part. - The active child threads card keeps its own open state, as Michael asked. On main it shared one open section with the context row. Now it can be open while changed files or the parent details are open, and it opens by itself when a child newly needs input even while another section is open. **Known follow-ups:** - The segment slot's `environment` folds in the "Show Git changes and Commit button" setting. That setting should become the git plugin's own when changed files move out of core, and the `git` segment group moves with it. - `experimental_THREAD_INFO_ROW_GROUPS.pullRequest` (from #6117) still names a plugin's group in core. Removing it is a public SDK removal, so it is left for a separate change. ## How you verified - Parity checklist: every banner row and segment, the Info PR row, refresh sources, phone and desktop layout, and each composer. Item IDs: A composers, B inline row, C child card, D read-only, E disclosure, F data, G layout, H Info row. <details><summary>Checklist results</summary> | Checklist | Result | |---|---| | A1, A2, A3, A8 | Same. A4–A7 unchanged code paths (banner only in the follow-up stack); not driven separately. | | B1–B5, B11, B13–B15 | Same text and pixels at 1400 and 390 px for: PR + changed files, PR alone, parent + PR + changed files, parent + PR. | | B6–B8, B10 | Same: menu items, Convert to draft, Mark ready, Squash merge on disposable PRs; toasts identical. | | B7 persistence | Same key `bb.pullRequest.mergeMethod`; Squash merge remembered. | | B9 | Deviation: core commit/push no longer disables the PR buttons. | | C1–C6 | Same content, auto-open on a new waiting question and 8 px spacing; the card is now its own row with its own open state (deviation above). | | D1–D3 | Same pixels for archived child with parent. | | E1–E4 | Same: parent disclosure body, focus to Collapse, focus back to toggle. | | F1–F6 | Same PR reads (4 per scripted session); fewer WS frames on the branch. | | G1–G4 | Same compact rules (390 px and narrowed by the right panel). | | H1–H4 | Same markup and row order; Show Git changes off keeps the row on both; plugin disabled hides it on both. | </details> Each item was driven in two source dev instances side by side, one on this branch and one on `origin/main` 2884950, with identical fixtures and disposable PRs in `ymichael/test-project`. - Text was identical at 1400 and 390 px for PR + changed files, PR alone, parent + PR + changed files, and parent + PR. - Screenshots were pixel-identical apart from the caret and the scheduled-time text. - The same held for archived history, Show Git changes off, the plugin disabled, the child-thread card with a waiting question, the pending-question stack, and the parent disclosure with its focus handoff. - Toasts: the PR plugin's Mark ready toasts match main's pixel for pixel; the loading toast differs only in the spinner frame. The Drafts plugin's "Draft saved" and the probe's `success`, `error`, `info` and `promise` toasts render as core toasts, with the close button, the outlined icon and an entry in the notification center. - Actions on disposable PRs: Convert to draft, Mark ready and Squash merge went through with the same toasts and the segment refreshed. The merge method was remembered. A CLI `bb pull-request draft` updated the segment live in the production build (`pnpm start:worktree`). - Requests, from browser CDP counts of `bb--github-pr-status` HTTP reads and WebSocket frames. The scripted session: load a thread with a PR and wait 40 s, open Info, switch to a thread on the same environment and back, switch to another environment and back, then fire a page show after 35 s. | | PR reads | WS frames | |---|---|---| | main (dev) | 4 | 12 | | branch (dev) | 4 | 8 | | branch (production build) | 4 | 8 | Before the WebSocket fix the branch sent 16 frames, because of resubscribes on same-environment switches. With a probe plugin that renders `experimental_useSidebarThreadPullRequest` in the thread header (an old marketplace sidebar's call), the same session gave: | | load | 4 thread switches | page show | |---|---|---|---| | main | 1 | 4 | 1 | | branch | 1 | 4 | 1 | Before the shared announcement, the branch's page show read twice. - Tests: - new host contract tests (`ThreadPromptContextBanner.segments.test.tsx`): group and order placement, a plugin's own group, `segments` keys, visibility, one-open disclosure, per-component and `useVisible` crash isolation, read-only, and the row held while git loads; - child-threads row tests: auto-open for a newly waiting child while changed files are open, and the question flow through `ThreadChildThreadsBanner`; - plugin tests for label rules, the attention matrix, actions and visibility; - query tests for refetch on first show and same-commit remounts, which fail without the deferral; - a WebSocketManager test for same-task resubscribe; - a plugin `toast` test through the real toaster (error and promise), which fails on the old shim; - a test with the plugin's hook and the retired member's hook on one environment: a stale page show makes one read, and two without the announcement. - `pnpm exec turbo run test typecheck lint --filter='...[origin/main]' --continue`: 239/244 passed on the first run. - Fixed: the Automations Info fixture (`environment`), the server's slot-prop docs table, and the 500-line cap on `frontend-registration.md`. - Passed when rerun alone: `CommandPalette`, `PluginSettings`, `builtin-plugins` hot-reload and the MCP CLI timeout (the first run had heavy parallel load). - Affected packages rerun green: `bb-plugin-plugin-api-docs`, `bb-plugin-automations`, `@bb/server`. - `bb plugin build` passes for `plugins/plugin-api-docs` and `plugins/github-pr-status`. The Plugin Guide's Banners card and fixture were checked in the app at desktop and phone layouts. - After the groups and component split: `pnpm exec turbo run test typecheck lint --filter='...[origin/main]' --continue` gave 242/244. A test-harness mock of the banner and the old auto-open test were updated and `@bb/app` reran green; `bb-plugin-bb--storage-retention` (untouched) passed when rerun alone. - In the production build (`pnpm start:worktree`) on a checkout of this branch: parent, PR and changed files in that order with Merge at the end; the child-threads row above the context row, open together with changed files; only the child row beside a waiting question. - CI: see the checks on this PR. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Oct 23, 2026
Closed
ymichael
added a commit
that referenced
this pull request
Oct 27, 2026
## Human comments ## What was wrong An open thread view could show a stale PR status indefinitely. In `plugins/github-pr-status/store.ts`, when a client read was the first to fetch a changed PR, `publishChanges` skipped invalidating that environment, on the assumption that the reader is the only viewer. Readers were tracked by environment ID, not by client, so every other open view of the same thread was never told. The store then recorded the new row in `served`, so later polls saw no change and never published either. The view stayed wrong until it remounted (switching threads does refetch) or reloaded. Any plugin RPC without a plugin token is a `client` caller, so `bb thread show` and `bb pull-request show` count as viewer reads. Agents and manager threads that run them froze open views of the threads they inspected. Core's implementation before #6125 (`pull-request-watch.ts`) published every change to every watcher. The exemption arrived with the move into the plugin and was kept in #6143. ## What changed - `store.ts`: removed the reader exemption (`loadingReaders`, the `readers` parameter of `load`, and the per-environment check in `publishChanges`). Every change now invalidates every watched environment that shows it. The client that triggered the fetch refetches once more, and that read is served from the 10 s cache without calling `gh`. - No wire, CLI, SDK or doc changes. The README's "publishes only changed rows" still holds. ## How you verified - New `store.test.ts` case: a viewer read that finds a change must publish to the environment's watchers. It fails on `main` (`expected "vi.fn()" to be called once with arguments: [ [ 'a' ] ]`) and passes with the change. - `pnpm exec turbo run test typecheck lint --filter=bb-plugin-bb--github-pr-status`: 158 tests passed, typecheck and lint clean. - End to end on an isolated `pnpm start:worktree` instance. A fake `gh` served GraphQL PR reads from a state file, and headless pages ran against a real thread: - Two pages on one thread. I flipped the PR to passing and reloaded only page B. On `main`, B showed "Ready to merge" and A stayed on "Checks failing" for more than 6 minutes, including after the scheduled poll fetched the new state. With this change, A updated within 6 s, with one `gh` call. - One open page plus `bb thread show` in the CLI. On `main`, the CLI printed passing and the page stayed failing 30 s later. With this change, it updated within 3 s. - Switching threads away and back refetches and shows the new status, so a view is stuck only while it stays open. - On the live server, with the thread open, polling (every 5 minutes when quiet, a 30 s follow-up after a push) and push detection (refresh 13 s after a simulated push) both fired on schedule, so neither is part of this bug. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED Co-authored-by: Michael Yong <review@local> Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Oct 28, 2026
ymichael
added a commit
that referenced
this pull request
Oct 30, 2026
#6684) ## Human comments ## What was wrong Since #6143, the GitHub PR Status plugin saves a link from each environment to its PR and re-reads that URL on later loads. It only looks up the branch again when the branch name changes. When a PR merged and the thread opened a second PR from the same branch, the environment stayed linked to the merged PR forever. For example, a thread whose branch carried merged #6596 and then open #6613 kept showing #6596. Before #6143 every load ran `gh pr view` on the current branch, which prefers an open PR. ## What changed - `plugins/github-pr-status/store.ts`: adds `isSettled(environmentId)`, which says whether the environment's linked PR is merged or closed. `staleAfterMs` now uses it. - `plugins/github-pr-status/server.ts`: `prepareLoad` looks up the branch (`url: null`) instead of reading the saved URL when the linked PR is settled, just as it already does after a branch change. The branch lookup prefers an open PR and otherwise returns the same settled PR, so this takes one GitHub request per load, not two. There are no wire, CLI or SDK changes. Performance, measured against GitHub on the affected branch: a settled link's reload goes from a URL read (~760 ms, 1 rate-limit point) to a branch read (~990 ms, 3 points). Settled PRs are never polled. They reload only when a viewer sees one over an hour old, when a CLI read finds one more than 10 s old, on push, or after a turn that ran `gh`. App viewers are served the cached row immediately and refreshed in the background. ## How you verified - A new `server.test.ts` case checks that a link to a merged PR switches to the branch's newer open PR, with exactly one host read per load. It fails before this change and passes after. - `pnpm exec turbo run test typecheck lint --filter=bb-plugin-bb--github-pr-status` passes (182 tests). - On the real affected branch, the GitHub branch lookup returns #6613 (open) ahead of #6596 (merged). > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) 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.
Human comments
What was wrong
Follow-up to #6125. PR snapshots were shared by URL, but loads and timers were keyed by environment, so five environments watching one PR repeated the same GitHub work. Each open-PR load used two requests (
gh pr viewplus a merge-queue query), ref changes expired the cache without comparing upstream commits, unrelated completed turns could run gh, and a restart lost every snapshot.What changed
bb.storage.database()/migrate(). There is no core migration and no history; snapshots no link references are deleted, and identical content or links write nothing. Persisted rows are validated on restore and invalid ones are dropped and rediscovered.PERSISTENCE_ENABLEDinpersistence.tsturns saving off in one line; bumpingPERSISTENCE_VERSIONdiscards rows saved by older code (kept in SQLiteuser_version, no schema change).gh. Viewers are invalidated only when their row changes.gh pr createthenbb pull-request showin one turn still sees the new PR.gh api graphql, grouped by GitHub hostname and credential into documents of at most 25 PRs with a 10 ms collection window. Rate limits pause only the affected credential. A GitHub Enterprise server withoutisInMergeQueueis retried once without it and remembered.gh pr view. The base repo is thegh-resolved remote (gh repo set-default), elseupstream,github,origin, then any other remote, andGH_REPOoverrides it. A branch pushed to another owner matches only that owner's fork PRs; otherwise only same-repository PRs match, and the default branch ignores merged and closed PRs. bb's existing rules for branches tracking a differently named fork branch are unchanged.The keyed
pullRequestsread keeps main's contract (onepullRequestper environment), so existing plugin callers are unaffected. No SDK member, daemon wire field or plugin RPC shape changes. The host-entry contract gainsviewinputs (url,refresh) and anupstreammethod, which ship together with the plugin.ETags were measured and excluded: check-runs and commit statuses each returned 304 but still cost one request each, versus one combined GraphQL read.
How you verified
Baseline: origin/main
2884950f17(#6125). Fresh isolated source dev apps, real browser/plugin/realtime stack, real agent turns and disposable PRs in ymichael/test-project, with a temporary workspace-host gh wrapper counting child processes and GitHub HTTP requests (not shipped).A completed turn without tools caused two gh/HTTP calls on main and zero on the branch. The same runs exercised Draft/Ready/Merge from the UI, pushes showing the new head with pending checks, an agent
gh pr createappearing without reload, suspended-machine refusals, hot plugin disable, and CLI show/ready/draft/merge.These real-app measurements predate the last commit (
c48b1c6a1b), which went back to the one-PR read shape, aligned discovery with gh, and fixed restart reads. That commit removes requests (no linked historical PRs are refetched) rather than adding any. It is covered by new regression tests (the first and fourth were reproduced failing against the previous branch head before the fix):mainare not matched;upstreamremote is looked up in the upstream repository, and agh-resolvedremote is honoured;isInMergeQueueis retried without the field and remembered;The 5-minute timing and persistence switch commits (
28725412ff,ce87a99bc8) add tests that fail on the previous store: staggered quiet PRs join one round and merged PRs are never rechecked; "no PR" is reused by viewers for 5 minutes but not by CLI reads or forced discovery; rows from another persistence version are discarded. WithPERSISTENCE_ENABLED = false, typecheck passes and only the 5 save/restore tests fail. A host bench reading 20 real open get-bb/bb PRs by URL, with the per-checkupstreamgit step, made 3gh api graphqlcalls per lined-up round in 3.7–4.4 s (three runs); without the git step the same round is 1 call, so per-check git work spreads reads across the 10 ms window. Unaligned 5-minute timers would make about 20 calls per round.Turbo
typecheck test lint --filter='...[origin/main]'atce87a99bc8: 29/29 tasks passed. Earlier, 39/39 tasks passed (app, CLI, PR Status, GitHub, Tasks, bb-guide, plugin-api-docs, host-daemon, demo-server, integration tests).🤖 Generated with Claude Code