@@ -3009,6 +3009,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
30093009 if ( threadInput . existingProviderThread ?. nativeThreadRef != null ) {
30103010 return yield * runtimeSession . resumeThread ( {
30113011 providerThread : threadInput . existingProviderThread ,
3012+ runtimePolicy : threadInput . runtimePolicy ,
30123013 } ) ;
30133014 }
30143015 // No title: OpenCode generates one from the first prompt only when
@@ -3064,7 +3065,19 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
30643065 const response = yield * sdkCall ( "session.get" , { sessionID : sessionId } , ( ) =>
30653066 client . session . get ( { sessionID : sessionId } ) ,
30663067 ) ;
3067- const nativeSession = unwrapData ( "session.get" , response ) ;
3068+ let nativeSession = unwrapData ( "session.get" , response ) ;
3069+ // OpenCode keeps the rules a session was created with, so a
3070+ // runtime mode change must replace them or the old mode's
3071+ // approvals survive the switch.
3072+ if ( threadInput . runtimePolicy !== undefined ) {
3073+ const permission = openCodePermissionRules ( threadInput . runtimePolicy ) ;
3074+ nativeSession = unwrapData (
3075+ "session.update" ,
3076+ yield * sdkCall ( "session.update" , { sessionID : sessionId , permission } , ( ) =>
3077+ client . session . update ( { sessionID : sessionId , permission } ) ,
3078+ ) ,
3079+ ) ;
3080+ }
30683081 const resumedAt = yield * DateTime . now ;
30693082 const providerThread = {
30703083 ...threadInput . providerThread ,
0 commit comments