@@ -836,6 +836,7 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
836836 // Preserve state that should survive recreation
837837 const config = existing . config ;
838838 const pendingContext = existing . pendingContext ;
839+ const configOptions = existing . configOptions ;
839840
840841 await this . cleanupSession ( taskRunId ) ;
841842
@@ -844,11 +845,28 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
844845 throw new Error ( `Failed to recreate session: ${ taskRunId } ` ) ;
845846 }
846847
847- // Restore preserved state
848848 if ( pendingContext ) {
849849 newSession . pendingContext = pendingContext ;
850850 }
851851
852+ if ( configOptions ) {
853+ await Promise . all (
854+ configOptions . map ( ( opt ) =>
855+ this . setSessionConfigOption (
856+ taskRunId ,
857+ opt . id ,
858+ opt . currentValue ,
859+ ) . catch ( ( err ) => {
860+ log . warn ( "Failed to restore config option during recreation" , {
861+ taskRunId,
862+ configId : opt . id ,
863+ err,
864+ } ) ;
865+ } ) ,
866+ ) ,
867+ ) ;
868+ }
869+
852870 return newSession ;
853871 }
854872
@@ -1001,6 +1019,14 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
10011019 value,
10021020 } ) ;
10031021 session . configOptions = result . configOptions ?? session . configOptions ;
1022+
1023+ const updatedModeOption = session . configOptions ?. find (
1024+ ( opt ) => opt . category === "mode" ,
1025+ ) ;
1026+ if ( updatedModeOption ) {
1027+ session . config . permissionMode = updatedModeOption . currentValue ;
1028+ }
1029+
10041030 log . info ( "Session config option updated" , { sessionId, configId, value } ) ;
10051031 } catch ( err ) {
10061032 log . error ( "Failed to set session config option" , {
0 commit comments