Skip to content

feat(sessions): let the container upload its own logs, and drop the size cap - #289

Merged
artempartos merged 1 commit into
developfrom
artempartos/container-side-log-upload
Sep 17, 2026
Merged

artempartos merged 1 commit into
developfrom
artempartos/container-side-log-upload

Conversation

@artempartos

@artempartos artempartos commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Why

Step 2, and the end of the thread that started with a run reporting COMPLETED while its logs said nothing.

#282 put a 4 MB tail in as a stopgap. The cap was never about storage — it was about redaction: the scrubbing ran in this process, so every log had to be copied out of the container, across the API server, into a Ruby string, before it could be cleaned. /var/log/mitm/http.log reaches 90 MB in 33 minutes of agent work, and the cleanup phase has 120 seconds for all of it.

#283 moved the scrubbing to the point of writing. So the transfer is no longer ours to make.

What this changes

before:  container → k8s API server → Ruby string → redact → S3     (capped at 4 MB)
after:   container ──────────── presigned PUT ────────────→ S3      (uncapped)
                     app records the key; the save promotes with a server-side copy

The machinery already existed in both directions — Api::V1::AssetsController#presign signs PUTs for Uppy, and read_tool_result already hands the agent presigned URLs to curl. This points the same arrow the other way.

Two things keep the bounded read, both deliberately:

  • A container built before the filters shipped. Probed for in the same exec as the listing (/opt/mitm/aixle_redact.py), never assumed — guessing wrong writes an unredacted log to storage. Old images keep the path where this process scrubs, and age out on their own.
  • A log whose content an adapter parses. grok, cursor_cli and codex price a session from artifacts["logs/http.log"], so it has to come back. That is now declared — #usage_log_paths — rather than inferred. claude_code parses nothing and is 96% of workflow-step sessions, which is exactly where the 90 MB log lives.

A failed upload falls back to the same bounded read and says so in the collection report, so a transient storage blip costs a truncation, not a log.

--noproxy '*' on the upload: every other outbound request in the container goes through the mitm proxy, which would relay and log the transfer — writing the log into the log.

One bug found on the way, worth knowing about

SessionLogUploader.storages is not Shrine.storages. A Shrine subclass copies the registry when it is defined, so the two can silently disagree — the signed PUT resolved one and the attachment the other. It only showed up when the whole file ran: in isolation the test passed, because the subclass had not been autoloaded yet at the moment the storage was registered and so inherited it.

Production was never affected (:cache is registered before any subclass loads), but the collector now resolves through the uploader's own registry, which is the one the attachment uses, so the two cannot drift.

Verification

test/services/sessions, test/services/agents, test/services/container_strategies, test/services/internal_tools, test/temporal: 1168 runs, 3644 assertions, 0 failures, 0 errors. rubocop clean on the changed files, brakeman clean on the tree.

New coverage drives the real path against the runtime fake, which learned the two commands involved: the container PUTs and is not also read through this process; an uploaded log keeps its full 5000 bytes against a max_bytes of 8, and leaves no truncation report; a container without the filters keeps the bounded read; a log an adapter parses for usage keeps it too; a failed upload falls back and says so. The fake records the transfer and the test says what arriving means, so the attachment that follows is a real one rather than a stub.

Sequencing

Safe to merge and deploy in any order — the capability probe is what makes that true. The direct path only engages for a container that carries the filters, which means images built from #283 onward; anything older behaves exactly as it does today.

Still open for cursor_cli/grok/codex, with the cause corrected after measuring it: their http.log was never lost to the cleanup phase. Over 30 days, 277 of their 281 sessions collected some log — cleanup ran — while only 52 got http.log, and the largest that ever survived was 2.04 MB. One session in 30 days failed in cleanup, across every agent. The ceiling was the tar copy through the API server, not the 120-second budget.

So the fix is not a job. All three parsers already iterate each_line, so the remaining work is to upload their log whole like everything else and hand #collect_usage something that streams rather than a String. Memory, the transport ceiling and the phase budget all drop out together; a job only becomes worth it if wall-clock later says so.

🤖 Generated with Claude Code

…ize cap

The 4 MB tail was never about storage. It was about redaction: the scrubbing ran in
this process, so every log had to be copied out of the container, through the API
server and into a Ruby string before it could be cleaned, and the cleanup phase has
120 seconds for all of it. /var/log/mitm/http.log reaches 90 MB in half an hour of
agent work.

Now that the container scrubs its own logs as it writes them, the transfer is no
longer ours to make: mint a presigned PUT, let the container curl the file up, and
record only the key. The save promotes the object with a server-side copy, so the
bytes never pass through here at all and nothing caps them.

Two things keep the bounded read, both deliberately. A container built before those
filters shipped — probed for in the same exec as the listing, never assumed, because
guessing wrong writes an unredacted log to storage. And a log whose CONTENT an
adapter parses to price the session, now declared as #usage_log_paths rather than
inferred; those have to come back through us. A failed upload falls back to the same
read and says so in the collection report.

The upload bypasses the proxy every other request in the container goes through,
which would otherwise relay and log the transfer — writing the log into the log.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit e98130b into develop Sep 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant