@@ -482,6 +482,113 @@ describe("AgentAwarenessRelay", () => {
482482 } ) ,
483483 ) ;
484484
485+ it . effect ( "publishes a cleared thread's tombstone once while it stays cleared" , ( ) =>
486+ Effect . gen ( function * ( ) {
487+ const { relay, currentShell, publications } = yield * makeTestRelay ( ) ;
488+ yield * relay . publishThread ( THREAD_ID ) ;
489+ const completed = shell ( { status : "completed" } ) ;
490+ yield * Ref . set ( currentShell , completed ) ;
491+ yield * relay . publishThread ( THREAD_ID ) ;
492+ yield * TestClock . adjust ( "5 seconds" ) ;
493+ yield * relay . drain ;
494+ yield * Ref . set ( currentShell , {
495+ ...completed ,
496+ settledOverride : "settled" ,
497+ settledAt : yield * DateTime . now ,
498+ lastVisitedAt : null ,
499+ } ) ;
500+ yield * relay . publishThread ( THREAD_ID ) ;
501+ yield * TestClock . adjust ( "5 seconds" ) ;
502+ yield * relay . drain ;
503+ assert . deepEqual (
504+ publications . map ( ( publication ) => publication . state ?. phase ?? null ) ,
505+ [ "running" , "completed" , null ] ,
506+ ) ;
507+
508+ for ( let i = 0 ; i < 3 ; i ++ ) {
509+ yield * relay . publishThread ( THREAD_ID ) ;
510+ yield * TestClock . adjust ( "5 seconds" ) ;
511+ yield * relay . drain ;
512+ }
513+ assert . deepEqual (
514+ publications . map ( ( publication ) => publication . state ?. phase ?? null ) ,
515+ [ "running" , "completed" , null ] ,
516+ ) ;
517+ } ) ,
518+ ) ;
519+
520+ it . effect ( "does not alert an old completion after publishing its thread's tombstone" , ( ) =>
521+ Effect . gen ( function * ( ) {
522+ const oldCompleted = shell ( {
523+ status : "completed" ,
524+ latestRunCompletedAt : DateTime . makeUnsafe ( "2026-09-04T11:59:00.000Z" ) ,
525+ } ) ;
526+ yield * TestClock . setTime ( DateTime . toEpochMillis ( DateTime . makeUnsafe ( NOW ) ) ) ;
527+ const { relay, currentShell, publications } = yield * makeTestRelay ( ) ;
528+ yield * Ref . set ( currentShell , {
529+ ...oldCompleted ,
530+ settledOverride : "settled" ,
531+ settledAt : DateTime . makeUnsafe ( NOW ) ,
532+ lastVisitedAt : null ,
533+ } ) ;
534+ yield * relay . publishThread ( THREAD_ID ) ;
535+ yield * TestClock . adjust ( "5 seconds" ) ;
536+ yield * relay . drain ;
537+ assert . deepEqual (
538+ publications . map ( ( publication ) => publication . state ) ,
539+ [ null ] ,
540+ ) ;
541+
542+ yield * Ref . set ( currentShell , oldCompleted ) ;
543+ yield * relay . publishThread ( THREAD_ID ) ;
544+ yield * TestClock . adjust ( "5 seconds" ) ;
545+ yield * relay . drain ;
546+ assert . deepEqual (
547+ publications . map ( ( publication ) => publication . state ) ,
548+ [ null ] ,
549+ ) ;
550+ } ) ,
551+ ) ;
552+
553+ it . effect ( "alerts a completion settled during its hold after an earlier tombstone" , ( ) =>
554+ Effect . gen ( function * ( ) {
555+ yield * TestClock . setTime ( DateTime . toEpochMillis ( DateTime . makeUnsafe ( NOW ) ) ) ;
556+ const { relay, currentShell, publications } = yield * makeTestRelay ( ) ;
557+ const settledAt = DateTime . makeUnsafe ( NOW ) ;
558+ yield * Ref . set ( currentShell , {
559+ ...shell ( { status : "completed" } ) ,
560+ settledOverride : "settled" ,
561+ settledAt,
562+ lastVisitedAt : null ,
563+ } ) ;
564+ yield * relay . publishThread ( THREAD_ID ) ;
565+ yield * TestClock . adjust ( "5 seconds" ) ;
566+ yield * relay . drain ;
567+
568+ const completed = shell ( {
569+ status : "completed" ,
570+ latestRunCompletedAt : DateTime . makeUnsafe ( "2026-09-04T12:00:06.000Z" ) ,
571+ } ) ;
572+ yield * Ref . set ( currentShell , completed ) ;
573+ yield * relay . publishThread ( THREAD_ID ) ;
574+ yield * Ref . set ( currentShell , {
575+ ...completed ,
576+ settledOverride : "settled" ,
577+ settledAt,
578+ lastVisitedAt : null ,
579+ } ) ;
580+ yield * relay . publishThread ( THREAD_ID ) ;
581+ yield * TestClock . adjust ( "5 seconds" ) ;
582+ yield * relay . drain ;
583+ yield * TestClock . adjust ( "5 seconds" ) ;
584+ yield * relay . drain ;
585+ assert . deepEqual (
586+ publications . map ( ( publication ) => publication . state ?. phase ?? null ) ,
587+ [ null , "completed" , null ] ,
588+ ) ;
589+ } ) ,
590+ ) ;
591+
485592 it . effect ( "drops a held completion when a queued continuation hides the thread" , ( ) =>
486593 Effect . gen ( function * ( ) {
487594 const { relay, currentShell, publications } = yield * makeTestRelay ( ) ;
0 commit comments