Skip to content

fix: compact tool results while preserving full execution evidence - #67

Merged
locez merged 3 commits into
mainfrom
fix/compact-tool-output
Sep 21, 2026
Merged

locez merged 3 commits into
mainfrom
fix/compact-tool-output

Conversation

@locez

@locez locez commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Summary

Separate tool-authored model bodies from full display/evidence artifacts so repeated model requests do not replay redundant output envelopes.

  • Persist optional model text/JSON for transcript replay, session resume, and compaction, while artifact reads and checkpoint references retain full evidence.
  • Return compact process status, stdout/stderr, and applicable guidance. Preserve UTF-8 text unchanged; label non-UTF-8 replacement characters explicitly and retain exact captured bytes in the full artifact instead of replaying JSON/base64 to the model.
  • Compact read_text, apply_patch, and workspace failure results without dropping line ranges, truncation notices, errors, or actionable guidance.
  • Unify result-content ownership and constructor validation, borrow compaction history rather than cloning full payloads, and emit recovery guidance only once per model result.
  • Share process-output fields between the writer, TUI, and debug shell; preserve historical integer statuses and optional metadata, and keep malformed stream payloads inspectable as raw text.

Boundaries and compatibility

  • Tools own result semantics. Generic runtime code only validates, persists, and selects the supplied bodies; provider adapters remain unchanged.
  • Existing results without a separate model body keep their prior behavior. Permission review and exact evidence access continue to use full artifacts.
  • Tool definitions, schemas, ordering, and stable request prefixes remain unchanged, with deterministic boundary coverage for replay and cache-prefix stability.
  • Binary inspection output is not summarized by runtime. Non-UTF-8 model text is explicitly lossy; lossless captured bytes remain in artifacts.

Validation

Completed on the submitted code before creating this PR:

  • git diff --check
  • cargo fmt --all --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all
  • cargo build -p merry-cli
  • Python dependency sync, Ruff, and ty
  • Rebuilt the Python native extension with test-utils; 78 Python tests passed
  • uv build (wheel and source distribution)

Regression coverage includes binary stdout/stderr at multiple sizes, output truncation and exceptional statuses, duplicate guidance, byte-exact artifacts, save/resume and checkpoint readback, full permission-review evidence, atomic rejection of invalid results, and TUI legacy/malformed-output handling.

Keep full tool artifacts for evidence and presentation while replaying compact tool-authored bodies to the model. Cover process and workspace outputs, persistence, compaction budgets, and checkpoint reads.

Validation: cargo fmt --all --check; git diff --cached --check; 18 focused runtime, workspace-tool, and provider-boundary tests passed. Baseline commit before the requested result-contract and history-allocation refactor.
Always emit tool-authored process text instead of falling back to the full JSON envelope for non-UTF-8 captures. Preserve captured bytes in artifacts, label lossy text explicitly, and deduplicate recovery guidance.

Unify tool result content ownership and constructor validation, borrow compaction history instead of cloning payloads, and share process output fields with TUI and debug-shell readers. Preserve historical artifact compatibility and keep malformed streams inspectable.

Validation: cargo fmt --all --check; cargo clippy --all-targets --all-features -- -D warnings; cargo test --all; cargo build -p merry-cli; Python Ruff and ty; rebuilt native extension with test-utils; 78 Python tests; uv build; git diff --check.
Use exact-byte fixtures and cover LF/CRLF behavior. Validation: 84 tests passed on Python 3.10 and 3.14; Ruff, ty and packaging passed.
@locez
locez merged commit 744de00 into main Sep 21, 2026
8 checks passed
@locez
locez deleted the fix/compact-tool-output branch September 21, 2026 16:48
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