@@ -664,6 +664,124 @@ it.effect("memory projection keeps restart-cancelled work through a stale run.up
664664 restartCancelledWorkSurvivesStaleRunUpdate . pipe ( Effect . provide ( ProjectionStore . layerMemory ) ) ,
665665) ;
666666
667+ const backgroundThreadUpdatesKeepTimestamp = Effect . gen ( function * ( ) {
668+ const store = yield * ProjectionStore . ProjectionStoreV2 ;
669+ const createdAt = DateTime . makeUnsafe ( "2026-10-06T14:00:00.000Z" ) ;
670+ const threadId = ThreadId . make ( "thread:background-updates" ) ;
671+ const thread = {
672+ createdBy : "user" as const ,
673+ creationSource : "web" as const ,
674+ id : threadId ,
675+ projectId : ProjectId . make ( "project:background-updates" ) ,
676+ title : "Background updates" ,
677+ providerInstanceId,
678+ modelSelection,
679+ runtimeMode : "full-access" as const ,
680+ interactionMode : "default" as const ,
681+ branch : null ,
682+ worktreePath : null ,
683+ activeProviderThreadId : null ,
684+ lineage : { parentThreadId : null , relationshipToParent : null , rootThreadId : threadId } ,
685+ forkedFrom : null ,
686+ createdAt,
687+ updatedAt : createdAt ,
688+ archivedAt : null ,
689+ settledOverride : null ,
690+ settledAt : null ,
691+ lastVisitedAt : null ,
692+ deletedAt : null ,
693+ } ;
694+ yield * store . apply ( {
695+ id : EventId . make ( "event:background-updates:created" ) ,
696+ type : "thread.created" ,
697+ threadId,
698+ occurredAt : createdAt ,
699+ payload : thread ,
700+ } ) ;
701+ const readActivity = Effect . gen ( function * ( ) {
702+ const projection = yield * store . getThreadProjection ( threadId ) ;
703+ const thread = yield * store . getThread ( threadId ) ;
704+ const shell = yield * store . getThreadShell ( threadId ) ;
705+ const listed = ( yield * store . getShellSnapshot ( ) ) . threads . find ( ( entry ) => entry . id === threadId ) ;
706+ assert . deepEqual ( projection . thread . updatedAt , createdAt ) ;
707+ assert . deepEqual ( thread . updatedAt , createdAt ) ;
708+ assert . deepEqual ( shell ?. updatedAt , createdAt ) ;
709+ assert . deepEqual ( listed ?. updatedAt , createdAt ) ;
710+ return projection ;
711+ } ) ;
712+ const link = {
713+ host : "github.com" ,
714+ repository : "owner/repository" ,
715+ number : 42 ,
716+ url : "https://github.com/owner/repository/pull/42" ,
717+ source : "manual" as const ,
718+ linkedAt : DateTime . formatIso ( createdAt ) ,
719+ snapshot : null ,
720+ stack : null ,
721+ } ;
722+ yield * store . apply ( {
723+ id : EventId . make ( "event:background-updates:pull-request-synced" ) ,
724+ type : "thread.pull-request-synced" ,
725+ threadId,
726+ occurredAt : DateTime . add ( createdAt , { minutes : 45 } ) ,
727+ payload : { ...thread , pullRequests : [ link ] } ,
728+ } ) ;
729+ const synced = yield * readActivity ;
730+ assert . deepEqual ( synced . updatedAt , createdAt ) ;
731+ assert . equal ( synced . thread . pullRequests ?. [ 0 ] ?. number , 42 ) ;
732+
733+ const snapshot = {
734+ state : "open" as const ,
735+ title : "Ship it" ,
736+ headBranch : "feature" ,
737+ baseBranch : "main" ,
738+ isDraft : false ,
739+ updatedAt : DateTime . formatIso ( DateTime . add ( createdAt , { minutes : 46 } ) ) ,
740+ syncedAt : DateTime . formatIso ( DateTime . add ( createdAt , { minutes : 47 } ) ) ,
741+ closedAt : null ,
742+ mergedAt : null ,
743+ } ;
744+ yield * store . apply ( {
745+ id : EventId . make ( "event:background-updates:pull-request-link-updated" ) ,
746+ type : "thread.pull-request-link-updated" ,
747+ threadId,
748+ occurredAt : DateTime . add ( createdAt , { minutes : 48 } ) ,
749+ payload : { ...link , snapshot } ,
750+ } ) ;
751+ const refreshed = yield * readActivity ;
752+ assert . deepEqual ( refreshed . updatedAt , createdAt ) ;
753+ assert . deepEqual ( refreshed . thread . pullRequests ?. [ 0 ] ?. snapshot , snapshot ) ;
754+
755+ yield * store . apply ( {
756+ id : EventId . make ( "event:background-updates:active-reordered" ) ,
757+ type : "thread.active-reordered" ,
758+ threadId,
759+ occurredAt : DateTime . add ( createdAt , { minutes : 50 } ) ,
760+ payload : { ...refreshed . thread , activeOrderKey : "a" } ,
761+ } ) ;
762+ const reordered = yield * readActivity ;
763+ assert . deepEqual ( reordered . updatedAt , createdAt ) ;
764+ assert . equal ( reordered . thread . activeOrderKey , "a" ) ;
765+
766+ // An already-unpinned thread keeps its activity time even when replay's envelope advances.
767+ yield * store . apply ( {
768+ id : EventId . make ( "event:background-updates:already-unpinned" ) ,
769+ type : "thread.unpinned" ,
770+ threadId,
771+ occurredAt : DateTime . add ( createdAt , { minutes : 55 } ) ,
772+ payload : { ...reordered . thread , pinnedAt : null , pinOrderKey : null } ,
773+ } ) ;
774+ yield * readActivity ;
775+ } ) ;
776+
777+ it . effect ( "memory projection keeps background thread updates out of updatedAt" , ( ) =>
778+ backgroundThreadUpdatesKeepTimestamp . pipe ( Effect . provide ( ProjectionStore . layerMemory ) ) ,
779+ ) ;
780+
781+ it . effect ( "SQL projection keeps background thread updates out of updatedAt" , ( ) =>
782+ backgroundThreadUpdatesKeepTimestamp . pipe ( Effect . provide ( layerTest ) ) ,
783+ ) ;
784+
667785it . effect ( "memory recovery selection ignores unfinished items from rolled-back runs" , ( ) =>
668786 Effect . gen ( function * ( ) {
669787 const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
0 commit comments