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 @@ -219,12 +219,15 @@ export function threadWokeAt(
219219 ) {
220220 return latestRun . completedAt ;
221221 }
222- return (
223- ( shell . hasPendingUserInput ? shell . pendingUserInputAt : null ) ??
224- runtime ?. updatedAt ??
225- shell . snoozedAt ??
226- null
227- ) ;
222+ if (
223+ shell . hasPendingUserInput &&
224+ shell . pendingUserInputAt != null &&
225+ shell . snoozedAt != null &&
226+ Date . parse ( shell . pendingUserInputAt ) > Date . parse ( shell . snoozedAt )
227+ ) {
228+ return shell . pendingUserInputAt ;
229+ }
230+ return runtime ?. updatedAt ?? shell . snoozedAt ?? null ;
228231 }
229232 // No raised hand: woke iff the timer elapsed (still-snoozed → null).
230233 return wakeAtMs <= Date . parse ( options . now ) ? shell . snoozedUntil : null ;
Original file line number Diff line number Diff line change @@ -310,6 +310,26 @@ describe("threadWokeAt", () => {
310310 ) . toBe ( "2026-04-10T11:00:00.000Z" ) ;
311311 } ) ;
312312
313+ it . each ( [ "failure" , "subagent request" ] as const ) (
314+ "keeps an old question from masking a newer %s wake" ,
315+ ( wake ) => {
316+ const shell = {
317+ ...makeShell ( {
318+ snoozedUntil : FUTURE_WAKE ,
319+ pending : "user-input" ,
320+ pendingUserInputAt : SNOOZED_AT ,
321+ sessionStatus : wake === "failure" ? "error" : "running" ,
322+ } ) ,
323+ pendingSubagentRequest : wake === "subagent request" ? ( "user_input" as const ) : null ,
324+ } ;
325+ const lastVisitedAt = "2026-04-10T10:00:00.000Z" ;
326+ expect ( effectiveSnoozed ( shell , { now : NOW } ) ) . toBe ( false ) ;
327+ const wokeAt = threadWokeAt ( shell , { now : NOW } ) ;
328+ expect ( wokeAt ) . toBe ( "2026-04-10T11:00:00.000Z" ) ;
329+ expect ( Date . parse ( wokeAt ! ) ) . toBeGreaterThan ( Date . parse ( lastVisitedAt ) ) ;
330+ } ,
331+ ) ;
332+
313333 it ( "keeps the early wake authoritative after the scheduled time passes" , ( ) => {
314334 // Woke early at 10:30 via run-completed; the scheduled wake (PAST_WAKE
315335 // 10:00 relative to a later now) has ALSO passed. Reporting the
You can’t perform that action at this time.
0 commit comments