Skip to content

filters: universal no-bloat guard — never emit output larger than raw #95

Closed

Description

@thehoff

Symptom

Several filters produce output larger than the raw command output — negative savings. Measured from the production tracking DB (30d):

Bucket Calls Savings
tsc -b 5 −94%
pytest --verbose 26 −75%
gh pr create 5 −23%
git push -u 5 −7%
small grep results many negative (header overhead exceeds tiny raw output; a no-match grep emits "0 matches for…" ≈ 13 tokens where raw grep emits 0)

Same root class as #89 (git add recorded −1300%): a filter adds framing/summary to a command whose raw output was already small or empty.

Fix

A single guard in the filter dispatch path — after a filter produces its output, before emitting and tracking:

// A filter must never cost more than it saves. If the filtered form is
// larger than the raw output, emit raw — the wrapper has nothing to add here.
let final_output = if filtered.len() >= raw.len() { &raw } else { &filtered };

Apply at the common dispatch site so it covers every filter (Rust command filters AND the TOML-filter path), not per-filter. Track against final_output so the dashboard reflects reality.

Caveats

  • The grep no-match case ("0 matches for…") is arguably useful signal even though it's larger than empty. Decide: either let the guard emit raw-empty (agent sees nothing, same as bare grep), or special-case a 1-token marker. Recommend: emit raw — consistency over a 13-token convenience.
  • Don't let the guard mask a filter that's supposed to summarise (e.g. git add's --stat baseline from git add: tracking records -1300% savings (filter adds info to silent command) #89 is intentionally informational) — those track against a synthetic baseline, not raw, so they won't trip the guard. Verify the guard sits after baseline selection.

Acceptance

  • No command bucket in contextcrawler gain shows negative savings.
  • tsc -b, gh pr create, git push, small/no-match grep all show 0% (passthrough) rather than negative.
  • A regression test: feed a filter input where the filtered form would be larger, assert raw is emitted.

Activity

  1. added 2 commits that reference this issue on Jun 4, 2026
    b39597b
    9134e51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions