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

Traces 1: one normalized trace for every Talk conversation and crew run, read from the raw record #17999

opened this in answer to

Parked 10h 56m ago

Every Talk conversation and crew run now has one normalized trace, rebuilt from the raw record on each read, with a list and a tree on the API and in the terminal. The new tests pass, along with the contract, route-mark, migration and dead-code checks I ran; tsc --noEmit is clean and the gate reports no failing rule.

Notes

opened this

Every Talk conversation and crew run now has one normalized trace, rebuilt from the raw record on each read, with a list and a tree on the API and in the terminal. The new tests pass, along with the contract, route-mark, migration and dead-code checks I ran; tsc --noEmit is clean and the gate reports no failing rule. I did not run the whole suite, so the forge's check will be the first to run the rest.

What changed

  • Shape. src/trace/model.ts gains cost, account and outcome on each step (plus stopped), and a title, repository, model, account and outcome on each trace. src/trace/build.ts builds a run trace from the run row, its usage-ledger line and its log. It builds a Talk trace from the turn rows and each turn's log, with archived logs restored first. Nothing but the raw bytes holds content.
  • Index. A new migration adds trace_index (one summary row per trace) and trace_mark. A sweep (src/trace/sweep.ts, started lazily from main.ts) walks runs and Talk turns by id, 20 at a time, and yields to the event loop between slices. The first pass backfills what exists and later passes keep up, so a row appears within about a minute of a run finishing.
  • API.
    • GET /api/v1/traces: newest first, limit and cursor, filters repository, kind, model, outcome and from/to (YYYY-MM-DD).
    • GET /api/v1/traces/:id: the tree.
    • Both are in the contract (getApiV1Traces, getApiV1TracesId), tagged runs, with a mark file and the lazy route list regenerated.
  • Terminal. The Traces palette entry (src/tui/screens/traces.ts) lists the same rows, and Enter opens one as a tree. The API and terminal share src/actions/traces.ts.
  • Access. A Talk conversation is its person's alone. A run's trace is read by whoever may read its log, and its cost only by whoever sees the owner's facts, as on the run page.
  • Docs. docs/features/trace-index.md is new. I first overwrote the existing traces.md by mistake, restored it, and added a one-line pointer to the new doc.

Tests. test/traces.test.ts covers the log reader and the run and Talk trace builds. The run trace has the same steps, tokens and cost the run page uses (usage ledger and run.costUsd). The test also covers the sweep, API filters, cursor, refusals and access. With 10,000 rows, a filtered page comes back in under 100 ms and the query plans use an index. I changed one existing fixture in test/trace.test.ts because the widened Trace type needed the new fields.

Left out, on purpose

  • Per-line detail. A run's log has no per-line clock and no per-call tokens. So a run is one model step carrying its recorded totals, and its tool calls take the run's own span. Cached tokens read 0 where the ledger doesn't say.
  • Reviews. They are not traced yet.
  • OTLP. toOtlp already takes Trace, but no route exposes it yet.
  • Talk index timing. A Talk row follows its last finished turn, so a title change alone does not refresh it.
  • Hooks. The sweep covers "filled as written", so I added no hooks in the run or conversation finishers.
  • Plan. I did not keep a plan on the issue, because the keep_plan tool was not available to me.

The gate notes three possible duplicate functions (outcomeOf, treeLines, linesScreen) as notes, not failures. I judged each to be a different concept from the function it was compared to.

Try it. Open /api/v1/traces with a token on the preview and then /api/v1/traces/<id> for one item. Or open the Traces command in the terminal.

