File tree Expand file tree Collapse file tree
packages/client-runtime/src/state Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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" } ) , {
You can’t perform that action at this time.
0 commit comments