tools: measure tool-output sizes, then tune caps and masking #155

Open
opened 2026-10-15 20:18:04 +00:00 by hermes · 0 comments
Collaborator

Problem (hypothesis, unmeasured)

read allows 600 lines / 20,000 bytes (MAX_LINES, MAX_BYTES in crates/hx-tools/src/lib.rs); bash truncates at the same 20,000 (head 4,000 + tail). Roughly 5k tokens per result, resent each turn. Masking (window.rs, mask.rs) starts only once context passes min(compact_at/3, 60k) tokens, only elides results >= 4,000 bytes, and keeps the last 8 turns. The 60k value comes from two sessions (see the ponytail comment in window.rs). Cache reads are cheap, so the real saving may be small.

Steps

  1. Run hx stats on several real sessions and record resent bytes per tool (bash/read/other), as the stats command already reports.
  2. Only if bash or read dominate: lower the bash cap (e.g. ~10k bytes, keep more of the tail since errors sit at the end), and/or lower MASK_FROM_MAX, KEEP, MIN_BYTES.
  3. Do not change anything if the numbers say resend cost is small.

Effect

Unknown; my rough guess is 5-15% of input cost, low confidence.

Risk

Agent re-reads files it needed; masked-stub rewrites invalidate the cache from the first changed result.

Verify

Same sessions/tasks before and after: compare hx stats resent bytes and the number of repeated read calls on one file.

## Problem (hypothesis, unmeasured) `read` allows 600 lines / 20,000 bytes (`MAX_LINES`, `MAX_BYTES` in `crates/hx-tools/src/lib.rs`); `bash` truncates at the same 20,000 (head 4,000 + tail). Roughly 5k tokens per result, resent each turn. Masking (`window.rs`, `mask.rs`) starts only once context passes `min(compact_at/3, 60k)` tokens, only elides results >= 4,000 bytes, and keeps the last 8 turns. The 60k value comes from two sessions (see the `ponytail` comment in `window.rs`). Cache reads are cheap, so the real saving may be small. ## Steps 1. Run `hx stats` on several real sessions and record resent bytes per tool (bash/read/other), as the stats command already reports. 2. Only if bash or read dominate: lower the `bash` cap (e.g. ~10k bytes, keep more of the tail since errors sit at the end), and/or lower `MASK_FROM_MAX`, `KEEP`, `MIN_BYTES`. 3. Do not change anything if the numbers say resend cost is small. ## Effect Unknown; my rough guess is 5-15% of input cost, low confidence. ## Risk Agent re-reads files it needed; masked-stub rewrites invalidate the cache from the first changed result. ## Verify Same sessions/tasks before and after: compare `hx stats` resent bytes and the number of repeated `read` calls on one file.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: johannes/hx#155