Skip to content

fix(runtime): spill oversized shell_exec output instead of truncating (#6242)#6246

Merged
houko merged 3 commits into
mainfrom
feat/6242-shell-spill
Jun 20, 2026
Merged

fix(runtime): spill oversized shell_exec output instead of truncating (#6242)#6246
houko merged 3 commits into
mainfrom
feat/6242-shell-spill

Conversation

@houko

@houko houko commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Refs #6242 — implements the core information-loss fix from @pavver's proposal (the gap in Option 1).

The artifact store (#3347) already spills oversized tool results to disk and hands the agent a read_artifact stub. But shell_exec truncated its stdout/stderr lossily (safe_truncate_str at max_output_bytes, default 100 KB) before the universal spill ever saw the bytes — so a long run's dropped middle was gone, not recoverable. That is the one place the store leaked information, and it's exactly the issue's motivating example (a 25k-line cargo test losing its middle).

Change

shell_exec now routes oversized stdout/stderr through artifact_store::maybe_spill (via the existing spill::spill_or_passthrough helper) instead of safe_truncate_str. Streams ≤ max_output pass through inline; over it, the agent gets a compact stub recoverable via read_artifact. Reuses the existing store — GC, dedup, atomic writes, the read_artifact retrieval tool — so there's no new subsystem; the change is confined to shell.rs plus a unit test in spill.rs.

Verification

Adds spill.rs unit tests: below-threshold passthrough returns the body unchanged, and above-threshold spill writes a recoverable artifact (isolated via LIBREFANG_HOME + a tempdir, so the real home is untouched). The underlying spill machinery (maybe_spill / write / build_spill_stub) is already covered by artifact_store.rs tests.

Follow-ups (not in this PR)

Options 2/3 (exit-code-aware line filtering) and Option 4 (a prompt quiet-flag bullet) from the proposal are optional enhancements that should build on this spill — filter the context view, never the stored bytes. Please close #6242 if this core fix is sufficient, or keep it open to track those.

…#6242)

`shell_exec` capped stdout/stderr at `max_output_bytes` (default 100 KB) with `safe_truncate_str` plus an `[truncated, N total bytes]` note, so the dropped middle of a long run (e.g. a 25k-line test log) was unrecoverable — the universal artifact spill (#3347) never saw those bytes because the tool truncated them first.

Oversized streams now route through `artifact_store::maybe_spill` (via the existing `spill::spill_or_passthrough` helper), yielding a compact stub the agent can page back in full via `read_artifact`.
Streams at or below `max_output` pass through inline, and the universal post-tool spill still applies to the assembled result, so small streams are unaffected.

Adds unit tests for `spill_or_passthrough`: passthrough below threshold, and a recoverable artifact written above it (isolated via `LIBREFANG_HOME` + tempdir).
@github-actions github-actions Bot added size/M 50-249 lines changed area/docs Documentation and guides area/runtime Agent loop, LLM drivers, WASM sandbox has-conflicts PR has merge conflicts that need resolution labels Jun 20, 2026
…move multi-line comment

The fix(runtime) bullet was filed under ### Added, which is reserved for new
features — a behaviour change to an existing tool belongs under ### Changed.

Removes the 7-line comment block from shell.rs: it restated what
spill_or_passthrough's name already communicates, referenced issue numbers
that will rot, and exceeded the repo's one-short-line-max comment rule.
@github-actions github-actions Bot added ready-for-review PR is ready for maintainer review and removed has-conflicts PR has merge conflicts that need resolution labels Jun 20, 2026
@houko
houko enabled auto-merge (squash) June 20, 2026 01:39
@houko
houko merged commit 6ced8fa into main Jun 20, 2026
31 checks passed
@houko
houko deleted the feat/6242-shell-spill branch June 20, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation and guides area/runtime Agent loop, LLM drivers, WASM sandbox ready-for-review PR is ready for maintainer review size/M 50-249 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: Active Tool Output Optimization & Diagnostic Log Offloading

1 participant