Skip to content

Commit 2c4a108

Browse files
Radu028claude
andcommitted
fix(acp-registry): Copilot SDK stops a turn whose permission mode Copilot kept
Copilot's permissions.setMode reports whether it switched. A refused switch now fails the turn before the prompt instead of running it under allow-all. Each setting is unknown while its call is out, so a failed call is retried on the next turn, and the mode goes first because it can change the model. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 896649f commit 2c4a108

2 files changed

Lines changed: 71 additions & 9 deletions

File tree

‎packages/provider-acp-registry/src/server/copilotSdkAdapter.test.ts‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ const makeFakeCopilot = Effect.fnUntraced(function* () {
123123
const switchResults: Array<Awaited<ReturnType<CopilotSdkSession["rpc"]["model"]["switchTo"]>>> =
124124
[];
125125
const switchFailures: Array<Error> = [];
126+
// Each entry refuses one permission-mode switch, reporting the mode Copilot kept.
127+
const permissionRefusals: Array<"allow-all" | "manual"> = [];
126128
const gate = () => {
127129
let release!: () => void;
128130
const promise = new Promise<void>((resolve) => {
@@ -175,7 +177,10 @@ const makeFakeCopilot = Effect.fnUntraced(function* () {
175177
permissions: {
176178
setMode: async (params) => {
177179
record("permissions.setMode", params);
178-
return { success: true, mode: params.mode };
180+
const kept = permissionRefusals.shift();
181+
return kept === undefined
182+
? { success: true, mode: params.mode }
183+
: { success: false, mode: kept };
179184
},
180185
handlePendingPermissionRequest: async (params) => {
181186
record("permissions.handlePendingPermissionRequest", params);
@@ -323,6 +328,9 @@ const makeFakeCopilot = Effect.fnUntraced(function* () {
323328
queueSwitchResult: (result: (typeof switchResults)[number]) => {
324329
switchResults.push(result);
325330
},
331+
refuseNextPermissionMode: (kept: (typeof permissionRefusals)[number]) => {
332+
permissionRefusals.push(kept);
333+
},
326334
config: () => config,
327335
hangAbort: () => {
328336
hangAbort = true;
@@ -1604,10 +1612,11 @@ describe("CopilotSdkAdapterV2", () => {
16041612
{ id: "reasoning_effort", value: "high" },
16051613
]),
16061614
);
1615+
// The mode goes first: Copilot can switch to a configured plan model with it.
1616+
assert.deepStrictEqual((yield* fake.takeCall("mode.set")).args, [{ mode: "autopilot" }]);
16071617
assert.deepStrictEqual((yield* fake.takeCall("model.switchTo")).args, [
16081618
{ modelId: "claude-sonnet-4.5", reasoningEffort: "high", contextTier: "long_context" },
16091619
]);
1610-
assert.deepStrictEqual((yield* fake.takeCall("mode.set")).args, [{ mode: "autopilot" }]);
16111620
assert.deepStrictEqual((yield* fake.takeCall("permissions.setMode")).args, [
16121621
{ mode: "allow-all" },
16131622
]);
@@ -1682,6 +1691,42 @@ describe("CopilotSdkAdapterV2", () => {
16821691
yield* harness.runtime.startTurn({ ...gpt, providerTurnOrdinal: 5 });
16831692
assert.deepStrictEqual((yield* fake.takeCall("model.switchTo")).args, switchToGpt);
16841693
yield* fake.takeCall("sendAndWait");
1694+
yield* fake.finishRun();
1695+
yield* harness.untilTerminal();
1696+
const planInput = yield* turnInput(
1697+
harness.providerThread,
1698+
[
1699+
{ id: "mode", value: "https://agentclientprotocol.com/protocol/session-modes#plan" },
1700+
{ id: "allow_all", value: true },
1701+
],
1702+
6,
1703+
);
1704+
const plan = {
1705+
...planInput,
1706+
modelSelection: { ...planInput.modelSelection, model: "gpt-5.5" },
1707+
};
1708+
yield* harness.runtime.startTurn(plan);
1709+
yield* fake.takeCall("sendAndWait");
1710+
yield* fake.finishRun();
1711+
yield* harness.untilTerminal();
1712+
// Copilot kept allow-all: a prompt now would auto-approve what T3 should ask about.
1713+
fake.refuseNextPermissionMode("allow-all");
1714+
const kept = yield* harness.runtime
1715+
.startTurn({ ...gpt, providerTurnOrdinal: 7 })
1716+
.pipe(Effect.flip);
1717+
assert.isTrue(Predicate.isTagged(kept.cause, "CopilotPromptNotSentError"));
1718+
assert.deepStrictEqual((yield* fake.takeCall("mode.set")).args, [{ mode: "interactive" }]);
1719+
assert.deepStrictEqual((yield* fake.takeCall("permissions.setMode")).args, [
1720+
{ mode: "manual" },
1721+
]);
1722+
// Copilot did leave plan mode, so going back to the earlier settings switches again.
1723+
yield* harness.runtime.startTurn({ ...plan, providerTurnOrdinal: 7 });
1724+
assert.deepInclude(yield* fake.nextCall, { method: "mode.set", args: [{ mode: "plan" }] });
1725+
assert.deepInclude(yield* fake.nextCall, {
1726+
method: "permissions.setMode",
1727+
args: [{ mode: "allow-all" }],
1728+
});
1729+
assert.deepInclude(yield* fake.nextCall, { method: "sendAndWait" });
16851730
}).pipe(Effect.scoped, Effect.provide(testLayer)),
16861731
);
16871732

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,14 +2496,27 @@ export const makeCopilotSdkAdapterV2 = Effect.fn("makeCopilotSdkAdapterV2")(func
24962496
catch: (cause) => protocolError(`Copilot ${operation} failed`, cause),
24972497
}),
24982498
);
2499+
// Each setting is unknown while its call is out, so a failed or refused call is retried on
2500+
// the next turn instead of being skipped as already applied.
24992501
const applySettings = Effect.fnUntraced(function* (
25002502
target: CopilotSdkSession,
25012503
settings: CopilotSessionSettings,
25022504
) {
2505+
if (applied.mode !== settings.mode) {
2506+
applied = { ...applied, mode: undefined };
2507+
const switched = yield* call("mode switch", () =>
2508+
target.rpc.mode.set({ mode: settings.mode }),
2509+
);
2510+
// A configured plan model can come with the mode; the model switch below sets it back.
2511+
applied = switched.modelChanged
2512+
? { ...applied, mode: settings.mode, model: undefined, reasoningEffort: undefined }
2513+
: { ...applied, mode: settings.mode };
2514+
}
25032515
if (
25042516
applied.model !== settings.model ||
25052517
applied.reasoningEffort !== settings.reasoningEffort
25062518
) {
2519+
applied = { ...applied, model: undefined, reasoningEffort: undefined };
25072520
// null clears an effort override; an omitted effort would keep the previous one.
25082521
const switched = yield* call("model switch", () =>
25092522
target.rpc.model.switchTo({
@@ -2527,7 +2540,6 @@ export const makeCopilotSdkAdapterV2 = Effect.fn("makeCopilotSdkAdapterV2")(func
25272540
yield* Effect.logWarning("Copilot queued the model switch instead of applying it", {
25282541
model: settings.model,
25292542
});
2530-
applied = { ...applied, model: undefined, reasoningEffort: undefined };
25312543
} else {
25322544
applied = {
25332545
...applied,
@@ -2536,15 +2548,20 @@ export const makeCopilotSdkAdapterV2 = Effect.fn("makeCopilotSdkAdapterV2")(func
25362548
};
25372549
}
25382550
}
2539-
if (applied.mode !== settings.mode) {
2540-
yield* call("mode switch", () => target.rpc.mode.set({ mode: settings.mode }));
2541-
}
25422551
if (applied.allowAll !== settings.allowAll) {
2543-
yield* call("permission mode switch", () =>
2544-
target.rpc.permissions.setMode({ mode: settings.allowAll ? "allow-all" : "manual" }),
2552+
applied = { ...applied, allowAll: undefined };
2553+
const requested = settings.allowAll ? "allow-all" : "manual";
2554+
const result = yield* call("permission mode switch", () =>
2555+
target.rpc.permissions.setMode({ mode: requested }),
25452556
);
2557+
// Running the prompt in another permission mode could auto-approve tools T3 should ask about.
2558+
if (!result.success || result.mode !== requested) {
2559+
return yield* protocolError(
2560+
`Copilot stayed in permission mode ${result.mode} instead of ${requested}`,
2561+
);
2562+
}
2563+
applied = { ...applied, allowAll: settings.allowAll };
25462564
}
2547-
applied = { ...applied, mode: settings.mode, allowAll: settings.allowAll };
25482565
currentSettings = settings;
25492566
providerSession = { ...providerSession, model: settings.model };
25502567
});

0 commit comments

Comments
 (0)