Skip to content

Commit 22aa37b

Browse files
authored
Preserve config options on agent session recreation (#1217)
1 parent 3dfa6cc commit 22aa37b

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

apps/code/src/main/services/agent/service.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)