diff --git a/packages/plugin/src/server/acp-internal/connection.ts b/packages/plugin/src/server/acp-internal/connection.ts index bc7c73cd83..23f340e10e 100644 --- a/packages/plugin/src/server/acp-internal/connection.ts +++ b/packages/plugin/src/server/acp-internal/connection.ts @@ -5,6 +5,7 @@ import { ClientSideConnection, CLIENT_METHODS, PROTOCOL_VERSION, + RequestError, ndJsonStream, type Client, type AgentCapabilities, @@ -649,7 +650,7 @@ class AcpRuntime { } this.modes = response.modes ?? null; this.configOptions = response.configOptions ?? []; - await this.applyInitialConfig(input.config); + await this.applyInitialConfig(input.config, Boolean(nativeSessionId)); const sessionCapabilities = connectionCapabilities.filter( (capability) => capability !== "session.configure" || @@ -1079,7 +1080,10 @@ class AcpRuntime { } } - private async applyInitialConfig(config: ProviderSessionConfig): Promise { + private async applyInitialConfig( + config: ProviderSessionConfig, + resuming: boolean, + ): Promise { const requested: AcpConfigChange[] = []; if (config.model) requested.push({ target: "model", value: config.model }); const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode; @@ -1097,7 +1101,9 @@ class AcpRuntime { for (const [id, value] of Object.entries(settings)) { requested.push({ target: "setting", id, value }); } - for (const change of this.inAgentOrder(requested)) await this.applyConfigChange(change); + for (const change of this.inAgentOrder(requested)) { + await this.applyConfigChange(change, resuming); + } } private offersMode(mode: string | undefined): boolean { @@ -1138,7 +1144,7 @@ class AcpRuntime { return modeOption(this.configOptions)?.id; } - private async applyConfigChange(change: AcpConfigChange): Promise { + private async applyConfigChange(change: AcpConfigChange, resuming = false): Promise { const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode; if ( change.target === "mode" && @@ -1167,9 +1173,40 @@ class AcpRuntime { return; } } + if (resuming && change.target === "model" && change.value) { + await this.restoreNativeModel(change.value); + return; + } await this.applyNativeConfigChange(change); } + private async restoreNativeModel(requested: string): Promise { + try { + await this.applyNativeConfigChange({ target: "model", value: requested }); + } catch (error) { + if (!(error instanceof RequestError) || error.code !== -32602) throw error; + const option = modelOption(this.configOptions); + const current = selectedValue(option); + if ( + !current || + current === requested || + selectOptions(option).some(({ value }) => value === requested) + ) { + throw error; + } + this.emit({ + type: "session.notice", + sessionId: this.options.boundarySessionId, + notice: { + id: "acp:saved-model-unavailable", + severity: "warning", + title: "Saved model unavailable", + description: `The provider no longer offers ${requested}. This chat reopened with ${current}.`, + }, + }); + } + } + private async applyNativeConfigChange(change: AcpConfigChange): Promise { if (change.target === "mode" && this.modes && !modeOption(this.configOptions)) { if (!change.value) { diff --git a/packages/server/src/server/daemon-e2e/antigravity-model-resume-fixture.cjs b/packages/server/src/server/daemon-e2e/antigravity-model-resume-fixture.cjs new file mode 100644 index 0000000000..3f1162ca8c --- /dev/null +++ b/packages/server/src/server/daemon-e2e/antigravity-model-resume-fixture.cjs @@ -0,0 +1,74 @@ +// ACP peer that stops offering a model between daemon runs. +const readline = require("node:readline"); + +const sessionId = "antigravity-model-resume"; +const models = process.env.AGY_TEST_RETIRED ? ["current-model", "other-model"] : ["old-model"]; +let model = models[0]; +const modes = { + currentModeId: "default", + availableModes: [{ id: "default", name: "Default" }], +}; + +function configOptions() { + return [ + { + id: "model", + name: "Model", + category: "model", + type: "select", + currentValue: model, + options: models.map((value) => ({ name: value, value })), + }, + ]; +} + +function send(message) { + process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\n"); +} + +function notify(update) { + send({ method: "session/update", params: { sessionId, update } }); +} + +readline.createInterface({ input: process.stdin }).on("line", (line) => { + const { id, method, params } = JSON.parse(line); + switch (method) { + case "initialize": + send({ + id, + result: { + protocolVersion: 1, + agentCapabilities: { loadSession: true, sessionCapabilities: { close: {} } }, + }, + }); + break; + case "session/load": + notify({ + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "A saved Antigravity reply" }, + }); + // Fall through to send the same selectors as session/new. + case "session/new": + notify({ sessionUpdate: "available_commands_update", availableCommands: [] }); + send({ id, result: { sessionId, modes, configOptions: configOptions() } }); + break; + case "session/set_config_option": + if (params.configId !== "model" || !models.includes(params.value)) { + send({ + id, + error: { code: -32602, message: `Unknown model ID: ${params.value}` }, + }); + break; + } + model = params.value; + send({ id, result: { configOptions: configOptions() } }); + break; + case "session/close": + send({ id, result: {} }); + break; + default: + if (id !== undefined) { + send({ id, error: { code: -32601, message: "Method not found" } }); + } + } +}); diff --git a/packages/server/src/server/daemon-e2e/models.e2e.test.ts b/packages/server/src/server/daemon-e2e/models.e2e.test.ts index d6d9b6635b..09e3767ca1 100644 --- a/packages/server/src/server/daemon-e2e/models.e2e.test.ts +++ b/packages/server/src/server/daemon-e2e/models.e2e.test.ts @@ -165,6 +165,96 @@ test("Antigravity creates an agent and answers a prompt with real agy", async ({ } }, 120000); +test.each(["timeline", "reload", "resume"] as const)( + "reopens a saved Antigravity chat after model retirement through %s", + async (action) => { + const root = await mkdtemp(path.join(os.tmpdir(), "paseo-antigravity-model-resume-")); + const start = async (retired: boolean) => { + const daemon = await createTestPaseoDaemon({ + paseoHomeRoot: root, + staticDir: path.join(root, "static"), + cleanup: false, + agentClients: {}, + mcpEnabled: false, + builtinPlugins: new BuiltinPluginLoader(undefined, ["antigravity-provider"]), + providerOverrides: { + antigravity: { + command: [ + process.execPath, + path.join(import.meta.dirname, "antigravity-model-resume-fixture.cjs"), + ], + env: { AGY_TEST_RETIRED: retired ? "1" : "" }, + paseoTools: { enabled: false }, + }, + }, + }); + const client = new DaemonClient({ + url: `ws://127.0.0.1:${daemon.port}/ws`, + appVersion: "0.16.0", + }); + return { + client, + close: async () => { + await client.close(); + await daemon.close(); + }, + }; + }; + + try { + const before = await start(false); + let agent; + try { + await before.client.connect(); + agent = await before.client.createAgent({ + provider: "antigravity", + cwd: root, + model: "old-model", + }); + expect(agent.model).toBe("old-model"); + } finally { + await before.close(); + } + + const { client, close } = await start(true); + try { + await client.connect(); + let agentId = agent.id; + if (action === "resume") { + const handle = agent.persistence; + if (!handle) throw new Error("Antigravity did not return a persistence handle"); + agentId = (await client.resumeAgent(handle)).id; + } else if (action === "reload") { + await client.refreshAgent(agentId); + } + + const timeline = await client.fetchAgentTimeline(agentId, { limit: 100 }); + expect(timeline.entries.map(({ item }) => item)).toContainEqual( + expect.objectContaining({ type: "assistant_message", text: "A saved Antigravity reply" }), + ); + expect(timeline.entries.map(({ item }) => item)).toContainEqual({ + type: "notification", + level: "warning", + message: + "Saved model unavailable\nThe provider no longer offers old-model. This chat reopened with current-model.", + }); + expect((await client.fetchAgent(agentId))?.agent).toMatchObject({ + model: "old-model", + runtimeInfo: { model: "current-model" }, + }); + await expect(client.setAgentModel(agentId, "old-model")).rejects.toThrow(/old-model/); + await client.setAgentModel(agentId, "other-model"); + expect((await client.fetchAgent(agentId))?.agent.model).toBe("other-model"); + } finally { + await close(); + } + } finally { + await rm(root, { recursive: true, force: true }); + } + }, + 60_000, +); + test("bundled fx requires a config entry and lists models instead of its providers", async () => { const root = await mkdtemp(path.join(os.tmpdir(), "paseo-fx-optin-")); const record = path.join(root, "launches.txt");