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(pi): propagate one-shot provider failures
vastsae6b6e0ecff00
diff --git a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md b/docs/zh-CN/spec/03-runtime/02-agent-runtime.mdindex 12b23502f..deb7eadcf 100644--- a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md+++ b/docs/zh-CN/spec/03-runtime/02-agent-runtime.md@@ -1032,17 +1032,14 @@ sidecar 序列化针对相同标准化路径的 IPC/`sequential` 调用跟踪差距(MVP 后积压):更丰富的系统提示组成 (§7) 和provider/model 目录发现超出当前有线路径。-### Provider certificate trust (issue #714)--The desktop sidecar starts with Node's `--use-system-ca`, retaining bundled-roots and inherited `NODE_EXTRA_CA_CERTS`. It uses the OS trust store without-turning off chain or hostname validation. Restart after updating local trust-or the extra-CA startup environment. Headless pi-host launch behavior and-System/Direct/Custom proxy routing are unchanged.--Explicit certificate verification errors are terminal for both setup and-stream recovery in main sessions and built-in delegates. Their structured-cause survives adapter message flattening, remains on the final error row,-and never triggers a provider transport rebuild. Protocol errors such as-`EPROTO` keep their existing retry behavior. See-[certificate trust ADR](../../../adr/provider-system-certificates.md).+### Provider certificate trust(issue #714)++桌面 sidecar 使用 Node 的 `--use-system-ca` 启动,同时保留内置根证书和继承的+`NODE_EXTRA_CA_CERTS`。它使用操作系统信任库,但不会关闭证书链或主机名校验。+更新本地信任库或额外 CA 启动环境后,需要重启桌面应用。无头 pi-host 启动行为以及+System/Direct/Custom 代理路由保持不变。++在主 session 和内置 delegate 中,明确的证书校验错误在初始化和流恢复阶段都视为+终态。结构化原因会穿过 adapter 的错误扁平化,保留在最终错误行中,也不会触发+provider transport 重建。`EPROTO` 等协议错误继续使用原有重试行为。详见+[证书信任 ADR](../../../adr/provider-system-certificates.md)。diff --git a/docs/zh-CN/spec/03-runtime/08-error-codes.md b/docs/zh-CN/spec/03-runtime/08-error-codes.mdindex 19020f18c..d16e8bbf1 100644--- a/docs/zh-CN/spec/03-runtime/08-error-codes.md+++ b/docs/zh-CN/spec/03-runtime/08-error-codes.md@@ -413,19 +413,15 @@ errors.<code>.action代码;仅允许记录的预转目录后备,并且不进行任何工作正在重播-### Certificate verification failures (issue #714)--`NETWORK_ERROR` is non-retriable when `details.networkCode` is a recognized-certificate verification failure, including an untrusted/self-signed chain,-an expired/not-yet-valid certificate, or `ERR_TLS_CERT_ALTNAME_INVALID`.-A concrete certificate cause takes precedence over generic socket/proxy-wrapper codes. Captured fetch causes apply this policy after adapter error-flattening as well as during direct classification. Unknown and non-certificate-TLS/protocol errors retain existing recovery behavior.--The transcript keeps the stable error code, transport errno and raw details,-but uses localized certificate guidance instead of the generic connectivity-summary. It asks the user to check the certificate, clock, and trusted roots-used by security software/proxies, then restart after changing trust. It does-not claim that interception is the only possible cause or offer a TLS bypass.-Manual Continue remains available after the cause is corrected.+### 证书校验失败(issue #714)++当 `details.networkCode` 是已识别的证书校验错误时,`NETWORK_ERROR` 不可重试,+包括不受信任或自签名链、证书已过期或尚未生效,以及+`ERR_TLS_CERT_ALTNAME_INVALID`。具体证书原因优先于通用 socket/proxy 包装错误。+即使 adapter 已将错误扁平化,捕获的 fetch 原因仍会应用这条策略。未知 TLS 错误和+非证书协议错误继续使用原有恢复行为。++transcript 保留稳定错误码、传输 errno 和原始 details,但使用本地化的证书指引,+而不是通用连接错误摘要。它会提示用户检查证书、系统时间以及安全软件或代理使用的+信任根,并在修改信任设置后重启。文案不会断言一定是流量拦截,也不会提供关闭 TLS+校验的绕过方式。修复原因后,用户仍可手动继续。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.mdindex e2f3b037e..3864f4983 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@@ -8161,28 +8161,23 @@ the latest destination. These assertions measure work counts, not device FPS.### E2E-PROVIDER-certificate-trust-and-terminal-errors-- **Preconditions:** Built request candidate incorporating current `origin/main`,- Electron installed, isolated test process/profile and loopback HTTPS fixture.- No real provider, credentials, user profile, or OS certificate-store writes.-- **Steps:** Run `node scripts/e2e-provider-certificates.mjs`. Launch the actual- desktop sidecar and submit a chat prompt against an untrusted localhost- certificate. Relaunch with its CA in `NODE_EXTRA_CA_CERTS`, then request the- same certificate through a hostname absent from its SAN.-- **Expected:** The child's default CA set includes system roots and extra CAs.- The first request fails once with a non-retriable certificate error and no- retry status; the trusted request returns text; the hostname mismatch still- fails once. TLS and hostname verification remain enabled.-- **UI:** Run `node scripts/e2e-provider-certificate-ui.mjs` for the real error- component in isolated Chromium. Certificate errors get localized guidance;- DNS and protocol errors retain the generic summary. Errno/raw details remain- visible, and details can be closed and reopened. Optional- `PI_CERTIFICATE_EVIDENCE_DIR` records a screenshot; `--baseline` uses the- upstream error component with the same fixture and stylesheet.-- **Lower-level coverage:** `provider-certificate-flow.test.ts` enters main- session `prompt()` and delegate `run()` through real Agent/pi-ai wiring,- with only the external fetch mocked. Both stop after one request and retain- the certificate cause. Error classification and recovery suites cover direct,- nested, flattened, non-certificate and wrapped certificate failures.-- **Limits:** OS-root inclusion is checked without installing a root. The TLS- success fixture uses a child-only extra CA; it does not reproduce a specific- antivirus installation or claim native macOS/Linux verification.+- **前提:** 已构建、包含当前 `origin/main` 的任务候选版本,已安装 Electron,使用+ 隔离的测试进程/配置和回环 HTTPS 夹具。不使用真实 provider、凭据或用户配置,+ 也不写入操作系统证书库。+- **步骤:** 运行 `node scripts/e2e-provider-certificates.mjs`。启动真实桌面+ sidecar,使用不受信任的 localhost 证书提交聊天提示。再将其 CA 放入+ `NODE_EXTRA_CA_CERTS` 后重启,并通过 SAN 中不存在的主机名请求同一证书。+- **预期:** 子进程默认 CA 集合包含系统根证书和额外 CA。首次请求只失败一次,+ 返回不可重试的证书错误且没有重试状态;信任 CA 后请求返回文本;主机名不匹配+ 仍只失败一次。TLS 和主机名校验始终保持启用。+- **UI:** 运行 `node scripts/e2e-provider-certificate-ui.mjs`,在隔离 Chromium+ 中验证真实错误组件。证书错误显示本地化指引;DNS 和协议错误保留通用摘要。+ errno/原始 details 仍可见,详情可以关闭并重新打开。可选的+ `PI_CERTIFICATE_EVIDENCE_DIR` 会记录截图;`--baseline` 使用相同夹具和样式的+ upstream 错误组件。+- **低层覆盖:** `provider-certificate-flow.test.ts` 通过真实 Agent/pi-ai wiring+ 进入主 session 的 `prompt()` 和 delegate 的 `run()`,仅 mock 外部 fetch。两条+ 路径都只请求一次并保留证书原因;错误分类和恢复测试覆盖直接、嵌套、扁平化、+ 非证书以及包装后的证书错误。+- **限制:** OS 根证书的纳入在不安装根证书的条件下检查。TLS 成功夹具只使用+ 子进程额外 CA,不复现某个具体杀毒软件安装,也不宣称已完成 macOS/Linux 实机验证。diff --git a/packages/agent-runtime/src/one-shot-complete.ts b/packages/agent-runtime/src/one-shot-complete.tsindex 1a173d06b..1344a5626 100644--- a/packages/agent-runtime/src/one-shot-complete.ts+++ b/packages/agent-runtime/src/one-shot-complete.ts@@ -25,6 +25,10 @@ import {withOpenCodeSessionHeaders,} from "./opencode-session-headers.js";import { mergeProviderHeaders, withProviderHeaders } from "./provider-headers.js";+import {+ withProviderFetchFailure,+ type ProviderFetchFailure,+} from "./provider-transport-recovery.js";import {captureProviderResponse,createProviderRetryStream,@@ -83,6 +87,7 @@ export async function completeOneShot(models.streamSimple(requestModel, requestContext, streamOptions));let providerStatus: number | undefined;let providerHeaders: Record<string, string> | undefined;+ let providerFailure: ProviderFetchFailure | undefined;let transientRetryAttempt = 0;let rateLimitRetryAttempt = 0;@@ -92,9 +97,10 @@ export async function completeOneShot(...(options.signal ? { signal: options.signal } : {}),maxRetries: 0,...(thinkingLevel !== "off" ? { reasoning: thinkingLevel } : {}),- fetch: captureProviderResponse(undefined, (response) => {+ fetch: captureProviderResponse(undefined, (response, _requestBytes, failure) => {providerStatus = response?.status;providerHeaders = response?.headers;+ providerFailure = failure;}),},{@@ -131,6 +137,7 @@ export async function completeOneShot(},headers: () => providerHeaders,status: () => providerStatus,+ failure: () => providerFailure,},);const result = await stream.result();@@ -139,7 +146,10 @@ export async function completeOneShot(throw completeError("TURN_ABORTED", "The completion was aborted.");}if (result.stopReason === "error") {- const classified = classifyAgentError(result.errorMessage || "Completion failed.");+ const classified = withProviderFetchFailure(+ classifyAgentError(result.errorMessage || "Completion failed."),+ providerFailure,+ );throw completeError(classified.code,classified.message,diff --git a/packages/agent-runtime/src/opencode-session-headers.test.ts b/packages/agent-runtime/src/opencode-session-headers.test.tsindex 579b1d63c..c965ec7de 100644--- a/packages/agent-runtime/src/opencode-session-headers.test.ts+++ b/packages/agent-runtime/src/opencode-session-headers.test.ts@@ -1,5 +1,5 @@import { readFileSync } from "node:fs";-import { describe, expect, it } from "vitest";+import { describe, expect, it, vi } from "vitest";import {createAssistantMessageEventStream,type AssistantMessage,@@ -271,6 +271,58 @@ describe("completeOneShot OpenCode headers", () => {expect(captured?.sessionId).toBe("session-9");expect(captured?.headers?.[OPENCODE_SESSION_HEADER]).toBeUndefined();});++ it("keeps a certificate rejection terminal in one-shot completions", async () => {+ const fetchSpy = vi.spyOn(globalThis, "fetch").mockRejectedValue(+ Object.assign(new TypeError("fetch failed"), {+ cause: Object.assign(new Error("certificate rejected"), {+ code: "SELF_SIGNED_CERT_IN_CHAIN",+ }),+ }),+ );+ let attempts = 0;+ try {+ await expect(+ completeOneShot(+ provider,+ { systemPrompt: "s", messages: [] },+ "off",+ {+ stream: (_model, _context, options) => {+ attempts += 1;+ const stream = createAssistantMessageEventStream();+ const failed = {+ ...assistantOk(),+ content: [],+ stopReason: "error" as const,+ errorMessage: "fetch failed",+ };+ void options?.fetch?.("https://provider.invalid", {}).then(+ () => {+ stream.push({ type: "error", reason: "error", error: failed });+ stream.end(failed);+ },+ () => {+ stream.push({ type: "error", reason: "error", error: failed });+ stream.end(failed);+ },+ );+ return stream;+ },+ },+ ),+ ).rejects.toMatchObject({+ errorCode: "NETWORK_ERROR",+ data: {+ networkCode: "SELF_SIGNED_CERT_IN_CHAIN",+ retriable: false,+ },+ });+ expect(attempts).toBe(1);+ } finally {+ fetchSpy.mockRestore();+ }+ });});describe("OpenCode header call-site wiring", () => {