Skip to content

Commit ad35d95

Browse files
fix(threads): date an approval wake after the snooze, not at an earlier failure
1 parent cda59f2 commit ad35d95

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,17 @@ export function threadWokeAt(
170170
) {
171171
return latestRun.completedAt;
172172
}
173+
// A failure from before the snooze did not cause this wake (an approval
174+
// or user input did), so its time would read as a wake the user already saw.
175+
const failedAt = failureEdgeAt(shell);
176+
if (
177+
failedAt != null &&
178+
(shell.snoozedAt == null || Date.parse(failedAt) > Date.parse(shell.snoozedAt))
179+
) {
180+
return failedAt;
181+
}
173182
const runtime = shell.runtime ?? shell.session ?? null;
174-
return failureEdgeAt(shell) ?? runtime?.updatedAt ?? shell.snoozedAt ?? null;
183+
return runtime?.updatedAt ?? shell.snoozedAt ?? null;
175184
}
176185
return wakeAtMs <= Date.parse(options.now) ? shell.snoozedUntil : null;
177186
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ describe("effectiveSnoozed", () => {
140140
expect(threadWokeAt(shell, { now: NOW })).toBe("2026-04-10T10:00:00.000Z");
141141
});
142142

143+
it("dates an approval wake after the snooze, not at an earlier failure", () => {
144+
const shell: ThreadSnoozeShell = {
145+
...makeShell({ snoozedUntil: FUTURE_WAKE, pending: "approval" }),
146+
runtime: { status: "failed", updatedAt: "2026-04-10T11:00:00.000Z" },
147+
latestRun: { status: "failed", completedAt: "2026-04-08T13:00:00.000Z" },
148+
};
149+
expect(effectiveSnoozed(shell, { now: NOW })).toBe(false);
150+
expect(threadWokeAt(shell, { now: NOW })).toBe("2026-04-10T11:00:00.000Z");
151+
});
152+
143153
it("stays snoozed while the session keeps working — snooze never pauses the agent", () => {
144154
expect(
145155
effectiveSnoozed(makeShell({ snoozedUntil: FUTURE_WAKE, sessionStatus: "running" }), {

0 commit comments

Comments
 (0)