Skip to content

A child's completion notice is dropped when the parent's status changes while the notice is being prepared #6241

Closed

Description

@gperezmz

Summary

A parent spawned three child threads with bb thread spawn --parent-self. Two children woke the parent with a child-completed notice. The third ended while the parent's turn was about to finish, and its notice never arrived: no client/turn/requested was written, nothing was queued, and nothing was logged. I expected every child that ends to wake its parent, either right away or once the parent is idle.

Versions and environment

  • bb 0.47.1, npm install (bb-app), Node 24.22.1, Linux 6.18 (NixOS 26.11)
  • Parent and children on claude-code, Claude Code 2.1.310
  • Children in one worktree environment; parent parentNotifications: auto on every child
  • The server was under load at the time: frequent Event loop stalled reports (max delay 0.5 to 1.7 s)

Steps to reproduce

I could not reproduce this on demand; the loss depends on timing. Below is the closest faithful repro. It is unverified, because I have not run it.

  1. Start a parent thread on any provider. Have it spawn two children with bb thread spawn --parent-self, where child A ends about 5 s before child B. A child prompt like Run "sleep 20", then reply only with ok. gives that control.
  2. Instruct the parent so that each child-completed notice starts a turn that lasts about 3 to 4 s, for example run "sleep 3", then reply ok.
  3. Child B then ends while the turn that A's notice started is still running. That turn ends shortly after B's 2 s batch flush.
  4. Check bb thread log <parent> --json for a client/turn/requested naming B.

This is more likely on a loaded server or with many skills installed (see "Suspected cause"). A deterministic repro would be a server test that delays prepareTurnSubmitCommandPayload in queueActiveParentSystemMessage, and ends the parent's active turn during that delay.

Expected vs actual

parent thr_8bevt3uhsz, children thr_7mhvqrz4n3, thr_ydvkra8ggs, thr_zuz47nertm (local times)

21:23:20.273  thr_7mhvqrz4n3 turn/completed
21:23:27.415  parent client/turn/requested systemMessageKind=child-completed (subject thr_7mhvqrz4n3)  seq 567
21:23:27.459  parent turn/started
21:23:28.443  thr_ydvkra8ggs turn/completed  (its only turn)
21:23:31.060  parent turn/completed  seq 580
21:23:50.305  thr_zuz47nertm turn/completed
21:24:04.481  parent client/turn/requested systemMessageKind=child-completed (subject thr_zuz47nertm)  seq 582


Expected: a `client/turn/requested` for `thr_ydvkra8ggs`, either steered into the running turn or queued until the parent is idle.

Actual: none. The parent's event sequence from 563 to 592 has no gaps, so no event was written and pruned later. The DB has no `queued_thread_messages` row for the parent, and the server logged nothing for it.

Evidence

Observed: two code paths drop the notice. Code links are permalinks at the desktop-v0.47.1 tag (5e1acd7). parent-system-messages.ts and child-thread-notifications.ts are byte-identical on main at 9eb0c09.

