Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(live-voice): repair Gemini work setup and report protocol failures

Seraph-x4d5bb44cdf12
diff --git a/apps/desktop/electron/main/live-voice/call-service.ts b/apps/desktop/electron/main/live-voice/call-service.ts
index f9e95f74f..9e0892f50 100644
--- a/apps/desktop/electron/main/live-voice/call-service.ts
+++ b/apps/desktop/electron/main/live-voice/call-service.ts
@@ -638,7 +638,8 @@ export class LiveCallService {
if (event.code === "LIVE_EXECUTION_NOT_CONNECTED") {
slot.notice = { code: event.code, retriable: false };
this.publish(slot);
- } else void this.failAndCleanup(slot, liveError(event.code), "protocol");
+ } else void this.failAndCleanup(slot,
+ Object.assign(new Error(event.reason ?? event.code), { errorCode: event.code }), "protocol");
return;
case "turn-complete":
slot.assistantSpeaking = false;
diff --git a/apps/desktop/electron/main/live-voice/gemini-adapter.ts b/apps/desktop/electron/main/live-voice/gemini-adapter.ts
index 219c11e71..96dad572c 100644
--- a/apps/desktop/electron/main/live-voice/gemini-adapter.ts
+++ b/apps/desktop/electron/main/live-voice/gemini-adapter.ts
@@ -18,6 +18,7 @@ export function createGeminiAdapter(context: LiveAdapterContext): LiveAdapter {
const apiKey = context.auth.apiKey;
let socket: Awaited<ReturnType<typeof openLiveWebSocket>> | null = null;
let closed = false;
+ let failed = false;
let muted = context.signal.aborted;
let setupSent = false;
let readyResolve: (() => void) | null = null;
@@ -71,8 +72,21 @@ export function createGeminiAdapter(context: LiveAdapterContext): LiveAdapter {
).catch(() => context.onEvent({ kind: "error", code: "LIVE_WORK_INTENT_UNAVAILABLE" }));
}
- function onSocketFailure(): void {
- if (!closed && !context.signal.aborted) context.onEvent({ kind: "error", code: "LIVE_NETWORK_ERROR" });
+ function onSocketFailure(code: string, reason: string): void {
+ if (closed || failed || context.signal.aborted) return;
+ failed = true;
+ // connect() crosses IPC; raw provider diagnostics belong only in the log.
+ readyReject?.(Object.assign(new Error(code), { errorCode: code }));
+ context.onEvent({ kind: "error", code, reason });
+ }
+
+ function onSocketClose(code: number, reason: Buffer): void {
+ const errorCode = [1002, 1003, 1007, 1008, 1009].includes(code) ? "LIVE_PROTOCOL_ERROR" : "LIVE_NETWORK_ERROR";
+ onSocketFailure(errorCode, `Gemini Live socket closed (${code}): ${reason.toString("utf8")}`);
+ }
+
+ function onSocketError(error: Error): void {
+ onSocketFailure("LIVE_NETWORK_ERROR", error.message);
}
function onSocketMessage(data: unknown): void {
@@ -120,8 +134,8 @@ export function createGeminiAdapter(context: LiveAdapterContext): LiveAdapter {
}
socket = liveSocket;
liveSocket.on("message", onSocketMessage);
- liveSocket.once("close", onSocketFailure);
- liveSocket.once("error", onSocketFailure);
+ liveSocket.once("close", onSocketClose);
+ liveSocket.once("error", onSocketError);
await waitForSocketReady(liveSocket, context.signal);
if (closed || context.signal.aborted) {
liveSocket.terminate();
@@ -160,8 +174,8 @@ export function createGeminiAdapter(context: LiveAdapterContext): LiveAdapter {
closed = true;
if (setupSent) readyReject?.(new Error("Gemini Live call closed"));
socket?.off("message", onSocketMessage);
- socket?.off("close", onSocketFailure);
- socket?.off("error", onSocketFailure);
+ socket?.off("close", onSocketClose);
+ socket?.off("error", onSocketError);
if (socket && socket.readyState !== WebSocket.CLOSED) socket.close(1000, "call ended");
completedFunctionCalls.clear();
socket = null;
diff --git a/apps/desktop/test/live-voice-gemini-adapter.test.mjs b/apps/desktop/test/live-voice-gemini-adapter.test.mjs
new file mode 100644
index 000000000..12ec9fb93
--- /dev/null
+++ b/apps/desktop/test/live-voice-gemini-adapter.test.mjs
@@ -0,0 +1,103 @@
+import assert from "node:assert/strict";
+import { EventEmitter } from "node:events";
+import test from "node:test";
+import { fileURLToPath } from "node:url";
+import { createServer } from "vite";
+
+async function fixture(t, respond) {
+ const key = `gemini-adapter-${crypto.randomUUID()}`;
+ const socket = new EventEmitter();
+ socket.readyState = 1;
+ socket.bufferedAmount = 0;
+ socket.sent = [];
+ socket.send = (body, callback) => {
+ const message = JSON.parse(body);
+ socket.sent.push(message);
+ queueMicrotask(() => { callback?.(); respond?.(socket, message); });
+ };
+ socket.close = () => { socket.readyState = 3; socket.emit("close", 1000, Buffer.from("call ended")); };
+ globalThis[key] = async () => socket;
+ const server = await createServer({
+ root: fileURLToPath(new URL("..", import.meta.url)), configFile: false,
+ server: { middlewareMode: true, hmr: false, ws: false }, appType: "custom",
+ optimizeDeps: { noDiscovery: true, include: [] },
+ plugins: [{
+ name: "gemini-transport-fixture", enforce: "pre",
+ resolveId(source) {
+ if (source === "./websocket-transport") return "\0gemini-transport-fixture";
+ },
+ load(id) {
+ if (id === "\0gemini-transport-fixture") return `export const openLiveWebSocket = () => globalThis[${JSON.stringify(key)}]();`;
+ },
+ }],
+ });
+ const { createGeminiAdapter } = await server.ssrLoadModule("/electron/main/live-voice/gemini-adapter.ts");
+ const events = [];
+ const abort = new AbortController();
+ const adapter = createGeminiAdapter({
+ callId: "fixture-call",
+ binding: { id: "gemini", adapterId: "gemini-live", providerId: "google", modelId: "fixture-model", voice: "Kore" },
+ provider: {},
+ auth: { kind: "api-key", apiKey: "fixture-key", baseUrl: "https://fixture.invalid" },
+ signal: abort.signal, onEvent: (event) => events.push(event),
+ workProfile: { version: 1, instructions: "work instructions", startupContext: "work scope" },
+ });
+ t.after(async () => {
+ await adapter.close("user-ended");
+ delete globalThis[key];
+ await server.close();
+ });
+ return { adapter, socket, events, abort };
+}
+
+test("Gemini connects with a work target and sends audio only after valid setup", { timeout: 60_000 }, async (t) => {
+ const { adapter, socket, events } = await fixture(t, (socket, message) => {
+ if (message.setup) {
+ const parameters = message.setup.tools[0].functionDeclarations[0].parameters;
+ if ("additionalProperties" in parameters) {
+ socket.emit("close", 1007, Buffer.from('Unknown name "additionalProperties"'));
+ } else socket.emit("message", Buffer.from('{"setupComplete":{}}'));
+ }
+ });
+ await adapter.connect();
+ assert.deepEqual(events, [{ kind: "ready" }]);
+ assert.equal(socket.sent[0].setup.tools[0].functionDeclarations[0].parameters.type, "object");
+ await adapter.setInputMuted(false);
+ adapter.sendInputPcm(new Uint8Array([0, 0]));
+ assert.ok(socket.sent.at(-1).realtimeInput);
+});
+
+test("Gemini rejects setup immediately with protocol diagnostics on close 1007", { timeout: 60_000 }, async (t) => {
+ const reason = 'Invalid JSON payload. Unknown name "additionalProperties"';
+ const { adapter, events } = await fixture(t, (socket) => {
+ socket.emit("close", 1007, Buffer.from(reason));
+ socket.emit("error", new Error("secondary transport failure"));
+ });
+ const error = await Promise.race([
+ adapter.connect().then(() => null, (error) => error),
+ new Promise((resolve) => setImmediate(() => resolve(null))),
+ ]);
+ assert.equal(error?.errorCode, "LIVE_PROTOCOL_ERROR", "setup rejects on close, without waiting for its timeout");
+ assert.equal(error.message, "LIVE_PROTOCOL_ERROR", "connect rejection can cross IPC without provider content");
+ assert.equal(events.length, 1);
+ assert.equal(events[0].code, "LIVE_PROTOCOL_ERROR");
+ assert.match(events[0].reason, /1007/);
+ assert.ok(events[0].reason.includes(reason));
+});
+
+test("Gemini retains transport errors and ignores terminal events after cancellation", { timeout: 60_000 }, async (t) => {
+ const { adapter, socket, events, abort } = await fixture(t, (socket) => {
+ socket.emit("message", Buffer.from('{"setupComplete":{}}'));
+ });
+ await adapter.connect();
+ socket.emit("error", new Error("connection reset"));
+ socket.emit("close", 1006, Buffer.alloc(0));
+ assert.equal(events.filter((event) => event.kind === "error").length, 1);
+ assert.equal(events.at(-1).code, "LIVE_NETWORK_ERROR");
+ assert.match(events.at(-1).reason, /connection reset/);
+ abort.abort();
+ await adapter.close("user-ended");
+ assert.equal(socket.listenerCount("message"), 0);
+ assert.equal(socket.listenerCount("close"), 0);
+ assert.equal(socket.listenerCount("error"), 0);
+});
diff --git a/apps/desktop/test/live-voice-service-lifecycle.test.mjs b/apps/desktop/test/live-voice-service-lifecycle.test.mjs
index 654c4b22e..b240a539a 100644
--- a/apps/desktop/test/live-voice-service-lifecycle.test.mjs
+++ b/apps/desktop/test/live-voice-service-lifecycle.test.mjs
@@ -200,3 +200,34 @@ test("a failed call logs one root cause with its code while the view keeps only
assert.equal(failures[0].data.stage, "handshake");
assert.equal(failures[0].data.reason, secret, "the raw reason stays in the log channel, which redacts it");
});
+
+test("adapter close diagnostics are logged once and never enter call views", async (t) => {
+ const { LiveCallService } = await loadModules(t);
+ const reason = 'Gemini Live socket closed (1007): Unknown name "additionalProperties"';
+ const records = [];
+ let service;
+ const { deps, state } = dependencies({
+ log: (level, message, data) => records.push({ level, message, data }),
+ sendControl: (_owner, control) => {
+ state.controls.push(control);
+ if (control.kind === "release-media") {
+ queueMicrotask(() => service.reportMedia(owner, { callId: control.callId, kind: "released" }));
+ }
+ },
+ });
+ service = new LiveCallService(deps);
+ t.after(() => service.endForLifecycle("app-quit", owner, true));
+ const prepared = await prepare(service);
+ await service.connect(owner, { callId: prepared.callId, offerSdp: "v=0\r\n" });
+ state.adapters[0].onEvent({ kind: "error", code: "LIVE_PROTOCOL_ERROR", reason });
+ state.adapters[0].onEvent({ kind: "error", code: "LIVE_NETWORK_ERROR", reason: "secondary failure" });
+ await service.endForLifecycle("app-quit", owner, true);
+
+ const status = await service.status();
+ assert.equal(status.call.error.code, "LIVE_PROTOCOL_ERROR");
+ assert.equal(status.call.error.retriable, false);
+ assert.equal(JSON.stringify({ status, events: state.events, controls: state.controls }).includes(reason), false);
+ const failures = records.filter((record) => record.message === "live voice call failed");
+ assert.equal(failures.length, 1);
+ assert.equal(failures[0].data.reason, reason);
+});
diff --git a/docs/spec/03-runtime/09-logging-and-observability.md b/docs/spec/03-runtime/09-logging-and-observability.md
index 6e0743242..6407613d8 100644
--- a/docs/spec/03-runtime/09-logging-and-observability.md
+++ b/docs/spec/03-runtime/09-logging-and-observability.md
@@ -55,7 +55,8 @@ The application categories are:
- `provider` — provider/model discovery, retries, and cache failures, plus
live voice call failures: one `live voice call failed` `warn` per root cause
carrying `callId`, `adapterId`, `phase`, `stage`, `code`, `retriable` and the
- Logger-redacted raw `reason`, and one `live voice microphone release
+ Logger-redacted raw `reason` (including Gemini WebSocket close code and UTF-8
+ reason), and one `live voice microphone release
unconfirmed` `error` when a release could not be confirmed and the lease is
quarantined. Call views carry the `code` only.
- `persistence` — transcript and outbox persistence failures
diff --git a/docs/spec/03-runtime/live-voice.md b/docs/spec/03-runtime/live-voice.md
index 1cd748028..6eb8a40e7 100644
--- a/docs/spec/03-runtime/live-voice.md
+++ b/docs/spec/03-runtime/live-voice.md
@@ -133,7 +133,14 @@ Codex Live uses its dedicated Codex OAuth endpoint and WebRTC answer exchange;
its browser data channel only handles normalized protocol events and the
unsupported-delegation response. It does not use public GPT-Live session
events. Gemini Live waits for `setupComplete` before sending 16 kHz mono
-PCM16. Realtime waits for `session.updated`, sends 24 kHz mono PCM16, and
+PCM16. Gemini work tools use its OpenAPI Schema subset, excluding
+`additionalProperties`; OpenAI retains its strict JSON Schema and Host argument
+validation stays strict for both. Gemini closes with codes 1002/1003/1007/1008/1009
+are protocol failures rather than network failures. A close or transport error
+rejects pending setup immediately and reports one root cause. Its code and UTF-8
+reason go only to the redacted provider log; connection rejections, call views
+and Renderer controls carry the public error code without raw provider content.
+Realtime waits for `session.updated`, sends 24 kHz mono PCM16, and
selects an explicit GA or compat-v1 wire profile. The supported models and
voices are editable per binding; defaults are candidates, not claims of
account access or service availability.
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 433e758e5..ff4f0ca3b 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -166,6 +166,27 @@
returns memory to the OS and that the existing lazy-load path reloads it.
- **Specs:** [Live Voice](../03-runtime/live-voice.md).
+### E2E-LIVE-VOICE-gemini-work-schema
+
+- **Preconditions:** Production Gemini adapter with a deterministic transport
+ fixture and a bound work profile; no credentials or hardware devices.
+- **Steps:** Start the call with a work target, accept a valid setup, unmute and
+ send PCM. Reject another setup with close 1007 and a UTF-8 reason. Repeat
+ with a transport error followed by close; cancel and close the adapter.
+- **Expected:** Gemini sends the supported Schema subset and connects; OpenAI's
+ schema and Host argument validation remain strict. Setup rejection settles
+ immediately as `LIVE_PROTOCOL_ERROR`, transport errors remain network errors,
+ and only one failure is reported. The raw reason reaches only the provider
+ log; even the connect rejection crossing IPC contains only the public code.
+ Cancellation suppresses terminal noise and close removes socket observers.
+- **Specs:** `03-runtime/live-voice.md`, `09-logging-and-observability.md`.
+- **Acceptance:** C, E, Security, Quality.
+- **Milestone:** Maintenance, issue #1812.
+- **Automation:** `live-voice-gemini-adapter.test.mjs`,
+ `live-voice-service-lifecycle.test.mjs`, and voice-runtime `live/protocol.test.ts`.
+- **Status:** Adapter/service contract-covered; full Electron/Gemini account and
+ physical microphone acceptance remain separate and are not certified here.
+
### E2E-LIVE-VOICE-public-settings-and-reconnect
- **Preconditions:** A built production Renderer and real Electron/Main/Host,
@@ -10209,6 +10230,7 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.
| Acceptance | Scenarios |
|---|---|
+| C / E / Security / Quality — Gemini work setup | E2E-LIVE-VOICE-gemini-work-schema |
| B / Security / Quality — Optional provider client certificate requests | E2E-PROVIDER-optional-client-certificate |
| C / E / F / Quality / Security — Session Todo checklist | E2E-CHAT-session-todo-checklist |
| C / E / Security / Quality — Live Voice four-stage interaction | E2E-LIVE-VOICE-four-stage-ui |
@@ -17601,6 +17623,15 @@ the latest destination. These assertions measure work counts, not device FPS.
- **Status:** Unit-covered; no end-to-end driver issues a real provider request
against a duplicated transcript.
+- **Reused-id regression (#1815):** Run two actual tool executions whose
+ provider responses reuse the same id, then inspect the next request. Both
+ results must remain, with distinct paired ids and no synthetic placeholder.
+ Repeat after context trimming and restored history, and verify cancellation,
+ metadata and replayed pending snapshots retain their semantics.
+ `runtime.test.ts` covers the parent prompt path; `subagent-fallback.test.ts`
+ drives the real Pi adapter over local HTTP with two executions and three
+ requests; `tool-call-identity.test.ts` covers retained identities after trim.
+
### E2E-RUNTIME-system-update-during-tool-call-restore
- **Preconditions:** A session transcript with a model system record saved
diff --git a/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md b/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md
index d4d837e4f..fbb22b685 100644
--- a/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md
+++ b/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md
@@ -52,7 +52,7 @@ host 和 agent stderr 使用标记进行分类;无法分类的子进程输出
- `tool` — 工具执行结果和中断
- `permission` — 权限请求和决定
- `plugin` — 插件加载、服务和插件工具执行
-- `provider` — provider/model 发现、重试和缓存失败,以及实时语音通话失败:每个根因写一条 `live voice call failed` `warn`,`data` 带 `callId`、`adapterId`、`phase`、`stage`、`code`、`retriable` 与经 Logger 脱敏的原始 `reason`;释放无法确认、租约被隔离时另写一条 `live voice microphone release unconfirmed` `error`。通话视图只携带 `code`。
+- `provider` — provider/model 发现、重试和缓存失败,以及实时语音通话失败:每个根因写一条 `live voice call failed` `warn`,`data` 带 `callId`、`adapterId`、`phase`、`stage`、`code`、`retriable` 与经 Logger 脱敏的原始 `reason`(含 Gemini WebSocket 关闭码和 UTF-8 原因);释放无法确认、租约被隔离时另写一条 `live voice microphone release unconfirmed` `error`。通话视图只携带 `code`。
- `persistence` — 成绩单和发件箱持久化失败
- `updater` — 更新器诊断和错误
- `diagnostics` — 阻止导航、菜单、模板以及对外请求的诊断。技能市场的两个通道会为每个没有产出结果的源或文档各记录一条 `skillMarket.sourceFailed` / `skillMarket.documentFailed`:`data` 里带 `source`、`host`、`kind`、`address`,以及被守卫拒绝时的 `reason`、`addressKind` 与 `route`。`kind` 在守卫判定的是目标自身地址时为 `policy`,判定的是本地代理伪造的 fake-IP 占位地址时为 `fake-ip`,本地解析没有返回答案时为 `unresolved`,其余为 `network`;`code` 前两者为 `NETWORK_POLICY_BLOCKED`,第三者为 `NETWORK_RESOLVE_FAILED`,因此一行日志即可区分「目标地址不是公网」「代理用了 fake-IP」与「解析器没有应答」。`reason` 记录守卫自己的分支(`url-syntax`、`resolve-failed`、`non-public-address`、`redirect-limit`),`addressKind` 记录被拒地址的类别(TUN fake-IP 为 `benchmark`,RFC1918 为 `private`),`route` 记录该地址是在哪条线路上被判定的(`proxied`、`direct`,或传输层读不出线路时的 `unknown`),因此「直连线路上的 fake-IP 拒绝」与「读不出线路的拒绝」可以区分(ADR 0272)。记录会保留主机名、被解析到的地址、该地址的类别与该线路 —— 但绝不包含 URL、其路径、查询串或凭据 —— 因为目录源 URL 由用户提供,而被拒绝的主机、地址及其类别正是全部诊断价值所在(issue #419)。Chromium 进程崩溃后,下一次启动会写一条 `crashDumpsFound` 记录(任一新转储属于 browser/main 进程则为 `error`,否则为 `warn`),`data` 带 `count`、`total`、`byProcessType`、`directory` 与 `newestMtimeMs`。已恢复的 renderer 崩溃因此不会被写成「上次运行已死」。扫描失败是一条 `crashDumpReportFailed` 警告,永不挡住第一扇窗口(D602)。
diff --git a/docs/zh-CN/spec/03-runtime/live-voice.md b/docs/zh-CN/spec/03-runtime/live-voice.md
index 7848cb096..9474b083b 100644
--- a/docs/zh-CN/spec/03-runtime/live-voice.md
+++ b/docs/zh-CN/spec/03-runtime/live-voice.md
@@ -30,7 +30,11 @@ Live 与 Dictation 共用 Main 进程的麦克风租约。本地 mute 会在 IPC
通话状态为 `preparing → acquiring-mic → negotiating/connecting → connected → closing → ended|failed`。request ID 让 prepare 幂等,并可在 call ID 返回前取消。启动、握手、heartbeat、中断确认和释放等待均有时限。每个 Desktop 实例同时只能有一个通话;后续通话需要用户明确发起,不会自动切换 Provider、模型或计费路径。
-Codex Live 使用专用 Codex OAuth endpoint 和 WebRTC answer exchange;浏览器 data channel 只处理规范化协议事件和不支持 delegation 的响应。它不使用公共 GPT-Live session 事件。Gemini Live 在发送 16 kHz 单声道 PCM16 前会等待 `setupComplete`。Realtime 会等待 `session.updated`,使用 24 kHz 单声道 PCM16,并明确选择 GA 或 compat-v1 wire profile。用户可分别编辑每项绑定的模型和音色;默认值只是候选项,不代表账号有访问权限或服务可用。
+Codex Live 使用专用 Codex OAuth endpoint 和 WebRTC answer exchange;浏览器 data channel 只处理规范化协议事件和不支持 delegation 的响应。它不使用公共 GPT-Live session 事件。Gemini Live 在发送 16 kHz 单声道 PCM16 前会等待 `setupComplete`。
+Gemini 工作工具使用不含 `additionalProperties` 的 OpenAPI Schema 子集,OpenAI 保留严格 JSON Schema;两者的 Host 参数校验仍严格执行。
+Gemini 以 1002/1003/1007/1008/1009 关闭时报告协议失败,而非网络失败。关闭或传输错误立即拒绝待完成 setup,只报告首个根因。
+关闭码和 UTF-8 reason 仅进入脱敏后的 provider 日志;连接异常、通话视图和 Renderer 控制只携带公开错误码,不含原始提供商内容。
+Realtime 会等待 `session.updated`,使用 24 kHz 单声道 PCM16,并明确选择 GA 或 compat-v1 wire profile。用户可分别编辑每项绑定的模型和音色;默认值只是候选项,不代表账号有访问权限或服务可用。
PCM 采集使用 AudioWorklet,依据实际 `AudioContext.sampleRate` 进行有状态抗混叠重采样,并产生有界的 20 ms worklet 帧。PCM 输出由独立播放通路排队,记录每个 item 实际播放位置;中断会推进 playback epoch 并丢弃过期队列。如果浏览器阻止播放,通话面板会提供用户手势来恢复声音。输入音频不会回环到本地扬声器。
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index d6b118154..f81bcc0ff 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -37,6 +37,27 @@
`TranscribeModel.dispose()` 会向操作系统归还内存,且现有延迟加载路径可重新加载。
- **规格:** [实时语音](../03-runtime/live-voice.md)。
+### E2E-LIVE-VOICE-gemini-work-schema
+
+- **Preconditions:** Production Gemini adapter with a deterministic transport
+ fixture and a bound work profile; no credentials or hardware devices.
+- **Steps:** Start the call with a work target, accept a valid setup, unmute and
+ send PCM. Reject another setup with close 1007 and a UTF-8 reason. Repeat
+ with a transport error followed by close; cancel and close the adapter.
+- **Expected:** Gemini sends the supported Schema subset and connects; OpenAI's
+ schema and Host argument validation remain strict. Setup rejection settles
+ immediately as `LIVE_PROTOCOL_ERROR`, transport errors remain network errors,
+ and only one failure is reported. The raw reason reaches only the provider
+ log; even the connect rejection crossing IPC contains only the public code.
+ Cancellation suppresses terminal noise and close removes socket observers.
+- **Specs:** `03-runtime/live-voice.md`, `09-logging-and-observability.md`.
+- **Acceptance:** C, E, Security, Quality.
+- **Milestone:** Maintenance, issue #1812.
+- **Automation:** `live-voice-gemini-adapter.test.mjs`,
+ `live-voice-service-lifecycle.test.mjs`, and voice-runtime `live/protocol.test.ts`.
+- **Status:** Adapter/service contract-covered; full Electron/Gemini account and
+ physical microphone acceptance remain separate and are not certified here.
+
### E2E-LIVE-VOICE-public-settings-and-reconnect
- **前提:** 生产 Renderer 构建、真实 Electron/Main/Host、隔离数据和测试项目、关闭开发者模式、本地 TLS Realtime fixture 及合成麦克风。仅在测试子进程中信任 fixture CA,不关闭 TLS、sender、沙盒或麦克风权限校验。
@@ -5792,6 +5813,7 @@ eleven-tool-round desktop paths are verified by
## 8. 可追溯性矩阵
| 验收 | 应用场景 |
|---|---|
+| C / E / Security / Quality — Gemini work setup | E2E-LIVE-VOICE-gemini-work-schema |
| B / Security / Quality — Optional provider client certificate requests | E2E-PROVIDER-optional-client-certificate |
| C / E / F / Quality / Security — Session Todo checklist | E2E-CHAT-session-todo-checklist |
| C / E / Security / Quality — Live Voice 四阶段交互 | E2E-LIVE-VOICE-four-stage-ui |
@@ -9309,6 +9331,15 @@ Follow the [current S3 acceptance scenario](/spec/06-delivery/04-e2e-test-plan#e
- **状态:** 单元测试覆盖;没有端到端驱动对重复转录发出真实提供商请求。
+- **Reused-id regression (#1815):** Run two actual tool executions whose
+ provider responses reuse the same id, then inspect the next request. Both
+ results must remain, with distinct paired ids and no synthetic placeholder.
+ Repeat after context trimming and restored history, and verify cancellation,
+ metadata and replayed pending snapshots retain their semantics.
+ `runtime.test.ts` covers the parent prompt path; `subagent-fallback.test.ts`
+ drives the real Pi adapter over local HTTP with two executions and three
+ requests; `tool-call-identity.test.ts` covers retained identities after trim.
+
### E2E-RUNTIME-system-update-during-tool-call-restore
- **先决条件:** 一份会话转录,其中一条模型系统记录在工具调用执行期间保存:位于发出该调用的助手行之后、该调用的工具行之前
diff --git a/packages/voice-runtime/src/live/protocol.test.ts b/packages/voice-runtime/src/live/protocol.test.ts
index 7f331c5fc..a47c2e556 100644
--- a/packages/voice-runtime/src/live/protocol.test.ts
+++ b/packages/voice-runtime/src/live/protocol.test.ts
@@ -5,6 +5,8 @@ import {
geminiSetupMessage,
geminiToolResponseMessage,
geminiWorkFeedbackMessage,
+ geminiWorkToolDeclaration,
+ liveWorkToolDeclaration,
LIVE_WORK_TOOL_NAME,
parseLiveWorkArguments,
parseCodexMessage,
@@ -76,7 +78,7 @@ describe("Live wire profiles", () => {
expect(geminiSetupMessage({ modelId: "gemini-live", voice: "Kore", workProfile: { instructions: "work instructions", startupContext: "work scope" } })).toMatchObject({
setup: {
systemInstruction: { parts: [{ text: "work instructions\n\nwork scope" }] },
- tools: [{ functionDeclarations: [{ name: LIVE_WORK_TOOL_NAME, parameters: { additionalProperties: false } }] }],
+ tools: [{ functionDeclarations: [{ name: LIVE_WORK_TOOL_NAME, parameters: { type: "object", required: ["instruction"] } }] }],
},
});
const events = parseGeminiMessage({ serverContent: { modelTurn: { parts: [
@@ -114,6 +116,21 @@ describe("Live wire profiles", () => {
]);
});
+ it("uses Gemini's Schema subset while retaining OpenAI's strict object schema", () => {
+ const tools = geminiWorkToolDeclaration();
+ expect(tools).toMatchObject({ functionDeclarations: [{
+ name: LIVE_WORK_TOOL_NAME,
+ parameters: {
+ type: "object",
+ properties: { instruction: { type: "string", description: expect.any(String) } },
+ required: ["instruction"],
+ },
+ }] });
+ expect(JSON.stringify(tools)).not.toContain("additionalProperties");
+ expect(liveWorkToolDeclaration()).toMatchObject({ parameters: { additionalProperties: false } });
+ expect(parseLiveWorkArguments({ instruction: "Run tests", extra: true })).toBeNull();
+ });
+
it("truncates realtime output at the played cursor after cancelling", () => {
expect(realtimeTruncateMessages({ itemId: "item-1", contentIndex: 0, audioEndMs: 825.9 })).toEqual([
{ type: "response.cancel" },
diff --git a/packages/voice-runtime/src/live/protocol.ts b/packages/voice-runtime/src/live/protocol.ts
index 1b7e17815..827b48b04 100644
--- a/packages/voice-runtime/src/live/protocol.ts
+++ b/packages/voice-runtime/src/live/protocol.ts
@@ -25,7 +25,7 @@ export type LiveWireEvent =
| { kind: "tool-candidate"; providerRequestId: string; toolName: string; arguments: unknown }
| { kind: "tool-call-cancelled"; ids: string[] }
| { kind: "closed"; code?: number }
- | { kind: "error"; code: string };
+ | { kind: "error"; code: string; /** Main-only diagnostic; never publish to Renderer. */ reason?: string };
export function parseCodexMessage(value: unknown): LiveWireEvent[] {
const event = record(value);
@@ -402,7 +402,7 @@ export function parseRealtimeMessage(value: unknown, profile: "realtime-ga" | "r
}
}
-export function liveWorkToolDeclaration(): Record<string, unknown> {
+export function liveWorkToolDeclaration() {
return {
type: "function",
name: LIVE_WORK_TOOL_NAME,
@@ -423,11 +423,14 @@ export function liveWorkToolDeclaration(): Record<string, unknown> {
export function geminiWorkToolDeclaration(): Record<string, unknown> {
const declaration = liveWorkToolDeclaration();
+ // Gemini's OpenAPI Schema subset rejects JSON Schema additionalProperties.
+ // Host argument validation remains strict for every adapter.
+ const { additionalProperties: _additionalProperties, ...parameters } = declaration.parameters;
return {
functionDeclarations: [{
name: declaration.name,
description: declaration.description,
- parameters: declaration.parameters,
+ parameters,
}],
};
}