← Back to PRs

#8961: feat: smarter compaction tool truncation + token count in system prompt report

by SocialNerd42069 open 2026-02-04 17:20 View on GitHub →
docs gateway cli docker agents size: M
## Changes ### 1. Compaction tool output truncation (`compaction-safeguard.ts`) When sessions get compacted, large tool outputs (e.g. massive file reads, search results) were being kept in full, bloating the compacted history. This adds intelligent truncation: - Caps tool result tokens at 2% of total context (min 400 tokens / 2000 chars) - Replaces excess with `[Tool output truncated for compaction]` - Keeps compacted sessions leaner without losing critical information ### 2. Token estimation in system prompt report (`system-prompt-report.ts` + `types.ts`) Adds actual token estimation to the system prompt report alongside the existing character count. Useful for understanding real token budget usage of the system prompt. --- Small, self-contained patches. Been running these in production for weeks with no issues. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR updates the compaction safeguard and system prompt reporting. - `src/agents/pi-extensions/compaction-safeguard.ts` introduces constants/imports intended to truncate large tool outputs during session compaction, but the truncation behavior is not actually implemented in the current code. - `src/agents/system-prompt-report.ts` extends the system prompt report to include an estimated token count (now reflected in `src/config/sessions/types.ts`). Overall, the direction fits the existing compaction/reporting utilities, but a couple of changes appear incomplete or may not function as intended without additional wiring/validation. <h3>Confidence Score: 3/5</h3> - This PR has a couple of correctness gaps that should be addressed before merging. - The compaction truncation described in the PR does not appear to be implemented (unused constants/import), and the token estimation call may be using an incorrect input shape and can silently produce no token count due to broad error swallowing. - src/agents/pi-extensions/compaction-safeguard.ts, src/agents/system-prompt-report.ts <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs