Skip to content

Let Claude workflows run without blocking the composer - #854

Merged
SawyerHood merged 1 commit into
mainfrom
bb/avoid-queued-claude-workflows-thr_tym78nnbnb
Jul 22, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/avoid-queued-claude-workflows-thr_tym78nnbnb

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Summary

A native Claude workflow (local_workflow) was treated as completion-blocking by hasCompletionBlockingClaudeTasks, so the logical bb turn stayed open for the workflow's entire run. That kept the thread active, and shouldQueueFollowUpMessage queues on active — so typing during a workflow queued the message instead of sending it. Introduced in #633, which added the predicate for background agents and folded workflows in alongside them.

Workflows now let the turn complete and the thread go idle. Background agents and legacy subagents still block, unchanged. When the workflow settles and reinvokes the parent model, that work opens a fresh turn.

The busy status disappears with no UI change. displayStatus derives from thread.status plus host connectivity only — background activity never feeds it. So once the turn completes, the thread-row indicator falls through from the generic "Thread working" spinner to the specific "Workflow running" glyph, while the timeline pill and the composer workflow cards keep rendering off background-task activity. All three workflow indicators survive; only the busy status goes.

Two consequences handled here:

  • Parent notification. A child thread can now report an outcome while its workflow is still running, so the notification says so (@thread:x completed, with 2 workflows still running:) and tells the parent to expect a second report rather than reading the excerpt as final. The count is captured at queue time, the same instant as the output excerpt.
  • Runtime eviction. With the turn closed, the thread no longer sits in the runtime's active set, so evictIdleRuntimeEntries could shut a runtime down mid-workflow and SIGTERM the provider process running it. AgentRuntime now tracks open background tasks from the event stream it already observes and exposes hasOpenBackgroundWork(), which entryHasActiveRuntimeWork counts as active work. This also fixes the pre-existing case of a backgrounded dev server being killed by a shell-env change.

HOST_DAEMON_PROTOCOL_VERSION 63 → 64 so enrolled daemons pick up the new turn timing. The wire shape is unchanged, so an older daemon keeps the old blocking behavior rather than entering an invalid-message loop.

Notes

  • RuntimeBackgroundWorkState observes the normalized event stream rather than plumbing the adapter's hasOpenClaudeBackgroundTasks up through AgentRuntime — the adapter's copy is buried in a per-provider turn-state registry reachable only by the LRU pruner, and reading events keeps this provider-agnostic.
  • Ambient (skipTranscript) tasks do count for eviction. Keep Claude child threads active while subagents run #633 excluded them from turn completion because they're long-lived, but hiding a task from the transcript doesn't make it survive a SIGTERM. This matches the adapter's existing isEvictable.

Tests

  • pnpm exec turbo run typecheck test --filter=@bb/agent-runtime — 794 passed
  • pnpm exec turbo run typecheck test --filter=@bb/host-daemon — 467 passed
  • pnpm exec turbo run typecheck test --filter=@bb/server — 1249 passed
  • pnpm exec turbo run typecheck test --filter=@bb/app --filter=@bb/thread-view — passed

New coverage:

  • the turn completes while a workflow stays open, leaving the task pending
  • a settled workflow's reinvocation opens a fresh turn (turn-2) and completes it
  • RuntimeBackgroundWorkState across multi-task settling, terminal-status-via-progress, ambient tasks, and per-thread clearing
  • an entry with open background work survives replaceBaseShellEnv, then evicts once the work settles — verified to fail without the fix

One pre-existing local failure unrelated to this change: internal-skill-trees.test.ts expects file mode 420 and gets 436 (umask artifact); it fails identically on a clean tree.

🤖 Generated with Claude Code

A native Claude workflow (`local_workflow`) was completion-blocking, so the
logical bb turn stayed open for the workflow's whole run. That kept the thread
`active`, which made the composer queue follow-ups instead of sending them.

Workflows now let the turn complete and the thread go idle. Background agents
and legacy subagents still block, as before. When the workflow settles and
reinvokes the parent model, that work opens a fresh turn.

The busy status disappears without any UI change: `displayStatus` derives from
`thread.status` alone, so the thread-row indicator falls through from the
generic "Thread working" spinner to the specific "Workflow running" glyph, and
the timeline pill plus the composer workflow card keep rendering from
background-task activity.

Two consequences handled here:

- A child thread can now report an outcome while its workflow is still
  running, so the parent notification says so and tells the parent to expect a
  second report rather than reading the excerpt as final.
- With the turn closed, the thread no longer sits in the runtime's active set,
  so `evictIdleRuntimeEntries` could shut a runtime down mid-workflow and
  SIGTERM the provider process running it. `AgentRuntime` now tracks open
  background tasks from the event stream it already observes and exposes
  `hasOpenBackgroundWork()`, which `entryHasActiveRuntimeWork` counts as active
  work. This also fixes the pre-existing case of a backgrounded dev server
  being killed by a shell-env change.

Bumps HOST_DAEMON_PROTOCOL_VERSION so enrolled daemons pick up the new turn
timing; the wire shape is unchanged, so an older daemon keeps the old blocking
behavior rather than failing to parse.

Tests:
- pnpm exec turbo run typecheck test --filter=@bb/agent-runtime
- pnpm exec turbo run typecheck test --filter=@bb/host-daemon
- pnpm exec turbo run typecheck test --filter=@bb/server

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/avoid-queued-claude-workflows-thr_tym78nnbnb branch from c328b74 to 8e855a7 Compare July 22, 2026 16:18
@SawyerHood
SawyerHood merged commit 785a7e5 into main Jul 22, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the bb/avoid-queued-claude-workflows-thr_tym78nnbnb branch July 22, 2026 16:24
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