Direction: a trace is rebuilt from the raw bytes already kept, listed from a small index, and read by the API and the terminal alike (#17991)

🤖 Generated with Claude Code

Closes #17991

Show 2 earlier items

7 earlier comments · 1 event
commented

Every Talk conversation and crew run now has one normalized trace, rebuilt from the raw record on each read. That covers thread → turns → steps, each with times, model, account, tokens in, cached and out, cost and outcome. The failing check's six red tests are fixed and pushed. I reran each of them locally and they pass, and tsc --noEmit and the gate are clean. I did not rerun the whole suite.

What changed

  • Reading: src/trace/build.ts builds a crew run's trace from its row, usage-ledger line and log. It builds a Talk trace from the conversation's turns and each turn's log, restoring archived logs first. Nothing is stored beside the raw record.
  • Index: a new trace_index table (migration 20261204020000-trace-index) holds one summary row per trace, so the list never opens a log. A sweep (src/trace/sweep.ts, started at boot) fills it 20 rows at a time, giving the event loop back between slices. The first pass backfills what exists, and a row follows a finished run or turn within about a minute.
  • API: GET /api/v1/traces lists newest first with limit, cursor and the filters repository, kind, model, outcome and from/to. GET /api/v1/traces/:id returns the tree. Both are in the OpenAPI contract and tested.
  • Terminal: the Traces palette entry lists the same rows and opens one as a tree, through the same code in src/actions/traces.ts. The how-to is docs/features/trace-index.md.
  • Access: a Talk conversation is its person's alone. A run's trace goes to whoever may read its log, and its cost only to whoever sees the owner's facts, as on the run page.

Test results

  • A run trace and a Talk trace give the same step counts, tokens and cost the run page shows.
  • The list over 10,000 rows takes at most 2 statements and walks an index. I replaced the old 100 ms stopwatch assertion, which the check refused, with that statement count.
  • The check's other reds were all in the new code or its tests:
    • The sweep timer now runs inside background("trace-sweep", …).
    • A duplicate import in the test is merged.
    • /api/v1/traces/:id is listed as one the seed cannot fill, in test/security-floor-routes.test.ts and test/budgets/unfixtured/.
  • I edited one existing fixture, in test/trace.test.ts, because the widened Trace type needed the new fields.

Left out

  • Per-call detail: a run's log carries no clock per line and no tokens per call. A run is therefore one model step with its recorded totals, and its tool calls take the run's own span. Cached tokens read 0 where the ledger doesn't say.
  • Reviews: they are not traced yet.
  • OTLP: toOtlp already takes a Trace, but no route exposes it yet.
  • Stale Talk rows: a Talk row follows its last finished turn, so a title change alone does not refresh it.

Try it: open /api/v1/traces on the preview with a token, then /api/v1/traces/<id> for one item, or use the Traces command in the terminal.

Direction: a trace is rebuilt from the raw bytes already kept, listed from a small index, and read by the API and the terminal alike (#17991)

🤖 Generated with Claude Code

commented

Every Talk conversation and crew run now has one normalized trace, rebuilt from the raw record on each read. The last failing check was the job-slices rule; test/job-slices.test.ts passes locally and the fix is pushed, so the forge's check will run again. I did not rerun the whole suite.

What changed

  • Reading: src/trace/build.ts rebuilds a crew run's trace from its row, usage-ledger line and log, and a Talk trace from the conversation's turns and logs. Nothing is stored beside the raw record.
  • Index: a new trace_index table holds one summary row per trace so the list never opens a log. A sweep (src/trace/sweep.ts) fills it 20 rows at a time and gives the event loop back between slices. It backfills what exists, then follows a finished run or turn within about a minute. It runs inside background("trace-sweep", …); the job-slices test requires every such job to be timed or named in UNTIMED, and I named it there with its reason.
  • API: GET /api/v1/traces lists newest first with limit, cursor and the filters repository, kind, model, outcome and from/to. GET /api/v1/traces/:id returns the tree. Both are in the OpenAPI contract with tests.
  • Terminal: the Traces palette entry lists the same rows and opens one as a tree, through the same code in src/actions/traces.ts. The how-to is docs/features/trace-index.md.
  • Access: a Talk conversation is its person's alone. A run's trace goes to whoever may read its log, and its cost only to whoever sees the owner's facts, as on the run page.

Tests: a run trace and a Talk trace give the same step counts, tokens and cost the run page shows. The list over 10,000 rows takes at most 2 statements and walks an index; I used a statement count because the check refuses wall-clock assertions. I edited one existing fixture, in test/trace.test.ts, because the widened Trace type needed the new fields.

Left out

  • Per-call detail: a run's log has no clock per line and no tokens per call. So a run is one model step with its recorded totals, and its tool calls take the run's own span. Cached tokens read 0 where the ledger doesn't say.
  • Reviews: they are not traced yet.
  • OTLP: toOtlp already takes a Trace, but no route exposes it yet.
  • Stale Talk rows: a Talk row follows its last finished turn, so a title change alone does not refresh it.

Try it: open /api/v1/traces on the preview with a token, then /api/v1/traces/<id> for one item, or use the Traces command in the terminal.

Direction: a trace is rebuilt from the raw bytes already kept, listed from a small index, and read by the API and the terminal alike (#17991)

🤖 Generated with Claude Code

commented

Every Talk conversation and crew run now reads as one normalized trace (thread → turns → steps), built from the raw record. This push fixes the check that failed three times in a row.

The failure. no GET route answers 200 without a session phase unless the allowlist names it failed because GET /api/v1/traces answers 200 with no session phase. It is one indexed read, so I added it to UNTIMED in test/route-timing-coverage.test.ts with that reason and #17991, as its neighbours do. /api/v1/traces/:id was not flagged: the fixture has no trace to open there. I did not add a timing phase to the list route, since it has no page to phase.

What the pull holds.

  • List: GET /api/v1/traces reads a small index, filterable and paged.
  • Tree: GET /api/v1/traces/:id rebuilds the tree from the raw bytes on each read.
  • Access: both go through src/actions/traces.ts, which decides who may read what.
  • Index: a migration creates it and a sweep (src/trace/sweep.ts) fills it.
  • Terminal: a Traces screen in src/tui/screens/traces.ts shows the list and the tree through the same actions.
  • Docs: docs/features/trace-index.md is the how-to.

What I checked.

  • bun scripts/gate.ts --explain is clean; the "both doors" and "name the issue" rules pass.
  • bun x tsc --noEmit is clean.
  • test/unused-exports.test.ts, test/module-state.test.ts, test/traces.test.ts, test/trace.test.ts, test/job-slices.test.ts and test/security-floor-routes.test.ts pass. I did not run the whole suite; the forge runs it on the push.
  • test/security-floor-routes.test.ts logged two SQLITE_IOERR lines on a temp database but passed. I took it to be teardown noise and did not investigate.

Not done. The gate flags treeLines in src/tui/screens/traces.ts as 0.60 similar to traceLines in src/cli/commands/trace.ts. It is only a note and I left it, because the two format different shapes. Merging them is a follow-up.

Try it. Sign in and call GET /api/v1/traces, then GET /api/v1/traces/<id> with an id from the list. In the terminal, open Traces: j/k scroll, Enter opens the tree, Esc goes back.

🤖 Generated with Claude Code

commented

I merged main into this branch and pushed it. The merge conflict was in src/generated/marks.ts.

  • Conflict: I took main's copy of src/generated/marks.ts and regenerated it with bun scripts/own-source.ts, so it holds the marks from both sides.
  • Type fix: after the merge, bun x tsc --noEmit failed in src/trace/run_log.ts. Main's Trace and Step types gained required fields (title, repository, model, account, outcome, costUsd).
    • parseRunLog now fills them in: no cost, account or model, and the title is the prompt on one line.
    • The trace's outcome is error if any step failed, otherwise unknown.
    • Its source is now "run", where it was "claude-code".
  • Checks: tsc is clean. I ran the trace tests, test/own-source.test.ts, test/security-floor-routes.test.ts, test/tui-runlog.test.ts and test/otlp-errors.test.ts. All 63 tests pass. I did not run the full suite; the forge's check runs it on this push.
  • Gate: bun scripts/gate.ts --fix changed nothing. It still prints two "one implementation?" similarity notes in src/tui/screens/traces.ts. I left them alone.
commented

I merged main into the branch and pushed it. The conflict was in src/trace/model.ts.

  • Conflict: both sides had changed Trace.source. Main added "codex", and this branch added "talk" and "run". I kept every field this branch added to Trace and made the kinds the union: TraceKind = "claude-code" | "codex" | "talk" | "run".
  • Type fix: main's new src/trace/codex.ts built Trace and Step values without the fields this branch made required. It now sets empty or undefined values for title, repository, model, account and outcome on the trace, and costUsd (0) and account on each step. It leaves title empty, the same way claude_code.ts does.
  • Checks: bun x tsc --noEmit is clean. I ran the trace tests, the codex tests, test/own-source.test.ts and test/security-floor-routes.test.ts. All 44 pass. I did not run the full suite; the forge's check does that on this push.
  • Gate: bun scripts/gate.ts --fix changed nothing. It still prints the same two similarity notes in src/tui/screens/traces.ts.
commented

Still red on current main: every column that names a user is covered > by its cascade or by a row of COVERED. Fix it and push.

commented

I fixed the failing tests and pushed. The three suites that were red on this pull (account-purge, palette-roster, palette-entries) pass locally, and tsc is clean. I did not run the full suite. The gate printed only two "one implementation?" similarity notes and I changed nothing for them.

  • Account purge: the new trace_index.user_id column wasn't covered. I added it to COVERED in src/core/account_purge.ts as FORMER, so after a purge the row names the placeholder account. I chose FORMER over DELETE because the sweep rebuilds the index from the raw records, so a deleted row would come back. If you want a purged person's trace rows gone entirely, that needs a different rule.
  • Palette order: the Traces entry had rank 1120, which put it after "New issue", and a test pins "New issue" as the last entry. I moved it to rank 1105, just ahead of "security". I also added the Traces row to the three signed-in rosters in test/palette-roster.test.ts. Those pinned lists were stale because they predate the new entry, not because the code was wrong.
  • Still red, not mine: list-cursor-state fails on main at 4513adb too, so the check doesn't count it against this pull. I did not touch it.
the crew's run was interrupted: provider limit, resumes 05:10 UTC — every subscription this repository may use is resting (API Error: 402 This request requires more credits, or fewer max_tokens. You requested up to 128000 tokens, but can only afford 4000. To increase, visit https://)
commented

Closed by the crew: main moved under it 2 times and the branch could not be brought up to date. Conflicting files: src/main.ts, src/tui/screens/traces.ts.

Sign in to join this conversation.

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

Keyboard shortcuts

Docs