Skip to content

Batch parent ownership notices and show bb notices usefully in the queue drawer - #7029

Merged
ymichael merged 4 commits into
mainfrom
bb/batch-parent-ownership-notices-through-coalesced-thr_h9ft2uy2m7
Nov 4, 2026
Merged

ymichael merged 4 commits into
mainfrom
bb/batch-parent-ownership-notices-through-coalesced-thr_h9ft2uy2m7

Conversation

@ymichael

@ymichael ymichael commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Ownership notices were one turn per child. thread-ownership.ts debounced each child separately with an in-memory WeakMap + 2 s setTimeout, then called queueParentSystemMessage once per child. Unassigning N threads together sent the parent N separate notices, each its own steer or turn. In production, thr_bgwkk8ing5 got 6 within one minute on 2026-10-22. A server restart inside the 2 s window lost the notice. Child turn-end notices had the same design until #6728 moved them to one durable coalesced queue row per parent.

Queued bb notices were noisy in the queue drawer and sidebar.

  • The drawer rendered their raw prompt text ("[bb system] These threads are now children…") with a "From System" label.
  • They offered every user-message action (edit, reschedule, drag).
  • They appeared for their 2 s coalescing window and then vanished.
  • They turned the sidebar's queued clock on even when nothing of the user's was queued.
  • The collapsed summary could show a notice's schedule as if it were the user's.
  • The drawer was capped at 198 px, so a third row sat under a fade.

What changed

Ownership notices go through the coalesced queue (thread-ownership.ts). The WeakMap/timer path is gone. Each change posts to postCoalescedSystemNotice with a thread-ownership key and a 2 s window. All changes to one parent become one durable queued row with a typed, zod-parsed coalesceState, listing every child assigned or unassigned. The timer's per-child behaviour is kept:

  • A move undone before the parent is told is withdrawn. If the row ends up empty, it is deleted (message.cancelled is emitted to plugins).
  • An assigned entry remembers the parent the child had before the window, so A→B→C notifies only A and C, and A→B→A notifies nobody, even with parentNotifications stuck/off.
  • Removal notices are still skipped unless parentNotifications is auto.
  • Once a row is delivered, the next change starts a new one.
  • Works with main's current coalescing. Let users turn on automatic bb updates that install once threads finish (updateWhenIdle) #7011 reverted Merge child notices while the parent is blocked, and skip /compact turns #7028's "merge into rows waiting on the parent", so today a row can only be merged into or withdrawn from during its 2 s window. If Merge child notices while the parent is blocked, and skip /compact turns #7028 is restored, ownership notices pick that up with no change here.
  • postCoalescedSystemNotice's merge may return null to withdraw, using the new deleteCoalescedQueuedThreadMessageInTransaction, which only deletes a row that is still waiting to be sent.
  • A single change renders exactly as before. Two or more use the new system-message-thread-ownership-batch template and ownership-batch kind with a thread-batch subject; the timeline titles it "Ownership changed for N threads".
  • Deliberate change: the old timer skipped a notice if the child was archived or deleted inside the 2 s window. The row's content is fixed when it is posted, so that narrow case now still notifies.

The queue drawer shows notices usefully.

  • ThreadQueuedMessage gains systemNotice. Notice rows use the timeline's own title and icon ("3 threads updated", "X assigned to you") and show only their wait reason underneath.
  • Notice rows offer only send-now and delete: no edit, no send-time change, no drag. The server reports them editable: false and the update route refuses a rewrite with 409, so the CLI and SDK follow the same rule.
  • Notices still collecting or being delivered (time wait or no wait) are left out of the drawer, so they no longer flicker. Held, failed and stuck notices still show.
  • The sidebar's queued-waiting status counts only non-notice rows; a failed notice still shows as failed.
  • The collapsed header adds "· N from bb" and prefers the user's own wait line over a notice's.
  • The drawer cap is 30% of the window height, between 198 and 360 px. A short queue still fits its content exactly.

Other

  • @get-bb/plugin-sdk bumped to 0.6.124. The bundled types inline SystemMessageKind and ThreadQueuedMessage.
  • No daemon wire change, no CLI/config surface change.

How you verified

