@@ -312,6 +312,70 @@ it.effect("memory projection keeps restart-cancelled work through a stale run.up
312312 restartCancelledWorkSurvivesStaleRunUpdate . pipe ( Effect . provide ( ProjectionStore . layerMemory ) ) ,
313313) ;
314314
315+ // Clients read a failed thread's updatedAt as its failure edge, so background
316+ // writes must keep the orchestrator's timestamp in both stores.
317+ const backgroundThreadUpdatesKeepTimestamp = Effect . gen ( function * ( ) {
318+ const store = yield * ProjectionStore . ProjectionStoreV2 ;
319+ const createdAt = DateTime . makeUnsafe ( "2026-10-06T14:00:00.000Z" ) ;
320+ const threadId = ThreadId . make ( "thread:background-updates" ) ;
321+ const thread = {
322+ createdBy : "user" as const ,
323+ creationSource : "web" as const ,
324+ id : threadId ,
325+ projectId : ProjectId . make ( "project:background-updates" ) ,
326+ title : "Background updates" ,
327+ providerInstanceId,
328+ modelSelection,
329+ runtimeMode : "full-access" as const ,
330+ interactionMode : "default" as const ,
331+ branch : null ,
332+ worktreePath : null ,
333+ activeProviderThreadId : null ,
334+ lineage : { parentThreadId : null , relationshipToParent : null , rootThreadId : threadId } ,
335+ forkedFrom : null ,
336+ createdAt,
337+ updatedAt : createdAt ,
338+ archivedAt : null ,
339+ settledOverride : null ,
340+ settledAt : null ,
341+ lastVisitedAt : null ,
342+ deletedAt : null ,
343+ } ;
344+ yield * store . apply ( {
345+ id : EventId . make ( "event:background-updates:created" ) ,
346+ type : "thread.created" ,
347+ threadId,
348+ occurredAt : createdAt ,
349+ payload : thread ,
350+ } ) ;
351+ yield * store . apply ( {
352+ id : EventId . make ( "event:background-updates:pull-request-synced" ) ,
353+ type : "thread.pull-request-synced" ,
354+ threadId,
355+ occurredAt : DateTime . add ( createdAt , { minutes : 45 } ) ,
356+ payload : thread ,
357+ } ) ;
358+ yield * store . apply ( {
359+ id : EventId . make ( "event:background-updates:active-reordered" ) ,
360+ type : "thread.active-reordered" ,
361+ threadId,
362+ occurredAt : DateTime . add ( createdAt , { minutes : 50 } ) ,
363+ payload : { ...thread , activeOrderKey : "a" } ,
364+ } ) ;
365+ const projection = yield * store . getThreadProjection ( threadId ) ;
366+ assert . deepEqual ( projection . thread . updatedAt , createdAt ) ;
367+ assert . deepEqual ( projection . updatedAt , createdAt ) ;
368+ assert . deepEqual ( ( yield * store . getThreadShell ( threadId ) ) ?. updatedAt , createdAt ) ;
369+ } ) ;
370+
371+ it . effect ( "memory projection keeps background thread updates out of updatedAt" , ( ) =>
372+ backgroundThreadUpdatesKeepTimestamp . pipe ( Effect . provide ( ProjectionStore . layerMemory ) ) ,
373+ ) ;
374+
375+ it . effect ( "SQL projection keeps background thread updates out of updatedAt" , ( ) =>
376+ backgroundThreadUpdatesKeepTimestamp . pipe ( Effect . provide ( layerTest ) ) ,
377+ ) ;
378+
315379it . effect ( "memory recovery selection ignores unfinished items from rolled-back runs" , ( ) =>
316380 Effect . gen ( function * ( ) {
317381 const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
0 commit comments