@devries-cameron20 / t3code-1 / commits / 6641231797
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(secrets): notify when a delegated agent asks for a secret (#33585)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Stanislav Zmiev committed Nov 13, 2026 at 03:17 UTC 6641231797754d91c105aa8ae637cc4ba79ae625
10 files changed +293 -33
apps/server/src/orchestration-v2/ProjectionStore.test.ts
+5
@@ -8829,6 +8829,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
8829 ]) {
8830 assert.equal(shell?.pendingRuntimeRequest?.id, "secret:b");
8831 assert.isTrue(shell?.pendingRuntimeRequest?.blocking);
8832 + assert.isTrue(shell?.pendingRuntimeRequest?.userOnly);
8833 }
8834
8835 const requestId = RuntimeRequestId.make(`request:${suffix}:async`);
@@ -8920,6 +8921,10 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
8921 [thread?.pendingRuntimeRequest?.blocking, memoryShell.pendingRuntimeRequest?.blocking],
8922 terminal ? [false, false] : [true, true],
8923 );
8924 + assert.deepEqual(
8925 + [thread?.pendingRuntimeRequest?.userOnly, memoryShell.pendingRuntimeRequest?.userOnly],
8926 + terminal ? [undefined, undefined] : [true, true],
8927 + );
8928 }
8929 }),
8930 );
apps/server/src/orchestration-v2/ProjectionStore.ts
+1
@@ -1605,6 +1605,7 @@ function secretRequestAsPendingInput(
1605 kind: "user_input",
1606 createdAt: item.startedAt ?? item.updatedAt,
1607 blocking: true,
1608 + userOnly: true,
1609 };
1610 }
1611
apps/server/src/orchestration-v2/ShellStream.test.ts
+17 -3
@@ -38,8 +38,8 @@ const emptyShellSnapshot = {
38 } as OrchestrationV2ShellSnapshot;
39
40 describe("subagent shell events", () => {
41 - const stored = (threadId: string, type: string) =>
42 - ({ event: { threadId, type } }) as ApplicationStoredEvent;
41 + const stored = (threadId: string, type: string, itemType = "command_execution") =>
42 + ({ event: { threadId, type, payload: { type: itemType } } }) as ApplicationStoredEvent;
43
44 it("keeps regular threads and subagent state changes while omitting subagent transcript updates", () => {
45 const subagents = new Set(["child"]);
@@ -49,6 +49,14 @@ describe("subagent shell events", () => {
49 expect(
50 shouldPublishShellApplicationEvent(stored("child", "turn-item.updated"), subagents),
51 ).toBe(false);
52 + for (const itemType of ["secret_request", "link_request", "user_message"]) {
53 + expect(
54 + shouldPublishShellApplicationEvent(
55 + stored("child", "turn-item.updated", itemType),
56 + subagents,
57 + ),
58 + ).toBe(true);
59 + }
60 expect(shouldPublishShellApplicationEvent(stored("child", "node.updated"), subagents)).toBe(
61 false,
62 );
@@ -198,7 +206,13 @@ describe("omitIdleSubagentShells", () => {
206 expect(omitted.threads.map((thread) => thread.id)).toEqual(["root"]);
207 expect(
208 shouldPublishShellApplicationEvent(
201 - { event: { threadId: "idle", type: "turn-item.updated" } } as ApplicationStoredEvent,
209 + {
210 + event: {
211 + threadId: "idle",
212 + type: "turn-item.updated",
213 + payload: { type: "command_execution" },
214 + },
215 + } as ApplicationStoredEvent,
216 omitted.subagentThreadIds,
217 ),
218 ).toBe(false);
apps/server/src/orchestration-v2/ShellStream.ts
+4
@@ -18,6 +18,7 @@ import {
18 OrchestrationProjectShell as ProjectShellSchema,
19 OrchestrationV2ThreadShell as ThreadShellSchema,
20 } from "@t3tools/contracts";
21 +import { turnItemCanChangeUserWait } from "@t3tools/shared/agentAwareness";
22 import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
23 // @effect-diagnostics-next-line nodeBuiltinImport:off - a synchronous digest of a few project rows.
24 import * as NodeCrypto from "node:crypto";
@@ -547,6 +548,9 @@ export function shouldPublishShellApplicationEvent(
548 // Replay and the live tail overlap; keep known IDs so late events stay filtered.
549 return true;
550 }
551 + if (event.type === "turn-item.updated" && turnItemCanChangeUserWait(event.payload)) {
552 + return true;
553 + }
554 return !(
555 subagentThreadIds.has(event.threadId) &&
556 (event.type === "node.updated" ||
apps/server/src/relay/AgentAwarenessRelay.test.ts
+154
@@ -377,6 +377,160 @@ describe("AgentAwarenessRelay", () => {
377 }),
378 );
379
380 + it.effect("publishes the parent as needing input when its subagent raises a secret card", () =>
381 + Effect.gen(function* () {
382 + const now = DateTime.makeUnsafe(NOW);
383 + const child = waitingChild({
384 + pendingRuntimeRequest: {
385 + id: RuntimeRequestId.make("child-secret-card"),
386 + kind: "user_input",
387 + createdAt: now,
388 + blocking: true,
389 + userOnly: true,
390 + },
391 + });
392 + const parent = shell({ status: "completed" });
393 + const events = yield* Queue.unbounded<OrchestrationV2DomainEvent>();
394 + const pulls = yield* Queue.unbounded<void>();
395 + const { relay, publications } = yield* makeTestRelay({
396 + readShell: (threadId) => Effect.succeed(threadId === child.id ? child : parent),
397 + domainEvents: Stream.fromEffectRepeat(
398 + Queue.offer(pulls, undefined).pipe(Effect.andThen(Queue.take(events))),
399 + ),
400 + });
401 + yield* relay.start();
402 + yield* Queue.take(pulls);
403 + const runId = RunId.make("run:child-secret-card");
404 + // Recording a secret card emits only this event for the child.
405 + yield* Queue.offer(events, {
406 + id: EventId.make("event:child-secret-card"),
407 + type: "turn-item.updated",
408 + threadId: CHILD_THREAD_ID,
409 + runId,
410 + occurredAt: now,
411 + payload: {
412 + id: TurnItemId.make("child-secret-card"),
413 + threadId: CHILD_THREAD_ID,
414 + runId,
415 + nodeId: NodeId.make("node:child-secret-card"),
416 + providerThreadId: null,
417 + providerTurnId: null,
418 + nativeItemRef: null,
419 + parentItemId: null,
420 + ordinal: 1,
421 + status: "waiting",
422 + title: "SMS code",
423 + startedAt: now,
424 + completedAt: null,
425 + updatedAt: now,
426 + type: "secret_request",
427 + label: "SMS code",
428 + reason: "The agent needs the code.",
429 + secretStatus: "pending",
430 + },
431 + });
432 + yield* Queue.take(pulls);
433 + yield* relay.drain;
434 + assert.equal(publications.length, 1);
435 + assert.isTrue(publications[0]?.url.includes(`/threads/${THREAD_ID}/`) ?? false);
436 + assert.equal(publications[0]?.state?.phase, "waiting_for_input");
437 + }).pipe(Effect.scoped),
438 + );
439 +
440 + it.effect(
441 + "clears the parent's input wait when the user steers its subagent past a link card",
442 + () =>
443 + Effect.gen(function* () {
444 + const now = DateTime.makeUnsafe(NOW);
445 + let child = waitingChild({
446 + pendingRuntimeRequest: {
447 + id: RuntimeRequestId.make("child-link-card"),
448 + kind: "user_input",
449 + createdAt: now,
450 + blocking: true,
451 + userOnly: true,
452 + },
453 + });
454 + const parent = shell({ status: "completed" });
455 + const events = yield* Queue.unbounded<OrchestrationV2DomainEvent>();
456 + const pulls = yield* Queue.unbounded<void>();
457 + const { relay, publications } = yield* makeTestRelay({
458 + readShell: (threadId) => Effect.succeed(threadId === child.id ? child : parent),
459 + domainEvents: Stream.fromEffectRepeat(
460 + Queue.offer(pulls, undefined).pipe(Effect.andThen(Queue.take(events))),
461 + ),
462 + });
463 + yield* relay.start();
464 + yield* Queue.take(pulls);
465 + const runId = RunId.make("run:child-link-card");
466 + const item = {
467 + threadId: CHILD_THREAD_ID,
468 + runId,
469 + nodeId: NodeId.make("node:child-link-card"),
470 + providerThreadId: null,
471 + providerTurnId: null,
472 + nativeItemRef: null,
473 + parentItemId: null,
474 + title: null,
475 + startedAt: now,
476 + updatedAt: now,
477 + } as const;
478 + yield* Queue.offer(events, {
479 + id: EventId.make("event:child-link-card"),
480 + type: "turn-item.updated",
481 + threadId: CHILD_THREAD_ID,
482 + runId,
483 + occurredAt: now,
484 + payload: {
485 + ...item,
486 + id: TurnItemId.make("child-link-card"),
487 + ordinal: 1,
488 + status: "waiting",
489 + completedAt: null,
490 + type: "link_request",
491 + url: "https://example.com/login",
492 + label: "Sign in",
493 + reason: "The agent needs you to sign in.",
494 + linkStatus: "pending",
495 + },
496 + });
497 + yield* Queue.take(pulls);
498 + yield* relay.drain;
499 + assert.equal(publications[0]?.state?.phase, "waiting_for_input");
500 +
501 + // Steering a running child records only these events for it; the
502 + // projection then stops counting the link card as pending.
503 + child = waitingChild({ pendingRuntimeRequest: null });
504 + yield* Queue.offer(events, {
505 + id: EventId.make("event:child-steer"),
506 + type: "turn-item.updated",
507 + threadId: CHILD_THREAD_ID,
508 + runId,
509 + occurredAt: now,
510 + payload: {
511 + ...item,
512 + id: TurnItemId.make("child-steer"),
513 + ordinal: 2,
514 + status: "completed",
515 + completedAt: now,
516 + createdBy: "user",
517 + creationSource: "web",
518 + type: "user_message",
519 + messageId: MessageId.make("message:child-steer"),
520 + inputIntent: "steer",
521 + text: "Skip the login.",
522 + attachments: [],
523 + },
524 + });
525 + yield* Queue.take(pulls);
526 + // The relay confirms a move into completed before publishing it.
527 + yield* TestClock.adjust("5 seconds");
528 + yield* relay.drain;
529 + assert.equal(publications.length, 2);
530 + assert.equal(publications[1]?.state?.phase, "completed");
531 + }).pipe(Effect.scoped),
532 + );
533 +
534 it.effect("republishes a completed parent for its waiting child after a relink", () =>
535 Effect.gen(function* () {
536 const parent = shell({ status: "completed" });
apps/server/src/relay/AgentAwarenessRelay.ts
+14 -5
@@ -16,7 +16,8 @@ import {
16 import {
17 type SubagentRequestAwareness,
18 projectThreadAwarenessV2,
19 - subagentAwaitsApproval,
19 + subagentAwaitsUser,
20 + turnItemCanChangeUserWait,
21 } from "@t3tools/shared/agentAwareness";
22 import { turnItemUpdateCanEndBackgroundWork } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
23 import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
@@ -128,7 +129,11 @@ function shouldPublishAgentAwarenessEvent(
129 case "provider-session.detached":
130 case "provider-turn.updated":
131 case "turn-item.updated":
131 - return isTurnItemPayload(event.payload) && turnItemUpdateCanEndBackgroundWork(event.payload);
132 + return (
133 + isTurnItemPayload(event.payload) &&
134 + (turnItemUpdateCanEndBackgroundWork(event.payload) ||
135 + turnItemCanChangeUserWait(event.payload))
136 + );
137 case "message.updated":
138 case "plan.updated":
139 case "checkpoint-scope.created":
@@ -308,7 +313,7 @@ interface SubagentAlert {
313 }
314
315 const waitingApprovalId = (thread: AgentAwarenessThread | null) =>
311 - thread !== null && thread.archivedAt === null && subagentAwaitsApproval(thread)
316 + thread !== null && thread.archivedAt === null && subagentAwaitsUser(thread)
317 ? thread.pendingRuntimeRequest?.id
318 : undefined;
319
@@ -377,7 +382,7 @@ export function resolveAgentAwarenessRelayActiveThreadIds(input: {
382 return input.threads
383 .filter((thread) => {
384 // Publishing a waiting subagent republishes its top-level thread.
380 - if (subagentAwaitsApproval(thread)) return true;
385 + if (subagentAwaitsUser(thread)) return true;
386 const project = projectById.get(thread.projectId);
387 if (!project) {
388 return false;
@@ -758,7 +763,11 @@ export const make = Effect.gen(function* () {
763 if (requestId !== entry.requestId) subagentRequests.set(childId, { ...entry, requestId });
764 // The newest wait is the one to announce.
765 if (pending === null || DateTime.isGreaterThan(child.updatedAt, pending.updatedAt)) {
761 - pending = { requestId, updatedAt: child.updatedAt };
766 + pending = {
767 + requestId,
768 + updatedAt: child.updatedAt,
769 + waitsForInput: child.pendingRuntimeRequest?.kind === "user_input",
770 + };
771 }
772 }
773 return pending;
packages/client-runtime/src/state/threadShell.test.ts
+45
@@ -160,6 +160,36 @@ describe("v2 thread shell lists", () => {
160 registry.dispose();
161 });
162
163 + it("flags the parent while a live subagent waits on a secret card", () => {
164 + const { registry, threads, snapshotAtom } = makeHarness();
165 + const root = v2ThreadShell;
166 + const child = {
167 + ...root,
168 + id: ThreadId.make("child"),
169 + creationSource: "mcp" as const,
170 + status: "running" as const,
171 + activityRunStatus: "running" as const,
172 + lineage: {
173 + ...root.lineage,
174 + parentThreadId: root.id,
175 + relationshipToParent: "subagent" as const,
176 + },
177 + pendingRuntimeRequest: {
178 + id: RuntimeRequestId.make("secret-card"),
179 + kind: "user_input" as const,
180 + createdAt: v2Now,
181 + blocking: true,
182 + userOnly: true,
183 + },
184 + };
185 + registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [root, child] });
186 + expect(
187 + registry.get(threads.threadShellAtom({ environmentId, threadId: root.id }))
188 + ?.pendingSubagentRequest,
189 + ).toBe("user_input");
190 + registry.dispose();
191 + });
192 +
193 it("rolls a side chat's questions and approvals up to its parent row", () => {
194 const { registry, threads, snapshotAtom } = makeHarness();
195 const root = v2ThreadShell;
@@ -380,6 +410,21 @@ describe("v2 thread shell lists", () => {
410 expect(registry.get(threads.threadShellAtom(parentRef))?.pendingSubagentRequest).toBeNull();
411 expect(registry.get(inputs).map((thread) => thread.id)).toEqual([helper.id]);
412
413 + // A secret card needs the user, so it still reaches the parent here.
414 + registry.set(snapshotAtom(remoteEnvironmentId), {
415 + ...v2ShellSnapshot,
416 + threads: [
417 + task,
418 + {
419 + ...helper,
420 + pendingRuntimeRequest: { ...approval, kind: "user_input" as const, userOnly: true },
421 + },
422 + ],
423 + });
424 + expect(registry.get(threads.threadShellAtom(parentRef))?.pendingSubagentRequest).toBe(
425 + "user_input",
426 + );
427 +
428 // A task whose parent is gone there is listed on its own, as is one whose
429 // parent's environment is switched off.
430 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [] });
packages/client-runtime/src/state/threadShell.ts
+29 -18
@@ -30,7 +30,7 @@ import {
30 const EMPTY_THREADS: ReadonlyArray<OrchestrationV2ThreadShell> = Object.freeze([]);
31 const EMPTY_SCOPED_THREAD_REFS: ReadonlyArray<ScopedThreadRef> = Object.freeze([]);
32 const EMPTY_THREAD_INDEX: ReadonlyMap<ThreadId, OrchestrationV2ThreadShell> = new Map();
33 -const EMPTY_SUBAGENT_REQUESTS: ReadonlyMap<ThreadId, PendingSubagentRequest> = new Map();
33 +const EMPTY_SUBAGENT_REQUESTS: ReadonlyMap<ThreadId, never> = new Map<ThreadId, never>();
34 const EMPTY_SIDE_CHATS_BY_PARENT: ReadonlyMap<
35 ThreadId,
36 ReadonlyArray<OrchestrationV2ThreadShell>
@@ -85,6 +85,17 @@ function subagentRequest(thread: OrchestrationV2ThreadShell): PendingSubagentReq
85 return kind === "user_input" ? "user_input" : "approval";
86 }
87
88 +/** A user-only card keeps its mark through roll-ups; clients see it as user_input. */
89 +type RolledUpRequest = PendingSubagentRequest | "user_only_input";
90 +
91 +const rolledUpRequest = (
92 + thread: OrchestrationV2ThreadShell,
93 + request: PendingSubagentRequest | null,
94 +): RolledUpRequest | null =>
95 + request === "user_input" && thread.pendingRuntimeRequest?.userOnly === true
96 + ? "user_only_input"
97 + : request;
98 +
99 /** A side chat asks its user directly, so questions roll up to the parent as well as approvals. */
100 function sideChatRequest(thread: OrchestrationV2ThreadShell): PendingSubagentRequest | null {
101 const kind = thread.pendingRuntimeRequest?.kind;
@@ -104,17 +115,13 @@ function pendingSubagentRequestsByThread(
115 threads: ReadonlyArray<OrchestrationV2ThreadShell>,
116 delegated: ReadonlyArray<{
117 readonly parentThreadId: ThreadId;
107 - readonly request: PendingSubagentRequest;
118 + readonly request: RolledUpRequest;
119 }> = [],
109 -): ReadonlyMap<ThreadId, PendingSubagentRequest> {
110 - const requests = new Map<ThreadId, PendingSubagentRequest>();
120 +): ReadonlyMap<ThreadId, RolledUpRequest> {
121 + const requests = new Map<ThreadId, RolledUpRequest>();
122 let byId: ReadonlyMap<ThreadId, OrchestrationV2ThreadShell> | undefined;
112 - const flag = (
113 - firstParentId: ThreadId | null,
114 - request: PendingSubagentRequest,
115 - seen: Set<ThreadId>,
116 - ) => {
117 - // The coordinator answers child questions; only approvals need user attention.
123 + const flag = (firstParentId: ThreadId | null, request: RolledUpRequest, seen: Set<ThreadId>) => {
124 + // The coordinator answers child questions; approvals and user-only cards need the user.
125 if (request === "user_input") return;
126 byId ??= new Map(threads.map((thread) => [thread.id, thread] as const));
127 let parentId = firstParentId;
@@ -138,7 +145,7 @@ function pendingSubagentRequestsByThread(
145 continue;
146 }
147 if (child.lineage.relationshipToParent !== "subagent") continue;
141 - const request = subagentRequest(child);
148 + const request = rolledUpRequest(child, subagentRequest(child));
149 if (request !== null) flag(parentId, request, new Set([child.id]));
150 }
151 for (const task of delegated) flag(task.parentThreadId, task.request, new Set());
@@ -146,8 +153,8 @@ function pendingSubagentRequestsByThread(
153 }
154
155 const sameRequests = (
149 - left: ReadonlyMap<ThreadId, PendingSubagentRequest>,
150 - right: ReadonlyMap<ThreadId, PendingSubagentRequest>,
156 + left: ReadonlyMap<ThreadId, RolledUpRequest>,
157 + right: ReadonlyMap<ThreadId, RolledUpRequest>,
158 ) =>
159 left.size === right.size &&
160 [...right].every(([threadId, request]) => left.get(threadId) === request);
@@ -274,7 +281,7 @@ export function createEnvironmentThreadShellAtoms(input: {
281 // environments run for it, so two environments delegating to each other
282 // never read each other's totals.
283 const localSubagentRequestsAtom = Atom.family((environmentId: EnvironmentId) => {
277 - let previous = EMPTY_SUBAGENT_REQUESTS;
284 + let previous: ReadonlyMap<ThreadId, RolledUpRequest> = EMPTY_SUBAGENT_REQUESTS;
285 return Atom.make((get) => {
286 const next = pendingSubagentRequestsByThread(get(environmentThreadsAtom(environmentId)));
287 if (sameRequests(previous, next)) return previous;
@@ -305,7 +312,7 @@ export function createEnvironmentThreadShellAtoms(input: {
312 else tasks.push(task);
313 }
314 }
308 - let flags = new Map<EnvironmentId, ReadonlyMap<ThreadId, PendingSubagentRequest>>();
315 + let flags = new Map<EnvironmentId, ReadonlyMap<ThreadId, RolledUpRequest>>();
316 const requestsOf = (environmentId: EnvironmentId) =>
317 flags.get(environmentId) ?? get(localSubagentRequestsAtom(environmentId));
318 for (let changed = tasksByDelegator.size > 0; changed;) {
@@ -313,7 +320,7 @@ export function createEnvironmentThreadShellAtoms(input: {
320 const next = new Map(flags);
321 for (const [environmentId, tasks] of tasksByDelegator) {
322 const delegated = tasks.flatMap(({ runsIn, thread, parentThreadId }) => {
316 - const own = subagentRequest(thread);
323 + const own = rolledUpRequest(thread, subagentRequest(thread));
324 const nested = requestsOf(runsIn).get(thread.id);
325 const request = own === "approval" ? own : (nested ?? own);
326 return request === null ? [] : [{ parentThreadId, request }];
@@ -333,11 +340,15 @@ export function createEnvironmentThreadShellAtoms(input: {
340 }).pipe(Atom.withLabel("environment-delegated-subagent-requests"));
341
342 const pendingSubagentRequestsAtom = Atom.family((environmentId: EnvironmentId) => {
336 - let previous = EMPTY_SUBAGENT_REQUESTS;
343 + let previous: ReadonlyMap<ThreadId, PendingSubagentRequest> = EMPTY_SUBAGENT_REQUESTS;
344 return Atom.make((get) => {
338 - const next =
345 + const rolledUp =
346 get(delegatedSubagentRequestsAtom).get(environmentId) ??
347 get(localSubagentRequestsAtom(environmentId));
348 + const next = new Map<ThreadId, PendingSubagentRequest>();
349 + for (const [threadId, request] of rolledUp) {
350 + next.set(threadId, request === "user_only_input" ? "user_input" : request);
351 + }
352 if (sameRequests(previous, next)) return previous;
353 previous = next;
354 return next;
packages/contracts/src/orchestrationV2.ts
+2
@@ -2127,6 +2127,8 @@ export const OrchestrationV2PendingRuntimeRequestSummary = Schema.Struct({
2127 createdAt: Schema.DateTimeUtc,
2128 /** False for async questions the run keeps working past. Absent from older servers. */
2129 blocking: Schema.optional(Schema.Boolean),
2130 + /** Secret and link cards: only the user can answer them, never a coordinating agent. */
2131 + userOnly: Schema.optional(Schema.Boolean),
2132 });
2133 export type OrchestrationV2PendingRuntimeRequestSummary =
2134 typeof OrchestrationV2PendingRuntimeRequestSummary.Type;
packages/shared/src/agentAwareness.ts
+22 -7
@@ -27,10 +27,23 @@ export interface SubagentRequestAwareness {
27 readonly requestId: RuntimeRequestId;
28 /** The child's own update time, which moves whenever its request changes. */
29 readonly updatedAt: DateTime.Utc;
30 + /** A card only the user can answer, rather than an approval. */
31 + readonly waitsForInput?: boolean;
32 }
33
32 -/** Provider-native subagents ask on their parent; the coordinator answers child questions. */
33 -export function subagentAwaitsApproval(
34 +/**
35 + * Turn items that can start or end a subagent's user-only wait: its secret or link card,
36 + * or a user message that moves past a link card. Filters that drop subagent transcript
37 + * updates must keep these, or the parent's "Input needed" never appears or never clears.
38 + */
39 +export const turnItemCanChangeUserWait = (item: { readonly type: string }) =>
40 + item.type === "secret_request" || item.type === "link_request" || item.type === "user_message";
41 +
42 +/**
43 + * Provider-native subagents ask on their parent. The coordinator answers child questions,
44 + * but not a card only the user can answer, such as a secret.
45 + */
46 +export function subagentAwaitsUser(
47 thread: Pick<
48 OrchestrationV2ThreadShell,
49 "activityRunStatus" | "creationSource" | "lineage" | "pendingRuntimeRequest"
@@ -40,7 +53,7 @@ export function subagentAwaitsApproval(
53 return (
54 kind !== undefined &&
55 kind !== "auth_refresh" &&
43 - kind !== "user_input" &&
56 + (kind !== "user_input" || thread.pendingRuntimeRequest?.userOnly === true) &&
57 thread.lineage.relationshipToParent === "subagent" &&
58 !isProviderNativeSubagentThread(thread) &&
59 // The activity run stays set when a follow-up is queued behind a blocked run.
@@ -86,7 +99,7 @@ export interface ProjectThreadAwarenessV2Input {
99 | "title"
100 | "updatedAt"
101 >;
89 - /** The approval a live subagent below this thread is waiting on. */
102 + /** What a live subagent below this thread is waiting on the user for. */
103 readonly pendingSubagentRequest?: SubagentRequestAwareness | null;
104 }
105
@@ -96,7 +109,7 @@ export function projectThreadAwarenessV2(
109 const { environmentId, project, thread } = input;
110 if (!isListedThreadLineage(thread.lineage)) return null;
111 const subagentRequest = input.pendingSubagentRequest ?? null;
99 - const phase = resolveThreadAwarenessPhaseV2(thread, subagentRequest !== null);
112 + const phase = resolveThreadAwarenessPhaseV2(thread, subagentRequest);
113 if (phase === null) {
114 return null;
115 }
@@ -140,7 +153,7 @@ export function projectThreadAwarenessV2(
153
154 function resolveThreadAwarenessPhaseV2(
155 thread: ProjectThreadAwarenessV2Input["thread"],
143 - childAwaitsApproval: boolean,
156 + subagentRequest: SubagentRequestAwareness | null,
157 ): AgentAwarenessPhase | null {
158 if (thread.pendingRuntimeRequest?.kind === "user_input") return "waiting_for_input";
159 if (
@@ -151,7 +164,9 @@ function resolveThreadAwarenessPhaseV2(
164 }
165 // The parent can finish its own turn while a delegated child keeps working,
166 // so a child's request outranks the parent's run status.
154 - if (childAwaitsApproval) return "waiting_for_approval";
167 + if (subagentRequest !== null) {
168 + return subagentRequest.waitsForInput === true ? "waiting_for_input" : "waiting_for_approval";
169 + }
170 switch (thread.activityRunStatus ?? thread.status) {
171 case "preparing":
172 case "starting":