← Back to PRs

#22701: fix(reply): make usage footer reflect full turn usage and avoid transient-status noise

by artwalker open 2026-02-21 14:47 View on GitHub →
agents size: S
## Summary This PR fixes inconsistent Usage footer behavior in chat replies by separating three concerns: 1. **Avoid missing footer when aggregate usage is absent** - Fallback from `agentMeta.usage` to `agentMeta.lastCallUsage` for footer generation. 2. **Prefer full-turn totals for footer reporting** - Add `agentMeta.turnUsage` (accumulated across tool loops/retries/compaction retries). - Footer precedence is now: `turnUsage` -> `usage` -> `lastCallUsage`. 3. **Suppress footer on transient operational status blurbs** - Keep final reply usage visible, but suppress footer on short status-like texts (e.g. `Running...`, `Checking...`). ## Why Previously users could see the opposite of expected UX: - transient status text showing `Usage: ...`, and/or - final short reply missing `Usage: ...` even when usage existed. This change makes footer reporting both more accurate and less noisy. ## Changes - `src/agents/pi-embedded-runner/types.ts` - add `turnUsage` to `EmbeddedPiAgentMeta`. - `src/agents/pi-embedded-runner/run.ts` - accumulate and expose `turnUsage`. - `src/auto-reply/reply/agent-runner.ts` - footer usage source precedence updated to `turnUsage ?? usage ?? lastCallUsage`. - transient status detection guard for footer append. - Tests - `src/agents/pi-embedded-runner/usage-reporting.test.ts` - `src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts` ## Validation - `pnpm -s vitest src/agents/pi-embedded-runner/usage-reporting.test.ts src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts` - `pnpm -s build` Both pass locally. <!-- greptile_comment --> <h3>Greptile Summary</h3> Improved usage footer accuracy by separating concerns for context-window reporting vs billing totals, and suppressing footer noise on transient status messages. The changes add `turnUsage` tracking in `EmbeddedPiAgentMeta` to capture accumulated usage across tool loops and retries, update footer precedence to prefer `turnUsage` over the context-window-focused `usage`, and implement detection logic to skip appending usage lines to short operational status texts. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - Changes are well-scoped, address a clear UX issue with proper separation of concerns, include comprehensive tests validating both the turnUsage accumulation and the transient status detection, and follow established patterns in the codebase - No files require special attention <sub>Last reviewed commit: 3c71e9f</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs