Skip to content

Commit 945cb7a

Browse files
fix(server): reapply an ACP agent's selected mode after it switches mode itself
When the agent left its configured mode on its own (OMP leaving plan mode), later turns with an unchanged selection skipped configureSession, so the turn ran in the agent's mode while T3 showed the selected one. startTurn now also reconfigures when the live mode differs from the one configureSession left. Setting the mode-category config option now updates the runtime's mode state too; it previously stayed at the old mode, which hid a drift back to it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ed40a5a commit 945cb7a

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎packages/provider-acp/src/server/AcpSessionRuntime.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,17 @@ export const make = Effect.fn("AcpSessionRuntime.make")(function* (
20312031
"session/set_config_option",
20322032
requestPayload,
20332033
acp.agent.setSessionConfigOption(requestPayload),
2034-
).pipe(Effect.tap((response) => updateConfigOptions(response)));
2034+
).pipe(
2035+
Effect.tap((response) => updateConfigOptions(response)),
2036+
Effect.tap((response) =>
2037+
existing?.category === "mode" && typeof value === "string"
2038+
? updateCurrentModeId(
2039+
parseSessionModeState({ configOptions: response.configOptions })
2040+
?.currentModeId ?? value,
2041+
)
2042+
: Effect.void,
2043+
),
2044+
);
20352045
}),
20362046
),
20372047
),

‎packages/provider-acp/src/server/adapter.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
15961596
});
15971597
const activeSelection = yield* Ref.make<ModelSelection | null>(null);
15981598
const activeInteractionMode = yield* Ref.make<ProviderInteractionMode | null>(null);
1599+
// The mode configureSession left the agent in; the agent may leave it on its own.
1600+
const configuredModeId = yield* Ref.make<string | undefined>(undefined);
15991601
const promptInstructionStates = yield* Ref.make(new Map<string, T3AcpInstructionState>());
16001602
// Unique markers keep delayed prompt completions from clearing later compactions.
16011603
const compactionMarkers = yield* Ref.make(new Map<string, symbol>());
@@ -6874,10 +6876,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
68746876
nativeBuildConfigurationBySessionId.delete(startResult.sessionId);
68756877
}
68766878
}
6879+
const configuredModeState = yield* runtime.getModeState;
6880+
yield* Ref.set(configuredModeId, configuredModeState?.currentModeId);
68776881
yield* (
68786882
flavor.onSessionConfigurationUpdate?.(
68796883
yield* runtime.getConfigOptions,
6880-
yield* runtime.getModeState,
6884+
configuredModeState,
68816885
(yield* Ref.get(activeSessionSetup))?.sessionSetupResult.models,
68826886
) ?? Effect.void
68836887
);
@@ -7352,7 +7356,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
73527356
if (
73537357
configuredSelection === null ||
73547358
!modelSelectionsEqual(configuredSelection, turnInput.modelSelection) ||
7355-
configuredInteractionMode !== turnInput.runtimePolicy.interactionMode
7359+
configuredInteractionMode !== turnInput.runtimePolicy.interactionMode ||
7360+
(yield* runtime.getModeState)?.currentModeId !== (yield* Ref.get(configuredModeId))
73567361
) {
73577362
const currentSessionSetup = yield* Ref.get(activeSessionSetup);
73587363
if (currentSessionSetup === null) {

0 commit comments

Comments
 (0)