Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(live-voice): show the real error cause and log call failures
vastsacb4b5f2ed031
diff --git a/apps/desktop/electron/main/index.ts b/apps/desktop/electron/main/index.tsindex e21de2c8a..506fce3ee 100644--- a/apps/desktop/electron/main/index.ts+++ b/apps/desktop/electron/main/index.ts@@ -847,6 +847,7 @@ const liveCallService = createLiveCallService({mode: "agent",});},+ log: (level, message, data) => logger.app("provider", level, message, { data }),});function registerIpc() {diff --git a/apps/desktop/electron/main/live-voice/call-service-internals.ts b/apps/desktop/electron/main/live-voice/call-service-internals.tsindex 4c5e5182d..8b7d199de 100644--- a/apps/desktop/electron/main/live-voice/call-service-internals.ts+++ b/apps/desktop/electron/main/live-voice/call-service-internals.ts@@ -59,6 +59,13 @@ export type LiveCallServiceDeps = {deliverReceipt: (receipt: LiveProviderReceipt) => Promise<LiveReceiptDelivery>,) => Promise<void>;onWorkOperation?: (callId: string, operation: LiveWorkOperationView, delegationId?: string) => void;+ /**+ * Optional Main-side sink for terminal call failures. Nothing under+ * live-voice/ used to log, and IPC errors were only returned to the+ * renderer, so a collapsed generic toast could never be traced back to+ * the error code that produced it.+ */+ log?: (level: "warn" | "error", message: string, data: Record<string, unknown>) => void;};export type Slot = {diff --git a/apps/desktop/electron/main/live-voice/call-service.ts b/apps/desktop/electron/main/live-voice/call-service.tsindex 8aa0b5391..3d2894446 100644--- a/apps/desktop/electron/main/live-voice/call-service.ts+++ b/apps/desktop/electron/main/live-voice/call-service.ts@@ -663,6 +663,13 @@ export class LiveCallService {slot.releaseMicrophone = null;slot.mediaRelease = "unconfirmed";slot.error = { code: "LIVE_MEDIA_RELEASE_UNCONFIRMED", stage: "cleanup", retriable: false };+ this.deps.log?.("error", "live voice microphone release unconfirmed", {+ callId: slot.callId,+ adapterId: slot.binding?.adapterId ?? "unknown",+ code: slot.error.code,+ stage: slot.error.stage ?? "cleanup",+ retriable: slot.error.retriable,+ });}transition(slot, slot.error ? "failed" : "ended");this.publish(slot);@@ -672,7 +679,23 @@ export class LiveCallService {private async failAndCleanup(slot: Slot, error: unknown, stage: string): Promise<void> {if (this.current !== slot) return;- if (!slot.error) slot.error = { ...errorCode(error), stage };+ // Only the first failure is the cause; later failures are consequences of+ // the same teardown and would bury it.+ if (!slot.error) {+ slot.error = { ...errorCode(error), stage };+ this.deps.log?.("warn", "live voice call failed", {+ callId: slot.callId,+ adapterId: slot.binding?.adapterId ?? "unknown",+ phase: slot.phase,+ stage,+ code: slot.error.code,+ retriable: slot.error.retriable,+ // The raw reason is log-only: the Logger redacts bearer tokens and key+ // material, while a call view may show only the code and its localized+ // message (live-voice spec: no provider response content in views).+ ...(error instanceof Error && error.message && error.message !== slot.error.code ? { reason: error.message } : {}),+ });+ }await this.endSlot(slot, slot.error.code === "LIVE_TIMEOUT" ? "timeout" : slot.error.code === "LIVE_AUDIO_BACKPRESSURE" ? "audio-backpressure" : "network-error");}diff --git a/apps/desktop/electron/main/live-voice/runtime.ts b/apps/desktop/electron/main/live-voice/runtime.tsindex af39ac7a1..e728bdc2a 100644--- a/apps/desktop/electron/main/live-voice/runtime.ts+++ b/apps/desktop/electron/main/live-voice/runtime.ts@@ -34,6 +34,8 @@ export function createLiveCallService(input: {providerId: string;sidecarParams: { provider: import("@pi-desktop/agent-runtime").RuntimeProviderConfig };}>;+ /** Terminal call failures land in the `provider` log channel (see spec 09). */+ log?: (level: "warn" | "error", message: string, data: Record<string, unknown>) => void;}): LiveCallService {const backgroundLeases = new Map<number, BackgroundLease>();const authorizedWorkspaces = new WeakMap<object, string | null>();@@ -82,6 +84,7 @@ export function createLiveCallService(input: {return host.call<AppSettings>("settings.get");},authResolver,+ log: input.log,resolveWorkBinding: async (target) => {if (target.workSessionId.startsWith("native-pi:")) {throw Object.assign(new Error("Live work integration does not support native Pi sessions"), {diff --git a/apps/desktop/src/features/voice/live/LiveVoiceCallBar.tsx b/apps/desktop/src/features/voice/live/LiveVoiceCallBar.tsxindex 04b4faf45..44cc79420 100644--- a/apps/desktop/src/features/voice/live/LiveVoiceCallBar.tsx+++ b/apps/desktop/src/features/voice/live/LiveVoiceCallBar.tsx@@ -99,6 +99,11 @@ export function LiveVoiceCallBar({{issue ? (<p className={issue.warning ? "live-voice-feedback live-voice-hint" : "live-voice-feedback live-voice-error"} role={issue.warning ? "status" : "alert"}>{t(issue.message)}+ {/* The localized sentence alone cannot say whether authentication,+ entitlement or the transport failed; the allow-listed code can,+ and it is what a log line or bug report needs. Raw provider text+ never reaches this bar (live-voice spec). */}+ <code className="live-voice-error-code">{issue.code}</code></p>) : null}</div>diff --git a/apps/desktop/src/features/voice/live/live-voice-error.ts b/apps/desktop/src/features/voice/live/live-voice-error.tsindex bcd5af0f9..8a3b3149b 100644--- a/apps/desktop/src/features/voice/live/live-voice-error.ts+++ b/apps/desktop/src/features/voice/live/live-voice-error.ts@@ -11,6 +11,7 @@ const errorKeys: Record<string, string> = {LIVE_RATE_LIMITED: "errors.PROVIDER_RATE_LIMITED",LIVE_NETWORK_ERROR: "errors.NETWORK_ERROR",LIVE_TIMEOUT: "errors.TIMEOUT",+ LIVE_NETWORK_POLICY_UNSUPPORTED: "errors.NETWORK_POLICY_BLOCKED",};export function liveVoiceErrorKey(code: string): string {diff --git a/apps/desktop/src/features/voice/live/live-voice-presentation.ts b/apps/desktop/src/features/voice/live/live-voice-presentation.tsindex 0cbc5429e..4869a7ddf 100644--- a/apps/desktop/src/features/voice/live/live-voice-presentation.ts+++ b/apps/desktop/src/features/voice/live/live-voice-presentation.ts@@ -1,5 +1,6 @@import type { LiveStatus } from "@pi-desktop/shared";import type { LiveVoiceSnapshot } from "./live-call-controller";+import { liveVoiceErrorKey } from "./live-voice-error";export type LiveVoiceMode = "idle" | "connecting" | "reconnecting" | "connected" | "stopping";@@ -57,12 +58,21 @@ export function liveVoiceIssue(snapshot: LiveVoiceSnapshot) {: call?.error?.code ?? snapshot.errorCode ?? notice?? (!terminal && call?.playbackBlocked ? "LIVE_PLAYBACK_BLOCKED" : undefined);if (!code) return null;+ // The bar must name the actual cause: the call-specific table wins,+ // `liveVoiceErrorKey` covers the account/transport codes, and only genuinely+ // unmapped codes fall back — a network failure no longer reads as a generic+ // "check your service configuration" problem. Only this key and the verbatim+ // code reach the bar; a raw provider or credential message never does.+ const mapped = ERROR_MESSAGES[code] ?? liveVoiceErrorKey(code);+ const message = mapped !== "liveVoice.errorGeneric"+ ? mapped+ : code.startsWith("LIVE_WORK_") ? "liveVoice.workActionFailed"+ : call?.phase === "connected" ? "liveVoice.callActionFailed"+ : "liveVoice.errorGeneric";return {code,key: `${call?.callId ?? "start"}:${code}`,- message: ERROR_MESSAGES[code] ?? (code.startsWith("LIVE_WORK_")- ? "liveVoice.workActionFailed"- : call?.phase === "connected" ? "liveVoice.callActionFailed" : "liveVoice.errorGeneric"),+ message,warning: code === "LIVE_PLAYBACK_BLOCKED",};}diff --git a/apps/desktop/src/styles/voice.css b/apps/desktop/src/styles/voice.cssindex 6d6fc5d97..ad3eb6beb 100644--- a/apps/desktop/src/styles/voice.css+++ b/apps/desktop/src/styles/voice.css@@ -333,6 +333,18 @@font-size: var(--text-sm);}+/* The error code stays verbatim: it is what a log line or bug report needs,+ and translating it would break the lookup the spec documents. */+.live-voice-error-code {+ display: block;+ margin-top: 2px;+ color: var(--ds-text-secondary);+ font-family: var(--font-mono);+ font-size: var(--text-xs);+ -webkit-user-select: text;+ user-select: text;+}+.live-voice-transcripts {display: grid;gap: 6px;diff --git a/apps/desktop/test/live-voice-controls.test.mjs b/apps/desktop/test/live-voice-controls.test.mjsindex bc2e8e155..5e9d833a1 100644--- a/apps/desktop/test/live-voice-controls.test.mjs+++ b/apps/desktop/test/live-voice-controls.test.mjs@@ -125,4 +125,18 @@ test("Live Voice separates idle entry and compact call presentation", async (t)assert.equal(liveVoiceIssue({ ...snapshot, call: { ...call, playbackBlocked: false, notice: { code: "LIVE_PLAYBACK_BLOCKED", retriable: true } } }), null);assert.equal(liveVoiceIssue({ ...snapshot, call: { ...call, notice: { code: "LIVE_EXECUTION_NOT_CONNECTED", retriable: false } } }).message, "liveVoice.workNotConnected");});+ await t.test("a stopped call names its real cause and shows the verbatim error code", () => {+ const failed = { ...snapshot, call: { ...call, phase: "failed", error: { code: "LIVE_NETWORK_ERROR", retriable: true } } };+ assert.equal(liveVoiceIssue(failed).message, "errors.NETWORK_ERROR");+ const html = renderBar(failed);+ assert.match(html, /errors\.NETWORK_ERROR/);+ assert.match(html, /<code class="live-voice-error-code">LIVE_NETWORK_ERROR<\/code>/);+ // account failures read as account failures, not as generic configuration advice+ const auth = liveVoiceIssue({ ...snapshot, call: { ...call, phase: "failed", error: { code: "LIVE_AUTH_REQUIRED", retriable: false } } });+ assert.equal(auth.message, "liveVoice.authRequired");+ // genuinely new codes still fall back, with the code visible for a report+ const unknown = liveVoiceIssue({ ...snapshot, call: { ...call, phase: "failed", error: { code: "LIVE_SOMETHING_NEW", retriable: false } } });+ assert.equal(unknown.message, "liveVoice.errorGeneric");+ assert.equal(unknown.code, "LIVE_SOMETHING_NEW");+ });});diff --git a/apps/desktop/test/live-voice-error.test.mjs b/apps/desktop/test/live-voice-error.test.mjsindex f469e6ee4..8fa4de218 100644--- a/apps/desktop/test/live-voice-error.test.mjs+++ b/apps/desktop/test/live-voice-error.test.mjs@@ -17,6 +17,8 @@ test("Live Voice distinguishes account access from microphone and transport failLIVE_NETWORK_ERROR: "errors.NETWORK_ERROR",LIVE_RATE_LIMITED: "errors.PROVIDER_RATE_LIMITED",LIVE_TIMEOUT: "errors.TIMEOUT",+ LIVE_TIMEOUT: "errors.TIMEOUT",+ LIVE_NETWORK_POLICY_UNSUPPORTED: "errors.NETWORK_POLICY_BLOCKED",};for (const [code, key] of Object.entries(expected)) {assert.equal(liveVoiceErrorKey(code), key);diff --git a/apps/desktop/test/live-voice-service-lifecycle.test.mjs b/apps/desktop/test/live-voice-service-lifecycle.test.mjsindex c8e13d06d..654c4b22e 100644--- a/apps/desktop/test/live-voice-service-lifecycle.test.mjs+++ b/apps/desktop/test/live-voice-service-lifecycle.test.mjs@@ -167,3 +167,36 @@ test("provider error sentinels do not enter public call views or controls", asynassert.equal(state.adapters.length, 0);assert.equal(state.releasedMic.length, 1);});++test("a failed call logs one root cause with its code while the view keeps only the code", async (t) => {+ const { LiveCallService } = await loadModules(t);+ const secret = "Bearer fixture-secret-SDP-private-workspace";+ 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" }));+ }+ },+ });+ deps.authResolver.resolve = async () => { throw Object.assign(new Error(secret), { errorCode: "LIVE_AUTH_REQUIRED" }); };+ service = new LiveCallService(deps);+ t.after(() => service.endForLifecycle("app-quit", owner, true));+ const prepared = await prepare(service);+ await assert.rejects(service.connect(owner, { callId: prepared.callId, offerSdp: "v=0\r\n" }), { errorCode: "LIVE_AUTH_REQUIRED" });++ const status = await service.status();+ assert.equal(status.call.error.code, "LIVE_AUTH_REQUIRED");+ assert.equal(JSON.stringify({ prepared, status, events: state.events, controls: state.controls }).includes(secret), false);++ const failures = records.filter((record) => record.message === "live voice call failed");+ assert.equal(failures.length, 1, "one root-cause record, not one per teardown step");+ assert.equal(failures[0].level, "warn");+ assert.equal(failures[0].data.code, "LIVE_AUTH_REQUIRED");+ assert.equal(failures[0].data.adapterId, "codex-live");+ 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");+});diff --git a/docs/spec/03-runtime/09-logging-and-observability.md b/docs/spec/03-runtime/09-logging-and-observability.mdindex 86f84dbfe..e23646949 100644--- a/docs/spec/03-runtime/09-logging-and-observability.md+++ b/docs/spec/03-runtime/09-logging-and-observability.md@@ -52,7 +52,12 @@ The application categories are:- `tool` — tool execution outcomes and interruptions- `permission` — permission requests and decisions- `plugin` — plugin loading, services, and plugin tool execution-- `provider` — provider/model discovery, retries, and cache failures+- `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+ 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- `updater` — updater diagnostics and errors- `diagnostics` — blocked navigation, menu, template, and outbound-fetchdiff --git a/docs/spec/03-runtime/live-voice.md b/docs/spec/03-runtime/live-voice.mdindex fa35c52ab..12f2e1088 100644--- a/docs/spec/03-runtime/live-voice.md+++ b/docs/spec/03-runtime/live-voice.md@@ -69,7 +69,11 @@ persisted settings:the visibility-gated chat and Composer subtree, so in-app navigation cannothide the call controls.Playback blocking and errors, including playback-resume failure, are visible- directly in the bar instead of requiring Details. Non-terminal action or+ directly in the bar instead of requiring Details. The bar pairs the+ localized message with the verbatim `LIVE_*` error code, so a failure whose+ code has no localized message is still attributable from a screenshot or+ bug report; the raw reason behind that code never reaches a view and stays+ in the redacted `provider` log instead. Non-terminal action ormissing-work-binding warnings do not falsely say the call has stopped.4. **Details open:** an explicitly opened secondary surface contains thetransient transcript, provider identity, and any scoped work actions anddiff --git a/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md b/docs/zh-CN/spec/03-runtime/09-logging-and-observability.mdindex 0c58498af..4839af8c0 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 发现、重试和缓存失败+- `provider` — provider/model 发现、重试和缓存失败,以及实时语音通话失败:每个根因写一条 `live voice call failed` `warn`,`data` 带 `callId`、`adapterId`、`phase`、`stage`、`code`、`retriable` 与经 Logger 脱敏的原始 `reason`;释放无法确认、租约被隔离时另写一条 `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.mdindex 001605ea8..435ab7e8a 100644--- a/docs/zh-CN/spec/03-runtime/live-voice.md+++ b/docs/zh-CN/spec/03-runtime/live-voice.md@@ -38,7 +38,7 @@ PCM 采集使用 AudioWorklet,依据实际 `AudioContext.sampleRate` 进行有Voice 在开发构建和打包构建中均向普通用户开放,不再要求开发者模式。实验标记用于提示可用性限制,不是访问门槛。实时语音仍默认关闭,开启设置不会开始采集麦克风。需要配置或恢复账号时,Composer 提供“打开设置”操作。云同步和 Remote Hosts 保留各自的开发构建限制。-账号列表明确区分加载中、可重试的加载失败和无兼容账号。加载失败不会清除已保存的绑定。设置页提供现有模型配置入口,用于登录和管理账号。通话错误区分缺少认证、账号访问被拒、协议不支持、网络/限流及麦克风故障,不显示服务响应内容或凭证。+账号列表明确区分加载中、可重试的加载失败和无兼容账号。加载失败不会清除已保存的绑定。设置页提供现有模型配置入口,用于登录和管理账号。通话错误区分缺少认证、账号访问被拒、协议不支持、网络/限流及麦克风故障,不显示服务响应内容或凭证。通话条会在本地化文案旁同时显示对应的 `LIVE_*` 错误码本身,因此没有专属文案的失败也能从截图或工单中定位;该错误码背后的原始原因不进入任何视图,只写入脱敏后的 `provider` 日志。Voice 设置入口现在只展示实时语音:用户可绑定现有兼容 Provider、选择下次通话使用的绑定,以及设置模型、音色和 Realtime profile。通话进行中,当前绑定不可修改。关闭实时语音会结束通话。Provider 凭证继续由现有 Provider/secret 或 VendorOAuth 系统管理。旧的本地 Dictation 设置和 Composer 入口已隐藏;已有 `voice` 设置值及底层 Dictation 能力保持不变,不会因 UI 调整而删除或改写。旧设置中没有 `liveVoice` 时,会按关闭且无绑定处理。