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

Finished run logs archive to the BlobStore #16710

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

Finished run logs now go to the BlobStore, and a finished log whose local file was evicted is restored the next time it's read. The new test and the neighbouring run-log, prune and MCP tests pass, as do tsc and design-lint.

Notes

opened this

Finished run logs now go to the BlobStore, and a finished log whose local file was evicted is restored the next time it's read. The new test and the neighbouring run-log, prune and MCP tests pass, as do tsc and design-lint. I did not run the whole suite, because fast.ts found the diff too broad to name tests; the forge runs it on the push.

  • Archive (src/runs/archive.ts): the sweep that already prunes run files in crew/dispatch.ts now runs first. It puts each finished run's runs/<id>.log to the store, streamed from disk in the infrequent class. A failed put leaves the file local and the next sweep retries it. Only terminal runs are touched, so a run in progress is never archived.
  • Store: resolved once per data dir — the bucket when S3_* is set, otherwise <data>/run-archive as a directory store, with retries.
  • Eviction: a local log is removed only after the store reports the same byte size and the file has been idle for a day. Because the archive sweep runs first, the existing 7-day prune can no longer remove the only copy.
  • Read-back: the run page, GET …/runs/:id/log and the MCP run_log first stream an evicted finished log back from the store, so readRunLog and its many callers stay synchronous. The live tail is unchanged.
  • Tests (test/run-log-archive.test.ts):
    • A finished run is archived, evicted, and /runs/<id> still shows the log, as does the REST log.
    • A run in progress is never archived or restored.
    • A failed put stays local and is retried by the next sweep.
  • Reused: withRetries, dirStore, s3Store and s3FromEnv from blob/store.ts, getRun and isTerminal, and the existing prune hook. docs/BLOBS.md has a new section.

Not done:

  • Other readers: the TUI, the check-text tail and preview views read only the local file, so an evicted log shows as empty there until a page or API read restores it.
  • Presigned redirect: the log is not redirected to a presigned URL for a bucket; it is restored to disk and read from there.
  • Not run: the unix-socket suites are skipped here and run in the forge's check.

How to try: set S3_* or use the default directory, finish a run, wait for the hourly sweep, delete runs/<id>.log, then open /<owner>/<repo>/runs/<id>.

Closes #4545

6 earlier comments
commented

Finished run logs now go to the BlobStore, and a finished log whose local file was evicted is restored the next time it's read. The new test and the neighbouring run-log, prune and MCP tests pass, as do tsc and design-lint. I did not run the whole suite, because fast.ts found the diff too broad to name tests; the forge runs it on the push.

  • Archive (src/runs/archive.ts): the sweep that already prunes run files in crew/dispatch.ts now runs first. It puts each finished run's runs/<id>.log to the store, streamed from disk in the infrequent class. A failed put leaves the file local and the next sweep retries it. Only terminal runs are touched, so a run in progress is never archived.
  • Store: resolved once per data dir — the bucket when S3_* is set, otherwise <data>/run-archive as a directory store, with retries.
  • Eviction: a local log is removed only after the store reports the same byte size and the file has been idle for a day. Because the archive sweep runs first, the existing 7-day prune can no longer remove the only copy.
  • Read-back: the run page, GET …/runs/:id/log and the MCP run_log first stream an evicted finished log back from the store, so readRunLog and its many callers stay synchronous. The live tail is unchanged.
  • Tests (test/run-log-archive.test.ts):
    • A finished run is archived, evicted, and /runs/<id> still shows the log, as does the REST log.
    • A run in progress is never archived or restored.
    • A failed put stays local and is retried by the next sweep.
  • Reused: withRetries, dirStore, s3Store and s3FromEnv from blob/store.ts, getRun and isTerminal, and the existing prune hook. docs/BLOBS.md has a new section.

Not done:

  • Other readers: the TUI, the check-text tail and preview views read only the local file, so an evicted log shows as empty there until a page or API read restores it.
  • Presigned redirect: the log is not redirected to a presigned URL for a bucket; it is restored to disk and read from there.
  • Not run: the unix-socket suites are skipped here and run in the forge's check.

How to try: set S3_* or use the default directory, finish a run, wait for the hourly sweep, delete runs/<id>.log, then open /<owner>/<repo>/runs/<id>.

commented

<!-- look-pages 8e6ee7b05bf2 --> Look pages for 8e6ee7b, from the gate:

  • look pages (inferred): this pull changes src/web/pages/runs.ts; the forge pictures /board (src/web/pages/runs.ts), /settings/crew (src/web/pages/runs.ts), /settings/crew?help (src/web/pages/runs.ts) and 5 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

Finished run logs now archive to the BlobStore and are read back when the local file is evicted. This push only fixes the gate failure. The code is unchanged from the earlier push, and I did not re-run tests or the type check for this push.

