fix(server): ambient Claude tasks no longer keep a thread running #17320
ClosedJohnZolton(GitHub profile, opens in a new tab)wants to merge 13 commits into
main fromrefs/pull/17320/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 6223OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -6201,4 +6217,7 @@62016217 }6202621862036219 if (message.type === "system" && message.subtype === "task_started") {6204- if (isClaudeNonSubagentTask(message)) {6220+ if (isClaudeAmbientTask(message)) {6221+ // Later frames for this task (progress, notification) must not6222+ // create a subagent either.6223+ context.ignoredTaskIds.add(message.task_id);juliusmarminge added labelsmacroscope-review
juliusmarminge assignedjuliusmarminge
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 9238OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -9144,0 +9218,21 @@9218+ if (liveQuery?.query === input.query && message.type === "system") {9219+ if (message.subtype === "background_tasks_changed") {9220+ for (const task of Array.isArray(message.tasks) ? message.tasks : []) {9221+ if (typeof task?.task_id !== "string" || task.task_id.length === 0) {9222+ continue;9223+ }9224+ if (task.ambient === true && isClaudeAmbientBackgroundTaskType(task.task_type)) {9225+ liveQuery.ambientTaskIds.add(task.task_id);9226+ } else if (task.ambient === false) {9227+ liveQuery.ambientTaskIds.delete(task.task_id);9228+ }9229+ }9230+ } else if (9231+ message.subtype === "task_started" ||9232+ message.subtype === "task_notification"9233+ ) {9234+ if (9235+ message.ambient === true &&9236+ isClaudeAmbientBackgroundTaskType(claudeTaskTypeFromSdkMessage(message))9237+ ) {9238+ liveQuery.ambientTaskIds.add(message.task_id);
- @@ -7505,0 +7536,21 @@7536+ const context =7537+ current?.nativeThreadId === liveQuery.nativeThreadId ? current : liveQuery.lastTurn;7538+ if (yield* clearPendingBackgroundTask(liveQuery.nativeThreadId, taskId)) {7539+ yield* emitRosterUpdate(liveQuery.nativeThreadId, current);7540+ }7541+ yield* clearTaskIdFromNativeThreadSet(7542+ wakeEligibleBackgroundTasksByNativeThread,7543+ liveQuery.nativeThreadId,7544+ taskId,7545+ );7546+ if (7547+ registered !== undefined &&7548+ context !== null &&7549+ !liveQuery.subagentsFromEarlierProcesses.has(registered)7550+ ) {7551+ // Retire the mistaken child projection without stopping the native watcher.7552+ liveQuery.retiredAmbientSubagentTaskIds.add(taskId);7553+ yield* updateClaudeSubagentNode({7554+ context,7555+ taskId,7556+ status: "cancelled",
juliusmarminge closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review.
0f73cf7b-cfea-4ae4-a25c-68f02d86cc8bReviewing files that changed from the base of the PR and between ce10f7781a7103d8794c8d9da228b750c40c4e3f and 31618e8cd24e3f2c24a3f4175ba43015b13b348d.
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Walkthrough
The Claude adapter now tracks ambient task IDs per live query. It excludes ambient tasks from pending-work rosters and subagent projections, reconciles later task notifications, and marks replayed frames so they do not change ambient classification. Tests cover classification changes, process replacement, and resumed background work.
Changes: Claude ambient task filtering
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsEstimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)#
Suggested reviewers:
gigioxxMerge Risk:
Minimal · up to
31618The previously reported cross-turn activity issue is addressed. No actionable merge-blocking risk remains in the supplied evidence.
Architecture risk:
Medium · up to
ce10fThe change affects 1 system.
Changed systems:
apps/serverArchitecture concerns No architecture-level concerns identified.
Review details
Systems and components
Before / after behavior
monitor_wstask frames to check that the task does not project as a subagent, appear in the pending-task roster, or keep background work pending after the turn completes.isClaudeAmbientTask, which identifies systemtask_startedmessages whoseambientfield istrue.parseClaudeBackgroundTaskEntrynow excludes roster entries withambient: true; other entries continue through the existing task-type filter.Reliability and maintainability
Pre-merge checks:
4
Full details: Title check
Explanation
The title says ambient Claude tasks no longer keep a thread running. The changeset classifies ambient background tasks (Claude artifact live-update watchers), filters them from subagent, wake, and Waiting-roster handling, and stops them from counting as pending work. The title names the primary user-visible effect and uses the conventional commit format with a clear scope.
Full details: Description check
Explanation
The description follows the template. It has a problem statement (Claude artifact watchers creating a permanent running subagent, and IDs lost between turns), a change section explaining ambient classification with the live SDK process and the handling of ambient tasks, and a verification section listing the test command, results, and what was not checked. The Scope and approval section is present but does not link a triaged issue or maintainer approval comment. It cites PR
#17320and a maintainer comment on that PR, which the reviewer should confirm meets the approval requirement.Finishing Touches
🧪 Generate unit tests (beta)
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.