#22701: fix(reply): make usage footer reflect full turn usage and avoid transient-status noise
agents
size: S
Cluster:
Memory Management Enhancements
## 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
#17253: fix: propagate lastTurnTotal through usage accumulator for accurate...
by robbyczgw-cla · 2026-02-15
80.6%
#18072: fix(Telegram): usage footer not sent to Telegram when blockStreamin...
by yinghaosang · 2026-02-16
80.5%
#8477: TUI: persist session token totals when usage metadata is missing
by LarHope · 2026-02-04
76.7%
#22387: fix: session_status context tracking undercount for cached providers
by 1ucian · 2026-02-21
75.8%
#15126: fix(status): avoid false 100% context usage when totals mirror context
by AlexAnys · 2026-02-13
75.7%
#13215: fix: pass agentId to loadCostUsageSummary in /usage cost command
by veast · 2026-02-10
75.5%
#15999: fix: handle null/undefined in activity feed filters
by pamnlambert · 2026-02-14
75.1%
#19412: fix(status): prefer configured contextTokens over session entry
by rafaelipuente · 2026-02-17
75.1%
#22089: feat: persist default /usage mode via agents.defaults.usage
by AIflow-Labs · 2026-02-20
75.0%
#17109: fix: preserve responseUsage across session resets
by Limitless2023 · 2026-02-15
74.9%