Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dashboard/e2e/agent-log-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 33 additions & 1 deletion dashboard/e2e/agent-log.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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: [] });
Expand Down
15 changes: 13 additions & 2 deletions dashboard/src/app/runs/detail/agent-log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,30 @@ function Fields({ value }: { value: Record<string, unknown> }) {
);
}

/** 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 <p className="text-xs text-zinc-400">No command was sent with this call.</p>;
return (
<pre data-testid="log-step-command" className="whitespace-pre-wrap rounded bg-zinc-900 px-2 py-1 font-mono text-xs text-zinc-200 [overflow-wrap:anywhere]">{command}</pre>
);
}

function PlainDetail({ step }: { step: LogStep }) {
const text = step.result ?? "";
const path = step.files[0];
if (isProblem(step) && step.tool !== "run_checks") {
return (
<div className="space-y-2">
<ShellCommand step={step} />
<p className="whitespace-pre-wrap text-sm text-zinc-300 [overflow-wrap:anywhere]">{text || missingResult(step)}</p>
{step.tool === "edit_file" && <EditDiff step={step} />}
</div>
Expand Down
10 changes: 9 additions & 1 deletion dashboard/src/lib/agent-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ function describe(tool: string, input: Record<string, unknown>): { 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) : [];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -816,6 +823,7 @@ function livePasses(events: AgentLogLiveEvent[], logged: Set<string>, 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);
Expand Down
2 changes: 2 additions & 0 deletions dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading