Public: anyone can read this; the crew can change it.

Talk logs one line per model call: account, model, seconds, how it ended #17980

opened this

Merged 18h 13m ago, live in production

scout/forge:scout/17976-talk-logs-one-line-per-model-call-accoun → main 0 commits fork

  • Merged. scout/17976-talk-logs-one-line-per-model-call-accoun was merged into main as 353f588.

Review

Sign in to review this change.
3 files changed +26 −22
src/crew/call_line.ts +5 −5
@@ -21,13 +21,13 @@ export interface CallEnd {
2121 readonly stopped: boolean;
2222 }
2323
24 /** How a call ended: answered, timed_out, refused, limit, stopped, or `error:<class>`. */
24 /** How a call ended: ok, timeout, refused, limit, stopped, or `error:<class>`. */
2525 export function callOutcome(end: Pick<CallEnd, "outcome" | "refused" | "stopped">): string {
2626 const { outcome } = end;
27 if (outcome?.ok === true) return "answered";
27 if (outcome?.ok === true) return "ok";
2828 if (end.stopped) return "stopped";
2929 if (outcome === undefined) return "error:threw";
30 if (outcome.reason === "timeout") return "timed_out";
30 if (outcome.reason === "timeout") return "timeout";
3131 if (end.refused || outcome.limit?.refused === true) return "refused";
3232 if (outcome.limit !== undefined || outcome.reason === "rate_limited") return "limit";
3333 return `error:${outcome.reason.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 40) || "unknown"}`;
@@ -39,13 +39,13 @@ export function callFields(end: CallEnd): LogFields {
3939 account: end.account,
4040 model: end.model,
4141 seconds: Math.round(end.ms / 100) / 10,
42 outcome: callOutcome(end),
42 end: callOutcome(end),
4343 };
4444 }
4545
4646 /** What each class of ending says as a cause; an error's class is added to its words. */
4747 const CAUSES: Readonly<Record<string, string>> = {
48 timed_out: "it ran out of time",
48 timeout: "it ran out of time",
4949 refused: "the provider refused it (its credit is spent)",
5050 limit: "the account hit a rate limit",
5151 };
src/crew/conversation.ts +5 −2
@@ -50,7 +50,7 @@ import { GateRefusedError } from "../kernel/outbound.ts";
5050 import { getUserById } from "../core/users.ts";
5151 import { mintViaToken, VIA_TOKEN_MAX_MS } from "../core/via_token.ts";
5252 import { id } from "../kernel/id.ts";
53 import { redactHeld, releaseValues } from "../kernel/log.ts";
53 import { createLog, redactHeld, releaseValues } from "../kernel/log.ts";
5454 import { running } from "../kernel/version.ts";
5555 import { err, ok, type Result } from "../kernel/result.ts";
5656 import { storedText } from "../kernel/blocked.ts";
@@ -76,6 +76,9 @@ import { listenForSteer, steerable, steerRun } from "./steer.ts";
7676 import { sandboxPolicy } from "./sandbox.ts";
7777 import { sandboxRefusal } from "./sandbox_policy.ts";
7878
79 /** The scope of the one line each model call writes (#17976). */
80 const talkLog = createLog("talk");
81
7982 export interface ConversationOptions {
8083 readonly binary: string;
8184 /** Where this forge answers on this machine: `/mcp` is reached here. */
@@ -951,7 +954,7 @@ function begin(
951954 let lastEnd: CallEnd | undefined;
952955 const logCall = (startedAt: number, result: AgentOutcome | undefined): void => {
953956 lastEnd = endOf(startedAt, result);
954 app.log.info("talk model call", callFields(lastEnd));
957 talkLog.info("talk model call", callFields(lastEnd));
955958 };
956959 try {
957960 const cwd = turnDir(app.config.dataDir);
test/talk-call-line.test.ts +16 −15
@@ -58,8 +58,8 @@ beforeAll(async () => {
5858 if (!made.ok) throw new Error(made.error);
5959 promote(app.db, made.value);
6060 user = made.value;
61 teeLines((_scope, message, line) => {
62 if (message === "talk model call") lines.push(line);
61 teeLines((scope, message, line) => {
62 if (message === "talk model call" && scope === "talk") lines.push(line);
6363 });
6464 });
6565 afterAll(async () => {
@@ -85,13 +85,14 @@ const call = async (end: Partial<AgentOutcome> | "throw"): Promise<string> => {
8585
8686 test("each way a call ends is one line with account, model, seconds and the outcome", async () => {
8787 const cases: [Partial<AgentOutcome> | "throw", string][] = [
88 [{}, "outcome=answered"],
89 [{ ok: false, reason: "timeout", result: "" }, "outcome=timed_out"],
90 [{ ok: false, reason: "error", result: "API Error: 402 credit" }, "outcome=refused"],
91 [{ ok: false, reason: "error", result: "x", limit: { refused: true } }, "outcome=refused"],
92 [{ ok: false, reason: "error", result: "x", limit: { said: "5 hour limit" } }, "outcome=limit"],
93 [{ ok: false, reason: "exit 1", result: "SECRET-STDERR" }, "outcome=error:exit_1"],
94 ["throw", "outcome=error:threw"],
88 [{}, "end=ok"],
89 [{ ok: false, reason: "timeout", result: "" }, "end=timeout"],
90 [{ ok: false, reason: "error", result: "API Error: 402 credit" }, "end=refused"],
91 [{ ok: false, reason: "error", result: "x", limit: { refused: true } }, "end=refused"],
92 [{ ok: false, reason: "error", result: "x", limit: { said: "5 hour limit" } }, "end=limit"],
93 [{ ok: false, reason: "exit 1", result: "SECRET-STDERR" }, "end=error:exit_1"],
94 [{ ok: false, reason: "rate_limited", result: "429 SECRET-STDERR" }, "end=limit"],
95 ["throw", "end=error:threw"],
9596 ];
9697 for (const [end, outcome] of cases) {
9798 const line = await call(end);
@@ -125,8 +126,8 @@ test("a lost session then a fresh start is two calls, two lines", async () => {
125126 queue = [{ ok: false, reason: "error", result: "No conversation found with session ID: s-old" }, {}];
126127 await sayIn(conversation.value.id);
127128 expect(lines).toHaveLength(2);
128 expect(lines[0]).toContain("outcome=error:error");
129 expect(lines[1]).toContain("outcome=answered");
129 expect(lines[0]).toContain("end=error:error");
130 expect(lines[1]).toContain("end=ok");
130131 });
131132
132133 test("no runner call, no line: a removed chosen connection logs nothing", async () => {
@@ -140,7 +141,7 @@ test("no runner call, no line: a removed chosen connection logs nothing", async
140141 });
141142
142143 test("a call that answered stays answered even when a stop came after", () => {
143 expect(callOutcome({ outcome: base, refused: false, stopped: true })).toBe("answered");
144 expect(callOutcome({ outcome: base, refused: false, stopped: true })).toBe("ok");
144145 expect(callOutcome({ outcome: { ...base, ok: false, reason: "cancelled" }, refused: false, stopped: true })).toBe("stopped");
145146 });
146147
@@ -186,13 +187,13 @@ test("a call that answered adds no cause line, and a stopped one is not a failed
186187 });
187188
188189 test("the pane's words are the log line's outcome, said in words", () => {
189 expect(causeWords("answered", "a", "m")).toBe("");
190 expect(causeWords("ok", "a", "m")).toBe("");
190191 expect(causeWords("stopped", "a", "m")).toBe("");
191192 expect(causeWords("limit", "work", "opus")).toBe("Which call failed: opus on work; the account hit a rate limit.");
192 expect(causeWords("timed_out", "work", "opus")).toBe("Which call failed: opus on work; it ran out of time.");
193 expect(causeWords("timeout", "work", "opus")).toBe("Which call failed: opus on work; it ran out of time.");
193194 expect(causeWords("refused", "work", "opus")).toBe("Which call failed: opus on work; the provider refused it (its credit is spent).");
194195 expect(causeWords("error:exit_1", "work", "opus")).toBe("Which call failed: opus on work; the account or model returned an error (exit_1).");
195196 expect(causeWords("error:exit_1", "work", "opus", "call")).toBe("Which call failed: opus on work.");
196197 expect(causeWords("error:exit_1", "work", "opus", "cause")).toBe("Why: the account or model returned an error (exit_1).");
197 expect(causeWords("timed_out", "platform", "default")).toBe("Which call failed: the default model on platform; it ran out of time.");
198 expect(causeWords("timeout", "platform", "default")).toBe("Which call failed: the default model on platform; it ran out of time.");
198199 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs