fix(chat): keep tool totals neutral and count individual errors
This commit is contained in:
@@ -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,
|
||||
|
||||
+1
-1
@@ -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); }
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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"]);
|
||||
});
|
||||
|
||||
@@ -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 = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
${["design/tokens/tokens","base","shell","lists","run-detail","chat","dialogs"].map(n=>`<link rel="stylesheet" href="/${n}.css">`).join("")}
|
||||
<div class="app-root"><main class="workspace"><div class="pane-main"><div class="content" id="content"></div></div></main></div>
|
||||
<script type="module">
|
||||
import { createChatView } from '/src/views/chat.js';
|
||||
import { createModalController } from '/src/modal.js';
|
||||
const id='scratch';
|
||||
const state={view:'chat',chatActiveId:id,chatSessions:[{id,title:'Tool summary regression',backend:'codex'}],
|
||||
chatOverrides:{},chatDrafts:{},chatToolRows:new Set(),chatThreads:new Map([[id,{loaded:true,draft:'',messages:[],attachments:[],notices:[],running:false}]])};
|
||||
const modal=createModalController();
|
||||
const rt={state,modal,repo:{},renderContent:()=>paint(),closeDetail:()=>{}};
|
||||
const view=createChatView(rt);
|
||||
window.paint=()=>{document.querySelector('#content').replaceChildren(view.renderChatConversation());modal.reconcile();};
|
||||
window.setErrors=(errors)=>{
|
||||
state.chatThreads.get(id).messages=[{id:'user',role:'user',parts:[{type:'text',text:'Check the project.'}]},
|
||||
{id:'assistant',role:'assistant',parts:[...Array.from({length:82},(_,i)=>({id:'tool-'+i,type:'tool',name:'read',state:{status:i<errors?'error':'completed',input:{path:'example.txt'},error:i<errors?'Fixture read failed':undefined}})),{type:'text',text:'Finished checking. The individual failed call remains visible in the tool details.'}]}];paint();};
|
||||
setErrors(1);
|
||||
</script>`;
|
||||
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));
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
Reference in New Issue
Block a user