The check failed on the "both doors" rule: the pull adds src/runs/archive.ts but no terminal screen or docs/features/ how-to. I chose not to add either, because the archive is internal storage behind the existing run-log views. It has no operator-facing surface of its own, and a screen or how-to would document nothing a person can do. I added a No door: line saying so to a new empty commit.

The gate also inferred look pages from the change to src/web/pages/runs.ts. The same commit carries a No look: line: those pages render the same log text as before, and only where the bytes are read from changed.

To try it, open a finished run's log after its local file has been evicted. It should still show the full text, now read from the BlobStore.

commented

The module-state failure is fixed and pushed. The job-alloc failure I left alone, because that test passes when run by itself.

  • Module state: src/runs/archive.ts held a module-level Map of stores, which the module-state rule refuses. I removed it, and runLogStore now builds its store on each call. Building one holds no state, so nothing is lost.
  • job-alloc: The test measures heap growth, so I read the shard failure as a timing flake. It passed alone in the check log and again here, and nothing I changed touches src/perf.
  • Local runs: tsc, bun test test/module-state.test.ts test/job-alloc.test.ts and test/run-log-archive.test.ts all pass here. scripts/fast.ts named 3,584 files, too many to run, so I ran only those three test files.
commented

I merged main into the branch and pushed it. The only conflict was in docs/BLOBS.md.

  • Conflict: the "Not here yet" paragraph differed on both sides. main still listed archiving run logs as a later step. I kept the branch's version, which says only attachments and the cold-tier lifecycle are still to come. I also kept the "Run logs (#4545)" section, and main's new Packs section came through unchanged.
  • Gate rewrap: scripts/gate.ts --fix reported rewrapping comments in one file. I committed that with the merge.
  • Checks: bun x tsc --noEmit is clean, and test/run-log-archive.test.ts and test/module-state.test.ts pass (6 tests). I did not run the full suite; the forge's check does that on this push.
commented

Finished run logs now archive to the BlobStore. The pull's earlier checks failed because of an unrelated edit, and I've reverted it.

The failure. The gate rule "the diff is the change" refused the pull because it had rewrapped a comment in test/capture-chromium.looks.test.ts that it didn't write. I restored that file to main, and the gate now passes with nothing printed. bun x tsc --noEmit is clean and test/run-log-archive.test.ts passes (3 tests). I did not run any other test files.

What changed:

  • src/runs/archive.ts is new. It archives finished run logs to the BlobStore and builds the store per call, with no module-level map.
  • The archive is wired into src/crew/dispatch.ts, src/http/api.ts, src/http/mcp/tools/run_log.ts and src/web/pages/runs.ts.
  • docs/BLOBS.md documents it.
  • test/run-log-archive.test.ts covers it.

Not done. I made no scope change beyond that revert. The failing check was a stray edit, so I did not split the issue.

Try it. Run bun test test/run-log-archive.test.ts.

🤖 Generated with Claude Code

commented

All five points are addressed and pushed. tsc and gate.ts are clean, and the tests for the run-log paths, prune, check text, previews and docs pass. I didn't run the whole suite; the forge's check does that on this push.

  1. Both doors.
    • runLog in src/actions/runs.ts is now async and is the one place an evicted log is restored. The terminal "Run log" screen, the REST route, MCP run_log, the run page and the check-text tail all go through it.
    • The pull page's check tail, the check-text own-author tail and the production deploy tail (warmProductionLog in src/web/studio/previews.ts) restore just before they read. The check-text cache now keeps the pending read, so waiters released together still share one read.
    • I added docs/features/run-logs.md for the page, terminal, REST and MCP doors.
  2. Restore before authorization. The restore calls are gone from the REST route, run page and MCP tool. runLog calls restoreRunLog only after the run is found in this repo and the viewer may read its log. The same holds for the studio pull page and check text.
  3. Prune and the only copy.
    • sweepRunLogs now returns mayPrune, which refuses the log of any finished run the store doesn't hold. pruneRunFiles takes it as a predicate for both the age and the size-cap removals.
    • If the sweep throws, no .log file is pruned.
  4. Overlapping sweeps. An archiving flag in dispatch.ts's sweepClones scope skips a tick while one sweep is running and clears when the sweep ends.
  5. Tests. test/run-log-archive.test.ts is tidied, with the await await and the indentation fixed. It now covers:
    • a log newer than EVICT_AFTER_MS (archived, not evicted);
    • another repo's run id (404 on the page and the REST route, and no local file written);
    • the MCP run_log restore;
    • the prune keeping an unheld log, then removing it once held.

    I changed one assertion to toMatchObject because the sweep result gained mayPrune.

Left as is:

  • Automation that reads logs directly (crew failure briefs, progress, slow_tests, sentinel evidence) still reads the local file only. It acts on runs from the last day, and eviction waits a day, so I did not make those paths async.
  • The REST ?follow=1 stream reads after runLog, so it is covered.
  • The in-flight guard has no test, since it lives inside the dispatch timer.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs