@@ -2019,6 +2019,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
20192019 loadingIndex : 0 ,
20202020 } ) ;
20212021 const snapshotReloadRequired = yield * Ref . make ( false ) ;
2022+ // Replayed history for the active session must not read as post-turn output.
2023+ const snapshotReloading = yield * Ref . make ( false ) ;
20222024 const resetConversationCaches = Effect . all (
20232025 [
20242026 Ref . set ( promptInstructionStates , new Map ( ) ) ,
@@ -4757,7 +4759,11 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
47574759 } ;
47584760 }
47594761 const rootSessionId = yield * Ref . get ( activeSessionId ) ;
4760- if ( rootSessionId === null || notification . sessionId !== rootSessionId ) {
4762+ if (
4763+ rootSessionId === null ||
4764+ notification . sessionId !== rootSessionId ||
4765+ ( yield * Ref . get ( snapshotReloading ) )
4766+ ) {
47614767 return {
47624768 buffered : false ,
47634769 offerContinuation : false ,
@@ -5076,6 +5082,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
50765082 if (
50775083 followsAgentWorkState &&
50785084 ! ( yield * Ref . get ( stoppedRunQuarantine ) ) &&
5085+ ! ( yield * Ref . get ( snapshotReloading ) ) &&
50795086 notification . sessionId === ( yield * Ref . get ( activeSessionId ) )
50805087 ) {
50815088 if ( update . sessionUpdate === "state_update" ) agentWork = update ;
@@ -9330,16 +9337,14 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
93309337 loadingMessageId : null ,
93319338 loadingIndex : 0 ,
93329339 } ) ;
9333- // Replayed history for the active session would read as post-turn output.
9334- yield * Ref . set ( activeSessionId , null ) ;
93359340 const mcpContext = yield * readMcpContext (
93369341 snapshotInput . providerThread . appThreadId ,
93379342 ) ;
93389343 prepareTerminalEnvironment ( mcpContext , sessionId ) ;
9339- const activated = yield * runtime . loadSession (
9340- sessionId ,
9341- acpMcpActivation ( mcpContext ) ,
9342- ) ;
9344+ yield * Ref . set ( snapshotReloading , reload ) ;
9345+ const activated = yield * runtime
9346+ . loadSession ( sessionId , acpMcpActivation ( mcpContext ) )
9347+ . pipe ( Effect . ensuring ( Ref . set ( snapshotReloading , false ) ) ) ;
93439348 yield * Ref . set ( snapshotReloadRequired , false ) ;
93449349 rememberTerminalEnvironment (
93459350 activated . sessionId ,
0 commit comments