feat(server): background wakes say which subagent, command, or monitor finished #13948
Mergedjuliusmarmingemerged 10 commits into
t3code/codex-turn-mapping fromrefs/pull/13948/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts line 5793Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5732,3 +5770,9 @@57325770 // Root-session tasks only: a cancelled subagent's re-run in57335771 // its child session must not gate root wake machinery.57345772 if ((yield* Ref.get(activeSessionId)) !== mutation.sessionId) return;5773+ if (5774+ mutation.status !== "running" &&5775+ mutation.report !== undefined &&5776+ !(yield* Ref.get(handledBackgroundTaskIdsInActiveTurn)).has(mutation.taskId)5777+ ) {5778+ yield* recordWakeReport(mutation.taskId, {apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts lines 5117 to 5117Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5069,3 +5092,11 @@50695092 const context = yield* Ref.get(activeTurn);50705093 const subagent =50715094 context === null ? undefined : context.subagentsBySessionId.get(notice.childSessionId);5095+ const known =5096+ subagent ??5097+ (yield* Ref.get(carryoverSubagents))?.subagents.find(5098+ (candidate) =>5099+ candidate.childSessionId === notice.childSessionId ||5100+ candidate.task.nativeTaskRef?.nativeId === notice.childSessionId,5101+ );5102+ if (known !== undefined && acpSubagentStatusBlocksTurnSettlement(known.task.status)) {apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 2887OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2864,0 +2867,21 @@2867+ // Background work that ended and has not been named by a wake offer yet,2868+ // by native thread and task id, with the user turn it ended in. Claude's2869+ // wake result carries no task id, and its wake can run after a prompt the2870+ // user queued meanwhile, so reports survive one user turn and then expire:2871+ // a notification Claude folded into its own turn cannot name a later wake.2872+ const wakeReportsByNativeThread = yield* Ref.make(2873+ new Map<2874+ string,2875+ ReadonlyMap<string, { readonly report: BackgroundWorkReport; readonly turn: number }>2876+ >(),2877+ );2878+ const userTurnCountByNativeThread = yield* Ref.make(new Map<string, number>());2879+ // Subagents Claude started in the background. Only their ends wake the root.2880+ const backgroundedSubagentTaskIds = yield* Ref.make<ReadonlySet<string>>(new Set());2881+ const recordWakeReport = (2882+ nativeThreadId: string,2883+ taskId: string,2884+ report: BackgroundWorkReport,2885+ ) =>2886+ Effect.gen(function* () {2887+ const turn = (yield* Ref.get(userTurnCountByNativeThread)).get(nativeThreadId) ?? 0;
- @@ -21,0 +101,21 @@101+ : "finished";102+ if (reports.length > 3 || reports.every((report) => reportLabel(report.label) === undefined)) {103+ const kinds = new Set(reports.map((report) => report.kind));104+ const noun = kinds.size === 1 ? KIND_NOUN[first.kind][1] : "background tasks";105+ return `${reports.length} ${noun} ${verb}`;106+ }107+ return `${joinNames(reports.map((report, index) => namedReport(report, index === 0)))} ${verb}`;108+}109+110+/** Reports of one kind share it; mixed kinds are generic background work. */111+function reportsSource(112+ reports: readonly [BackgroundWorkReport, ...ReadonlyArray<BackgroundWorkReport>],113+): OrchestrationV2NotificationSource {114+ const [first, ...rest] = reports;115+ if (rest.some((report) => report.kind !== first.kind)) return { kind: "background_task" };116+ switch (first.kind) {117+ case "subagent":118+ // One subagent is the thing the row opens; several open nothing.119+ return rest.length === 0 && first.childThreadId !== undefined120+ ? { kind: "subagent", childThreadId: first.childThreadId }121+ : { kind: "subagent" };
- apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 6582OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -6390,3 +6578,5 @@63906578 });63916579 return updated;63926580 });6581+ if (!isClaudeProviderContinuationTurn(turnInput)) {6582+ yield* startUserTurnForWakeReports(nativeThreadId);apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 5522Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5343,3 +5502,5 @@53435502 if (message.tool_use_id !== undefined) {53445503 context.pendingSubagentModelsByToolUseId.delete(message.tool_use_id);53455504 }5505+ if (message.is_backgrounded === true) {5506+ yield* Ref.update(backgroundedSubagentTaskIds, (current) =>
juliusmarminge merged thisb76f762
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed