@@ -658,8 +658,6 @@ it.effect("memory projection keeps restart-cancelled work through a stale run.up
658658 restartCancelledWorkSurvivesStaleRunUpdate . pipe ( Effect . provide ( ProjectionStore . layerMemory ) ) ,
659659) ;
660660
661- // Clients read a failed thread's updatedAt as its failure edge, so background
662- // writes must keep the orchestrator's timestamp in both stores.
663661const backgroundThreadUpdatesKeepTimestamp = Effect . gen ( function * ( ) {
664662 const store = yield * ProjectionStore . ProjectionStoreV2 ;
665663 const createdAt = DateTime . makeUnsafe ( "2026-10-06T14:00:00.000Z" ) ;
@@ -694,24 +692,80 @@ const backgroundThreadUpdatesKeepTimestamp = Effect.gen(function* () {
694692 occurredAt : createdAt ,
695693 payload : thread ,
696694 } ) ;
695+ const readActivity = Effect . gen ( function * ( ) {
696+ const projection = yield * store . getThreadProjection ( threadId ) ;
697+ const thread = yield * store . getThread ( threadId ) ;
698+ const shell = yield * store . getThreadShell ( threadId ) ;
699+ const listed = ( yield * store . getShellSnapshot ( ) ) . threads . find ( ( entry ) => entry . id === threadId ) ;
700+ assert . deepEqual ( projection . thread . updatedAt , createdAt ) ;
701+ assert . deepEqual ( thread . updatedAt , createdAt ) ;
702+ assert . deepEqual ( shell ?. updatedAt , createdAt ) ;
703+ assert . deepEqual ( listed ?. updatedAt , createdAt ) ;
704+ return projection ;
705+ } ) ;
706+ const link = {
707+ host : "github.com" ,
708+ repository : "owner/repository" ,
709+ number : 42 ,
710+ url : "https://github.com/owner/repository/pull/42" ,
711+ source : "manual" as const ,
712+ linkedAt : DateTime . formatIso ( createdAt ) ,
713+ snapshot : null ,
714+ stack : null ,
715+ } ;
697716 yield * store . apply ( {
698717 id : EventId . make ( "event:background-updates:pull-request-synced" ) ,
699718 type : "thread.pull-request-synced" ,
700719 threadId,
701720 occurredAt : DateTime . add ( createdAt , { minutes : 45 } ) ,
702- payload : thread ,
721+ payload : { ...thread , pullRequests : [ link ] } ,
722+ } ) ;
723+ const synced = yield * readActivity ;
724+ assert . deepEqual ( synced . updatedAt , createdAt ) ;
725+ assert . equal ( synced . thread . pullRequests ?. [ 0 ] ?. number , 42 ) ;
726+
727+ const snapshot = {
728+ state : "open" as const ,
729+ title : "Ship it" ,
730+ headBranch : "feature" ,
731+ baseBranch : "main" ,
732+ isDraft : false ,
733+ updatedAt : DateTime . formatIso ( DateTime . add ( createdAt , { minutes : 46 } ) ) ,
734+ syncedAt : DateTime . formatIso ( DateTime . add ( createdAt , { minutes : 47 } ) ) ,
735+ closedAt : null ,
736+ mergedAt : null ,
737+ } ;
738+ yield * store . apply ( {
739+ id : EventId . make ( "event:background-updates:pull-request-link-updated" ) ,
740+ type : "thread.pull-request-link-updated" ,
741+ threadId,
742+ occurredAt : DateTime . add ( createdAt , { minutes : 48 } ) ,
743+ payload : { ...link , snapshot } ,
703744 } ) ;
745+ const refreshed = yield * readActivity ;
746+ assert . deepEqual ( refreshed . updatedAt , createdAt ) ;
747+ assert . deepEqual ( refreshed . thread . pullRequests ?. [ 0 ] ?. snapshot , snapshot ) ;
748+
704749 yield * store . apply ( {
705750 id : EventId . make ( "event:background-updates:active-reordered" ) ,
706751 type : "thread.active-reordered" ,
707752 threadId,
708753 occurredAt : DateTime . add ( createdAt , { minutes : 50 } ) ,
709- payload : { ...thread , activeOrderKey : "a" } ,
754+ payload : { ...refreshed . thread , activeOrderKey : "a" } ,
755+ } ) ;
756+ const reordered = yield * readActivity ;
757+ assert . deepEqual ( reordered . updatedAt , createdAt ) ;
758+ assert . equal ( reordered . thread . activeOrderKey , "a" ) ;
759+
760+ // An already-unpinned thread keeps its activity time even when replay's envelope advances.
761+ yield * store . apply ( {
762+ id : EventId . make ( "event:background-updates:already-unpinned" ) ,
763+ type : "thread.unpinned" ,
764+ threadId,
765+ occurredAt : DateTime . add ( createdAt , { minutes : 55 } ) ,
766+ payload : { ...reordered . thread , pinnedAt : null , pinOrderKey : null } ,
710767 } ) ;
711- const projection = yield * store . getThreadProjection ( threadId ) ;
712- assert . deepEqual ( projection . thread . updatedAt , createdAt ) ;
713- assert . deepEqual ( projection . updatedAt , createdAt ) ;
714- assert . deepEqual ( ( yield * store . getThreadShell ( threadId ) ) ?. updatedAt , createdAt ) ;
768+ yield * readActivity ;
715769} ) ;
716770
717771it . effect ( "memory projection keeps background thread updates out of updatedAt" , ( ) =>
0 commit comments