Skip to content

Commit c771190

Browse files
committed
fix(text-generation): use configured drivers for automatic fallback
1 parent 10942f3 commit c771190

4 files changed

Lines changed: 72 additions & 6 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ describe("Copilot text generation", () => {
162162

163163
it.live.each([
164164
["tool_call", "Copilot attempted tool work during text generation."],
165+
["tool_call_completed", "Copilot attempted tool work during text generation."],
166+
["limit_exceeded", "Copilot text generation exceeded the output limit."],
167+
["empty", "Copilot returned empty text generation output."],
168+
["cancelled", "Copilot text generation was cancelled."],
165169
["permission", "Copilot requested a tool permission during text generation."],
166170
["read_file", "Copilot requested a client tool during text generation."],
167171
["auth_required", "Sign in to GitHub Copilot in provider settings."],
@@ -189,6 +193,16 @@ describe("Copilot text generation", () => {
189193
}).pipe(Effect.scoped, Effect.provide(layer)),
190194
);
191195

196+
it.live("accepts output exactly at the cumulative limit", () =>
197+
Effect.gen(function* () {
198+
const { textGeneration, readLog } = yield* harness({ scenario: "limit_exact" });
199+
assert.equal((yield* generateTitle(textGeneration, "default")).title, "Copilot title");
200+
const { launch } = readLog()[0]!;
201+
assert.isFalse(NodeFS.existsSync(launch!.cwd));
202+
assert.isFalse(NodeFS.existsSync(launch!.copilotHome!));
203+
}).pipe(Effect.scoped, Effect.provide(layer)),
204+
);
205+
192206
it.live(
193207
"refuses before launching when sign-in state is unreadable or a review guide is asked",
194208
() =>

‎packages/provider-acp-registry/src/server/testFixtures/copilot-text-mock-agent.mjs‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,16 @@ for await (const line of NodeReadline.createInterface({ input: process.stdin }))
4848
respond({ sessionId });
4949
break;
5050
case "session/prompt":
51-
// Each rejection scenario then hangs, so only the helper's own abort can settle it.
52-
if (scenario === "tool_call") {
51+
// Open-ended requests stay pending so rejection cannot wait for session/prompt.
52+
if (scenario === "tool_call" || scenario === "tool_call_completed") {
5353
update({ sessionUpdate: "tool_call", toolCallId: "t1", title: "bash", status: "pending" });
54+
if (scenario === "tool_call_completed") {
55+
update({
56+
sessionUpdate: "agent_message_chunk",
57+
content: { type: "text", text: '{"title":"Copilot title"}' },
58+
});
59+
respond({ stopReason: "end_turn" });
60+
}
5461
} else if (scenario === "permission") {
5562
write({
5663
jsonrpc: "2.0",
@@ -69,7 +76,17 @@ for await (const line of NodeReadline.createInterface({ input: process.stdin }))
6976
method: "fs/read_text_file",
7077
params: { sessionId, path: "/etc/hostname" },
7178
});
72-
} else {
79+
} else if (scenario === "empty" || scenario === "cancelled") {
80+
respond({ stopReason: scenario === "cancelled" ? "cancelled" : "end_turn" });
81+
} else if (scenario === "limit_exact" || scenario === "limit_exceeded") {
82+
const reply = JSON.stringify({ title: "Copilot title" }).padEnd(
83+
scenario === "limit_exact" ? 128000 : 128001,
84+
" ",
85+
);
86+
for (const part of [reply.slice(0, 64000), reply.slice(64000)])
87+
update({ sessionUpdate: "agent_message_chunk", content: { type: "text", text: part } });
88+
respond({ stopReason: "end_turn" });
89+
} else if (scenario === "reply") {
7390
update({
7491
sessionUpdate: "agent_message_chunk",
7592
content: { type: "text", text: "Info: Disabled tools: bash, view\n" },
@@ -79,6 +96,8 @@ for await (const line of NodeReadline.createInterface({ input: process.stdin }))
7996
content: { type: "text", text: JSON.stringify({ title: "Copilot title" }) },
8097
});
8198
respond({ stopReason: "end_turn" });
99+
} else {
100+
throw new Error("Unconfigured mock scenario: " + scenario);
82101
}
83102
break;
84103
default:

‎packages/shared/src/serverSettings.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
DEFAULT_SERVER_SETTINGS,
3+
DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER,
34
ProjectId,
45
ProviderDriverKind,
56
ProviderInstanceId,
@@ -39,6 +40,36 @@ describe("fallbackTextGenerationModelSelection", () => {
3940
).toEqual({ instanceId: "opencode", model: "opencode/big-pickle" });
4041
});
4142

43+
it.each(["acpRegistry", "claudeAgent"] as const)(
44+
"uses the configured %s driver behind a default instance ID",
45+
(driver) => {
46+
const checkedDrivers: string[] = [];
47+
const fallback = fallbackTextGenerationModelSelection(
48+
{
49+
[ProviderInstanceId.make("codex")]: {
50+
driver: ProviderDriverKind.make(driver),
51+
config: {},
52+
},
53+
},
54+
(instanceId, candidateDriver) => {
55+
if (instanceId !== "codex") return false;
56+
checkedDrivers.push(candidateDriver);
57+
return true;
58+
},
59+
);
60+
expect(fallback).toEqual(
61+
driver === "acpRegistry"
62+
? null
63+
: {
64+
instanceId: "codex",
65+
model:
66+
DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER[ProviderDriverKind.make("claudeAgent")],
67+
},
68+
);
69+
expect(checkedDrivers).toEqual(driver === "acpRegistry" ? [] : ["claudeAgent"]);
70+
},
71+
);
72+
4273
it("replaces and clears the fallback without carrying model options", () => {
4374
const fallbackModelSelection = { instanceId: ProviderInstanceId.make("codex"), model: "new" };
4475
const settings = applyServerSettingsPatch(

‎packages/shared/src/serverSettings.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ export function fallbackTextGenerationModelSelection(
8080
},
8181
): ModelSelection | null {
8282
const candidates = [
83-
...TEXT_GENERATION_FALLBACK_DRIVERS.map(
84-
(driver) => [defaultInstanceIdForDriver(driver), driver] as const,
85-
),
83+
...TEXT_GENERATION_FALLBACK_DRIVERS.flatMap((defaultDriver) => {
84+
const instanceId = defaultInstanceIdForDriver(defaultDriver);
85+
const driver = providerInstances[instanceId]?.driver ?? defaultDriver;
86+
return isAutomaticTextGenerationFallbackDriver(driver) ? [[instanceId, driver] as const] : [];
87+
}),
8688
...(options?.includeConfiguredInstances === true
8789
? Object.entries(providerInstances).flatMap(([instanceId, instance]) =>
8890
TEXT_GENERATION_FALLBACK_DRIVERS.includes(instance.driver)

0 commit comments

Comments
 (0)