@@ -324,7 +324,6 @@ export interface SessionServiceDeps {
324324 options : SessionConfigOption [ ] ,
325325 ) => void ;
326326 removePersistedConfigOptions : ( taskRunId : string ) => void ;
327- updatePersistedConfigOptionValue : ( ...args : any [ ] ) => any ;
328327 adapterStore : {
329328 getAdapter ( taskRunId : string ) : Adapter | undefined ;
330329 setAdapter ( taskRunId : string , adapter : Adapter ) : void ;
@@ -4029,7 +4028,7 @@ export class SessionService {
40294028 this . d . store . updateSession ( session . taskRunId , {
40304029 configOptions : updatedOptions ,
40314030 } ) ;
4032- this . d . updatePersistedConfigOptionValue ( session . taskRunId , configId , value ) ;
4031+ this . d . setPersistedConfigOptions ( session . taskRunId , updatedOptions ) ;
40334032
40344033 if (
40354034 ! session . isCloud &&
@@ -4054,20 +4053,25 @@ export class SessionService {
40544053 } ) ;
40554054 }
40564055 } catch ( error ) {
4057- // Rollback on error
4058- const rolledBackOptions = configOptions . map ( ( opt ) =>
4059- opt . id === configId
4060- ? ( { ...opt , currentValue : previousValue } as SessionConfigOption )
4061- : opt ,
4062- ) ;
4063- this . d . store . updateSession ( session . taskRunId , {
4064- configOptions : rolledBackOptions ,
4065- } ) ;
4066- this . d . updatePersistedConfigOptionValue (
4067- session . taskRunId ,
4068- configId ,
4069- String ( previousValue ) ,
4056+ const latestConfigOptions =
4057+ this . d . store . getSessionByTaskId ( taskId ) ?. configOptions ?? [ ] ;
4058+ const latestOption = latestConfigOptions . find (
4059+ ( option ) => option . id === configId ,
40704060 ) ;
4061+ if ( latestOption ?. currentValue === value ) {
4062+ const rolledBackOptions = latestConfigOptions . map ( ( option ) =>
4063+ option . id === configId
4064+ ? ( {
4065+ ...option ,
4066+ currentValue : previousValue ,
4067+ } as SessionConfigOption )
4068+ : option ,
4069+ ) ;
4070+ this . d . store . updateSession ( session . taskRunId , {
4071+ configOptions : rolledBackOptions ,
4072+ } ) ;
4073+ this . d . setPersistedConfigOptions ( session . taskRunId , rolledBackOptions ) ;
4074+ }
40714075 this . d . log . error ( "Failed to set session config option" , {
40724076 taskId,
40734077 configId,
@@ -4483,8 +4487,33 @@ export class SessionService {
44834487 runState ?: Record < string , unknown > ,
44844488 ) : ( ) => void {
44854489 const taskRunId = runId ;
4490+ const persistedConfigOptions = this . d . getPersistedConfigOptions ( taskRunId ) ;
4491+ const persistedAdapter = this . d . adapterStore . getAdapter ( taskRunId ) ;
4492+ const buildInitialConfigOptions = (
4493+ mode : string | undefined ,
4494+ configAdapter : Adapter | undefined = persistedAdapter ,
4495+ ) : SessionConfigOption [ ] => {
4496+ const defaults = addMissingCloudRuntimeConfigOptions (
4497+ buildCloudDefaultConfigOptions ( mode , adapter ) ,
4498+ adapter ,
4499+ initialModel ,
4500+ initialReasoningEffort ,
4501+ ) ;
4502+ if ( ! persistedConfigOptions ?. length ) return defaults ;
4503+ if ( configAdapter && configAdapter !== adapter ) return defaults ;
4504+
4505+ const defaultIds = new Set ( defaults . map ( ( option ) => option . id ) ) ;
4506+ const completeOptions = [
4507+ ...defaults ,
4508+ ...persistedConfigOptions . filter (
4509+ ( option ) => ! defaultIds . has ( option . id ) ,
4510+ ) ,
4511+ ] ;
4512+ return mergeConfigOptions ( completeOptions , persistedConfigOptions ) ;
4513+ } ;
44864514
44874515 if ( this . supersededRunIds . has ( runId ) ) return ( ) => { } ;
4516+ this . d . adapterStore . setAdapter ( taskRunId , adapter ) ;
44884517
44894518 const existingWatcher = this . cloudTaskWatchers . get ( taskId ) ;
44904519
@@ -4512,11 +4541,9 @@ export class SessionService {
45124541 if ( shouldRefreshConfigOptions ) {
45134542 this . d . store . updateSession ( existing . taskRunId , {
45144543 adapter,
4515- configOptions : addMissingCloudRuntimeConfigOptions (
4516- buildCloudDefaultConfigOptions ( currentMode , adapter ) ,
4517- adapter ,
4518- initialModel ,
4519- initialReasoningEffort ,
4544+ configOptions : buildInitialConfigOptions (
4545+ currentMode ,
4546+ existing . adapter ,
45204547 ) ,
45214548 } ) ;
45224549 } else {
@@ -4613,11 +4640,9 @@ export class SessionService {
46134640 session . status = "disconnected" ;
46144641 session . isCloud = true ;
46154642 session . adapter = adapter ;
4616- session . configOptions = addMissingCloudRuntimeConfigOptions (
4617- buildCloudDefaultConfigOptions ( initialMode , adapter ) ,
4618- adapter ,
4619- initialModel ,
4620- initialReasoningEffort ,
4643+ session . configOptions = buildInitialConfigOptions (
4644+ initialMode ,
4645+ existing ?. taskRunId === taskRunId ? existing . adapter : persistedAdapter ,
46214646 ) ;
46224647 this . d . store . setSession ( session ) ;
46234648 // Optimistic seeding for the initial task description is deferred
@@ -4636,11 +4661,9 @@ export class SessionService {
46364661 ) ?. currentValue ;
46374662 const currentMode =
46384663 typeof existingMode === "string" ? existingMode : initialMode ;
4639- updates . configOptions = addMissingCloudRuntimeConfigOptions (
4640- buildCloudDefaultConfigOptions ( currentMode , adapter ) ,
4641- adapter ,
4642- initialModel ,
4643- initialReasoningEffort ,
4664+ updates . configOptions = buildInitialConfigOptions (
4665+ currentMode ,
4666+ existing . adapter ,
46444667 ) ;
46454668 } else {
46464669 const configOptions = addMissingCloudRuntimeConfigOptions (
0 commit comments