@@ -5688,6 +5688,102 @@ it.layer(layerSharedApplicationDataPlaneTest)("visited projection", (it) => {
56885688 assert . instanceOf ( invalidVisit , Orchestrator . OrchestratorDispatchError ) ;
56895689 } ) ,
56905690 ) ;
5691+
5692+ it . effect ( "marks unread before the user's last turn when an automatic compaction followed" , ( ) =>
5693+ Effect . gen ( function * ( ) {
5694+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
5695+ const threadId = ThreadId . make ( "runtime-layer-mark-unread-compacted" ) ;
5696+ const turnCompletedAt = DateTime . makeUnsafe ( "2026-07-24T10:00:00.000Z" ) ;
5697+ yield * orchestrator . dispatch ( {
5698+ type : "thread.create" ,
5699+ createdBy : "user" ,
5700+ creationSource : "web" ,
5701+ commandId : CommandId . make ( `${ threadId } :create` ) ,
5702+ threadId,
5703+ projectId : ProjectId . make ( `${ threadId } :project` ) ,
5704+ title : "Compacted thread" ,
5705+ modelSelection,
5706+ runtimeMode : "full-access" ,
5707+ interactionMode : "default" ,
5708+ branch : null ,
5709+ worktreePath : null ,
5710+ } ) ;
5711+ const runs = [
5712+ { text : "Continue" , at : turnCompletedAt } ,
5713+ {
5714+ text : "/compact" ,
5715+ idleCompaction : "beforeCacheExpires" as const ,
5716+ at : DateTime . makeUnsafe ( "2026-07-24T11:00:00.000Z" ) ,
5717+ } ,
5718+ ] ;
5719+ yield * ( yield * EventSink . EventSinkV2 ) . write ( {
5720+ commandId : CommandId . make ( `${ threadId } :seed` ) ,
5721+ events : runs . flatMap ( ( { at, ...message } , index ) => {
5722+ const runId = RunId . make ( `${ threadId } :run-${ index } ` ) ;
5723+ const messageId = MessageId . make ( `${ threadId } :message-${ index } ` ) ;
5724+ return [
5725+ {
5726+ id : EventId . make ( `${ messageId } :event` ) ,
5727+ type : "message.updated" as const ,
5728+ threadId,
5729+ occurredAt : at ,
5730+ payload : {
5731+ ...message ,
5732+ id : messageId ,
5733+ threadId,
5734+ runId,
5735+ nodeId : null ,
5736+ role : "user" as const ,
5737+ attachments : [ ] ,
5738+ streaming : false ,
5739+ createdBy : "user" as const ,
5740+ creationSource : "web" as const ,
5741+ createdAt : at ,
5742+ updatedAt : at ,
5743+ } ,
5744+ } ,
5745+ {
5746+ id : EventId . make ( `${ runId } :event` ) ,
5747+ type : "run.created" as const ,
5748+ threadId,
5749+ runId,
5750+ providerInstanceId : modelSelection . instanceId ,
5751+ occurredAt : at ,
5752+ payload : {
5753+ id : runId ,
5754+ threadId,
5755+ ordinal : index + 1 ,
5756+ providerInstanceId : modelSelection . instanceId ,
5757+ modelSelection,
5758+ providerThreadId : null ,
5759+ userMessageId : messageId ,
5760+ rootNodeId : null ,
5761+ activeAttemptId : null ,
5762+ status : "completed" as const ,
5763+ queuePosition : null ,
5764+ requestedAt : at ,
5765+ startedAt : at ,
5766+ completedAt : at ,
5767+ checkpointId : null ,
5768+ contextHandoffId : null ,
5769+ } ,
5770+ } ,
5771+ ] ;
5772+ } ) ,
5773+ } ) ;
5774+
5775+ yield * orchestrator . dispatch ( {
5776+ type : "thread.mark-unread" ,
5777+ commandId : CommandId . make ( `${ threadId } :mark-unread` ) ,
5778+ threadId,
5779+ } ) ;
5780+ const projection = yield * orchestrator . getThreadProjection ( threadId ) ;
5781+ assert . deepEqual (
5782+ projection . thread . lastVisitedAt ,
5783+ DateTime . subtract ( turnCompletedAt , { milliseconds : 1 } ) ,
5784+ ) ;
5785+ } ) ,
5786+ ) ;
56915787} ) ;
56925788
56935789it . layer ( Layer . fresh ( layerSharedApplicationDataPlaneTest ) ) ( "thread opens" , ( it ) => {
0 commit comments