Tests

  • New thread-ownership-notices.test.ts replaces the timer-mock debounce test and runs against real queue rows. It covers:
    • Bulk unassign: one row, one delivered ownership-batch turn. This fails on main with expected [] to have a length of 1 but got +0. With a 2.3 s wait added on main, the same three unassigns produce 1 delivered turn plus 2 more queued notices.
    • The row is persisted and scheduled before the window elapses.
    • Same-child flip; intermediate parent never notified; withdrawing one child keeps the others.
    • Delivered-parent baseline.
    • stuck/off handling; single change keeps today's exact text.
  • Server: queued-work status for notice-only and mixed threads; a notice row reported editable: false with systemNotice, and a rewrite refused with 409.
  • App: notice-row title and actions, collapsed summary, transient-notice filter, drawer-cap math. Existing drawer tests that encoded "From System", a system second line and the 198 px cap are updated.
  • Targeted runs: server 99, app 452; turbo run test for domain, server-contract, cli and client-core. turbo run typecheck passes across server, app, db, cli, demo-server, plugin-sdk and test-helpers; app lint has no errors.

Live on pnpm start:worktree, with Claude Haiku managers and children, driven with the source CLI:

  • Ownership:
    • Three concurrent assigns and three concurrent unassigns: one notice each.
    • SIGKILL inside the window: the row was on disk and was delivered after the automatic restart.
    • Assigning then unassigning the same child withdrew the row.
    • A single change kept the old wording.
  • Notices held by the concurrency limit (global limit 0):
    • The drawer shows "Ownership changed for 4 threads · Held by Concurrency limit" next to the user's own scheduled message. That's two unassigns plus two assigns sent 10 s later, merged into the held row.
    • Hovering a notice offers only Send now and Delete.
    • Collapsed: "Queue · 1 from bb" with the user's own schedule.
    • Same at 390 px.
  • A MutationObserver on an idle manager saw no queue row or card while three children reported, and the notice was delivered as one turn.
  • With only notices queued, the thread list API reported queuedWork: none and the sidebar clock went away.

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael
ymichael force-pushed the bb/batch-parent-ownership-notices-through-coalesced-thr_h9ft2uy2m7 branch 2 times, most recently from 85ee385 to 8c89593 Compare November 4, 2026 20:10
@ymichael ymichael changed the title Batch parent ownership notices through coalesced queue rows Batch parent ownership notices and show bb notices usefully in the queue drawer Nov 4, 2026
@ymichael
ymichael force-pushed the bb/batch-parent-ownership-notices-through-coalesced-thr_h9ft2uy2m7 branch from 8c89593 to 622463e Compare November 4, 2026 20:18
ymichael and others added 4 commits November 4, 2026 12:48
Ownership notices used an in-memory per-child 2 s timer, so unassigning
several threads at once sent the parent one notice and one steer per child,
and a restart inside the window lost the notice. They now go through
postCoalescedSystemNotice with a thread-ownership coalesce key: every change
to one parent within the window becomes one durable queued row, listing each
assigned or unassigned child. A move undone inside the window withdraws the
pending entry, and an assignment entry remembers the parent the child had
before the window so intermediate parents are never notified.

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

Notices merged into a row already waiting on the parent can now be withdrawn
too, and the withdraw guards on the same drainable-row rule as the merge. The
delivered-baseline test now delivers the rows instead of expiring their window,
since an expired but undelivered row is still mergeable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Queued bb notices rendered as raw prompt text ("[bb system] These threads
are…") with a "From System" label, offered every user-message action, briefly
appeared and vanished during their 2 s coalescing window, and turned the
sidebar clock on even when nothing of the user's was queued.

- Queued rows now carry their systemNotice; the drawer titles notice rows the
  way the timeline does ("3 threads updated", "X assigned to you") with the
  timeline's icon, and shows only their wait reason underneath.
- Notice rows offer only send-now and delete: no edit (the server reports them
  not editable and refuses a rewrite), no send-time change, no drag.
- Notices still collecting or being delivered (time or no wait) are left out
  of the drawer, so they no longer flicker; held, failed and stuck notices
  still show.
- The sidebar's queued-waiting status counts only non-notice rows; a failed
  notice still shows as failed.
- The collapsed header adds "· N from bb" and prefers the user's own wait
  line over a notice's.
- The drawer may grow to 30% of the window (198-360 px) before it scrolls.
- Plugin SDK 0.6.123: ThreadQueuedMessage gains systemNotice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#7011 brought the coalesced-notice code back to its pre-#7028 shape, so the
pending lookup takes `now` again and a merge writes `sendAt` rather than
`windowEndsAt`. The test for withdrawing a change after its window but before
delivery depended on #7028 and is removed with it; main's plugin SDK is now
0.6.123.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/batch-parent-ownership-notices-through-coalesced-thr_h9ft2uy2m7 branch from 622463e to 64a82b3 Compare November 4, 2026 20:50
@ymichael
ymichael merged commit 5bc99dc into main Nov 4, 2026
95 of 96 checks passed
@ymichael
ymichael deleted the bb/batch-parent-ownership-notices-through-coalesced-thr_h9ft2uy2m7 branch November 4, 2026 21:01
ymichael added a commit that referenced this pull request Nov 4, 2026
## Human comments

## What was wrong

#7011 (updateWhenIdle settings) reverted two PRs that had merged about
30 minutes before its commit was created: #7028 (merge child notices
while the parent is blocked, skip `/compact` turns) and #7030 (count
only the latest workflow run in GitHub PR check status). Its body
mentions neither, so it looks accidental.

- #7011 is a single commit, `6b17f1bc04`, whose parent is #7028's merge
commit `920804af63`. Even so, the commit's own diff rewrites 11 files to
their earlier content:
- In #7028's 9 files it is an exact inverse of #7028, apart from four
exports #7011 added to `packages/db/src/data/index.ts`.
- #7030's 3 files in `plugins/github-pr-status/host/` went back to their
pre-#7030 content.
- That pattern fits a branch whose files came from an older checkout and
were committed onto a newer base.
- CI stayed green because each revert also removed the matching tests.
- No other PR was affected. Every file the commit touched was compared
with its earlier versions on main; only these two PRs match.

What users got back after #7011:
- **#7028:** a parent blocked on a question, a starting turn or an
offline host collects a separate notice for every child update again (on
Nov 3 one parent got ten from one child). `/compact` turns on a child
send the parent "No final output was recorded."
- **#7030:** bb shows green PRs as failing ("22 passed, 4 failed") when
GitHub cancelled a duplicate CI run.

## What changed

- Cherry-picks `b0e91c38f8` (#7030) and `920804af63` (#7028) onto
current main with `-x`. #7030 applies unchanged.
- #7028 conflicted only in `coalesced-system-notices.ts`, because #7029
(merged after #7011) added withdrawing a pending notice there. The
result is #7028's version with #7029's withdraw path kept: the pending
lookup has no `now` and a merge writes `windowEndsAt`. This is the
combination #7029 was tested with before #7011 landed.
`child-thread-notifications.ts` resolved to main's existing version,
which already guards on a scheduled row.
- Restores the #7029 test that depends on #7028: an ownership change
undone after its 2 s window but before delivery is withdrawn. Its test
helper comes back with it.
- `internal/events.ts` and `db/data/events.ts` merged cleanly with the
later #7031 and #7033 changes.
- No daemon wire, CLI, config or plugin SDK surface change;
`check-plugin-sdk-version` reports the surface unchanged.

## How you verified

- With main's current code and the restored tests, 7 tests fail. With
this branch they pass:
- `thread-ownership-notices`: "withdraw a move undone after its window
but before delivery"
- `system-notice-dispatch`: "merge later outcomes into a row still
waiting on the parent"
- `child-completion-turn-output`: "does not notify the parent for a turn
that only compacted context"
- `github-pr-status` `git-host` / `batch`: superseded workflow runs,
including on a later checks page and for drafts found through `gh pr
view`
- Server: ownership notices, notice dispatch, child completion output,
notice kinds, child outcomes, parenting, plugin events, queue updates,
sidebar status and child notifications all pass (112 tests).
- `turbo run test` for the GitHub PR Status plugin, `@bb/db` and
`@bb/templates` passes (10/10 tasks). `turbo run typecheck` for server,
db, app and the plugin passes (10/10 tasks).

> AGENT GENERATED

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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