Skip to content

Commit 90f8477

Browse files
committed
fix(threads): keep snoozed threads hidden when work finishes
Snooze is time-based. Completing a turn no longer raises a thread's hand, so a working thread stays in the snoozed shelf until the chosen wake time, an explicit unsnooze, or a real blocking request.
1 parent d23b181 commit 90f8477

4 files changed

Lines changed: 56 additions & 42 deletions

File tree

‎apps/server/src/orchestration/decider.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,8 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
12001200
// cleared here: snooze never pauses the agent, so its session starting
12011201
// or erroring is not the user re-engaging. Blocked/failed work still
12021202
// surfaces immediately — effectiveSnoozed refuses to classify a thread
1203-
// with a raised hand (approval / input / failure / fresh completion)
1204-
// as snoozed, without spending the return ticket.
1203+
// with a raised hand (approval / input / fresh failure) as snoozed,
1204+
// without spending the return ticket. Completion is not a raised hand.
12051205
const isSessionActivity =
12061206
command.session.status === "starting" || command.session.status === "running";
12071207
// Real activity resets ANY override (settled wakes, active unpins).

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,11 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
804804
// A woken thread reappears at its original position (the sort is
805805
// deliberately static), so the pill has to carry the weight. Snoozing is
806806
// an explicit act, so the pill clears only when the user re-engages:
807-
// reading a completion-triggered wake, clicking the pill, sending a
808-
// message, settling, archiving, or a change request state that settles the
809-
// thread. Timer wakes survive a mere visit. An unparseable visit timestamp
810-
// counts as never-visited, so corrupt local data cannot eat the wake signal.
807+
// visiting after a blocking early wake (approval / user-input / fresh
808+
// error), clicking the pill, sending a message, settling, archiving, or a
809+
// change request state that settles the thread. Timer wakes survive a mere
810+
// visit. An unparseable visit timestamp counts as never-visited, so
811+
// corrupt local data cannot eat the wake signal.
811812
const lastVisitedDate = lastVisitedAt === undefined ? null : parseTimestampDate(lastVisitedAt);
812813
const wokeAtDate = props.wokeAt === null ? null : parseTimestampDate(props.wokeAt);
813814
const isWoke =

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

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ export type ThreadSnoozeShell = Pick<
116116
>;
117117

118118
/**
119-
* A snoozed thread "raises its hand" when something happens that outranks
120-
* the user's snooze: the agent is blocked on them (approval / user input),
121-
* the session failed, or a run completed after the snooze was set — the
122-
* v1 taste of event-based snooze ("something happened" wakes early).
123-
* Raising a hand never clears the server-side snooze fields; it only stops
124-
* the thread from CLASSIFYING as snoozed, exactly like blocked work and
125-
* effectiveSettled.
119+
* A snoozed thread "raises its hand" when something user-blocking outranks
120+
* the chosen wake time: the agent is waiting on them (approval / user
121+
* input), or the session failed after the snooze was set. Snooze is an
122+
* attention overlay — work finishing updates execution state only and does
123+
* not surface the thread. Raising a hand never clears the server-side
124+
* snooze fields; it only stops the thread from CLASSIFYING as snoozed,
125+
* exactly like blocked work and effectiveSettled.
126126
*/
127127
export function threadRaisedHandWhileSnoozed(shell: ThreadSnoozeShell): boolean {
128128
if (shell.hasPendingApprovals || shell.hasPendingUserInput) return true;
@@ -136,14 +136,6 @@ export function threadRaisedHandWhileSnoozed(shell: ThreadSnoozeShell): boolean
136136
) {
137137
return true;
138138
}
139-
if (
140-
shell.snoozedAt != null &&
141-
shell.latestTurn?.state === "completed" &&
142-
shell.latestTurn.completedAt != null &&
143-
Date.parse(shell.latestTurn.completedAt) > Date.parse(shell.snoozedAt)
144-
) {
145-
return true;
146-
}
147139
return false;
148140
}
149141

@@ -209,14 +201,6 @@ export function threadWokeAt(
209201
// indicator the user already cleared by visiting (snoozedUntil is newer
210202
// than that visit's lastVisitedAt).
211203
if (threadRaisedHandWhileSnoozed(shell)) {
212-
if (
213-
shell.snoozedAt != null &&
214-
shell.latestTurn?.state === "completed" &&
215-
shell.latestTurn.completedAt != null &&
216-
Date.parse(shell.latestTurn.completedAt) > Date.parse(shell.snoozedAt)
217-
) {
218-
return shell.latestTurn.completedAt;
219-
}
220204
return shell.session?.updatedAt ?? shell.snoozedAt ?? null;
221205
}
222206
// No raised hand: woke iff the timer elapsed (still-snoozed → null).

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

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ describe("effectiveSnoozed", () => {
122122
).toBe(true);
123123
});
124124

