From e127bdf7a401ac40178b7406bb5a25aefcdf89b7 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Mon, 16 Nov 2026 13:01:30 -0500 Subject: [PATCH] Run log: a refused command shows its command and its reason while the step runs A shell step's sentence names its command however long it is (it used to drop any input over 80 characters), a refused or failed step shows the command above its reason, and a live step shows the reason the worker now sends with the event instead of waiting for the saved log. --- dashboard/e2e/agent-log-data.ts | 11 +++++++ dashboard/e2e/agent-log.spec.ts | 34 ++++++++++++++++++++- dashboard/src/app/runs/detail/agent-log.tsx | 15 +++++++-- dashboard/src/lib/agent-log.ts | 10 +++++- dashboard/src/lib/api.ts | 2 ++ 5 files changed, 68 insertions(+), 4 deletions(-) diff --git a/dashboard/e2e/agent-log-data.ts b/dashboard/e2e/agent-log-data.ts index 0faea5a4..686110f7 100644 --- a/dashboard/e2e/agent-log-data.ts +++ b/dashboard/e2e/agent-log-data.ts @@ -279,6 +279,17 @@ export function liveTail(): AgentLogLiveEvent[] { ]; } +/** A coding step still running: a refused shell command too long for one line, one sent with no command, and a refused page fetch. */ +export const LONG_COMMAND = + "cd e2e && pnpm install --ignore-workspace --silent && pnpm exec playwright install chromium && node -e 'const page = 1'"; +export function refusedShellTail(): AgentLogLiveEvent[] { + return [ + { tool: "bash", input_summary: `command: ${LONG_COMMAND}`, duration_ms: 7, is_error: false, timestamp: at(5000), pass: "implement", tool_use_id: "toolu_live_sh1", started_at: at(4999), outcome: { status: "refused", summary: "not run: Background commands don't run here" }, message: "Background commands don't run here: send each command on its own call." }, + { tool: "bash", input_summary: "{}", duration_ms: 0, is_error: true, timestamp: at(5010), pass: "implement", tool_use_id: "toolu_live_sh2", started_at: at(5010), outcome: { status: "refused", summary: "the agent policy did not allow it" }, message: "This command needs a person's approval." }, + { tool: "bash", input_summary: "command: curl -X POST https://www.example.com/api", duration_ms: 4, is_error: false, timestamp: at(5020), pass: "implement", tool_use_id: "toolu_live_sh3", started_at: at(5020), outcome: { status: "refused", summary: "not run: This `curl` sends a POST request, which can change data, so it doesn't run here" } }, + ]; +} + /** An old log (format 1): a bare entry array per pass, JSON-encoded results, no times, turns restarting in a second call. */ export function formatOneLog() { const enc = (s: string) => JSON.stringify(s); diff --git a/dashboard/e2e/agent-log.spec.ts b/dashboard/e2e/agent-log.spec.ts index b3e830ce..8e5afedd 100644 --- a/dashboard/e2e/agent-log.spec.ts +++ b/dashboard/e2e/agent-log.spec.ts @@ -3,7 +3,7 @@ import fs from "node:fs"; import path from "node:path"; import { buildLog, decodeResult, filterPass, parseInputSummary, splitIntent, type LogStep } from "../src/lib/agent-log"; import { runTimeline } from "../src/lib/run-timeline"; -import { at, formatOneLog, formatTwoLog, liveTail, RUN_ID } from "./agent-log-data"; +import { at, formatOneLog, formatTwoLog, liveTail, LONG_COMMAND, refusedShellTail, RUN_ID } from "./agent-log-data"; import { LOG_TRACES, logRun, mockRunApi } from "./agent-log-mock"; // The run page's agent log: the pure model (lib/agent-log.ts) on old and new @@ -142,6 +142,22 @@ test.describe("buildLog", () => { expect(old.passes[0].steps[0].target).toBe('"ScheduleTable"'); }); + test("a refused shell command always names its command, and a live refusal carries its reason", () => { + const log = formatTwoLog(); + const m = buildLog({ ...log, live_events: [...log.live_events, ...refusedShellTail()] }); + const [long, empty, post] = ["toolu_live_sh1", "toolu_live_sh2", "toolu_live_sh3"].map((id) => step(m, id)); + // However long the command, the step names it. + expect(`${long.verb} ${long.target}`).toBe(`Ran ${LONG_COMMAND}`); + expect(long.status).toBe("refused"); + // The reason is there while the step runs, not only once it is saved. + expect(long.result).toBe("Background commands don't run here: send each command on its own call."); + // A call with no command says so. + expect(empty.target).toBe("a shell command (none was sent)"); + // An event without a message still says why, from its outcome. + expect(post.target).toBe("curl -X POST https://www.example.com/api"); + expect(post.summary).toContain("sends a POST request"); + }); + test("small readers", () => { expect(decodeResult({ type: "tool_result", content: '"a\\nb"', content_encoding: "json" }).text).toBe("a\nb"); expect(decodeResult({ type: "tool_result", content: "plain error", content_encoding: "text" }).text).toBe("plain error"); @@ -273,6 +289,22 @@ test("filters, search and the view are kept in the URL; a step link opens that s await shot(page, "agent-log-timeline", [1280]); }); +test("a refused command shows its command and its reason while the step runs", async ({ page }) => { + const errors = watchConsole(page); + const log = formatTwoLog(); + await mockRunApi(page, { log: { ...log, live_events: [...log.live_events, ...refusedShellTail()] } }); + await openLog(page); + const refused = page.locator('[data-testid="log-step"][data-status="refused"][data-tool="bash"]').first(); + await expect(refused).toContainText("Not allowed: Ran cd e2e && pnpm install"); + const detail = refused.getByTestId("log-step-detail"); + if (!(await detail.count())) await refused.getByRole("button").first().click(); + await expect(refused.getByTestId("log-step-command")).toHaveText(LONG_COMMAND); + await expect(refused.getByTestId("log-step-detail")).toContainText("Background commands don't run here: send each command on its own call."); + await expect(page.getByTestId("agent-log-panel")).not.toContainText("The full message is shown once"); + expect(errors).toEqual([]); + await shot(page, "agent-log-refused-command"); +}); + test("the old log (format 1) still reads, with its problems and times", async ({ page }) => { const errors = watchConsole(page); await mockRunApi(page, { log: formatOneLog(), traces: [] }); diff --git a/dashboard/src/app/runs/detail/agent-log.tsx b/dashboard/src/app/runs/detail/agent-log.tsx index 8d6647a4..e7535046 100644 --- a/dashboard/src/app/runs/detail/agent-log.tsx +++ b/dashboard/src/app/runs/detail/agent-log.tsx @@ -182,19 +182,30 @@ function Fields({ value }: { value: Record }) { ); } -/** What a step without a stored result says: its outcome in words, and when the full message arrives. */ +/** What a step without a stored result says: its outcome in words (live events carry the message itself). */ function missingResult(step: LogStep): string { const why = step.summary ? `${step.summary.charAt(0).toUpperCase()}${step.summary.slice(1)}.` : ""; - if (step.live) return `${why} The full message is shown once this part of the run is saved.`.trim(); + if (step.live && !why) return "The full message is shown once this part of the run is saved."; return why || "The tool returned nothing."; } +/** The command a shell step ran or tried, in full. */ +function ShellCommand({ step }: { step: LogStep }) { + const command = String(step.input.command ?? step.input.cmd ?? "").trim(); + if (step.tool !== "bash") return null; + if (!command) return

