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

Traces 1a: a trace index table, filled when a run or Talk turn ends and backfilled once off the serving thread #18061

opened this

Merged 11h 51m ago, live in production

A trace index now exists: one row is written when an agent run or a Talk turn ends, and a one-time backfill fills in the older ones. listTraceIndex returns the rows newest first with a cursor. Nothing reads it yet — no route or page here; that is 1b.

Notes

opened this

A trace index now exists: one row is written when an agent run or a Talk turn ends, and a one-time backfill fills in the older ones. listTraceIndex returns the rows newest first with a cursor. Nothing reads it yet — no route or page here; that is 1b.

tsc, the gate and 102 tests pass locally. That run covered the new test, the trace page and trace tests, talk-stop, unused-exports, migrations-bundle, reserved-names, check-list and hollow. I did not run the full suite; the forge runs it on the push.

What changed

  • Table: migration 20261204052000-trace-index adds trace_index and a small trace_index_backfill table that remembers how far each backfill source got, so a restart resumes. Both are new tables and nothing existing is altered. It also adds a newest-first index and one by repository, and the migration is pinned.
  • Row contents: each row is figures and a title only (kind, repository, title, model, account, steps, errors, tokens, cost, outcome, started, ended). The raw log stays the only record.
    • Run rows: step and failed-step counts come from totalsOf(parseRunLog(...)), so they match the trace page. Tokens and cost are what the run recorded, because a run log holds none.
    • Talk rows: a Talk turn's log is a run log, so it is parsed the same way. Its tokens, cost and model come from its conversation_run row.
  • Run hook: announceRun in src/actions/runs.ts indexes an agent run when it ends. A failure there is logged and never stops the announcement.
  • Talk hook: src/crew/conversation.ts indexes a turn at its two ending branches (answered, stopped). A turn cut by a restart is not indexed.
  • Backfill: backfillTraceIndex, started from src/main.ts unless the forge is read-only, does 25 rows per transaction and then yields. It skips rows that already exist, and once a source is done it is not walked again.
  • Listing: listTraceIndex filters on repository, kind, model, outcome, since and until, and takes an opaque cursor. Filters are bound parameters, and a malformed cursor is read as the first page. It does no access checks; that is for the route in 1b.
  • Test: test/trace-index.test.ts checks that:
    • a run's row carries the steps, failures, cost and tokens its trace page shows;
    • a Talk row carries its recorded tokens and cost, with a hand-counted step count of 4;
    • a deploy run and a run still going are not indexed;
    • the filters and cursor behave, including a hostile cursor;
    • a backfill over 10,000 runs never writes more than 25 rows between yields, and a page lists in under 100 ms;
    • the list queries use their indexes and no temp sort.

Choices and gaps

  • repository holds the repository id, not owner/name, so a rename does not break it. It is empty for Talk.
  • review is allowed as a kind but nothing writes it yet.
  • Cached tokens are 0 for runs and Talk, since neither log records them.
  • No page, route, terminal screen or how-to doc; the commit says No door: and why. The listTraceIndex caller arrives in 1b.
  • I did not add during jobs, module-level state or new dependencies.
  • I did not run bun scripts/similar.ts. The one reuse I'm sure of is readRunLog/readRunTimes, which I call for the log reads.

To try it: run bun test test/trace-index.test.ts.

Closes #18020

commented

A trace index now exists: one row is written when an agent run or a Talk turn ends, and a one-time backfill fills in the older ones. listTraceIndex returns the rows newest first with a cursor. Nothing reads it yet — no route or page here; that is 1b.

tsc, the gate and 102 tests pass locally. That run covered the new test, the trace page and trace tests, talk-stop, unused-exports, migrations-bundle, reserved-names, check-list and hollow. I did not run the full suite; the forge runs it on the push.

What changed

  • Table: migration 20261204052000-trace-index adds trace_index and a small trace_index_backfill table that remembers how far each backfill source got, so a restart resumes. Both are new tables and nothing existing is altered. It also adds a newest-first index and one by repository, and the migration is pinned.
  • Row contents: each row is figures and a title only (kind, repository, title, model, account, steps, errors, tokens, cost, outcome, started, ended). The raw log stays the only record.
    • Run rows: step and failed-step counts come from totalsOf(parseRunLog(...)), so they match the trace page. Tokens and cost are what the run recorded, because a run log holds none.
    • Talk rows: a Talk turn's log is a run log, so it is parsed the same way. Its tokens, cost and model come from its conversation_run row.
  • Run hook: announceRun in src/actions/runs.ts indexes an agent run when it ends. A failure there is logged and never stops the announcement.
  • Talk hook: src/crew/conversation.ts indexes a turn at its two ending branches (answered, stopped). A turn cut by a restart is not indexed.
  • Backfill: backfillTraceIndex, started from src/main.ts unless the forge is read-only, does 25 rows per transaction and then yields. It skips rows that already exist, and once a source is done it is not walked again.
  • Listing: listTraceIndex filters on repository, kind, model, outcome, since and until, and takes an opaque cursor. Filters are bound parameters, and a malformed cursor is read as the first page. It does no access checks; that is for the route in 1b.
  • Test: test/trace-index.test.ts checks that:
    • a run's row carries the steps, failures, cost and tokens its trace page shows;
    • a Talk row carries its recorded tokens and cost, with a hand-counted step count of 4;
    • a deploy run and a run still going are not indexed;
    • the filters and cursor behave, including a hostile cursor;
    • a backfill over 10,000 runs never writes more than 25 rows between yields, and a page lists in under 100 ms;
    • the list queries use their indexes and no temp sort.

Choices and gaps

  • repository holds the repository id, not owner/name, so a rename does not break it. It is empty for Talk.
  • review is allowed as a kind but nothing writes it yet.
  • Cached tokens are 0 for runs and Talk, since neither log records them.
  • No page, route, terminal screen or how-to doc; the commit says No door: and why. The listTraceIndex caller arrives in 1b.
  • I did not add during jobs, module-level state or new dependencies.
  • I did not run bun scripts/similar.ts. The one reuse I'm sure of is readRunLog/readRunTimes, which I call for the log reads.

To try it: run bun test test/trace-index.test.ts.

commented

The check's three failures are fixed and pushed; tsc and the three affected test files (trace-index, timers-named, flake) pass locally. I did not rerun the full suite.

  • Timer rule: the backfill yielded with setTimeout, which the "background timers run inside background" test refuses. It now yields with setImmediate, as checks/sweep.ts does.
  • Clock bound: the test asserted a page lists in under 100 ms against performance.now(), which the two wall-clock tests refuse. I removed it. The test still checks that the backfill writes at most 25 rows between yields and that the list queries use their indexes.

The pull description from my earlier message still stands, except that the 10,000-row test no longer times the listing.

Sign in to join this conversation.

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

Keyboard shortcuts

Docs