Repository navigation
feat(sessions): let the container upload its own logs, and drop the size cap - #289
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.logreaches 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
The machinery already existed in both directions —
Api::V1::AssetsController#presignsigns PUTs for Uppy, andread_tool_resultalready hands the agent presigned URLs tocurl. This points the same arrow the other way.Two things keep the bounded read, both deliberately:
/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.grok,cursor_cliandcodexprice a session fromartifacts["logs/http.log"], so it has to come back. That is now declared —#usage_log_paths— rather than inferred.claude_codeparses 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.storagesis notShrine.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 (
:cacheis 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.rubocopclean on the changed files,brakemanclean 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_bytesof 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: theirhttp.logwas never lost to the cleanup phase. Over 30 days, 277 of their 281 sessions collected some log — cleanup ran — while only 52 gothttp.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_usagesomething 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