No command was sent with this call.

; + return ( +
{command}
+ ); +} + function PlainDetail({ step }: { step: LogStep }) { const text = step.result ?? ""; const path = step.files[0]; if (isProblem(step) && step.tool !== "run_checks") { return (
+

{text || missingResult(step)}

{step.tool === "edit_file" && }
diff --git a/dashboard/src/lib/agent-log.ts b/dashboard/src/lib/agent-log.ts index e387d8e6..73e9608a 100644 --- a/dashboard/src/lib/agent-log.ts +++ b/dashboard/src/lib/agent-log.ts @@ -387,6 +387,11 @@ function describe(tool: string, input: Record): { verb: string; return { verb: "Ran", target: "the checks", isPath: false, files: [] }; case "run_codegen": return { verb: "Ran", target: "the code generator", isPath: false, files: [] }; + case "bash": { + // The command itself, however long: a refused or failed one is read by what it tried. + const command = str(input.command ?? input.cmd).trim(); + return { verb: "Ran", target: command || "a shell command (none was sent)", isPath: false, files: [] }; + } case "check_url": { const urls = Array.isArray(input.urls) ? (input.urls as unknown[]).map(str) : str(input.url) ? [str(input.url)] : []; const find = Array.isArray(input.find) ? (input.find as unknown[]).map(str).filter(Boolean) : []; @@ -442,11 +447,13 @@ function makeStep(opts: { call: unknown; live?: boolean; liveSummary?: string; + /** What a live event says the agent got back (a refusal's reason), before the log is saved. */ + liveText?: string | null; }): LogStep { const { tool, input } = opts; const d = describe(tool, input); const decoded = decodeResult(opts.result); - const text = decoded.text; + const text = decoded.text ?? (opts.liveText || null); const outcome = opts.outcome ?? opts.result?.outcome ?? null; const isError = opts.isError ?? !!opts.result?.is_error; const status: StepStatus = outcome ? outcome.status : text === null && !opts.live ? (isError ? "error" : "unknown") : statusFromText(tool, text ?? "", isError); @@ -816,6 +823,7 @@ function livePasses(events: AgentLogLiveEvent[], logged: Set, hasLogs: b startedAt: e.started_at ?? (e.timestamp ? new Date(Date.parse(e.timestamp) - (e.duration_ms || 0)).toISOString() : undefined), call: e, live: true, + liveText: e.message, }), ); const items = fold(steps.map((step) => ({ kind: "step" as const, step })), id); diff --git a/dashboard/src/lib/api.ts b/dashboard/src/lib/api.ts index d20c672a..1040deb6 100644 --- a/dashboard/src/lib/api.ts +++ b/dashboard/src/lib/api.ts @@ -2659,6 +2659,8 @@ export interface AgentLogLiveEvent { tool_use_id?: string | null; started_at?: string | null; outcome?: AgentLogOutcome | null; + /** A refused or failed call's message, sent while the step runs (null on calls that went through and on older events). */ + message?: string | null; } export interface AgentLog {