125-
it("wakes early when a run completes after the snooze was set", () => {
125+
it("stays snoozed when a run completes after the snooze was set", () => {
126126
expect(
127127
effectiveSnoozed(
128128
makeShell({ snoozedUntil: FUTURE_WAKE, turnCompletedAt: "2026-04-10T10:30:00.000Z" }),
129129
{ now: NOW },
130130
),
131-
).toBe(false);
131+
).toBe(true);
132132
});
133133

134134
it("ignores runs that completed before the snooze — the user saw that result", () => {
@@ -139,6 +139,19 @@ describe("effectiveSnoozed", () => {
139139
),
140140
).toBe(true);
141141
});
142+
143+
it("still wakes on a pending approval after work has finished", () => {
144+
expect(
145+
effectiveSnoozed(
146+
makeShell({
147+
snoozedUntil: FUTURE_WAKE,
148+
pending: "approval",
149+
turnCompletedAt: "2026-04-10T10:30:00.000Z",
150+
}),
151+
{ now: NOW },
152+
),
153+
).toBe(false);
154+
});
142155
});
143156

144157
describe("threadRaisedHandWhileSnoozed", () => {
@@ -159,6 +172,14 @@ describe("threadRaisedHandWhileSnoozed", () => {
159172
),
160173
).toBe(true);
161174
});
175+
176+
it("does not treat turn completion as a raised hand", () => {
177+
expect(
178+
threadRaisedHandWhileSnoozed(
179+
makeShell({ snoozedUntil: FUTURE_WAKE, turnCompletedAt: "2026-04-10T10:30:00.000Z" }),
180+
),
181+
).toBe(false);
182+
});
162183
});
163184

164185
describe("canSnooze", () => {
@@ -212,13 +233,22 @@ describe("threadWokeAt", () => {
212233
expect(threadWokeAt(makeShell({ snoozedUntil: PAST_WAKE }), { now: NOW })).toBe(PAST_WAKE);
213234
});
214235

215-
it("reports the completion time for an early run-completed wake", () => {
236+
it("does not treat a later completion as an early wake", () => {
216237
expect(
217238
threadWokeAt(
218239
makeShell({ snoozedUntil: FUTURE_WAKE, turnCompletedAt: "2026-04-10T10:30:00.000Z" }),
219240
{ now: NOW },
220241
),
221-
).toBe("2026-04-10T10:30:00.000Z");
242+
).toBe(null);
243+
});
244+
245+
it("reports the scheduled wake time even if a turn completed after the snooze", () => {
246+
expect(
247+
threadWokeAt(
248+
makeShell({ snoozedUntil: PAST_WAKE, turnCompletedAt: "2026-04-10T10:30:00.000Z" }),
249+
{ now: NOW },
250+
),
251+
).toBe(PAST_WAKE);
222252
});
223253

224254
it("falls back to session activity for blocked/failed early wakes", () => {
@@ -230,16 +260,15 @@ describe("threadWokeAt", () => {
230260
});
231261

232262
it("keeps the early wake authoritative after the scheduled time passes", () => {
233-
// Woke early at 10:30 via run-completed; the scheduled wake (PAST_WAKE
234-
// 10:00 relative to a later now) has ALSO passed. Reporting the
235-
// scheduled time would resurface a Woke pill the user already cleared
236-
// by visiting between the early wake and now.
263+
// Woke early at 11:00 via a fresh session error; the scheduled wake
264+
// (PAST_WAKE 10:00 relative to a later now) has ALSO passed. Reporting
265+
// the scheduled time would resurface a Woke pill the user already
266+
// cleared by visiting between the early wake and now.
237267
expect(
238-
threadWokeAt(
239-
makeShell({ snoozedUntil: PAST_WAKE, turnCompletedAt: "2026-04-10T09:30:00.000Z" }),
240-
{ now: NOW },
241-
),
242-
).toBe("2026-04-10T09:30:00.000Z");
268+
threadWokeAt(makeShell({ snoozedUntil: PAST_WAKE, sessionStatus: "error" }), {
269+
now: NOW,
270+
}),
271+
).toBe("2026-04-10T11:00:00.000Z");
243272
});
244273
});
245274

0 commit comments

Comments
 (0)