Skip to content

Commit e9e934b

Browse files
fix(acp): new Copilot threads run the model the composer shows (#35199)
1 parent 5911884 commit e9e934b

4 files changed

Lines changed: 154 additions & 13 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts‎

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as Stream from "effect/Stream";
2323
import * as Effect from "effect/Effect";
2424
import * as FileSystem from "effect/FileSystem";
2525
import * as Layer from "effect/Layer";
26+
import * as Option from "effect/Option";
2627
import * as Path from "effect/Path";
2728
import * as Schema from "effect/Schema";
2829
import * as HttpClient from "effect/http/HttpClient";
@@ -471,13 +472,15 @@ describe("AcpRegistryAdapterV2", () => {
471472
const openWithStoredPicks = Effect.fn("openWithStoredPicks")(function* (input: {
472473
readonly setup: unknown;
473474
readonly pickFrames: ReadonlyArray<Frame>;
475+
readonly agentId?: string;
474476
readonly customModels?: ReadonlyArray<string>;
475477
readonly storedModel?: string;
476478
readonly storedModePick?: string;
477479
readonly turnModels?: ReadonlyArray<string>;
478480
readonly rejectedModel?: string;
479481
readonly storedOptions?: ReadonlyArray<{ readonly id: string; readonly value: string }>;
480482
readonly failsConfiguration?: boolean;
483+
readonly liveConfiguration?: AcpRegistryLiveConfiguration;
481484
}) {
482485
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
483486
// Scope release gives the replay agent at most a second to exit, so the status
@@ -524,7 +527,7 @@ describe("AcpRegistryAdapterV2", () => {
524527
selfInvocation: yield* resolveSelfInvocation(),
525528
instanceId,
526529
settings: yield* decodeAcpRegistryAdapterSettings({
527-
agentId: "fixture-agent",
530+
agentId: input.agentId ?? "fixture-agent",
528531
authMethodId: "test",
529532
customModels: input.customModels ?? [],
530533
}),
@@ -545,6 +548,8 @@ describe("AcpRegistryAdapterV2", () => {
545548
layerInjectedRuntimeCatalog,
546549
Layer.mock(AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator)({
547550
withForegroundStartup: (_startupKey, effect) => effect,
551+
getLiveConfiguration: () =>
552+
Effect.sync(() => Option.fromUndefinedOr(published ?? input.liveConfiguration)),
548553
publishLiveConfiguration: (_instanceId, configuration) =>
549554
Effect.sync(() => {
550555
published = configuration;
@@ -799,6 +804,85 @@ describe("AcpRegistryAdapterV2", () => {
799804
}).pipe(Effect.provide(layerTest), Effect.scoped),
800805
);
801806

807+
// Copilot's session/new reports its built-in default, not the model it will run
808+
// (github/copilot-cli#5363), so the selected model must be written even when it matches,
809+
// and an unset effort gets the value the composer shows.
810+
it.effect(
811+
"writes the selected Copilot model and the shown effort when session/new reports defaults",
812+
() => {
813+
const copilotModel = (currentValue: string) => ({
814+
...modelOption("model", currentValue),
815+
options: ["claude-sonnet-5.5", "claude-haiku-4.5"].map((value) => ({
816+
value,
817+
name: value,
818+
})),
819+
});
820+
const effort = (currentValue: string) => ({
821+
id: "reasoning_effort",
822+
name: "Reasoning effort",
823+
category: "thought_level",
824+
type: "select",
825+
currentValue,
826+
options: ["medium", "xhigh"].map((value) => ({ value, name: value })),
827+
});
828+
return openWithStoredPicks({
829+
agentId: "github-copilot-cli",
830+
setup: { configOptions: [copilotModel("claude-sonnet-5.5"), effort("medium")] },
831+
storedModel: "claude-sonnet-5.5",
832+
liveConfiguration: {
833+
models: [],
834+
currentModelId: null,
835+
configOptions: [
836+
{
837+
id: "reasoning_effort",
838+
label: "Reasoning effort",
839+
type: "select",
840+
role: "reasoning",
841+
currentValue: "xhigh",
842+
options: [
843+
{ id: "medium", label: "medium" },
844+
{ id: "xhigh", label: "xhigh" },
845+
],
846+
},
847+
],
848+
},
849+
pickFrames: [
850+
// The new session's own update replaces the shared live configuration.
851+
{
852+
type: "emit_inbound",
853+
frame: {
854+
kind: "notification",
855+
method: "session/update",
856+
params: {
857+
sessionId: "agent-session",
858+
update: {
859+
sessionUpdate: "config_option_update",
860+
configOptions: [copilotModel("claude-sonnet-5.5"), effort("medium")],
861+
},
862+
},
863+
},
864+
},
865+
outbound("session/set_config_option", {
866+
sessionId: "agent-session",
867+
configId: "model",
868+
value: "claude-sonnet-5.5",
869+
}),
870+
answer("session/set_config_option", {
871+
configOptions: [copilotModel("claude-sonnet-5.5"), effort("medium")],
872+
}),
873+
outbound("session/set_config_option", {
874+
sessionId: "agent-session",
875+
configId: "reasoning_effort",
876+
value: "xhigh",
877+
}),
878+
answer("session/set_config_option", {
879+
configOptions: [copilotModel("claude-sonnet-5.5"), effort("xhigh")],
880+
}),
881+
],
882+
}).pipe(Effect.provide(layerTest), Effect.scoped);
883+
},
884+
);
885+
802886
it.effect.each([
803887
"config",
804888
"legacy",

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
258258
normalizeSessionUpdate: copilotRouting.normalizeSessionUpdate,
259259
extractSubagentUpdate: extractCopilotSubagentUpdate,
260260
restartRuntimeAfterPromptError: isCopilotLostSessionError,
261+
// session/new reports a built-in default, not the model Copilot runs (github/copilot-cli#5363).
262+
alwaysSetModel: true,
261263
}),
262264
makeRuntime: options.makeRuntime ?? makeAcpRegistryRuntime(runtimeOptions, catalog),
263265
...(runtimeCoordinator === undefined
@@ -268,6 +270,28 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
268270
options.instanceId,
269271
normalizeAcpRegistryCommands(commands),
270272
),
273+
// A new Copilot session starts at its own effort, not the one the composer shows.
274+
...(isCopilot
275+
? {
276+
unsetOptionDefaults: runtimeCoordinator
277+
.getLiveConfiguration(options.instanceId)
278+
.pipe(
279+
Effect.map(
280+
Option.match({
281+
onNone: () => [],
282+
onSome: ({ configOptions }) =>
283+
configOptions.flatMap((descriptor) =>
284+
descriptor.type === "select" &&
285+
descriptor.role === "reasoning" &&
286+
descriptor.currentValue !== undefined
287+
? [{ id: descriptor.id, value: descriptor.currentValue }]
288+
: [],
289+
),
290+
}),
291+
),
292+
),
293+
}
294+
: {}),
271295
onSessionConfigurationUpdate: (configOptions, modeState, modelState) =>
272296
runtimeCoordinator.publishLiveConfiguration(
273297
options.instanceId,

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,11 @@ export class AcpSessionRuntime extends Context.Service<
11861186
readonly setConfigOption: (
11871187
configId: string,
11881188
value: string | boolean,
1189-
options?: { readonly allowUnlistedValue?: boolean },
1189+
options?: {
1190+
readonly allowUnlistedValue?: boolean;
1191+
/** Sends the write even when the cached value already matches it. */
1192+
readonly resendCurrentValue?: boolean;
1193+
},
11901194
) => Effect.Effect<EffectAcpSchema.SetSessionConfigOptionResponse, EffectAcpErrors.AcpError>;
11911195
readonly setModel: (model: string) => Effect.Effect<void, EffectAcpErrors.AcpError>;
11921196
readonly request: (
@@ -2031,15 +2035,22 @@ export const make = Effect.fn("AcpSessionRuntime.make")(function* (
20312035
const setConfigOption = (
20322036
configId: string,
20332037
value: string | boolean,
2034-
options?: { readonly allowUnlistedValue?: boolean },
2038+
options?: {
2039+
readonly allowUnlistedValue?: boolean;
2040+
readonly resendCurrentValue?: boolean;
2041+
},
20352042
): Effect.Effect<EffectAcpSchema.SetSessionConfigOptionResponse, EffectAcpErrors.AcpError> =>
20362043
validateConfigOptionValue(configId, value, options?.allowUnlistedValue === true).pipe(
20372044
Effect.andThen(getStartedState),
20382045
Effect.flatMap((started) =>
20392046
SubscriptionRef.get(configOptionsRef).pipe(
20402047
Effect.flatMap((configOptions) => {
20412048
const existing = findSessionConfigOption(configOptions, configId);
2042-
if (existing && configOptionCurrentValueMatches(existing, value)) {
2049+
if (
2050+
existing &&
2051+
options?.resendCurrentValue !== true &&
2052+
configOptionCurrentValueMatches(existing, value)
2053+
) {
20432054
return Effect.succeed({
20442055
configOptions,
20452056
} satisfies EffectAcpSchema.SetSessionConfigOptionResponse);

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ export interface AcpAdapterV2Flavor {
374374
ChildProcessSpawner.ChildProcessSpawner | SecureRandom.SecureRandom | Scope.Scope
375375
>;
376376
readonly customModels?: ReadonlyArray<string>;
377+
/** The agent may run another model than session/new reports, so the model is always written. */
378+
readonly alwaysSetModel?: boolean;
379+
/** Values the client shows for options a new session's selection leaves unset. */
380+
readonly unsetOptionDefaults?: Effect.Effect<NonNullable<ModelSelection["options"]>>;
377381
readonly resolveModelId?: (selection: ModelSelection) => string | undefined;
378382
/**
379383
* The agent advertises its model option only after `session/new` returns
@@ -7155,6 +7159,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
71557159
},
71567160
);
71577161

7162+
// Read before the session exists: its own config updates replace what the client showed.
7163+
const unsetOptionDefaults = yield* flavor.unsetOptionDefaults ?? Effect.succeed([]);
71587164
const initialStart = yield* Effect.result(
71597165
startAcpRuntime(input.threadId, input.initialNativeThreadId),
71607166
);
@@ -7253,6 +7259,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
72537259
startResult: AcpSessionRuntime.AcpSessionRuntimeStartResult,
72547260
modelSelection: ModelSelection,
72557261
runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,
7262+
unsetOptionDefaults: NonNullable<ModelSelection["options"]> = [],
72567263
) {
72577264
yield* Ref.set(activeSelection, null);
72587265
yield* validateModelSelection(modelSelection);
@@ -7288,7 +7295,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
72887295
)
72897296
) {
72907297
yield* runtime
7291-
.setConfigOption(modelOption.id, requestedModel)
7298+
.setConfigOption(modelOption.id, requestedModel, {
7299+
resendCurrentValue: flavor.alwaysSetModel === true,
7300+
})
72927301
.pipe(Effect.mapError(rejectedModel));
72937302
appliedModel = requestedModel;
72947303
}
@@ -7343,13 +7352,21 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
73437352
: undefined;
73447353
return granted !== undefined && !isRuntimeModeAbove(granted, ceiling);
73457354
};
7346-
const optionSelections = (modelSelection.options ?? []).flatMap((selection) => {
7347-
if (flavor.ownedModelOptionIds?.includes(selection.id) === true) return [];
7348-
if (!withinCeiling(selection)) return [];
7349-
return [
7350-
selection.value === ACP_EMPTY_OPTION_VALUE ? { ...selection, value: "" } : selection,
7351-
];
7352-
});
7355+
const explicitSelections = modelSelection.options ?? [];
7356+
const implicitSelections = unsetOptionDefaults.filter(
7357+
(implicit) => !explicitSelections.some((selection) => selection.id === implicit.id),
7358+
);
7359+
const optionSelections = [...explicitSelections, ...implicitSelections].flatMap(
7360+
(selection) => {
7361+
if (flavor.ownedModelOptionIds?.includes(selection.id) === true) return [];
7362+
if (!withinCeiling(selection)) return [];
7363+
return [
7364+
selection.value === ACP_EMPTY_OPTION_VALUE
7365+
? { ...selection, value: "" }
7366+
: selection,
7367+
];
7368+
},
7369+
);
73537370
const availableConfigIds = new Set(configOptions.map((option) => option.id));
73547371
const hasNativeConfigWithSyntheticModeId = availableConfigIds.has(
73557372
ACP_SESSION_MODE_OPTION_ID,
@@ -7501,7 +7518,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
75017518
);
75027519
});
75037520

7504-
yield* configureSession(started, input.modelSelection, input.runtimePolicy);
7521+
yield* configureSession(
7522+
started,
7523+
input.modelSelection,
7524+
input.runtimePolicy,
7525+
started.sessionId !== input.initialNativeThreadId ? unsetOptionDefaults : [],
7526+
);
75057527
yield* Ref.set(activeSelection, input.modelSelection);
75067528
yield* Ref.set(activeInteractionMode, input.runtimePolicy.interactionMode);
75077529
const createdAt = yield* DateTime.now;

0 commit comments

Comments
 (0)