@@ -1478,6 +1478,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
14781478 const events = yield * Queue . unbounded < ProviderAdapter . ProviderAdapterV2Event > ( ) ;
14791479 const activeTurn = yield * Ref . make < ActiveAcpTurn | null > ( null ) ;
14801480 const activeSessionId = yield * Ref . make < string | null > ( null ) ;
1481+ const hydratedSessionId = yield * Ref . make < string | null > ( null ) ;
14811482 const contextUsageBySessionId = yield * Ref . make (
14821483 new Map < string , ThreadTokenUsageSnapshot > ( ) ,
14831484 ) ;
@@ -5796,6 +5797,13 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
57965797 const canLoadSession = started . initializeResult . agentCapabilities ?. loadSession === true ;
57975798 const canResumeSession =
57985799 started . initializeResult . agentCapabilities ?. sessionCapabilities ?. resume != null ;
5800+ if (
5801+ input . initialNativeThreadId === undefined ||
5802+ ! flavor . preferResumeSession ||
5803+ ! canResumeSession
5804+ ) {
5805+ yield * Ref . set ( hydratedSessionId , started . sessionId ) ;
5806+ }
57995807 const supportsImagePrompts = acpSupportsImagePrompts ( {
58005808 flavorSupportsImagePrompts : flavor . supportsImagePrompts ,
58015809 negotiatedImage :
@@ -5815,14 +5823,16 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
58155823 const mcpContext = yield * readMcpContext ( threadId ) ;
58165824 const activationOptions = acpMcpActivation ( mcpContext ) ;
58175825 prepareTerminalEnvironment ( mcpContext , sessionId ) ;
5818- const activated = canLoadSession
5826+ const useLoad = canLoadSession && ! ( flavor . preferResumeSession && canResumeSession ) ;
5827+ const activated = useLoad
58195828 ? yield * runtime . loadSession ( sessionId , activationOptions )
58205829 : canResumeSession
58215830 ? yield * runtime . resumeSession ( sessionId , activationOptions )
58225831 : yield * new ProviderAdapter . ProviderAdapterProtocolError ( {
58235832 driver,
58245833 detail : `ACP driver cannot load or resume session ${ sessionId } ` ,
58255834 } ) ;
5835+ yield * Ref . set ( hydratedSessionId , useLoad ? activated . sessionId : null ) ;
58265836 rememberTerminalEnvironment ( activated . sessionId , yield * readMcpContext ( threadId ) ) ;
58275837 return activated ;
58285838 } ) ;
@@ -6391,6 +6401,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
63916401 yield * restartAcpRuntime ( threadId ) ;
63926402 yield * Ref . set ( runtimeRestartRequired , false ) ;
63936403 yield * Ref . set ( activeSessionId , null ) ;
6404+ yield * Ref . set ( hydratedSessionId , null ) ;
63946405 yield * Ref . set ( activeSessionSetup , null ) ;
63956406 yield * Ref . set ( activeSelection , null ) ;
63966407 yield * Ref . set ( activeInteractionMode , null ) ;
@@ -7296,7 +7307,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
72967307 snapshotInput . providerThread . appThreadId ,
72977308 ) ;
72987309 const sessionId = yield * nativeThreadId ( driver , snapshotInput . providerThread ) ;
7299- if ( ( yield * Ref . get ( activeSessionId ) ) !== sessionId ) {
7310+ if (
7311+ ( yield * Ref . get ( activeSessionId ) ) !== sessionId ||
7312+ ( yield * Ref . get ( hydratedSessionId ) ) !== sessionId
7313+ ) {
73007314 if ( ! capabilities . threads . canReadThreadSnapshot ) {
73017315 return yield * new ProviderAdapter . ProviderAdapterProtocolError ( {
73027316 driver,
@@ -7322,6 +7336,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
73227336 activated . sessionId ,
73237337 yield * readMcpContext ( snapshotInput . providerThread . appThreadId ) ,
73247338 ) ;
7339+ yield * Ref . set ( hydratedSessionId , activated . sessionId ) ;
73257340 yield * Ref . set ( activeSessionId , activated . sessionId ) ;
73267341 yield * Ref . set ( activeSessionSetup , activated ) ;
73277342 yield * Ref . set ( activeSelection , null ) ;
0 commit comments