Skip to content

feat: short-output auto-passthrough — skip compression when raw output is already minimal#2674

Open
lg320531124 wants to merge 1 commit into
rtk-ai:developfrom
lg320531124:feat/short-output-auto-passthrough
Open

feat: short-output auto-passthrough — skip compression when raw output is already minimal#2674
lg320531124 wants to merge 1 commit into
rtk-ai:developfrom
lg320531124:feat/short-output-auto-passthrough

Conversation

@lg320531124

Copy link
Copy Markdown

Summary

Closes #2673

When command output is already minimal (≤5 lines, ≤500 bytes), skip the compression pipeline entirely and emit raw output unchanged. This prevents filter reshaping of short signal commands and avoids zero-savings compression overhead.

Problem

RTK compresses all command output. When output is already short, compression:

  • Yields zero token savings (nothing to compress)
  • Can reshape or inflate canonical markers (e.g. git push output, echo $?)
  • Adds unnecessary latency (filter pipeline runs for no benefit)

PR #2667 adds hook-level passthrough for predefined signal commands, but:

  1. Only covers the hook layer — rtk git status called directly still compresses
  2. Allowlist-based — echo $?, which python3, hostname etc. are not in the list
  3. Coarse heuristic — git status -uall (1000 lines) gets the same passthrough as clean git status (3 lines)

Solution

An output-length heuristic at the CLI execution layer that auto-passthroughs any short output, regardless of command name.

Both conditions must be met (AND logic):

  • line_count ≤ 5 — covers git push (2 lines), echo $? (1 line), clean git status (3 lines)
  • output.len() ≤ 500 — prevents passthrough for very long single-line output (e.g. minified JSON)

Interaction with #2667

Scenario #2667 (hook) This PR (CLI) Result
git push (2 lines) Hook skips rewrite N/A (raw command runs) ✅ Raw output
rtk git status (3 lines) N/A (already rtk) Auto-passthrough ✅ Raw output
rtk git status -uall (1000 lines) N/A Exceeds threshold → compressed ✅ Compressed
echo $? (1 line) Not in allowlist Auto-passthrough ✅ Raw output
rtk git log -50 (200 lines) N/A Exceeds threshold → compressed ✅ Compressed

Changes

File Change Lines
src/core/config.rs PassthroughConfig struct, effective_*() methods, config tests +88
src/core/runner.rs should_auto_passthrough(), integration in run_captured_filter(), tests +110
docs/contributing/DESIGN-short-output-passthrough.md Full design document +393

Total: ~90 lines of production code (excluding design doc and tests). No new files, no new modules, no new dependencies.

Config

# ~/.config/rtk/config.toml
[passthrough]
short_line_threshold = 5    # ≤ 5 lines → passthrough (default: 5)
short_byte_threshold = 500  # ≤ 500 bytes → passthrough (default: 500)
  • Default: Auto-passthrough ON (5 lines / 500 bytes)
  • Opt-out: Set short_line_threshold = 1 + short_byte_threshold = 1

Test Plan

  • Unit tests for should_auto_passthrough() (8 test cases)
  • Config deserialization tests (4 test cases)
  • cargo fmt --all && cargo clippy --all-targets && cargo test --all — all pass (2299 tests)
  • Manual test: rtk git status (short → passthrough) vs rtk git log -50 (long → compressed)
  • Performance: hyperfine comparison (passthrough should be faster for short commands)

Design Document

Full design doc: docs/contributing/DESIGN-short-output-passthrough.md

Covers: architecture, insertion point rationale, feature interaction matrix, edge cases, migration strategy, open questions.

@CLAassistant

CLAassistant commented Jun 28, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@lg320531124

Copy link
Copy Markdown
Author

Friendly nudge — open ~28h, CI green. This is a perf win for the common case: when raw model output is already minimal (short responses), skipping compression avoids unnecessary token/latency overhead with no behavior change for longer outputs. +591 all new code + tests, no changes to existing paths. Happy to split into smaller commits or add benchmarks if that eases review.

When command output is already minimal (≤5 lines, ≤500 bytes), skip the
compression pipeline entirely and emit raw output unchanged. This prevents
filter reshaping of short signal commands (git push, echo $?, hostname, etc.)
and avoids zero-savings compression overhead.

- Add PassthroughConfig with short_line_threshold / short_byte_threshold
- Add should_auto_passthrough() heuristic in runner.rs
- Integrate check in run_captured_filter() after capture, before filter
- Track auto-passthrough via track_passthrough() (honest 0% savings)
- Config defaults: 0/0 → effective 5/500 (auto-passthrough ON)
- Opt-out: set both thresholds to 1
- Complements PR rtk-ai#2667 (hook-level passthrough) at CLI execution layer

Files changed:
- src/core/config.rs: PassthroughConfig struct, effective_*() methods, tests
- src/core/runner.rs: should_auto_passthrough(), integration, tests
- docs/contributing/DESIGN-short-output-passthrough.md: full design doc
@lg320531124 lg320531124 force-pushed the feat/short-output-auto-passthrough branch from 026b879 to e8a29f1 Compare July 1, 2026 00:12
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.

feat: short-output auto-passthrough — skip compression when raw output is already minimal

2 participants