Skip to content

fix(sessions): stop losing session outputs with long file names - #47

Merged
artempartos merged 2 commits into
developfrom
fix/session-output-long-filenames
Aug 7, 2026
Merged

artempartos merged 2 commits into
developfrom
fix/session-output-long-filenames

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Problem

A session could finish with an empty Assets list even though the agent wrote files to /workspace/outputs. The files were found by find, read back, and then silently dropped — no log line, nothing to grep for.

read_file tars the requested path and picked the entry out of the archive by comparing File.basename(entry.full_name) against the requested basename. A tar header's name field is 100 bytes; past that the name travels out-of-band:

  • GNU/busybox tar — what KubernetesRuntime#copy_from runs, and prod is CONTAINER_RUNTIME=k8s — emits a ././@LongLink entry and truncates the real entry's name.
  • Docker's Go tar writer emits a PAX x header and garbles it.

Either way the comparison failed, extract_from_tar returned nil, and collect_outputs hit next if content.blank?.

On k8s the whole path is tarred, so the budget is ~82 bytes after workspace/outputs/. A Cyrillic title (2 bytes per character) overflows that at ~40 characters — which is why human-named deliverables vanished while machine-named ones came through. Reproduced against the real busybox tar in the container:

PATH bytes=108 workspace/outputs/report dir/Final report on the results of the security audit performed on 7 August 2026.md
  entry typeflag=L file?=false full_name="././@LongLink"
  entry typeflag=0 file?=true  full_name="workspace/outputs/report dir/Final report on the results of the security audit performed on 7 August"
  extract_from_tar => nil

Fix

Both runtimes tar exactly one path per read, so the first regular-file entry is the answer — the header name never needed to be trusted. The requested basename stays as a preference so a multi-entry archive still resolves correctly; L/x/g metadata entries are skipped via entry.file?.

Same real busybox tar, after the fix:

bytes=108 => "LONG"
bytes=138 => "CYR"     # Cyrillic path

Both collect_outputs paths now log the skip and separate unreadable from empty — the previous silence is what made this invisible in production.

Tests

base_runtime_test.rb builds the raw tar bytes header by header (regular, GNU L, PAX x, directory-only), so the cases don't depend on which tar binary the environment ships. Fail-first confirmed: without the fix exactly the two long-name tests fail.

One existing test pinned the old behaviour — a tar whose single entry has a different basename must yield nil. That premise cannot occur: archive_out always returns the tar of the path asked for. It now asserts the real contract: content wins over a mismatched header name, nil only when the archive carries no file entry at all.

docker compose exec -T web make check_all green.

🤖 Generated with Claude Code

artempartos and others added 2 commits August 7, 2026 20:51
A session could finish with an empty Assets list even though the agent wrote
files to /workspace/outputs. The files were found, read back, and silently
dropped.

read_file tars the requested path and picked the entry out of the archive by
comparing File.basename(entry.full_name) to the requested basename. A tar
header's name field is 100 bytes; past that the name is carried out-of-band —
GNU/busybox tar (what KubernetesRuntime#copy_from runs, and prod is k8s) emits a
`././@LongLink` entry and truncates the real entry's name, Docker's Go writer
emits a PAX `x` header and garbles it. Either way the comparison failed,
extract_from_tar returned nil, and collect_outputs skipped the file on
`next if content.blank?` without logging anything, so nothing pointed at the
loss. On k8s the whole path is tarred, so the budget is ~82 bytes after
`workspace/outputs/`; a Cyrillic title (2 bytes per character) overflows it at
around 40 characters, which is why human-named deliverables vanished while
machine-named ones came through.

Both runtimes tar exactly one path per read, so the first regular-file entry is
the answer and the header name never needed to be trusted; the requested
basename stays as a preference for a multi-entry archive. Verified against the
real busybox tar in the container: 108- and 138-byte paths that returned nil now
return their content.

Also log the skip in both collect_outputs paths, and split "unreadable" from
"empty" — the previous silence is what made this invisible in production.

One existing test pinned the old behaviour (a tar whose single entry has a
different basename must yield nil). Its premise cannot happen: archive_out
always returns the tar of the path asked for. It now asserts the real contract —
content wins over a mismatched header name, nil only when the archive carries no
file entry at all.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…stable

CI failed on this branch in a test the branch does not touch:

    inject_repositories falls back to per-repository tokens when one repo
    poisons the group token
    - expected [["good", "bad"], ["good"], ["bad"]]
    + actual   [["bad", "good"], ["bad"], ["good"]]

`Repository.where(id: ids)` carries no ORDER BY, so Postgres is free to hand
the rows back in any order. That order decides the `repositories:` list sent to
GitHub when minting the group installation token, and the order the repositories
clone in — a latent flake that had simply been landing the lucky way until now.

Order by id. The list GitHub sees and the clone order are now the order the
repositories were attached, run to run.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@artempartos
artempartos merged commit 1434542 into develop Aug 7, 2026
6 checks passed
alex-astafyev pushed a commit to alex-astafyev/flow that referenced this pull request Aug 19, 2026
* origin/develop:
  fix(sessions): stop losing session outputs with long file names (AixleHQ#47)
  chore(bmad): bump BMAD Method to 6.10.0 (AixleHQ#46)
  fix: size the Active Record pool from Puma's thread budget (AixleHQ#45)
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