Skip to content

Commit 7d0f426

Browse files
t3dotggLovelyCodeMonkeyclaude
committed
fix(clients): a thread can't be snoozed while its subagent waits on you
Snoozing it would wake it again at once, because a subagent's request raises the parent's hand. Co-Authored-By: lovelycodemonkey <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 658a4a7 commit 7d0f426

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

‎apps/mobile/src/features/home/useThreadListActions.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ export function useThreadListActions(): {
308308
if (!canSnooze(thread, { now: new Date().toISOString() })) {
309309
Alert.alert(
310310
"Could not snooze thread",
311-
thread.hasPendingApprovals || thread.hasPendingUserInput
311+
thread.hasPendingApprovals ||
312+
thread.hasPendingUserInput ||
313+
thread.pendingSubagentRequest != null
312314
? "This thread is waiting on you. Respond to the pending request before snoozing it."
313315
: "This thread is still starting a turn. Try again once it's running.",
314316
);

‎apps/mobile/src/features/threads/threadListV2.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,17 @@ export function resolveThreadListV2SwipeActions(input: {
144144
export function resolveThreadListV2SnoozeGateExpiryMs(
145145
thread: Pick<
146146
EnvironmentThreadShell,
147-
"hasPendingApprovals" | "hasPendingUserInput" | "latestRun" | "latestUserMessageAt" | "runtime"
147+
| "hasPendingApprovals"
148+
| "hasPendingUserInput"
149+
| "pendingSubagentRequest"
150+
| "latestRun"
151+
| "latestUserMessageAt"
152+
| "runtime"
148153
>,
149154
options: { readonly now: string },
150155
): number | null {
151156
if (thread.hasPendingApprovals || thread.hasPendingUserInput) return null;
157+
if (thread.pendingSubagentRequest != null) return null;
152158
if (!hasQueuedTurnStart(thread, options)) return null;
153159
const messageAtMs = Date.parse(thread.latestUserMessageAt ?? "");
154160
if (Number.isNaN(messageAtMs)) return null;

‎packages/client-runtime/src/state/threadSettled.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ export function threadRaisedHandWhileSnoozed(shell: ThreadSnoozeShell): boolean
131131
}
132132

133133
/**
134-
* A thread may be snoozed unless the agent is blocked on the user: hiding a
135-
* pending approval or user-input request defeats the request, and a queued
136-
* turn start (a message no turn has adopted yet) is invisible pending work
137-
* the same way it is for settle. A running session IS snoozable — snooze
134+
* A thread may be snoozed unless the agent or one of its subagents is blocked
135+
* on the user: hiding a pending approval or user-input request defeats the
136+
* request, and a queued turn start (a message no turn has adopted yet) is
137+
* invisible pending work the same way it is for settle. A running session IS snoozable — snooze
138138
* only affects visibility, never the agent. Client-side twin of the server
139139
* invariants so the UI can reject before a round trip.
140140
*/
@@ -143,6 +143,7 @@ export function canSnooze(
143143
ThreadSnoozeShell,
144144
| "hasPendingApprovals"
145145
| "hasPendingUserInput"
146+
| "pendingSubagentRequest"
146147
| "latestUserMessageAt"
147148
| "latestTurn"
148149
| "latestRun"
@@ -152,6 +153,7 @@ export function canSnooze(
152153
options: { readonly now: string },
153154
): boolean {
154155
if (shell.hasPendingApprovals || shell.hasPendingUserInput) return false;
156+
if (shell.pendingSubagentRequest != null) return false;
155157
if (hasQueuedTurnStart(shell, options)) return false;
156158
return true;
157159
}

‎packages/client-runtime/src/state/threadSnoozed.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ describe("canSnooze", () => {
189189
{ now: NOW },
190190
),
191191
).toBe(false);
192+
expect(
193+
canSnooze(
194+
{ ...makeShell({}), latestUserMessageAt: null, pendingSubagentRequest: "approval" },
195+
{ now: NOW },
196+
),
197+
).toBe(false);
192198
});
193199

194200
it("refuses a queued turn start — same invisible-pending-work rule as settle", () => {

0 commit comments

Comments
 (0)