Skip to content

Commit dbc7e99

Browse files
committed
fix(google): append continue nudge for Claude-on-Antigravity prefill
Claude-on-Antigravity rejects a history that ends on a model turn as assistant prefill. Context compaction and interrupted-turn replay can produce that shape. Mirror the anthropic adapter's user (continue) nudge on the CCA Claude path only. Closes #2065
1 parent bcc77c0 commit dbc7e99

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

‎src/adapters/google.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,17 @@ export function createGoogleAdapter(provider: OcxProviderConfig): ProviderAdapte
498498
} else {
499499
sanitizeAntigravityClaudeSignatures(contents);
500500
}
501+
// Claude-on-Antigravity rejects assistant-tail (model-tail in Gemini terms) histories
502+
// as prefill: "This model does not support assistant message prefill. The conversation
503+
// must end with a user message." Context compaction, previous_response_id expansion,
504+
// and interrupted-turn replay can all produce a model-tail history. Append a user
505+
// "(continue)" nudge, mirroring the anthropic adapter's tail guard (src/adapters/anthropic.ts).
506+
if (/claude/i.test(wireModelId)) {
507+
const last = contents.length > 0 ? contents[contents.length - 1] as { role?: string } : undefined;
508+
if (!last || last.role === "model") {
509+
contents.push({ role: "user", parts: [{ text: "(continue)" }] });
510+
}
511+
}
501512
}
502513
const envelope = {
503514
model: wireModelId,
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { describe, expect, test } from "bun:test";
2+
import { createGoogleAdapter as createGoogleAdapterProduction } from "../src/adapters/google";
3+
import type { OcxMessage, OcxParsedRequest, OcxProviderConfig } from "../src/types";
4+
import { withTestTranslatorBudget } from "./helpers/translator-budget";
5+
6+
const createGoogleAdapter = (...args: Parameters<typeof createGoogleAdapterProduction>) =>
7+
withTestTranslatorBudget(createGoogleAdapterProduction(...args));
8+
9+
const provider = {
10+
adapter: "google",
11+
baseUrl: "https://daily-cloudcode-pa.googleapis.com",
12+
googleMode: "cloud-code-assist",
13+
project: "proj-123",
14+
apiKey: "ya29.token",
15+
} as OcxProviderConfig;
16+
17+
function parsed(messages: OcxMessage[], modelId = "claude-opus-4-6-thinking"): OcxParsedRequest {
18+
return {
19+
modelId,
20+
stream: false,
21+
options: {},
22+
context: { messages, systemPrompt: [], tools: [] },
23+
} as unknown as OcxParsedRequest;
24+
}
25+
26+
async function envelopeContents(p: OcxParsedRequest): Promise<{ role: string; parts: unknown[] }[]> {
27+
const { body } = await createGoogleAdapter(provider).buildRequest(p);
28+
const envelope = JSON.parse(body);
29+
return envelope.request.contents;
30+
}
31+
32+
describe("google claude prefill guard", () => {
33+
test("appends a user continue nudge when CCA Claude context ends with model turn", async () => {
34+
const contents = await envelopeContents(parsed([
35+
{ role: "user", content: "start", timestamp: 0 },
36+
{ role: "assistant", content: [{ type: "text", text: "partial answer" }], model: "claude", timestamp: 0 },
37+
]));
38+
39+
expect(contents.at(-1)).toEqual({ role: "user", parts: [{ text: "(continue)" }] });
40+
});
41+
42+
test("leaves context ending with user unchanged", async () => {
43+
const contents = await envelopeContents(parsed([
44+
{ role: "assistant", content: [{ type: "text", text: "answer" }], model: "claude", timestamp: 0 },
45+
{ role: "user", content: "follow up", timestamp: 0 },
46+
]));
47+
48+
expect(contents.at(-1)!.role).toBe("user");
49+
expect(JSON.stringify(contents.at(-1))).not.toContain("(continue)");
50+
});
51+
52+
test("appends nudge when CCA Claude context is empty", async () => {
53+
const contents = await envelopeContents(parsed([]));
54+
55+
expect(contents.at(-1)).toEqual({ role: "user", parts: [{ text: "(continue)" }] });
56+
});
57+
58+
test("does not append nudge after tool result (tool result maps to user role)", async () => {
59+
const contents = await envelopeContents(parsed([
60+
{
61+
role: "assistant",
62+
content: [{ type: "toolCall", id: "call_1", name: "read_file", arguments: { path: "README.md" } }],
63+
model: "claude",
64+
timestamp: 0,
65+
},
66+
{
67+
role: "toolResult",
68+
toolCallId: "call_1",
69+
toolName: "read_file",
70+
content: "contents",
71+
isError: false,
72+
timestamp: 0,
73+
},
74+
] as OcxMessage[]));
75+
76+
// toolResult maps to role:"user" in Gemini format, so no nudge needed
77+
expect(contents.at(-1)!.role).toBe("user");
78+
expect(JSON.stringify(contents.at(-1))).not.toContain("(continue)");
79+
});
80+
81+
test("does not append nudge for non-Claude models on Antigravity", async () => {
82+
const contents = await envelopeContents(parsed([
83+
{ role: "user", content: "start", timestamp: 0 },
84+
{ role: "assistant", content: [{ type: "text", text: "answer" }], model: "gemini", timestamp: 0 },
85+
], "gemini-3.7-flash"));
86+
87+
// Gemini natively accepts model-tail; no nudge
88+
expect(contents.at(-1)!.role).toBe("model");
89+
expect(JSON.stringify(contents)).not.toContain("(continue)");
90+
});
91+
});

0 commit comments

Comments
 (0)