Public: anyone can read this; the crew can change it.
A crew run's page says how its model was fed, so a packed SubQ run compares with its explored run and with Claude #17925
Merged 21h 13m ago, live in production
mason/forge:mason/17920-a-crew-run-s-page-says-how-its-model-was → main 0 commits fork 2 threads · 2 unresolved
17 files
changed +250
−7
- docs/features/model-feed.md
- src/contract/openapi/schemas/run.ts
- src/core/migration-pins/20261203060000-run-feed.pin
- src/core/migrations/20261203060000-run-feed.ts
- src/core/run_feed.ts
- src/core/runs.ts
- src/crew/agent_runner.ts
- src/crew/openai_runner.ts
- src/crew/packed_run.ts
- src/crew/run_prepare.ts
- src/runs/run_compare.ts
- src/runs/run_facts.ts
- src/tui/screens/runlist.ts
- src/web/studio/lists.ts
- test/model-feed.test.ts
- test/run-feed.test.ts
- test/run-page-links.test.ts
docs/features/model-feed.md +11
| @@ -44,3 +44,14 @@ you write the line, and Talk's turns are never packed. | ||
| 44 | 44 | |
| 45 | 45 | The run log says it: `packed 1.2M tokens (812 files), cached 1.1M, 2 rounds, 14.2 s + 31.0 s per |
| 46 | 46 | round`, and each round's time, tokens read (and cached) and written. |
| 47 | ||
| 48 | ## Read it on the run (#17920) | |
| 49 | ||
| 50 | Every crew run records its feed as data: `explored`, or `packed` with the pack (tokens, files, the | |
| 51 | cached share), the rounds used and the time of each. The run's page and the terminal's run screen | |
| 52 | show it as a **Fed** line: `packed 1.2M tokens (812 files), cached 1.1M · 3 rounds · 40 s, 35 s, | |
| 53 | 22 s`, or `explored with tools`. The runs list, on the page and in the terminal, gives each agent | |
| 54 | run one row of `feed · steps or rounds · time · outcome` (`packed · 3 rounds · 1m 37s · ok`, | |
| 55 | `explored · 12 steps · 4m 2s · ok`), so a packed run, its explored run and a Claude run compare | |
| 56 | without opening a log. The run's JSON answer (`/api/v1/repos/:owner/:name/runs/:id`) has the same | |
| 57 | record as `feed` (null for a run from before this). |
src/contract/openapi/schemas/run.ts +15
| @@ -20,6 +20,19 @@ const CHECK_DETAIL: Schema = obj( | ||
| 20 | 20 | ["files", "failures"], |
| 21 | 21 | ); |
| 22 | 22 | |
| 23 | /** How an agent run's model was fed: the pack and the rounds when packed (#17920). */ | |
| 24 | const RUN_FEED: Schema = obj( | |
| 25 | { | |
| 26 | feed: words("explored", "packed"), | |
| 27 | tokens: int, | |
| 28 | files: int, | |
| 29 | cached: int, | |
| 30 | rounds: int, | |
| 31 | roundMs: list(int), | |
| 32 | }, | |
| 33 | ["tokens", "files", "cached", "rounds", "roundMs"], | |
| 34 | ); | |
| 35 | ||
| 23 | 36 | /** One run of a deploy, an agent or a check. */ |
| 24 | 37 | const RUN: Schema = obj({ |
| 25 | 38 | id: str, |
| @@ -42,6 +55,7 @@ const RUN: Schema = obj({ | ||
| 42 | 55 | turns: int, |
| 43 | 56 | contextTokens: int, |
| 44 | 57 | model: str, |
| 58 | feed: orNull(ref("RunFeed")), | |
| 45 | 59 | tokensIn: orNull(int), |
| 46 | 60 | tokensOut: orNull(int), |
| 47 | 61 | pushed: orNull(bool), |
| @@ -96,6 +110,7 @@ const PROPOSAL: Schema = obj( | ||
| 96 | 110 | |
| 97 | 111 | export const RUN_SCHEMAS: Readonly<Record<string, Schema>> = { |
| 98 | 112 | CheckDetail: CHECK_DETAIL, |
| 113 | RunFeed: RUN_FEED, | |
| 99 | 114 | Run: RUN, |
| 100 | 115 | Look: LOOK, |
| 101 | 116 | Plan: PLAN, |
src/core/migration-pins/20261203060000-run-feed.pin added +1
| @@ -0,0 +1,1 @@ | ||
| 1 | 80c29655712294b27c79f5b22c21f0d8a996fdb7379ee5df532bf63351cfebd7 |
src/core/migrations/20261203060000-run-feed.ts added +5
src/core/run_feed.ts added +54
| @@ -0,0 +1,54 @@ | ||
| 1 | /** | |
| 2 | * How a crew run's model was fed, kept as data on the run (#17920): `explored` (the tool loop, | |
| 3 | * every model's default) or `packed` (the repository sent once, `crew/packed_run.ts`) with the | |
| 4 | * pack, the rounds used and the time of each. The run's page, the terminal, the runs list and the | |
| 5 | * JSON API all say it from this one record, so a packed run, its explored run and a Claude run | |
| 6 | * compare without opening a log. Plain data in, plain words out. | |
| 7 | */ | |
| 8 | ||
| 9 | export type RunFeed = | |
| 10 | | { readonly feed: "explored" } | |
| 11 | | { | |
| 12 | readonly feed: "packed"; | |
| 13 | /** The pack's size in tokens, and the files in it. */ | |
| 14 | readonly tokens: number; | |
| 15 | readonly files: number; | |
| 16 | /** Prompt tokens the provider read from its cache, summed over the rounds. */ | |
| 17 | readonly cached: number; | |
| 18 | /** Rounds asked so far, and how long each took in milliseconds. */ | |
| 19 | readonly rounds: number; | |
| 20 | readonly roundMs: readonly number[]; | |
| 21 | }; | |
| 22 | ||
| 23 | /** A token count as a person reads it: 1.2M, 340k, 812. */ | |
| 24 | export const compact = (n: number): string => (n >= 1_000_000 ? `${(n / 1_000_000).toFixed(1)}M` : n >= 1_000 ? `${String(Math.round(n / 1_000))}k` : String(n)); | |
| 25 | ||
| 26 | const whole = (v: unknown): number => (typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.trunc(v) : 0); | |
| 27 | ||
| 28 | /** A stored feed back into data; undefined for none, or for what is not one. */ | |
| 29 | export function parseFeed(text: string): RunFeed | undefined { | |
| 30 | if (text === "") return undefined; | |
| 31 | try { | |
| 32 | const v = JSON.parse(text) as Record<string, unknown> | null; | |
| 33 | if (v === null || typeof v !== "object") return undefined; | |
| 34 | if (v.feed === "explored") return { feed: "explored" }; | |
| 35 | if (v.feed !== "packed") return undefined; | |
| 36 | const ms = Array.isArray(v.roundMs) ? v.roundMs.map(whole) : []; | |
| 37 | return { feed: "packed", tokens: whole(v.tokens), files: whole(v.files), cached: whole(v.cached), rounds: whole(v.rounds), roundMs: ms }; | |
| 38 | } catch { | |
| 39 | return undefined; | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | const secs = (ms: number): string => `${String(Math.round(ms / 1000))} s`; | |
| 44 | ||
| 45 | /** | |
| 46 | * The feed in one line: | |
| 47 | * `packed 1.2M tokens (812 files), cached 1.1M · 3 rounds · 40 s, 35 s, 22 s`, or | |
| 48 | * `explored with tools`. | |
| 49 | */ | |
| 50 | export function feedLine(f: RunFeed): string { | |
| 51 | if (f.feed === "explored") return "explored with tools"; | |
| 52 | const rounds = f.rounds === 0 ? "no round yet" : `${String(f.rounds)} round${f.rounds === 1 ? "" : "s"}`; | |
| 53 | return [`packed ${compact(f.tokens)} tokens (${String(f.files)} file${f.files === 1 ? "" : "s"}), cached ${compact(f.cached)}`, rounds, ...(f.roundMs.length === 0 ? [] : [f.roundMs.map(secs).join(", ")])].join(" · "); | |
| 54 | } |
src/core/runs.ts +13 −1
| @@ -14,6 +14,7 @@ import { BUDGET_PREFIX } from "../kernel/budgets.ts"; | ||
| 14 | 14 | import { id } from "../kernel/id.ts"; |
| 15 | 15 | import { appendRun } from "./ledger.ts"; |
| 16 | 16 | import { meterOf } from "./run_compute.ts"; |
| 17 | import { parseFeed, type RunFeed } from "./run_feed.ts"; | |
| 17 | 18 | |
| 18 | 19 | export type RunKind = "deploy" | "agent" | "check"; |
| 19 | 20 | |
| @@ -118,6 +119,11 @@ export interface Run { | ||
| 118 | 119 | readonly contextTokens: number; |
| 119 | 120 | /** For an agent run: the model it ran on; empty when not recorded. */ |
| 120 | 121 | readonly model: string; |
| 122 | /** | |
| 123 | * For an agent run: how its model was fed, the pack and the rounds (#17920); null when | |
| 124 | * unrecorded. | |
| 125 | */ | |
| 126 | readonly feed: RunFeed | null; | |
| 121 | 127 | /** |
| 122 | 128 | * For an agent run: tokens it read and wrote, all invocations summed; |
| 123 | 129 | * null when unknown (never 0 for unknown). |
| @@ -184,6 +190,7 @@ interface RunRow { | ||
| 184 | 190 | turns: number; |
| 185 | 191 | context_tokens: number; |
| 186 | 192 | model: string | null; |
| 193 | feed: string; | |
| 187 | 194 | tokens_in: number | null; |
| 188 | 195 | tokens_out: number | null; |
| 189 | 196 | pushed: number | null; |
| @@ -226,6 +233,7 @@ const toRun = (r: RunRow): Run => ({ | ||
| 226 | 233 | turns: r.turns, |
| 227 | 234 | contextTokens: r.context_tokens, |
| 228 | 235 | model: r.model ?? "", |
| 236 | feed: parseFeed(r.feed ?? "") ?? null, | |
| 229 | 237 | tokensIn: r.tokens_in ?? null, |
| 230 | 238 | tokensOut: r.tokens_out ?? null, |
| 231 | 239 | pushed: r.pushed === null ? null : r.pushed !== 0, |
| @@ -554,6 +562,8 @@ export function noteRunProgress( | ||
| 554 | 562 | /** Why that model: the agent's own, or what escalated the run to Opus. */ |
| 555 | 563 | modelReason?: string | undefined; |
| 556 | 564 | promptVersion?: string | undefined; |
| 565 | /** How the model is fed, with what the run has used of it so far (#17920). */ | |
| 566 | feed?: RunFeed | undefined; | |
| 557 | 567 | }, |
| 558 | 568 | ): void { |
| 559 | 569 | db.query( |
| @@ -567,7 +577,8 @@ export function noteRunProgress( | ||
| 567 | 577 | prompt_version = COALESCE(?11, prompt_version), |
| 568 | 578 | model_reason = COALESCE(?12, model_reason), |
| 569 | 579 | start = COALESCE(?13, start), |
| 570 | setup_ms = COALESCE(?14, setup_ms) | |
| 580 | setup_ms = COALESCE(?14, setup_ms), | |
| 581 | feed = COALESCE(?15, feed) | |
| 571 | 582 | WHERE id = ?1`, |
| 572 | 583 | ).run( |
| 573 | 584 | runId, |
| @@ -584,6 +595,7 @@ export function noteRunProgress( | ||
| 584 | 595 | progress.modelReason?.slice(0, 60) ?? null, |
| 585 | 596 | progress.start ?? null, |
| 586 | 597 | progress.setupMs === undefined ? null : Math.max(0, Math.trunc(progress.setupMs)), |
| 598 | progress.feed === undefined ? null : JSON.stringify(progress.feed), | |
| 587 | 599 | ); |
| 588 | 600 | } |
| 589 | 601 |
src/crew/agent_runner.ts +3
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | import type { Measure } from "../core/measure.ts"; |
| 11 | import type { RunFeed } from "../core/run_feed.ts"; | |
| 11 | 12 | import type { ModelProfile } from "../core/model_profile.ts"; |
| 12 | 13 | import type { LimitWindow } from "../core/standing.ts"; |
| 13 | 14 | import type { RunLimits } from "./run-cell.ts"; |
| @@ -75,6 +76,8 @@ export interface AgentRun { | ||
| 75 | 76 | * for this invocation, never deltas. |
| 76 | 77 | */ |
| 77 | 78 | readonly onUsage?: ((spent: Spent) => void) | undefined; |
| 79 | /** How the model is being fed, said at the start and again after each packed round (#17920). */ | |
| 80 | readonly onFeed?: ((feed: RunFeed) => void) | undefined; | |
| 78 | 81 | /** The provider's measurement of a window, each time the session reports one (#8960). */ |
| 79 | 82 | readonly onMeasure?: ((measure: Measure) => void) | undefined; |
| 80 | 83 | /** The provider said this window is under its thresholds: a stored reading of it is stale. */ |
src/crew/openai_runner.ts +1
| @@ -620,6 +620,7 @@ export async function runOpenAI(run: AgentRun, config: Record<string, string | u | ||
| 620 | 620 | test: () => shell(TEST_COMMAND), |
| 621 | 621 | push: (message) => shell(PUSH_COMMAND, { FORGE_PACKED_MESSAGE: message.slice(0, 500) }), |
| 622 | 622 | log: (line) => run.log(line), |
| 623 | feed: (f) => run.onFeed?.(f), | |
| 623 | 624 | say: (text) => run.onSaid?.({ kind: "text", text }), |
| 624 | 625 | }, |
| 625 | 626 | }); |
src/crew/packed_run.ts +6 −3
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | import type { AgentOutcome } from "./agent_runner.ts"; |
| 12 | 12 | import type { Pack } from "./context_pack.ts"; |
| 13 | 13 | import type { ModelProfile } from "../core/model_profile.ts"; |
| 14 | import { compact, type RunFeed } from "../core/run_feed.ts"; | |
| 14 | 15 | |
| 15 | 16 | /** One answer of the model, with what the endpoint said it read. */ |
| 16 | 17 | export type Asked = |
| @@ -31,6 +32,8 @@ export interface Hands { | ||
| 31 | 32 | /** Commit with `message` and push; the output with `[forge-exit N]` last. */ |
| 32 | 33 | push(message: string): Promise<string>; |
| 33 | 34 | log(line: string): void; |
| 35 | /** The feed as the run's record, said at the start and after each round (#17920). */ | |
| 36 | feed?(feed: RunFeed): void; | |
| 34 | 37 | /** What the run says in its thread. */ |
| 35 | 38 | say(text: string): void; |
| 36 | 39 | } |
| @@ -105,9 +108,6 @@ export const exitOf = (output: string): number | undefined => { | ||
| 105 | 108 | return m === null ? undefined : Number(m[1]); |
| 106 | 109 | }; |
| 107 | 110 | |
| 108 | /** A token count as a person reads it: 1.2M, 340k, 812. */ | |
| 109 | export const compact = (n: number): string => (n >= 1_000_000 ? `${(n / 1_000_000).toFixed(1)}M` : n >= 1_000 ? `${String(Math.round(n / 1_000))}k` : String(n)); | |
| 110 | ||
| 111 | 111 | const seconds = (ms: number): string => `${(ms / 1000).toFixed(1)} s`; |
| 112 | 112 | |
| 113 | 113 | /** |
| @@ -123,6 +123,8 @@ export async function runPacked(input: { pack: Pack; system: string; task: strin | ||
| 123 | 123 | hands.log(`packed ${compact(pack.tokens)} tokens (${String(pack.files)} files${pack.whole ? ", the whole repository" : ` of ${String(pack.offered)}`}), at most ${String(profile.rounds)} rounds`); |
| 124 | 124 | let cached = 0; |
| 125 | 125 | const times: number[] = []; |
| 126 | const record = () => hands.feed?.({ feed: "packed", tokens: pack.tokens, files: pack.files, cached, rounds: times.length, roundMs: [...times] }); | |
| 127 | record(); | |
| 126 | 128 | const wrap = (ok: boolean, result: string, rounds: number) => { |
| 127 | 129 | hands.log(`packed ${compact(pack.tokens)} tokens (${String(pack.files)} files), cached ${compact(cached)}, ${String(rounds)} round${rounds === 1 ? "" : "s"}, ${times.map(seconds).join(" + ") || "no time"} per round`); |
| 128 | 130 | return { ok, result, rounds }; |
| @@ -135,6 +137,7 @@ export async function runPacked(input: { pack: Pack; system: string; task: strin | ||
| 135 | 137 | if ("outcome" in got) return got; |
| 136 | 138 | times.push(Date.now() - began); |
| 137 | 139 | cached += got.cachedTokens; |
| 140 | record(); | |
| 138 | 141 | hands.log(`round ${String(round)}: ${seconds(times.at(-1)!)}, read ${compact(got.promptTokens)} tokens (cached ${compact(got.cachedTokens)}), wrote ${compact(got.outputTokens)}`); |
| 139 | 142 | messages.push({ role: "assistant", content: got.content }); |
| 140 | 143 | const parsed = parseChange(got.content); |
src/crew/run_prepare.ts +2
| @@ -269,6 +269,7 @@ export async function prepareAgent(s: PrepareState): Promise<Prepared> { | ||
| 269 | 269 | onSteer: (send) => { |
| 270 | 270 | listenForSteer(run.id, send); |
| 271 | 271 | }, |
| 272 | onFeed: (feed) => noteRunProgress(app.db, run.id, { feed }), | |
| 272 | 273 | onMeasure: (m) => noteMeasure(app.db, meter.subscriptionId ?? PLATFORM, m), |
| 273 | 274 | onCleared: (window) => forgetMeasure(app.db, meter.subscriptionId ?? PLATFORM, window), |
| 274 | 275 | onUsage: (so) => |
| @@ -301,6 +302,7 @@ export async function prepareAgent(s: PrepareState): Promise<Prepared> { | ||
| 301 | 302 | ); |
| 302 | 303 | if (!s.reviewing && s.resumeWhy !== "") write(s.resumeWhy); |
| 303 | 304 | noteRunProgress(app.db, run.id, { |
| 305 | feed: { feed: "explored" }, | |
| 304 | 306 | model: chosen.model, |
| 305 | 307 | modelReason: chosen.reason, |
| 306 | 308 | promptVersion: promptVersion(agent, brief.role), |
src/runs/run_compare.ts added +16
| @@ -0,0 +1,16 @@ | ||
| 1 | /** | |
| 2 | * One agent run as a row to read beside its neighbours (#17920): how its model was fed, the steps | |
| 3 | * (explored) or rounds (packed) it took, how long, and how it ended. The runs list on the page and | |
| 4 | * in the terminal prints it, so a packed run, its explored run and a Claude run on the same kind of | |
| 5 | * issue compare without opening a log. Nothing for a run that is not an agent's or recorded no | |
| 6 | * feed. | |
| 7 | */ | |
| 8 | import type { Run } from "../core/runs.ts"; | |
| 9 | import { durationText } from "./run_facts.ts"; | |
| 10 | ||
| 11 | export function compareWords(run: Run): string { | |
| 12 | if (run.kind !== "agent" || run.feed === null) return ""; | |
| 13 | const n = run.feed.feed === "packed" ? run.feed.rounds : run.turns; | |
| 14 | const unit = run.feed.feed === "packed" ? "round" : "step"; | |
| 15 | return [run.model, run.feed.feed, `${String(n)} ${unit}${n === 1 ? "" : "s"}`, durationText(run), run.state].filter((p) => p !== undefined && p !== "").join(" · "); | |
| 16 | } | |
src/runs/run_facts.ts +2
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | |
| 9 | 9 | import { placementWords } from "../checks/placement.ts"; |
| 10 | 10 | import { tookParts } from "../checks/took_line.ts"; |
| 11 | import { feedLine } from "../core/run_feed.ts"; | |
| 11 | 12 | import type { Run } from "../core/runs.ts"; |
| 12 | 13 | |
| 13 | 14 | export interface RunFact { |
| @@ -126,6 +127,7 @@ export function runFacts(i: RunFactsInput): RunFact[] { | ||
| 126 | 127 | facts.push({ label: "Ran on", text: where, ...(run.placement === "runner" && i.admin ? { href: "/settings/runners" } : {}) }); |
| 127 | 128 | } |
| 128 | 129 | if (i.account !== undefined) facts.push({ label: "Account", text: i.account }); |
| 130 | if (run.feed !== null) facts.push({ label: "Fed", text: feedLine(run.feed) }); | |
| 129 | 131 | if (run.startedAt !== null) facts.push({ label: "Started", text: run.startedAt, at: run.startedAt }); |
| 130 | 132 | if (i.took !== undefined) facts.push({ label: run.finishedAt === null ? "Running for" : "Took", text: i.took }); |
| 131 | 133 | if (run.attempt > 0) facts.push({ label: "Attempt", text: String(run.attempt + 1) }); |
src/tui/screens/runlist.ts +2
| @@ -20,6 +20,7 @@ import type { Run, RunState } from "../../core/runs.ts"; | ||
| 20 | 20 | import { getUsersByIds } from "../../core/users.ts"; |
| 21 | 21 | import { getUsage } from "../../core/usage.ts"; |
| 22 | 22 | import { priceWords } from "../../core/run_price.ts"; |
| 23 | import { compareWords } from "../../runs/run_compare.ts"; | |
| 23 | 24 | import { stillEnding } from "../../runs/ending.ts"; |
| 24 | 25 | import type { Ctx, Screen } from "../app/app.ts"; |
| 25 | 26 | import type { Rect, Screen as Surface } from "../term/screen.ts"; |
| @@ -111,6 +112,7 @@ export function runRows( | ||
| 111 | 112 | run.commitOid === "" ? "" : run.commitOid.slice(0, 7), |
| 112 | 113 | costText(run.costUsd), |
| 113 | 114 | counted(run), |
| 115 | compareWords(run), | |
| 114 | 116 | placementWords(run), |
| 115 | 117 | relTime(runWhen(run)), |
| 116 | 118 | ), |
src/web/studio/lists.ts +9 −2
| @@ -61,6 +61,7 @@ import { | ||
| 61 | 61 | } from "../ui.ts"; |
| 62 | 62 | import { emptyList } from "../empty_words.ts"; |
| 63 | 63 | import type { Run, RunState } from "../../core/runs.ts"; |
| 64 | import { compareWords } from "../../runs/run_compare.ts"; | |
| 64 | 65 | import { actorsFor, issuesFor, runTitleFrom } from "../pages/runs.ts"; |
| 65 | 66 | import { originGlyph } from "../pages/thread.ts"; |
| 66 | 67 | import { changeHref, listLine, PAGE_TITLES, pageTitle, tellHref } from "./nouns.ts"; |
| @@ -823,6 +824,12 @@ const RUNS_KIND_WORDS: Record<RunsKind, string> = { | ||
| 823 | 824 | check: "Checks", |
| 824 | 825 | }; |
| 825 | 826 | |
| 827 | /** An agent run's feed, steps or rounds, time and outcome, ahead of its date (#17920). */ | |
| 828 | const compareLead = (run: Run): string => { | |
| 829 | const words = compareWords(run); | |
| 830 | return words === "" ? "" : `${words} · `; | |
| 831 | }; | |
| 832 | ||
| 826 | 833 | /** |
| 827 | 834 | * GET /:owner/:name/runs: every run, for every repository and every viewer, |
| 828 | 835 | * one row per run in its studio word — who ran it, when it last moved, and |
| @@ -905,12 +912,12 @@ export async function runsListPage(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 905 | 912 | ? avatar(who) |
| 906 | 913 | : icon(run.kind === "check" ? "check" : "rocket"), |
| 907 | 914 | title: runTitleFrom(run, actors, issues), |
| 908 | meta: | |
| 915 | meta: html`${compareLead(run)}${ | |
| 909 | 916 | run.state === "failed" |
| 910 | 917 | ? html`${noteLine(info.note)} · ${time(run.finishedAt ?? run.createdAt)}` |
| 911 | 918 | : run.state === "queued" && run.notBefore !== null |
| 912 | 919 | ? html`${noteLine(info.note)} · ${time(run.createdAt)}` |
| 913 | : time(run.finishedAt ?? run.createdAt), | |
| 920 | : time(run.finishedAt ?? run.createdAt)}`, | |
| 914 | 921 | trail: wordBadge(info.word), |
| 915 | 922 | }); |
| 916 | 923 | }), |
test/model-feed.test.ts +2 −1
| @@ -18,7 +18,8 @@ import { buildPack, gitSource, type Source } from "../src/crew/context_pack.ts"; | ||
| 18 | 18 | import { runOpenAI } from "../src/crew/openai_runner.ts"; |
| 19 | 19 | import { runAccount } from "../src/crew/runner_env.ts"; |
| 20 | 20 | import { wordsOf } from "../src/crew/pack_rank.ts"; |
| 21 | import { compact, exitOf, parseChange, runPacked, type Asked, type Hands } from "../src/crew/packed_run.ts"; | |
| 21 | import { exitOf, parseChange, runPacked, type Asked, type Hands } from "../src/crew/packed_run.ts"; | |
| 22 | import { compact } from "../src/core/run_feed.ts"; | |
| 22 | 23 | import { seedAdmin } from "./helpers/admin.ts"; |
| 23 | 24 | import { gitRun } from "./helpers/git-client.ts"; |
| 24 | 25 | import { quietLogs } from "./helpers/globals.ts"; |
test/run-feed.test.ts added +107
| @@ -0,0 +1,107 @@ | ||
| 1 | /** | |
| 2 | * A crew run records how its model was fed (#17920): packed with the pack and rounds, or explored. | |
| 3 | * The run's page, the terminal's rows and facts, the runs list and the JSON answer all say it. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createRepo } from "../src/actions/repos.ts"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { feedLine, parseFeed, type RunFeed } from "../src/core/run_feed.ts"; | |
| 12 | import { claimRun, createRun, finishRun, getRun, noteRunProgress, type Run } from "../src/core/runs.ts"; | |
| 13 | import { createSession } from "../src/core/sessions.ts"; | |
| 14 | import { runPacked, type Asked, type Hands } from "../src/crew/packed_run.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { runFacts } from "../src/runs/run_facts.ts"; | |
| 17 | import { runRows } from "../src/tui/screens/runlist.ts"; | |
| 18 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 19 | import { quietLogs } from "./helpers/globals.ts"; | |
| 20 | ||
| 21 | quietLogs(); | |
| 22 | ||
| 23 | const PACKED: RunFeed = { feed: "packed", tokens: 1_200_000, files: 812, cached: 1_100_000, rounds: 3, roundMs: [40_000, 35_000, 22_000] }; | |
| 24 | const LINE = "packed 1.2M tokens (812 files), cached 1.1M · 3 rounds · 40 s, 35 s, 22 s"; | |
| 25 | ||
| 26 | let dir: string, app: App, servers: Servers, cookie: string, packed: Run, explored: Run, bare: Run; | |
| 27 | const get = async (path: string) => fetch(`${servers.url}${path}`, { headers: { cookie } }); | |
| 28 | ||
| 29 | beforeAll(async () => { | |
| 30 | dir = await mkdtemp(join(tmpdir(), "forge-run-feed-")); | |
| 31 | app = createApp({ dataDir: dir, port: 0 }); | |
| 32 | servers = await serve(app); | |
| 33 | const made = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-good-passphrase" }); | |
| 34 | if (!made.ok) throw new Error(made.error); | |
| 35 | const repo = await createRepo(app, made.value, { name: "feed", visibility: "public" }); | |
| 36 | if (!repo.ok) throw new Error(String(repo.error)); | |
| 37 | cookie = `forge_session=${createSession(app.db, made.value.id).token}`; | |
| 38 | const make = (feed: RunFeed | undefined, turns: number, model = "") => { | |
| 39 | const r = createRun(app.db, { repoId: repo.value.id, kind: "agent", actorId: made.value.id, reason: "assigned" }); | |
| 40 | claimRun(app.db, r.id); | |
| 41 | if (feed !== undefined) noteRunProgress(app.db, r.id, { feed, ...(model === "" ? {} : { model }) }); | |
| 42 | return finishRun(app.db, r.id, { state: "ok", summary: "All done", turns })!; | |
| 43 | }; | |
| 44 | packed = make(PACKED, 3, "subq-savant"); | |
| 45 | explored = make({ feed: "explored" }, 12, "claude-opus-5-5"); | |
| 46 | bare = make(undefined, 2); | |
| 47 | }, 60_000); | |
| 48 | ||
| 49 | afterAll(async () => { | |
| 50 | servers.stop(); | |
| 51 | app.close(); | |
| 52 | await rm(dir, { recursive: true, force: true }); | |
| 53 | }); | |
| 54 | ||
| 55 | test("a packed run's record carries the pack and the rounds, and the page says them in one line", async () => { | |
| 56 | expect(getRun(app.db, packed.id)!.feed).toEqual(PACKED); | |
| 57 | expect(feedLine(PACKED)).toBe(LINE); | |
| 58 | const page = await (await get(`/alice/feed/runs/${packed.id}`)).text(); | |
| 59 | expect(page).toContain(`<dt>Fed</dt><dd>${LINE}</dd>`); | |
| 60 | }); | |
| 61 | ||
| 62 | test("an explored run's page says it explored with tools, and a run with no record says nothing", async () => { | |
| 63 | expect(await (await get(`/alice/feed/runs/${explored.id}`)).text()).toContain("<dt>Fed</dt><dd>explored with tools</dd>"); | |
| 64 | expect(await (await get(`/alice/feed/runs/${bare.id}`)).text()).not.toContain("<dt>Fed</dt>"); | |
| 65 | }); | |
| 66 | ||
| 67 | test("the terminal's facts and the JSON answer carry the same feed", async () => { | |
| 68 | const facts = runFacts({ run: getRun(app.db, packed.id)!, base: "/alice/feed", defaultBranch: "main", admin: false, writer: true }); | |
| 69 | expect(facts.find((f) => f.label === "Fed")?.text).toBe(LINE); | |
| 70 | const one = (await (await get(`/api/v1/repos/alice/feed/runs/${packed.id}`)).json()) as { feed: unknown }; | |
| 71 | expect(one.feed).toEqual(PACKED); | |
| 72 | const list = (await (await get("/api/v1/repos/alice/feed/runs")).json()) as { items: { id: string; feed: unknown }[] }; | |
| 73 | expect(list.items.find((r) => r.id === explored.id)?.feed).toEqual({ feed: "explored" }); | |
| 74 | expect(list.items.find((r) => r.id === bare.id)?.feed).toBeNull(); | |
| 75 | }); | |
| 76 | ||
| 77 | test("the runs list reads side by side: feed, steps or rounds, time and outcome", async () => { | |
| 78 | const rows = runRows([getRun(app.db, packed.id)!, getRun(app.db, explored.id)!, getRun(app.db, bare.id)!], new Map()); | |
| 79 | expect(rows[0]!.meta).toContain("subq-savant · packed · 3 rounds"); | |
| 80 | expect(rows[0]!.meta).toContain("· ok"); | |
| 81 | expect(rows[1]!.meta).toContain("claude-opus-5-5 · explored · 12 steps"); | |
| 82 | expect(rows[2]!.meta).not.toContain("steps"); | |
| 83 | const page = await (await get("/alice/feed/runs")).text(); | |
| 84 | expect(page).toContain("subq-savant · packed · 3 rounds"); | |
| 85 | expect(page).toContain("claude-opus-5-5 · explored · 12 steps"); | |
| 86 | }); | |
| 87 | ||
| 88 | test("what is not a feed reads as none", () => { | |
| 89 | for (const junk of ["", "{", "null", "[]", '{"feed":"x"}']) expect(parseFeed(junk)).toBeUndefined(); | |
| 90 | expect(parseFeed('{"feed":"packed","tokens":"x","roundMs":[-1,5]}')).toEqual({ feed: "packed", tokens: 0, files: 0, cached: 0, rounds: 0, roundMs: [0, 5] }); | |
| 91 | }); | |
| 92 | ||
| 93 | test("a packed run says its feed at the start and after every round", async () => { | |
| 94 | const said: RunFeed[] = []; | |
| 95 | const hands: Hands = { | |
| 96 | ask: async (): Promise<Asked> => ({ content: "=== file: a.ts ===\nx\n=== end ===\n=== message ===\nm\n=== end ===", promptTokens: 10, cachedTokens: 4, outputTokens: 1 }), | |
| 97 | write: () => {}, | |
| 98 | remove: () => {}, | |
| 99 | test: async () => "[forge-exit 0]", | |
| 100 | push: async () => "[forge-exit 0]", | |
| 101 | log: () => {}, | |
| 102 | feed: (f) => void said.push(f), | |
| 103 | say: () => {}, | |
| 104 | }; | |
| 105 | await runPacked({ pack: { text: "P", tokens: 2_000, files: 3, offered: 3, whole: true, ranked: [] }, system: "", task: "t", profile: { model: "m", feed: "packed", window: 8_000, rounds: 2 }, hands }); | |
| 106 | expect(said.map((f) => (f.feed === "packed" ? [f.rounds, f.cached] : []))).toEqual([[0, 0], [1, 4]]); | |
| 107 | }); |
new above
offline
Principle 1 / issue box 3: the row has no model, so packed SubQ, explored and Claude runs cannot be told apart in the list. Lead with
run.modelwhen it is not empty. Add a test that two rows on different models show their model names.