Skip to content

Merge child notices while the parent is blocked, and skip /compact turns - #7028

Merged
ymichael merged 2 commits into
mainfrom
fix/child-parent-notices
Nov 4, 2026
Merged

ymichael merged 2 commits into
mainfrom
fix/child-parent-notices

Conversation

@ymichael

@ymichael ymichael commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Two separate causes produced noisy child → parent completion notices.

  1. Notices piled up while the parent was blocked. A child's turn-end notice only coalesced into a queued row that was still inside its 2 s scheduled window (getPendingCoalescedQueuedThreadMessage required state = 'scheduled' and send_at > now). Once that row moved to waiting (pending question, starting turn, offline host), every later outcome created another row. On 2026-11-03 a parent blocked on an AskUserQuestion from 22:23 to 04:31 received ten separate "completed" notices from one child, all steered in within two seconds of the answer. The same pile-up existed before Deliver parent/child notices through the dispatcher #6728 (pairs from one child appear in the event log since September); this is the first time a parent stayed blocked long enough for it to reach ten.
  2. /compact turns were reported as completions. A /compact on a child runs as its own turn whose only root item is the context compaction. Its turn end notified the parent with "No final output was recorded." just before the queued message behind it started the real work. All 7 "No final output" child notices since Scope child completion notices to the completed root turn #6821 were these turns. Before Scope child completion notices to the completed root turn #6821 the same turn re-sent the previous turn's output.

What changed

Area Change
packages/db getPendingCoalescedQueuedThreadMessage / updateCoalescedQueuedThreadMessageInTransaction Match any undelivered coalesced row (queued, scheduled, waiting). Only a row still inside its time window has send_at pushed back; a waiting row keeps its wait.
apps/server postCoalescedSystemNotice, child notifications Return the row as stored; arm the dispatch timer only for a scheduled row.
packages/db isStoredTurnContextCompactionOnly New: true when a turn's completed root items are all contextCompaction.
apps/server/src/internal/events.ts A completed child turn that only compacted context does not notify the parent. A turn that compacts and then answers still does.
bb guide threads --parent-notifications text says compaction-only turns are not reported.

No daemon wire change, so HOST_DAEMON_PROTOCOL_VERSION is unchanged. No schema change.

How you verified

  • apps/server/test/threads/system-notice-dispatch.test.ts: "merge later outcomes into a row still waiting on the parent" (parent on a pending question, two outcomes from one child plus one from another → one waiting row, latest status per child). Fails on main, passes here. It replaces "start a new row once the earlier window has expired", which pinned the pile-up.
  • apps/server/test/threads/child-completion-turn-output.test.ts: "does not notify the parent for a turn that only compacted context" (compaction-only turn → no notice; compaction + answer → notice with the answer). Fails without the events.ts change. The existing turn-scoping test now records the parent's latest notice per child turn, because its harness parent never accepts a turn and the old assertion counted the pile-up.
  • pnpm exec turbo run typecheck lint --filter=@bb/server --filter=@bb/db passes.
  • pnpm exec turbo run test --filter=@bb/server --filter=@bb/db: 3857 passed / 1 skipped, and 653 passed. One run hit a 40 s timeout in builtin-plugins.test.ts under load ~14; that file passes on its own (27/27).
  • Live QA against a pnpm start:worktree server: to follow in a comment.

🤖 Generated with Claude Code

AGENT GENERATED

ymichael and others added 2 commits November 4, 2026 10:42
A child's turn-end notice only coalesced into a queued row that was still
inside its 2 s scheduled window. Once that row moved to waiting (for a
pending question, a starting turn, an offline host), every later outcome
from the same child created another row, and they were all steered into
the parent at once when it unblocked. A parent blocked on a question for
six hours received ten separate "completed" notices from one child.

Later outcomes now merge into any undelivered coalesced row (queued,
scheduled or waiting). Only a row still inside its time window has its
send time pushed back; a waiting row keeps its wait.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A /compact on a child thread runs as its own turn whose only item is the
context compaction. Its turn end notified the parent as a completion with
"No final output was recorded.", right before the queued message behind
it started the child's real work. Every "No final output" child notice
since #6821 was one of these turns.

A completed turn whose only root items are context compactions no longer
notifies the parent. A turn that compacts and then answers still does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael

ymichael commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Live QA: the same scripted scenarios against pnpm start:worktree servers on this branch and on main (4f973b851a), using real Claude Code (Haiku 5.5) threads and the dev bb CLI.

Scenario main this branch
Parent waits on an AskUserQuestion while its child finishes 3 turns 3 queued rows; 3 notices steered in after the answer 1 queued row; 1 notice ("report 3")
Child runs bb thread compact, then a follow-up Parent gets "first result", "No final output was recorded.", "result after compact" Parent gets "first result", "result after compact"
Two children finish while the parent waits 1 row ("Child thread updates", 2 children), still waiting on the question
Hand-edited queued notice, then another outcome Edited row left alone; new outcome gets its own row; both delivered after the answer
bb guide threads Shows the compaction-only line

AGENT GENERATED

@ymichael
ymichael merged commit 920804a into main Nov 4, 2026
51 checks passed
@ymichael
ymichael deleted the fix/child-parent-notices branch November 4, 2026 19:19
ymichael added a commit that referenced this pull request Nov 4, 2026
…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]>
ymichael added a commit that referenced this pull request Nov 4, 2026
…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]>
ymichael added a commit that referenced this pull request Nov 4, 2026
…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]>
ymichael added a commit that referenced this pull request Nov 4, 2026
#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 added a commit that referenced this pull request Nov 4, 2026
…eue drawer (#7029)

## 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. #7011 reverted #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 #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](https://claude.com/claude-code)

---------

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