From aa57fe8a04aa389ea9a13cf908582cb37054b3bf Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Tue, 20 Oct 2026 22:05:21 +0100 Subject: [PATCH] fix(chat): keep tool totals neutral and count individual errors --- web/PARITY.md | 15 ++++++ web/chat.css | 2 +- web/src/chat.js | 5 ++ web/src/views/chat.js | 14 +++--- web/sw.js | 2 +- web/test/serviceWorker.test.mjs | 4 +- web/test/tool-summary-browser.mjs | 74 ++++++++++++++++++++++++++++++ web/test/toolFailureCount.test.mjs | 17 +++++++ 8 files changed, 123 insertions(+), 10 deletions(-) create mode 100644 web/test/tool-summary-browser.mjs create mode 100644 web/test/toolFailureCount.test.mjs diff --git a/web/PARITY.md b/web/PARITY.md index dbf8b6e8..c2136c8d 100644 --- a/web/PARITY.md +++ b/web/PARITY.md @@ -8,6 +8,21 @@ test, or a code change without a capture, is `partial` at best. Status legend: `todo` · `partial` (some of it works) · `done` (working + captured). +### Tool summary error scope (2026-10-20) + +The aggregate **N tools** label stays neutral and borderless even when a call +fails. Only the separate **· N errors** count is red; individual failed calls +remain marked inside the tool popup. Keyboard focus keeps its accessible focus +ring. This is an intentional browser presentation correction, not a protocol or +Android change. + +`test/tool-summary-browser.mjs` verifies 82 calls with zero, one and two errors +at 390/1100px, neutral aggregate color, transparent border, no resting outline, +correct accessible error counts, and exactly one failed row among 82 popup rows. +Captures are in the approved OpenCode temporary `tool-summary-captures/` +directory. Fixture-only browser evidence; no live chat/session was changed. +Shell cache v10 refreshes the changed modules on reload. + ### Generic alpha starters (2026-10-20) The embedded catalogue now presents small code change/review, research/fact-check, diff --git a/web/chat.css b/web/chat.css index c09ea5d1..1f4298c3 100644 --- a/web/chat.css +++ b/web/chat.css @@ -550,7 +550,7 @@ outline: 2px solid var(--accent); outline-offset: 1px; } -.chat-tool-chip-failed { border-color: var(--bad); color: var(--bad); } +.chat-tool-error-count { color: var(--bad); } .chat-tool-icon { font-size: 12px; line-height: 1; } .chat-tool-icon-failed { color: var(--bad); } .chat-tool-long { color: var(--bad); } diff --git a/web/src/chat.js b/web/src/chat.js index f90f3463..9f4a284c 100644 --- a/web/src/chat.js +++ b/web/src/chat.js @@ -235,6 +235,11 @@ export function toolCallCount(parts) { return (parts ?? []).filter((part) => part?.type === PART_TOOL).length; } +/** Errors belong to individual calls, not the entire turn's tool total. */ +export function toolFailureCount(parts) { + return (parts ?? []).filter((part) => part?.type === PART_TOOL && toolFailed(part.state)).length; +} + /** True while any tool call in [parts] is still in flight. */ export function toolsRunning(parts) { return (parts ?? []).some((part) => toolRunning(part)); diff --git a/web/src/views/chat.js b/web/src/views/chat.js index a4a3594e..8628751e 100644 --- a/web/src/views/chat.js +++ b/web/src/views/chat.js @@ -163,7 +163,7 @@ import { toolCallsAnnouncement, toolCallsLabel, toolDetail, - toolFailed, + toolFailureCount, toolLabel, toolLongRunning, toolRunning, @@ -3517,24 +3517,26 @@ function renderChatToolChip(turn, { streaming = false, elapsedMillis = () => 0 } if (parts.length === 0) return null; const count = toolCallCount(turn.parts); const running = streaming && toolsRunning(turn.parts); - const failed = parts.some((part) => toolFailed(part.state)); + const errors = toolFailureCount(turn.parts); + const errorLabel = errors === 1 ? "1 error" : `${errors} errors`; const long = running && parts.some((part) => toolRunning(part) && toolLongRunning(elapsedMillis(part))); const chip = h("button", { - class: `chip chat-tool-chip${failed ? " chat-tool-chip-failed" : ""}`, + class: "chat-tool-chip", type: "button", - "aria-label": toolCallsAnnouncement(count), + "aria-label": `${toolCallsAnnouncement(count)}${errors ? `, ${errorLabel}` : ""}`, "aria-expanded": "false", "aria-haspopup": "dialog", }); const currentTool = running ? parts.filter((part) => toolRunning(part)).at(-1) ?? null : null; chip.append( h("span", { - class: `chat-tool-icon${failed ? " chat-tool-icon-failed" : ""}`, + class: "chat-tool-icon", "aria-hidden": "true", - text: failed ? "\u26a0" : "\u29c9", + text: "\u29c9", }), ); chip.append(h("span", { class: "chat-tool-label", text: toolCallsLabel(count) })); + if (errors) chip.append(h("span", { class: "chat-tool-error-count", text: `· ${errorLabel}` })); if (currentTool) { const detail = toolDetail(currentTool); const name = toolLabel(currentTool); diff --git a/web/sw.js b/web/sw.js index 872442bd..d3554c45 100644 --- a/web/sw.js +++ b/web/sw.js @@ -1,7 +1,7 @@ // A shell cache for an installed Pipelines app. The API (the WebSocket proxy and // artifact files) is never cached; static files prefer the network and fall back // to the last good copy so an installed app still opens when the server is away. -const CACHE = "pipelines-shell-v9"; +const CACHE = "pipelines-shell-v10"; const SHELL = ["/", "/index.html", "/manifest.webmanifest", "/favicon.svg"]; self.addEventListener("install", (event) => { diff --git a/web/test/serviceWorker.test.mjs b/web/test/serviceWorker.test.mjs index 755f7a66..f123549a 100644 --- a/web/test/serviceWorker.test.mjs +++ b/web/test/serviceWorker.test.mjs @@ -9,9 +9,9 @@ test("shell updates retain unrelated caches and the current app cache", async () let activation; vm.runInNewContext(await readFile(new URL("../sw.js", import.meta.url), "utf8"), { self: { addEventListener: (type, handler) => handlers.set(type, handler), clients: { claim: async () => {} } }, - caches: { keys: async () => ["pipelines-shell-v8", "pipelines-shell-v9", "unrelated-user-cache"], delete: async (key) => deleted.push(key) }, + caches: { keys: async () => ["pipelines-shell-v9", "pipelines-shell-v10", "unrelated-user-cache"], delete: async (key) => deleted.push(key) }, }); handlers.get("activate")({ waitUntil: (promise) => { activation = promise; } }); await activation; - assert.deepEqual(deleted, ["pipelines-shell-v8"]); + assert.deepEqual(deleted, ["pipelines-shell-v9"]); }); diff --git a/web/test/tool-summary-browser.mjs b/web/test/tool-summary-browser.mjs new file mode 100644 index 00000000..f48ea832 --- /dev/null +++ b/web/test/tool-summary-browser.mjs @@ -0,0 +1,74 @@ +// Scratch-only chat rendering: no provider, backend, or production sessions. +import assert from "node:assert/strict"; +import { createServer } from "node:http"; +import { readFile, mkdir } from "node:fs/promises"; +import { resolve, extname, dirname } from "node:path"; +import { fileURLToPath } from "node:url"; +import { launchChrome } from "./browser.mjs"; + +const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const out = resolve(process.argv[2] ?? "captures-tool-summary"); +await mkdir(out, { recursive: true }); +const html = ` +${["design/tokens/tokens","base","shell","lists","run-detail","chat","dialogs"].map(n=>``).join("")} +
+`; +const server = createServer(async (req, res) => { + try { + const path = new URL(req.url, "http://fixture").pathname; + if (path === "/") { res.setHeader("Content-Type", "text/html"); res.end(html); return; } + const file = resolve(root, `.${path}`); + if (!file.startsWith(root + "/")) throw Error("outside fixture"); + res.setHeader("Content-Type", extname(file) === ".css" ? "text/css" : "text/javascript"); + res.end(await readFile(file)); + } catch { res.writeHead(404); res.end(); } +}); +await new Promise(r => server.listen(0, "127.0.0.1", r)); +let browser; +try { + browser = await launchChrome(); + const page = await browser.openPage(`http://127.0.0.1:${server.address().port}/`); + for (const width of [390, 1100]) { + await page.resize(width, 844); + for (const errors of [0, 1, 2]) { + await page.waitForSelector(".chat-tool-chip"); + await page.evaluate(`setErrors(${errors})`); + const data = await page.evaluate(`(() => { + const chip=document.querySelector('.chat-tool-chip'), label=chip.querySelector('.chat-tool-label'), error=chip.querySelector('.chat-tool-error-count'); + return {label:label.textContent,error:error?.textContent??'',color:getComputedStyle(label).color,bad:getComputedStyle(document.documentElement).getPropertyValue('--bad').trim(),border:getComputedStyle(chip).borderTopColor,outline:getComputedStyle(chip).outlineStyle,aria:chip.getAttribute('aria-label'),overflow:document.documentElement.scrollWidth>innerWidth}; + })()`); + assert.equal(data.label, "82 tools"); + assert.equal(data.error, errors ? `· ${errors} ${errors === 1 ? "error" : "errors"}` : ""); + assert.equal(data.border, "rgba(0, 0, 0, 0)"); + assert.equal(data.outline, "none"); + assert.equal(data.overflow, false); + assert.equal(await page.evaluate("getComputedStyle(document.querySelector('.chat-tool-label')).color === getComputedStyle(document.querySelector('.chat-tool-chevron')).color"), true); + if (errors) assert.match(data.aria, new RegExp(`${errors} error`)); + await page.screenshot(resolve(out, `tools-82-errors-${errors}-${width}.png`)); + } + } + await page.evaluate("setErrors(1)"); + await page.click(".chat-tool-chip"); + await page.waitForSelector(".chat-tool-row-failed"); + assert.equal(await page.evaluate("document.querySelectorAll('.chat-tool-row').length"), 82); + assert.equal(await page.evaluate("document.querySelectorAll('.chat-tool-row-failed').length"), 1); + await page.screenshot(resolve(out, "individual-error-in-tool-details.png")); + console.log("PASS: 82 tools stays neutral and borderless for zero/one/two errors; separate error counts and individual failures remain visible."); +} finally { + await browser?.close(); + await new Promise(r => server.close(r)); +} diff --git a/web/test/toolFailureCount.test.mjs b/web/test/toolFailureCount.test.mjs new file mode 100644 index 00000000..2e4ca8c6 --- /dev/null +++ b/web/test/toolFailureCount.test.mjs @@ -0,0 +1,17 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { toolFailureCount, toolCallCount } from "../src/chat.js"; + +test("one error among 82 calls is one failed call, not an entirely failed tool group", () => { + const parts = Array.from({ length: 82 }, (_, i) => ({type:"tool",state:{status:i===17?"error":"completed"}})); + assert.equal(toolCallCount(parts),82); + assert.equal(toolFailureCount(parts),1); + parts.push({type:"text",state:{status:"error"}}); + assert.equal(toolFailureCount(parts),1); +}); + +test("error counts ignore running and missing states and keep multiple failures", () => { + assert.equal(toolFailureCount(null),0); + assert.equal(toolFailureCount([{type:"tool"},{type:"tool",state:{status:"running"}}]),0); + assert.equal(toolFailureCount([{type:"tool",state:{status:"error"}},{type:"tool",state:{status:"error"}}]),2); +});