flushChildThreadTurnNotificationBatch (child-thread-notifications.ts#L389-L420) deletes the batch first. It ignores a false return from queueParentSystemMessage and logs and drops a throw, so nothing retries or queues the notice. queueParentSystemMessage reads the parent's status once, awaits the turn preparation, and only then rechecks the status inside the write transaction.

  1. Silent drop. The parent is active when the notice is prepared but idle by the transaction. queueActiveParentSystemMessage awaits prepareTurnSubmitCommandPayload (L305). Then queueActiveParentSystemMessageInTransaction sees currentThread.status !== "active" and returns null (L223-L235), and the caller returns false (L330-L331). This is the thr_ydvkra8ggs case:
    • its batch flushed at about 21:23:30.4, when the parent was active in turn t13;
    • t13 ended at 21:23:31.06, before the transaction ran;
    • the server logged Event loop stalled with maxDelayMs: 1718 at 21:23:30.398.
  2. Logged drop. The parent is idle when the notice is prepared, but a turn has started by the transaction, usually from a sibling's notice. queueReadyParentSystemMessage awaits prepareReadyThreadTurnCommand (L367). Then run.started from active throws inside the transaction (L386-L399). The rollback removes the client/turn/requested the transaction had just appended. The error is not one of the two that queueParentSystemMessage turns into a queued message (L458-L462). Example from the same parent:
    • thr_dpqj7vdnvw ended at 21:15:32 with the parent idle;
    • a parent turn started 3.1 s later;
    • then:
    21:16:11.745 Failed to queue batched parent turn notifications parentThreadId=thr_8bevt3uhsz childThreads=[thr_dpqj7vdnvw completed]
      ThreadLifecycleEventNotAppliedError: Thread lifecycle event not applied (illegal-transition): no transition for run.started from status active
        at requireThreadLifecycleEventApplied
        at deps.db.transaction.behavior   (inside queueReadyParentSystemMessage)
    

Counts. I took a read-only copy of the local DB and counted children with parent_notifications=auto and no origin_kind. A loss is a root turn/completed with status completed and no system client/turn/requested naming that child within 10 minutes. Versions are assigned by when each ran on this install, taken from the version in server log paths.

Version Child completions Lost Median / p90 child end to notice
0.46.1 (5 days) 1554 3 (cause unknown; that parent is now archived) 2.0 s / 2.2 s
0.47.0 (12 h) 184 0 2.0 s / 2.5 s
0.47.1 (7.5 h) 457 17 4.0 s / 11.3 s

Each 0.47.1 loss fits one of the two paths by timing:

  • 10 silent (path 1): the parent was active, and its turn ended 2.6 to 4.4 s after the child ended, just past the 2 s batch flush.
  • 7 logged (path 2): the parent was idle, and a parent turn started 2.6 to 19 s after the child ended. Each matches a Failed to queue batched parent turn notifications line.

That log message appears 9 times under 0.47.1 and in none of the 0.46.1 or 0.47.0 server logs still on disk. Event loop stalled reports per hour of log rose from about 5 (0.46.1) and about 8 (0.47.0) to about 80 (0.47.1).

Suspected cause of the jump in 0.47.1 (medium to high confidence, not measured per span). The two drop paths are the same code in 0.46.1, 0.47.0 and 0.47.1, so the race is old. What changed is the time between the two status checks.

In 0.47.1, resolveThreadRuntimeCommandConfig, which builds every turn dispatch including parent notices, now awaits skill discovery:

0.47.0 (c8d5860) 0.47.1 (5e1acd7)
const skillIdsByPlugin = discoverPluginSkillIds(deps.logger, { const skillIdsByPlugin = await discoverPluginSkillIds(deps.logger, {
const injectedSkillSources = resolveSkillCatalog(deps, { await resolveSkillCatalog(deps, {

scanSkillFiles awaits one fs.stat and one fs.readFile per SKILL.md, in sequence. Each await yields to the event loop, and with the loop stalling, preparation now takes seconds. During that time other daemon event posts are applied, including the parent's own turn/completed or turn/started.

What supports this:

  • It is the only change between 0.47.0 and 0.47.1 on the code path between the two checks.
  • Latency and losses jump at the upgrade.

What I did not establish:

  • The time spent in each span. Turn-trace spans runtimeConfig.pluginConfig to runtimeConfig.built for parent notices would settle it.
  • Whether other load, such as a third-party plugin's RPCs that dominate inFlightWorkAtObservation, adds to the stalls.

What you ruled out

Suggested priority and effort (optional)

No response

Checks

  • I reproduced this on the latest release or on main, or I say above that I could not.
  • I searched open and closed issues for the same problem.
  • If an agent wrote this, the body ends with > AGENT GENERATED and links the thread or report.

Activity

  1. added theissue type on Oct 24, 2026
  2. added
    threads
    confirmed-repro
    on Oct 24, 2026
  3. bb-slop-cop commented on Oct 24, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification applied: Bug · High priority · Medium effort · threads.
    • Reproduction report: REPRODUCED, high root-cause confidence; labeled confirmed-repro. Both races repeat in a second clean trusted checkout.
    • Root cause: Parent status changes during asynchronous command preparation either return false without recording the notice or trigger a lifecycle error that rolls it back.
    • Fix: Ready PR #6243 revalidates state transactionally and retries delivery against the current parent. It changes 195 text lines across two files.
    • Verification: Two deterministic regression cases fail before the fix and pass afterward; 70 relevant existing tests, server typecheck, formatting, and diff checks pass. Production loss rates and skill-discovery performance attribution remain unverified.

    AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reprothreads

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions