From 42b2bc44c58b4bf6c53e5cf680a2189fc976f6e1 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 17:24:11 +0800 Subject: [PATCH 1/5] fix: external summary credential tri-state visibility, per-attempt logging and bounded retry (#3488) --- src/external-summary-credentials.ts | 83 ++++++++++- src/external-summary-http.ts | 126 ++++++++++++++-- src/server.ts | 7 + src/web/api.ts | 12 +- src/web/client.ts | 17 ++- src/web/i18n.ts | 6 + tests/external-summary-http.test.ts | 97 ++++++++++++- tests/external-summary-runtime.test.ts | 10 +- tests/issue3488-credential-status.test.ts | 167 ++++++++++++++++++++++ 9 files changed, 499 insertions(+), 26 deletions(-) create mode 100644 tests/issue3488-credential-status.test.ts diff --git a/src/external-summary-credentials.ts b/src/external-summary-credentials.ts index df9e5fda33..4de43dc9c8 100644 --- a/src/external-summary-credentials.ts +++ b/src/external-summary-credentials.ts @@ -2,12 +2,29 @@ import { closeSync, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readF import { dirname } from "node:path"; import { randomUUID } from "node:crypto"; import { configFile } from "./paths.js"; -import { validSummaryCredentialName } from "./external-summary-settings.js"; +import { loadNamedProviders, loadRoutes, safeReadJson, type NamedProviderRecipe } from "./config.js"; +import { expandExternalSummaryChain, parseExternalSummaryChain, validSummaryCredentialName } from "./external-summary-settings.js"; function validKey(value: unknown): value is string { return typeof value === "string" && value.length > 0 && value.length <= 8192 && !/[\x00-\x20\x7f]/.test(value); } +/** #3488: resolve() has three distinct failure shapes (reference unset, value + * unusable, store unreadable) plus success; configured() collapsed all of + * them to `false`, so the UI could not tell an unset env var from a value + * full of whitespace or a corrupt private store. */ +export type SummaryCredentialState = "configured" | "missing" | "invalid_value" | "store_unreadable" | "invalid_reference"; + +export function describeCredentialState(reference: string, state: SummaryCredentialState): string { + switch (state) { + case "configured": return `${reference} resolves to a usable credential`; + case "missing": return reference.startsWith("env:") ? `environment variable ${reference.slice(4)} is not set` : `credential "${reference.slice(7)}" is not in the private store`; + case "invalid_value": return `environment variable ${reference.slice(4)} holds an unusable value (empty, whitespace/control characters, or over 8192 chars)`; + case "store_unreadable": return "the private credential store is unreadable (permissions or contents)"; + case "invalid_reference": return `${reference} is not a valid credential reference`; + } +} + /** Separate from configFile(): normal config GET/raw exports never read these bytes. */ export class SummaryCredentialStore { constructor(private readonly path: string = `${configFile()}.summary-credentials.json`) {} @@ -43,6 +60,20 @@ export class SummaryCredentialStore { try { return this.resolve(reference, env) !== undefined; } catch { return false; } } + status(reference: string, env: NodeJS.ProcessEnv = process.env): SummaryCredentialState { + if (/^env:[A-Za-z_][A-Za-z0-9_]*$/.test(reference)) { + const value = env[reference.slice(4)]; + return value === undefined ? "missing" : validKey(value) ? "configured" : "invalid_value"; + } + if (reference.startsWith("secret:") && validSummaryCredentialName(reference.slice(7))) { + let values: Record; + try { values = this.read(); } catch { return "store_unreadable"; } + // Stored values are validated on write, so a present entry is always usable. + return values[reference.slice(7)] === undefined ? "missing" : "configured"; + } + return "invalid_reference"; + } + set(name: string, key: string | null): void { if (!validSummaryCredentialName(name) || (key !== null && !validKey(key))) throw new Error("Invalid external summary credential"); mkdirSync(dirname(this.path), { recursive: true, mode: 0o700 }); @@ -71,3 +102,53 @@ export class SummaryCredentialStore { } } } + +/** #3488: readable problems for ONE raw chain block (file form). Unparseable + * blocks return [] — they already surface through config validation and the + * web view's hideInvalidSummary path, so auditing them here would double-report. */ +export function auditExternalSummaryCredentials(block: unknown, recipes: Record, env: NodeJS.ProcessEnv = process.env): string[] { + let chain; + try { chain = parseExternalSummaryChain(block); } catch { return []; } + if (!chain.enabled) return []; + let targets; + try { targets = expandExternalSummaryChain(chain, recipes).targets; } + catch (error) { return [error instanceof Error ? error.message : String(error)]; } + const store = new SummaryCredentialStore(); + const problems: string[] = []; + for (const target of targets) { + const ref = target.credentialRef ?? (target.apiKey === undefined ? "" : "(inline)"); + if (ref === "") problems.push(`target ${target.name}: recipe carries no apiKeyEnv/credentialRef and no inline key`); + else if (ref !== "(inline)") { + const state = store.status(ref, env); + if (state !== "configured") problems.push(`target ${target.name}: ${describeCredentialState(ref, state)}`); + } + } + return problems; +} + +/** #3488: boot-time scan of every EFFECTIVE enabled external-summary chain. + * Walks the same cascade mergeCompress uses (global → route → model, whole + * chain replace) so shadowed blocks are not reported, and identity-dedupes + * because one file object can be effective for many slots. Returns + * human-readable problem lines (empty when everything resolves). */ +export function auditStartupSummaryCredentials(env: NodeJS.ProcessEnv = process.env): string[] { + const file = safeReadJson(configFile()); + const compress = file && typeof file === "object" && !Array.isArray(file) ? (file as { compress?: unknown }).compress : undefined; + const globalBlock = compress && typeof compress === "object" && !Array.isArray(compress) ? (compress as { externalSummary?: unknown }).externalSummary : undefined; + const routes = loadRoutes(env); + const recipes = loadNamedProviders(env); + const seen = new Set(); + const problems: string[] = []; + const audit = (block: unknown): void => { + if (block === undefined || seen.has(block)) return; + seen.add(block); + for (const problem of auditExternalSummaryCredentials(block, recipes, env)) problems.push(problem); + }; + audit(globalBlock); + for (const route of Object.values(routes)) { + const routeBlock = route.compress?.externalSummary; + audit(routeBlock ?? globalBlock); + for (const model of Object.values(route.models ?? {})) audit(model.compress?.externalSummary ?? routeBlock ?? globalBlock); + } + return problems; +} diff --git a/src/external-summary-http.ts b/src/external-summary-http.ts index 91818c0f25..c5967c99f7 100644 --- a/src/external-summary-http.ts +++ b/src/external-summary-http.ts @@ -1,11 +1,82 @@ import type { SummaryCandidate, SummaryWork } from "./external-summary.js"; import { defaultCountTokens } from "acp-kernel"; -import { fetchWithTimeout } from "./fetch-util.js"; +import { classifyUpstreamFailure, isFailFastUpstreamKind } from "./upstream-fail.js"; +import { fetchWithTimeout, isTransientUpstreamError, sleep } from "./fetch-util.js"; import { extractSummaryFromSse, extractSummaryText, summaryPayload, type PreflightProtocol } from "./preflight.js"; +import { log as loggerLog } from "./logger.js"; +import { maskUrlForLog, maskUrlsInText } from "./log-mask.js"; import { normalizeSseLineEndings } from "./sse-util.js"; import { proxyDispatcher } from "./upstream-proxy.js"; import { PACKAGE_NAME, VERSION } from "./version.js"; +/** #3488: bounded retry budget for one candidate call. Total dispatches + * (initial + retries). Retries fire ONLY on transient verdicts and must fit + * the caller's per-attempt deadline (the executor aborts the attempt signal + * at targetTimeoutMs), so the wall-clock bound is unchanged from today's + * single dispatch — a retry can only recover a fast-failing transient, never + * lengthen a pass. */ +const SUMMARY_MAX_ATTEMPTS = 3; +const SUMMARY_RETRY_BASE_DELAY_MS = 1_000; +const SUMMARY_RETRY_MAX_DELAY_MS = 8_000; +/** A hostile Retry-After header must not eat the whole attempt budget. */ +const SUMMARY_RETRY_AFTER_CAP_MS = 15_000; +/** Failure bodies are logged truncated: enough to distinguish auth vs + * rate-limit vs risk-control text without dumping conversation content. */ +const SUMMARY_ERROR_BODY_LOG_CHARS = 1_024; +/** How much of a failure body to PULL at all — a hostile 5xx must not be + * buffered whole just to log its first kilobyte. */ +const SUMMARY_ERROR_BODY_READ_CHARS = 8_192; + +let summaryRetryDelayOverrideMs: number | null = null; +const scheduledSummaryRetryDelaysMs: number[] = []; +/** Test seam (#3488): override the actual sleep duration and record each + * scheduled delay so tests can assert backoff/Retry-After math without + * wall-clock waits. null = production behavior. */ +export function _setSummaryRetryDelayForTest(overrideMs: number | null): void { + summaryRetryDelayOverrideMs = overrideMs; + scheduledSummaryRetryDelaysMs.length = 0; +} +export function _summaryRetryDelaysForTest(): readonly number[] { + return scheduledSummaryRetryDelaysMs; +} + +function backoffDelayMs(attempt: number): number { + return Math.min(SUMMARY_RETRY_BASE_DELAY_MS * 2 ** (attempt - 1), SUMMARY_RETRY_MAX_DELAY_MS); +} + +function retryAfterDelayMs(header: string | null, fallbackMs: number): number { + if (header !== null) { + const seconds = Number(header); + if (Number.isFinite(seconds) && seconds >= 0) return Math.min(Math.ceil(seconds * 1000), SUMMARY_RETRY_AFTER_CAP_MS); + const dateMs = Date.parse(header); + if (!Number.isNaN(dateMs)) return Math.min(Math.max(dateMs - Date.now(), 0), SUMMARY_RETRY_AFTER_CAP_MS); + } + return fallbackMs; +} + +async function waitBeforeRetry(ms: number, signal: AbortSignal): Promise { + scheduledSummaryRetryDelaysMs.push(ms); + await sleep(summaryRetryDelayOverrideMs ?? ms, signal); +} + +async function readErrorSnippet(response: Response): Promise { + try { + const reader = response.body?.getReader(); + if (!reader) return ""; + const decoder = new TextDecoder("utf-8"); + let text = ""; + for (;;) { + const { done, value } = await reader.read(); + if (done) break; + text += decoder.decode(value, { stream: true }); + if (text.length >= SUMMARY_ERROR_BODY_READ_CHARS) { await reader.cancel().catch(() => { }); break; } + } + const trimmed = text.trim().replace(/\s+/g, " "); + if (!trimmed) return ""; + return trimmed.length > SUMMARY_ERROR_BODY_LOG_CHARS ? `${trimmed.slice(0, SUMMARY_ERROR_BODY_LOG_CHARS)}…` : trimmed; + } catch { return ""; } +} + /** Internal resolved request plan, not a user-config schema or credential store. */ export interface SummaryHttpTarget { readonly protocol: PreflightProtocol; @@ -160,22 +231,49 @@ export function createSummaryHttpCandidate(target: SummaryHttpTarget, maxRespons } } // Reuse the existing codecs without carrying the main request's auth or - // model. Each candidate dispatches exactly once. (The Go-specific + // model. Bounded retry (#3488): transient verdicts (429/5xx/risk-control + // body markers, fail-fast pre-response network deaths) re-dispatch up to + // SUMMARY_MAX_ATTEMPTS times total, honoring Retry-After within the cap. + // Every failed attempt lands in the local log with status + truncated + // body — the executor maps errors to outcome enums, so without this the + // operator sees nothing but `attempts=[t0:error]`. (The Go-specific // x-opencode-session / user-agent above are derived from bili's own // session id, not copied from the client's inbound headers — #2760.) - const { response, clearTimer } = await fetchWithTimeout(plan.url, { - method: "POST", headers: plan.headers, body: JSON.stringify(payload), redirect: "manual", dispatcher: proxyDispatcher(plan.proxyUrl), - }, undefined, signal); - try { - if (!response.ok) { - try { await response.body?.cancel(); } catch { /* transport may already be closed */ } - throw new Error("External summary upstream rejected the request"); - } - const result = parseSummary(plan.protocol, await readResponse(response, maxResponseBytes)); + const host = maskUrlForLog(plan.url); + let attempt = 0; + for (;;) { + attempt += 1; signal.throwIfAborted(); - return result; - } finally { - clearTimer(); + let dispatched; + try { + dispatched = await fetchWithTimeout(plan.url, { + method: "POST", headers: plan.headers, body: JSON.stringify(payload), redirect: "manual", dispatcher: proxyDispatcher(plan.proxyUrl), + }, undefined, signal); + } catch (error) { + const kind = classifyUpstreamFailure(error, { viaProxy: plan.proxyUrl !== undefined, externalAborted: signal.aborted }); + loggerLog("warn", `[external-summary] candidate ${plan.model} attempt ${attempt}/${SUMMARY_MAX_ATTEMPTS} failed before response (${kind}): ${maskUrlsInText(error instanceof Error ? error.message : String(error))}`); + if (attempt < SUMMARY_MAX_ATTEMPTS && !signal.aborted && isFailFastUpstreamKind(kind)) { + await waitBeforeRetry(backoffDelayMs(attempt), signal); + continue; + } + throw error; + } + try { + if (!dispatched.response.ok) { + const snippet = await readErrorSnippet(dispatched.response); + loggerLog("warn", `[external-summary] candidate ${plan.model} attempt ${attempt}/${SUMMARY_MAX_ATTEMPTS} rejected: HTTP ${dispatched.response.status} from ${host}${snippet ? ` — ${snippet}` : ""}`); + if (attempt < SUMMARY_MAX_ATTEMPTS && !signal.aborted && isTransientUpstreamError(dispatched.response.status, snippet)) { + await waitBeforeRetry(retryAfterDelayMs(dispatched.response.headers.get("retry-after"), backoffDelayMs(attempt)), signal); + continue; + } + throw new Error(`External summary upstream rejected the request with HTTP ${dispatched.response.status}`); + } + const result = parseSummary(plan.protocol, await readResponse(dispatched.response, maxResponseBytes)); + signal.throwIfAborted(); + return result; + } finally { + dispatched.clearTimer(); + } } }, }; diff --git a/src/server.ts b/src/server.ts index 229056ebc7..cf605af5eb 100644 --- a/src/server.ts +++ b/src/server.ts @@ -81,6 +81,7 @@ import { rulesEnabled, storeEffectiveRules } from "./rules-feature.js"; import { storeEffectiveSearchPlanAware } from "./decompress-shared.js"; import { armAutoFoldBackoff, autoFoldEngaged, AUTO_FOLD_BACKOFF_MS, externalQueueDroppedAll, withExternalSummaryTools } from "./external-summary-surface.js"; import { AUTO_FOLD_TARGET_MIN } from "./external-summary-settings.js"; +import { auditStartupSummaryCredentials } from "./external-summary-credentials.js"; import { applyRanges } from "./stream.js"; import { attachSubagentSessions } from "./subagent-sessions.js"; import { buildSessionCacheReport, handleAcpCache, learnedImageReserve, noteClientAbort, readKeySwitchStats, readModelSwitchStats, settleUsageReport } from "./cache-ledger.js"; @@ -1136,6 +1137,12 @@ export async function startServer(opts: ProxyOptions): Promise { ); } } + // #3488: a broken external-summary credential used to surface only as a + // once-per-process warn at first dial; audit every effective enabled + // chain now so "which env var / secret is broken" is answerable at boot. + for (const problem of auditStartupSummaryCredentials()) { + log("warn", `[config] external summary credential: ${problem}`); + } // #1723: residual zone drift is now an exception, not the norm — a // lane'd launch landing ABOVE its preferred port means that port was // held by something we must not wait on (foreign squatter, same-code diff --git a/src/web/api.ts b/src/web/api.ts index 69f4cd5a33..70e7eec0c3 100644 --- a/src/web/api.ts +++ b/src/web/api.ts @@ -20,7 +20,7 @@ import { } from "../config.js"; import { log } from "../logger.js"; import { validateHttpProxy } from "../upstream-proxy.js"; -import { SummaryCredentialStore } from "../external-summary-credentials.js"; +import { SummaryCredentialStore, type SummaryCredentialState } from "../external-summary-credentials.js"; import { parseExternalSummaryChain, expandExternalSummaryChain } from "../external-summary-settings.js"; import { agentProviderRecipes, agentRegistryStatus } from "../agent-providers.js"; @@ -91,6 +91,9 @@ export async function handleConfigGet(res: ServerResponse): Promise { const config = readConfig(); const rawCompress = config.compress && typeof config.compress === "object" ? config.compress as Record : undefined; const credentialStatus: Record = {}; + // #3488: additive five-state view (missing vs invalid value vs unreadable + // store) alongside the legacy boolean record scripts already consume. + const credentialDetail: Record = {}; let hideInvalidSummary = false; // Disabled chains skip strict target validation (an inert chain must not // brick the config view), so surface credential status from the raw @@ -112,7 +115,11 @@ export async function handleConfigGet(res: ServerResponse): Promise { ? Object.values(loadNamedProviders()).flatMap((recipe) => recipe.credentialRef !== undefined ? [`secret:${recipe.credentialRef}`] : recipe.apiKeyEnv !== undefined ? [`env:${recipe.apiKeyEnv}`] : []) : rawCredentialRefs(rawCompress.externalSummary); const store = new SummaryCredentialStore(); - for (const ref of refs) credentialStatus[ref] = store.configured(ref); + for (const ref of refs) { + const state = store.status(ref); + credentialStatus[ref] = state === "configured"; + credentialDetail[ref] = state; + } } catch { // A manually edited invalid block can contain inline credentials. // Never echo that block through either structured or raw config GET. @@ -130,6 +137,7 @@ export async function handleConfigGet(res: ServerResponse): Promise { upstreamProxyMode: upstream.mode, compress: config.compress ?? null, externalSummaryCredentials: credentialStatus, + externalSummaryCredentialStatus: credentialDetail, agentProviders: agentRegistryStatus(), passthrough: passthroughState(process.env), allowDshCompaction: allowDshCompactionState(process.env), diff --git a/src/web/client.ts b/src/web/client.ts index dfce0e086b..16434caa7b 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -276,7 +276,9 @@ export const WEB_CLIENT = `(function () { const res = await fetch(url, Object.assign({}, opts, ac ? { signal: ac.signal } : {})); let body = null; try { body = await res.json(); } catch (e) {} - if (!res.ok) throw new Error(body && body.error ? String(body.error) : "HTTP " + res.status); + // #3488: server errors may be objects ({type, message}); String() on + // them rendered "[object Object]" in the toast. + if (!res.ok) throw new Error(body && body.error ? (typeof body.error === "object" ? String(body.error.message || body.error.type || JSON.stringify(body.error)) : String(body.error)) : "HTTP " + res.status); return body; } finally { if (timer !== null) clearTimeout(timer); @@ -2473,6 +2475,8 @@ export const WEB_CLIENT = `(function () { const box = $("summary-fields"), fe = $("cfg-file-edit"); if (!box || !fe) return; const status = Object.assign({}, cfg.externalSummaryCredentials || {}); + // #3488: five-state view; falls back to the legacy boolean on old servers. + const detail = cfg.externalSummaryCredentialStatus || {}; function read() { const draft = JSON.parse(fe.value || "{}"); if (!draft || typeof draft !== "object" || Array.isArray(draft)) throw new Error(t("cfg.invalid_json")); @@ -2578,7 +2582,14 @@ export const WEB_CLIENT = `(function () { const row = document.createElement("div"); row.className = "summary-actions"; const ref = typeof recipe.credentialRef === "string" ? "secret:" + recipe.credentialRef : typeof recipe.apiKeyEnv === "string" ? "env:" + recipe.apiKeyEnv : null; const label = document.createElement("span"); label.textContent = name + " · " + (ref || "—"); row.appendChild(label); - const badge = document.createElement("span"); badge.className = "badge " + (ref && status[ref] ? "ok" : "disk"); badge.textContent = ref && status[ref] ? t("summary.key_set") : t("summary.key_missing"); row.appendChild(badge); + // #3488: distinguish "not set" from "set but unusable" and + // "store broken" — all of them used to render as 未配置. + const state = ref ? detail[ref] : undefined; + const badgeState = state === "configured" || state === undefined && ref && status[ref] ? "configured" : state === "missing" ? "missing" : state; + const badge = document.createElement("span"); + badge.className = "badge " + (badgeState === "configured" ? "ok" : badgeState === "missing" ? "disk" : "warn"); + badge.textContent = badgeState === "configured" ? t("summary.key_set") : badgeState === "missing" ? t("summary.key_missing") : badgeState === "invalid_value" ? t("summary.key_invalid") : badgeState === "store_unreadable" ? t("summary.key_unreadable") : t("summary.key_bad_ref"); + row.appendChild(badge); if (ref && ref.indexOf("secret:") === 0) { const key = field(row, "summary-key-" + name, t("summary.key"), "", () => {}, "password"); key.autocomplete = "new-password"; key.disabled = !!cfg.parseError; @@ -2586,7 +2597,7 @@ export const WEB_CLIENT = `(function () { busy(btn, true); try { const result = await json(API_ROOT + "/external-summary/credential", { method: "PUT", headers: { "content-type": "application/json" }, body: JSON.stringify({ name: recipe.credentialRef, key: value }) }); - key.value = ""; status[ref] = result.configured; + key.value = ""; status[ref] = result.configured; detail[ref] = result.configured ? "configured" : "missing"; render(); toast(t("summary.key_saved"), "ok"); } catch (e) { toast(e.message, "err"); } finally { busy(btn, false); } diff --git a/src/web/i18n.ts b/src/web/i18n.ts index dee2ee9f16..5de709b3a1 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -15,6 +15,9 @@ export const MESSAGES: Record> = { "summary.key_delete": "删除 Key", "summary.key_set": "已配置", "summary.key_missing": "未配置", + "summary.key_invalid": "值不可用(空、含空白/控制字符或超长)", + "summary.key_unreadable": "凭据存储不可读(权限或内容损坏)", + "summary.key_bad_ref": "引用格式无效", "summary.key_saved": "Key 已保存", "summary.total": "总时限 (ms)", "summary.timeout": "单目标时限 (ms)", @@ -494,6 +497,9 @@ export const MESSAGES: Record> = { "summary.key_delete": "Delete Key", "summary.key_set": "Configured", "summary.key_missing": "Not configured", + "summary.key_invalid": "Value unusable (empty, whitespace/control chars, or too long)", + "summary.key_unreadable": "Credential store unreadable (permissions or contents)", + "summary.key_bad_ref": "Invalid reference format", "summary.key_saved": "Key saved", "summary.total": "Total deadline (ms)", "summary.timeout": "Per-target timeout (ms)", diff --git a/tests/external-summary-http.test.ts b/tests/external-summary-http.test.ts index 042d00a0b7..81690ac15e 100644 --- a/tests/external-summary-http.test.ts +++ b/tests/external-summary-http.test.ts @@ -2,8 +2,9 @@ import assert from "node:assert/strict"; import http from "node:http"; import { afterEach, test } from "node:test"; import { ExternalSummaryExecutor, type SummaryWork } from "../src/external-summary.ts"; -import { createSummaryHttpCandidate, type SummaryHttpTarget } from "../src/external-summary-http.ts"; +import { createSummaryHttpCandidate, _setSummaryRetryDelayForTest, _summaryRetryDelaysForTest, type SummaryHttpTarget } from "../src/external-summary-http.ts"; import { _liveUpstreamTimersForTest } from "../src/fetch-util.ts"; +import { setLogCapture } from "../src/logger.ts"; import type { PreflightProtocol } from "../src/preflight.ts"; process.env.NODE_ENV = "test"; @@ -12,7 +13,11 @@ const budget = { totalTimeoutMs: 4000, targetTimeoutMs: 1500, maxSummaryBytes: 2 const summary = "Retained decisions, evidence, constraints and unfinished objectives."; const frame = (value: unknown) => `data: ${JSON.stringify(value)}\n\n`; -afterEach(() => assert.equal(_liveUpstreamTimersForTest(), 0)); +afterEach(() => { + _setSummaryRetryDelayForTest(null); + setLogCapture(null); + assert.equal(_liveUpstreamTimersForTest(), 0); +}); function completion(protocol: PreflightProtocol, text = summary): object { if (protocol === "responses") return { status: "completed", output_text: text }; @@ -82,9 +87,10 @@ for (const protocol of ["responses", "anthropic", "openai", "google"] as const) } } -for (const status of [400, 401, 403, 429, 500, 503]) { - test(`external summary HTTP: ${status} switches once to the backup without leaking errors`, async () => { +for (const status of [400, 401, 403]) { + test(`external summary HTTP: ${status} fails fast to the backup without leaking errors`, async () => { const paths: string[] = []; + _setSummaryRetryDelayForTest(0); await upstream((req, res) => { paths.push(req.url ?? ""); res.writeHead(req.url === "/primary" ? status : 200); @@ -97,9 +103,92 @@ for (const status of [400, 401, 403, 429, 500, 503]) { assert.equal(JSON.stringify(result).includes("test-summary-key"), false); }); assert.deepEqual(paths, ["/primary", "/backup"]); + assert.deepEqual(_summaryRetryDelaysForTest(), []); }); } +for (const status of [429, 500, 503]) { + test(`external summary HTTP: transient ${status} retries twice then switches to the backup without leaking errors`, async () => { + const paths: string[] = []; + const lines: string[] = []; + _setSummaryRetryDelayForTest(0); + setLogCapture((_level, msg) => lines.push(msg)); + await upstream((req, res) => { + paths.push(req.url ?? ""); + res.writeHead(req.url === "/primary" ? status : 200); + res.end(req.url === "/primary" ? "private-error test-summary-key" : JSON.stringify(completion("responses"))); + }, async (url) => { + const result = await new ExternalSummaryExecutor(1).execute(work, [createSummaryHttpCandidate(target(`${url}/primary`), 4096), createSummaryHttpCandidate(target(`${url}/backup`), 4096)], budget); + assert.equal(result.status, "success"); + if (result.status === "success") assert.equal(result.targetIndex, 1); + // #3488: results stay leak-free while the LOCAL log carries the + // per-attempt status + truncated body. + assert.equal(JSON.stringify(result).includes("private-error"), false); + assert.equal(JSON.stringify(result).includes("test-summary-key"), false); + assert.equal(lines.filter((line) => line.includes(`rejected: HTTP ${status}`)).length, 3); + assert.ok(lines.some((line) => line.includes(`rejected: HTTP ${status}`) && line.includes("private-error"))); + }); + assert.deepEqual(paths, ["/primary", "/primary", "/primary", "/backup"]); + assert.deepEqual(_summaryRetryDelaysForTest(), [1000, 2000]); + }); +} + +test("external summary HTTP: a transient 429 with Retry-After recovers on the second dispatch", async () => { + let hits = 0; + _setSummaryRetryDelayForTest(0); + await upstream((_req, res) => { + hits++; + if (hits === 1) { res.writeHead(429, { "retry-after": "1" }); res.end("rate limited"); return; } + res.end(JSON.stringify(completion("responses"))); + }, async (url) => { + const result = await new ExternalSummaryExecutor(1).execute(work, [createSummaryHttpCandidate(target(url), 4096)], budget); + assert.equal(result.status, "success"); + if (result.status === "success") assert.equal(result.targetIndex, 0); + }); + assert.equal(hits, 2); + assert.deepEqual(_summaryRetryDelaysForTest(), [1000]); +}); + +test("external summary HTTP: a risk-control 403 body retries like a rate limit", async () => { + let hits = 0; + _setSummaryRetryDelayForTest(0); + await upstream((_req, res) => { + hits++; + if (hits < 3) { res.writeHead(403); res.end('{"code":3007,"msg":"captcha verify failed"}'); return; } + res.end(JSON.stringify(completion("responses"))); + }, async (url) => { + const result = await new ExternalSummaryExecutor(1).execute(work, [createSummaryHttpCandidate(target(url), 4096)], budget); + assert.equal(result.status, "success"); + }); + assert.equal(hits, 3); +}); + +test("external summary HTTP: a pre-response socket death retries then recovers", async () => { + let hits = 0; + _setSummaryRetryDelayForTest(0); + await upstream((_req, res) => { + hits++; + if (hits === 1) { res.destroy(); return; } + res.end(JSON.stringify(completion("responses"))); + }, async (url) => { + const result = await new ExternalSummaryExecutor(1).execute(work, [createSummaryHttpCandidate(target(url), 4096)], budget); + assert.equal(result.status, "success"); + }); + assert.equal(hits, 2); +}); + +test("external summary HTTP: an exhausted transient chain logs every attempt and fails closed", async () => { + const lines: string[] = []; + _setSummaryRetryDelayForTest(0); + setLogCapture((_level, msg) => lines.push(msg)); + await upstream((_req, res) => { res.writeHead(503); res.end("upstream unavailable"); }, async (url) => { + const result = await new ExternalSummaryExecutor(1).execute(work, [createSummaryHttpCandidate(target(url), 4096)], budget); + assert.equal(result.status, "failed"); + assert.deepEqual(result.attempts, [{ targetIndex: 0, outcome: "error" }]); + }); + assert.equal(lines.filter((line) => line.includes("rejected: HTTP 503")).length, 3); +}); + for (const protocol of ["responses", "anthropic", "openai", "google"] as const) { test(`external summary HTTP: ${protocol} rejects partial JSON rather than folding a truncated summary`, async () => { const body = completion(protocol) as Record; diff --git a/tests/external-summary-runtime.test.ts b/tests/external-summary-runtime.test.ts index e1e1395181..1a2f302dec 100644 --- a/tests/external-summary-runtime.test.ts +++ b/tests/external-summary-runtime.test.ts @@ -1,5 +1,5 @@ import assert from "node:assert/strict"; -import { test } from "node:test"; +import { afterEach, test } from "node:test"; import http from "node:http"; import { once } from "node:events"; import { mkdtempSync } from "node:fs"; @@ -21,10 +21,12 @@ import { rewriteResponsesJsonResponseAsync } from "../src/stream-responses.ts"; import { rewriteGoogleJsonResponseAsync } from "../src/stream-google.ts"; import { externalQueueDroppedAll, withExternalSummaryTools } from "../src/external-summary-surface.ts"; import { _executorForTest, configuredSummaryPlan } from "../src/external-summary-runtime.ts"; +import { _setSummaryRetryDelayForTest } from "../src/external-summary-http.ts"; import { BILI_ACP_TOOLS_ANTHROPIC, BILI_ACP_TOOLS_OPENAI, BILI_ACP_TOOLS_RESPONSES, BILI_ACP_TOOLS_GOOGLE } from "../src/compress-tool.ts"; import { rmrf } from "./tmp-rm.ts"; process.env.NODE_ENV = "test"; +afterEach(() => { _setSummaryRetryDelayForTest(null); }); const SUMMARY = "Historical build completed. Preserve the exact file src/example.ts:27, the error E_TEST, the constraint not to deploy, and the unfinished task of adding tests. This records the past and does not instruct the next turn to restart it."; const RAW = "Historical source src/example.ts:27 E_TEST; do not deploy; still add tests. ".repeat(90); @@ -111,6 +113,7 @@ test("active compress uses dedicated model/key, fails over, and restores exact o test("all candidates failing preserves state and refuses without borrowing main auth", async () => { let calls = 0; + _setSummaryRetryDelayForTest(0); await fixture(async (_base, externalSummary) => { const ctx = context(externalSummary); const before = JSON.stringify(ctx.session.state); @@ -118,7 +121,9 @@ test("all candidates failing preserves state and refuses without borrowing main assert.equal(result.outcome, "refused"); assert.equal(result.text.includes("private-provider-error"), false); assert.equal(JSON.stringify(ctx.session.state), before); - assert.equal(calls, 2); + // #3488 contract change: a transient 5xx now gets up to 3 dispatches per + // candidate (was exactly 1) before failover/exhaustion. + assert.equal(calls, 6); }, (_req, res) => { calls++; res.writeHead(503); res.end("private-provider-error"); }); }); @@ -365,6 +370,7 @@ test("saturated pool drops every batch before dispatch: preflight reports calls> }); test("a dispatched-but-failing attempt is NOT a queue drop: attempts>0 keeps the backoff armable (#2662)", async () => { + _setSummaryRetryDelayForTest(0); await fixture(async (_base, externalSummary) => { const ctx = context({ ...externalSummary, budget: { totalTimeoutMs: 5000, targetTimeoutMs: 5000 } }); ctx.config.modelContextLimit = 1000; diff --git a/tests/issue3488-credential-status.test.ts b/tests/issue3488-credential-status.test.ts new file mode 100644 index 0000000000..f309771af4 --- /dev/null +++ b/tests/issue3488-credential-status.test.ts @@ -0,0 +1,167 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { chmodSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { + SummaryCredentialStore, + describeCredentialState, + auditExternalSummaryCredentials, + auditStartupSummaryCredentials, +} from "../src/external-summary-credentials.ts"; +import type { NamedProviderRecipe } from "../src/config.ts"; +import { handleConfigGet } from "../src/web/api.ts"; +import { rmrf } from "./tmp-rm.ts"; + +// #3488: the credential tri-state used to collapse to one boolean, so the UI +// could not tell "env var unset" from "value full of whitespace" from "store +// unreadable". These pin each state, the startup audit, and the additive +// config-GET field. + +const root = path.join(tmpdir(), `bili-issue3488-${process.pid}-${Date.now()}`); +const biliConfig = path.join(root, "billion-context.json"); +const storePath = `${biliConfig}.summary-credentials.json`; +const savedConfigFile = process.env.BILI_CONFIG_FILE; + +mkdirSync(root, { recursive: true }); +process.env.BILI_CONFIG_FILE = biliConfig; +writeFileSync(biliConfig, "{}\n", "utf8"); + +test.after(() => { + if (savedConfigFile === undefined) delete process.env.BILI_CONFIG_FILE; + else process.env.BILI_CONFIG_FILE = savedConfigFile; + rmrf(root); +}); + +test("credential status: env references distinguish missing, invalid value and configured", () => { + const store = new SummaryCredentialStore(); + assert.equal(store.status("env:ISSUE3488_NOPE", {}), "missing"); + assert.equal(store.status("env:ISSUE3488_NOPE", { ISSUE3488_NOPE: "sk-real" }), "configured"); + assert.equal(store.status("env:ISSUE3488_NOPE", { ISSUE3488_NOPE: "a b" }), "invalid_value"); + assert.equal(store.status("env:ISSUE3488_NOPE", { ISSUE3488_NOPE: "\t" }), "invalid_value"); + assert.equal(store.status("env:ISSUE3488_NOPE", { ISSUE3488_NOPE: "" }), "invalid_value"); + assert.equal(store.status("env:ISSUE3488_NOPE", { ISSUE3488_NOPE: "x".repeat(8193) }), "invalid_value"); +}); + +test("credential status: malformed references are reported as such, not as missing", () => { + const store = new SummaryCredentialStore(); + assert.equal(store.status("bogus"), "invalid_reference"); + assert.equal(store.status("env:9BAD"), "invalid_reference"); + assert.equal(store.status("secret:bad name!"), "invalid_reference"); +}); + +test("credential status: secret store lifecycle incl. corrupt and world-readable stores", () => { + const store = new SummaryCredentialStore(); + assert.equal(store.status("secret:nexus", {}), "missing"); + store.set("nexus", "sk-test-3488"); + assert.equal(new SummaryCredentialStore().status("secret:nexus", {}), "configured"); + store.set("nexus", null); + assert.equal(store.status("secret:nexus", {}), "missing"); + + store.set("nexus", "sk-test-3488"); + writeFileSync(storePath, "{not json\n", "utf8"); + assert.equal(store.status("secret:nexus", {}), "store_unreadable"); + + if (process.platform !== "win32") { + // A corrupt store must NOT be silently overwritten by set() (fail-fast); + // restore valid contents first, then loosen perms to hit the mode gate. + assert.throws(() => store.set("nexus", "sk-test-3488"), /unavailable|repair/); + writeFileSync(storePath, JSON.stringify({ nexus: "sk-test-3488" }) + "\n", "utf8"); + chmodSync(storePath, 0o644); + assert.equal(store.status("secret:nexus", {}), "store_unreadable"); + } +}); + +test("describeCredentialState names the exact broken thing", () => { + assert.match(describeCredentialState("env:NEXUS_API_KEY", "missing"), /NEXUS_API_KEY is not set/); + assert.match(describeCredentialState("env:NEXUS_API_KEY", "invalid_value"), /unusable value/); + assert.match(describeCredentialState("secret:nexus", "missing"), /not in the private store/); + assert.match(describeCredentialState("secret:nexus", "store_unreadable"), /unreadable/); + assert.match(describeCredentialState("bogus", "invalid_reference"), /not a valid credential reference/); +}); + +const recipes: Record = { + nexus: { baseUrl: "http://127.0.0.1:9/v1", api: "openai", apiKeyEnv: "NEXUS_API_KEY", models: { free: {} } }, +}; + +test("chain audit: reports broken refs per target, silent when everything resolves", () => { + const chain = { enabled: true, targets: ["nexus/free"] }; + let problems = auditExternalSummaryCredentials(chain, recipes, {}); + assert.equal(problems.length, 1); + assert.match(problems[0], /target nexus--free|target nexus\/free/); + assert.match(problems[0], /NEXUS_API_KEY is not set/); + + problems = auditExternalSummaryCredentials(chain, recipes, { NEXUS_API_KEY: "a b" }); + assert.equal(problems.length, 1); + assert.match(problems[0], /unusable value/); + + assert.deepEqual(auditExternalSummaryCredentials(chain, recipes, { NEXUS_API_KEY: "sk-x" }), []); + assert.deepEqual(auditExternalSummaryCredentials({ enabled: false, targets: ["nexus/free"] }, recipes, {}), []); + assert.deepEqual(auditExternalSummaryCredentials({ enabled: true }, recipes, {}), []); + + problems = auditExternalSummaryCredentials({ enabled: true, targets: ["ghost/model"] }, recipes, {}); + assert.equal(problems.length, 1); + assert.match(problems[0], /ghost/); +}); + +test("startup audit walks the global/route/model cascade and reports each effective broken chain once", () => { + writeFileSync(biliConfig, JSON.stringify({ + providers: { + nexus: { baseUrl: "http://127.0.0.1:9/v1", api: "openai", apiKeyEnv: "AUDIT_A", models: { free: {} } }, + other: { baseUrl: "http://127.0.0.1:10/v1", api: "openai", apiKeyEnv: "AUDIT_B", models: { small: {} } }, + "http://127.0.0.1:4000": { models: { free: { compress: { externalSummary: { enabled: true, targets: ["other/small"] } } } } }, + }, + compress: { externalSummary: { enabled: true, targets: ["nexus/free"] } }, + }, null, 2) + "\n", "utf8"); + + let problems = auditStartupSummaryCredentials({}); + assert.equal(problems.length, 2); + assert.ok(problems.some((p) => p.includes("AUDIT_A is not set"))); + assert.ok(problems.some((p) => p.includes("AUDIT_B is not set"))); + + problems = auditStartupSummaryCredentials({ AUDIT_A: "key-a" }); + assert.equal(problems.length, 1); + assert.ok(problems[0].includes("AUDIT_B is not set")); + + assert.deepEqual(auditStartupSummaryCredentials({ AUDIT_A: "key-a", AUDIT_B: "key-b" }), []); +}); + +function captureConfigGet(): Promise> { + return new Promise((resolve, reject) => { + const res = { + writeHead(_code: number, _headers?: Record): void { }, + end(data?: string): void { + try { resolve(JSON.parse(data ?? "{}") as Record); } catch (error) { reject(error); } + }, + }; + handleConfigGet(res as unknown as Parameters[0]).catch(reject); + }); +} + +test("config GET exposes the five-state map additively next to the legacy boolean record", async () => { + writeFileSync(biliConfig, JSON.stringify({ + providers: { + nexus: { baseUrl: "http://127.0.0.1:9/v1", api: "openai", apiKeyEnv: "WEB_KEY_3488", models: { free: {} } }, + }, + compress: { externalSummary: { enabled: true, targets: ["nexus/free"] } }, + }, null, 2) + "\n", "utf8"); + delete process.env.WEB_KEY_3488; + try { + let body = await captureConfigGet(); + assert.deepEqual(body.externalSummaryCredentials, { "env:WEB_KEY_3488": false }); + assert.deepEqual(body.externalSummaryCredentialStatus, { "env:WEB_KEY_3488": "missing" }); + + process.env.WEB_KEY_3488 = "a b"; + body = await captureConfigGet(); + assert.deepEqual(body.externalSummaryCredentials, { "env:WEB_KEY_3488": false }); + assert.deepEqual(body.externalSummaryCredentialStatus, { "env:WEB_KEY_3488": "invalid_value" }); + + process.env.WEB_KEY_3488 = "good-key"; + body = await captureConfigGet(); + assert.deepEqual(body.externalSummaryCredentials, { "env:WEB_KEY_3488": true }); + assert.deepEqual(body.externalSummaryCredentialStatus, { "env:WEB_KEY_3488": "configured" }); + } finally { + delete process.env.WEB_KEY_3488; + writeFileSync(biliConfig, "{}\n", "utf8"); + } +}); From 057aab1e75c8b40cee314f94bf1b672c454b8172 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 19:36:46 +0800 Subject: [PATCH 2/5] fix(external-summary): keep retry delay recording to test mode and mask urls in logged snippets Review fixes on #3541 (two small defects in the new retry loop): - waitBeforeRetry pushed every scheduled delay into the module-level scheduledSummaryRetryDelaysMs array even in production (override null), so long-lived processes leaked entries on every transient retry. The recording now only happens when the test override is armed. - the HTTP failure body snippet was logged raw while the pre-response path masks its error text; maskUrlsInText now applies to the log line only (the transient verdict below still needs the raw body markers). --- src/external-summary-http.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/external-summary-http.ts b/src/external-summary-http.ts index c5967c99f7..df060e4a35 100644 --- a/src/external-summary-http.ts +++ b/src/external-summary-http.ts @@ -55,7 +55,9 @@ function retryAfterDelayMs(header: string | null, fallbackMs: number): number { } async function waitBeforeRetry(ms: number, signal: AbortSignal): Promise { - scheduledSummaryRetryDelaysMs.push(ms); + // Recording is a test seam: in production (override null) the array must + // stay empty or every transient retry leaks entries into it forever. + if (summaryRetryDelayOverrideMs !== null) scheduledSummaryRetryDelaysMs.push(ms); await sleep(summaryRetryDelayOverrideMs ?? ms, signal); } @@ -261,7 +263,8 @@ export function createSummaryHttpCandidate(target: SummaryHttpTarget, maxRespons try { if (!dispatched.response.ok) { const snippet = await readErrorSnippet(dispatched.response); - loggerLog("warn", `[external-summary] candidate ${plan.model} attempt ${attempt}/${SUMMARY_MAX_ATTEMPTS} rejected: HTTP ${dispatched.response.status} from ${host}${snippet ? ` — ${snippet}` : ""}`); + // Mask only for the log line: the verdict below needs the raw body markers. + loggerLog("warn", `[external-summary] candidate ${plan.model} attempt ${attempt}/${SUMMARY_MAX_ATTEMPTS} rejected: HTTP ${dispatched.response.status} from ${host}${snippet ? ` — ${maskUrlsInText(snippet)}` : ""}`); if (attempt < SUMMARY_MAX_ATTEMPTS && !signal.aborted && isTransientUpstreamError(dispatched.response.status, snippet)) { await waitBeforeRetry(retryAfterDelayMs(dispatched.response.headers.get("retry-after"), backoffDelayMs(attempt)), signal); continue; From 1d30702b77434a7359c2ab992a2b117f7e35361a Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 19:36:46 +0800 Subject: [PATCH 3/5] fix(web): summary credential badge falls back to legacy boolean instead of mislabeling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The five-state badge expression left badgeState undefined when no detail entry existed AND the legacy boolean was false — reachable for recipes without credentialRef/apiKeyEnv (agent-registered #2336 providers) on NEW servers, rendering 'Invalid reference format' where the pre-PR UI showed 'Not configured'. Fallback now maps absent detail to configured/missing from the legacy record. --- src/web/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/client.ts b/src/web/client.ts index 16434caa7b..bf50d9f439 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -2585,7 +2585,7 @@ export const WEB_CLIENT = `(function () { // #3488: distinguish "not set" from "set but unusable" and // "store broken" — all of them used to render as 未配置. const state = ref ? detail[ref] : undefined; - const badgeState = state === "configured" || state === undefined && ref && status[ref] ? "configured" : state === "missing" ? "missing" : state; + const badgeState = state !== undefined ? state : (ref && status[ref]) ? "configured" : "missing"; const badge = document.createElement("span"); badge.className = "badge " + (badgeState === "configured" ? "ok" : badgeState === "missing" ? "disk" : "warn"); badge.textContent = badgeState === "configured" ? t("summary.key_set") : badgeState === "missing" ? t("summary.key_missing") : badgeState === "invalid_value" ? t("summary.key_invalid") : badgeState === "store_unreadable" ? t("summary.key_unreadable") : t("summary.key_bad_ref"); From 5f649d700679095ba6ff322861d19fda5f119f17 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 19:36:46 +0800 Subject: [PATCH 4/5] test(external-summary): pin Retry-After math with a header value distinct from backoff MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit retry-after: '1' computed to 1000 ms — identical to the attempt-1 backoff fallback — so the [1000] assertion could not tell a honored header from an ignored one. Now uses '7' (asserts [7000]) and adds a hostile '999' case pinning the 15 s cap. --- tests/external-summary-http.test.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/external-summary-http.test.ts b/tests/external-summary-http.test.ts index 81690ac15e..631ddbaba1 100644 --- a/tests/external-summary-http.test.ts +++ b/tests/external-summary-http.test.ts @@ -138,7 +138,9 @@ test("external summary HTTP: a transient 429 with Retry-After recovers on the se _setSummaryRetryDelayForTest(0); await upstream((_req, res) => { hits++; - if (hits === 1) { res.writeHead(429, { "retry-after": "1" }); res.end("rate limited"); return; } + // "7" deliberately differs from the attempt-1 backoff fallback (1000 ms) + // so this assertion proves the header value won, not the backoff default. + if (hits === 1) { res.writeHead(429, { "retry-after": "7" }); res.end("rate limited"); return; } res.end(JSON.stringify(completion("responses"))); }, async (url) => { const result = await new ExternalSummaryExecutor(1).execute(work, [createSummaryHttpCandidate(target(url), 4096)], budget); @@ -146,7 +148,22 @@ test("external summary HTTP: a transient 429 with Retry-After recovers on the se if (result.status === "success") assert.equal(result.targetIndex, 0); }); assert.equal(hits, 2); - assert.deepEqual(_summaryRetryDelaysForTest(), [1000]); + assert.deepEqual(_summaryRetryDelaysForTest(), [7000]); +}); + +test("external summary HTTP: a hostile Retry-After is capped so it cannot eat the attempt budget", async () => { + let hits = 0; + _setSummaryRetryDelayForTest(0); + await upstream((_req, res) => { + hits++; + if (hits === 1) { res.writeHead(429, { "retry-after": "999" }); res.end("rate limited"); return; } + res.end(JSON.stringify(completion("responses"))); + }, async (url) => { + const result = await new ExternalSummaryExecutor(1).execute(work, [createSummaryHttpCandidate(target(url), 4096)], budget); + assert.equal(result.status, "success"); + }); + assert.equal(hits, 2); + assert.deepEqual(_summaryRetryDelaysForTest(), [15000]); }); test("external summary HTTP: a risk-control 403 body retries like a rate limit", async () => { From b0129506dcdf7ccc50d2cab972260129bf975c0d Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 19:36:46 +0800 Subject: [PATCH 5/5] fix(external-summary): boot audit defers unresolvable references to their owning surfaces The startup audit expanded chains against FILE recipes only, but request time also sees agent-registered recipes (#2336, in-memory, registered after boot). A chain targeting an agent-layer provider therefore emitted a false 'unknown provider' warn at every start although it resolves fine at request time. Unresolvable references are already surfaced by web save (400) and the request-path one-shot warn, so the audit now reports only what only it can know: credential states of expandable chains. --- src/external-summary-credentials.ts | 9 ++++++--- tests/issue3488-credential-status.test.ts | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/external-summary-credentials.ts b/src/external-summary-credentials.ts index 4de43dc9c8..5b44e83a5b 100644 --- a/src/external-summary-credentials.ts +++ b/src/external-summary-credentials.ts @@ -104,15 +104,18 @@ export class SummaryCredentialStore { } /** #3488: readable problems for ONE raw chain block (file form). Unparseable - * blocks return [] — they already surface through config validation and the - * web view's hideInvalidSummary path, so auditing them here would double-report. */ + * blocks and unresolvable references both return [] — those surfaces are + * owned elsewhere (config validation / web save 400 / the request-path + * one-shot warn), and boot cannot see agent-registered recipes (#2336), so + * reporting a reference problem here would false-alarm on every start for + * chains that resolve fine once the plugin host registers its layer. */ export function auditExternalSummaryCredentials(block: unknown, recipes: Record, env: NodeJS.ProcessEnv = process.env): string[] { let chain; try { chain = parseExternalSummaryChain(block); } catch { return []; } if (!chain.enabled) return []; let targets; try { targets = expandExternalSummaryChain(chain, recipes).targets; } - catch (error) { return [error instanceof Error ? error.message : String(error)]; } + catch { return []; } const store = new SummaryCredentialStore(); const problems: string[] = []; for (const target of targets) { diff --git a/tests/issue3488-credential-status.test.ts b/tests/issue3488-credential-status.test.ts index f309771af4..1767ae5bd7 100644 --- a/tests/issue3488-credential-status.test.ts +++ b/tests/issue3488-credential-status.test.ts @@ -99,9 +99,10 @@ test("chain audit: reports broken refs per target, silent when everything resolv assert.deepEqual(auditExternalSummaryCredentials({ enabled: false, targets: ["nexus/free"] }, recipes, {}), []); assert.deepEqual(auditExternalSummaryCredentials({ enabled: true }, recipes, {}), []); - problems = auditExternalSummaryCredentials({ enabled: true, targets: ["ghost/model"] }, recipes, {}); - assert.equal(problems.length, 1); - assert.match(problems[0], /ghost/); + // Unresolvable references are silent here on purpose: web save (400) and + // the request-path one-shot warn own that surface, and boot cannot see + // agent-registered recipes (#2336), so reporting would false-alarm. + assert.deepEqual(auditExternalSummaryCredentials({ enabled: true, targets: ["ghost/model"] }, recipes, {}), []); }); test("startup audit walks the global/route/model cascade and reports each effective broken chain once", () => {