Closes #13965.
If a Claude turn ends with the agent leaving a dev server running, the desktop and web completion alert (sound, toast, notification) never fires, because the thread reads as Waiting for as long as the shell lives. The mobile push says "Agent finished" right away, even when the pending work is a subagent or monitor that will wake the agent. That second behavior is #13625.
What changed#
One rule decides it, based on the typed OrchestrationV2PendingBackgroundTask.kind. It never matches labels or task-type strings. The rule is backgroundWorkHoldsCompletion in packages/shared/src/orchestrationV2PendingBackgroundWork.ts. It lives in shared rather than client-runtime because the server builds the push and does not depend on client-runtime:
command (dev servers, long-lived shells): does not hold. The turn counts as finished.
subagent, monitor: hold, because they wake the agent and it continues.
background_task (opaque work, and what an unknown or missing kind decodes to): holds. This is the conservative choice.
Both surfaces call it:
- Desktop/web:
ThreadNotificationCoordinator records a completion when the thread is ready, or when it is waiting and the pending work does not hold completion.
- Mobile push:
projectThreadAwarenessV2, which the server relay publishes and the relay turns into the push, reports a completed run as running while held work is pending. AgentAwarenessRelay now also republishes on subagent.updated and provider-thread.updated, so a held completion goes out when that work ends. Before this, neither event triggered a publish, so nothing could release the hold.
The sidebar and the mobile list still show Waiting while a dev server runs. This PR only changes when the alert fires.
Also: the relay republishes on turn-item.updated when a background item type (command, dynamic tool, subagent) is no longer active (turnItemUpdateCanEndBackgroundWork, next to BACKGROUND_TURN_ITEM_TYPES); streaming output does not trigger a shell read.
Verification#
packages/shared: vp test run src/orchestrationV2PendingBackgroundWork.test.ts src/agentAwareness.test.ts: 35 passed. The rule table covers none, command-only, two commands, subagent, monitor, command+monitor, command+subagent, and background_task/unknown.
apps/web: vp test run src/components/ThreadNotificationCoordinator.test.tsx src/components/ThreadNotificationCoordinator.badge.test.tsx: 33 passed. The new case: no alert while a monitor is pending, then one "Thread completed" alert once only a command remains.
apps/server: vp test run src/relay/AgentAwarenessRelay.test.ts: 21 passed.
apps/server: vp test run src/orchestration-v2/ProjectionStore.test.ts: the new case "dates a completion released by held background work at the release" runs the real SQL shell read. The run completes, a monitor stays pending (push phase running), and the monitor ends 5 minutes later through provider-thread.updated. The push is then completed with updatedAt equal to the release time, so the relay's 2-minute freshness check (infra/relay/src/agentActivity/agentActivityAlerts.ts) keeps it. This already holds, because the store bumps the thread's updatedAt on every run, turn-item, subagent and provider-thread event. The test pins it: dropping that bump makes the test fail with the run's time.
apps/server: vp test run src/relay/AgentAwarenessRelay.test.ts: 22 passed. The new case "publishes a held completion when its background item ends, not on tool output" drives the relay's real event stream over the in-memory projection store. The run completes with a background dynamic_tool still running, and the push is running. Streaming assistant output and a running tool tick do not read the shell. The tool's terminal turn-item.updated publishes completed. It fails with the old filter (['running'], no completion) and with an unfiltered one (extra shell reads, 6 instead of 4). packages/shared adds a table for the turn-item predicate.
- Before/after: with the source changes reverted, the new awareness cases (monitor, command+subagent), the new coordinator case, and the relay event-filter case all fail. With the fix they pass.
tsc --noEmit for shared, web, server, and mobile: clean. vp lint on the 8 touched files: clean. vp run knip:check: clean.
- Not run: replay fixtures or a live provider run. The change is pure client and relay logic over the shell's
pendingBackgroundTasks, which already carries kinds.
Model: Claude Opus 5.5 (Claude Code)
🤖 Generated with Claude Code
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed