Done. This round fixed a coherent cluster of real bugs in context compaction — the two the prior audit flagged plus a related one — rather than manufacturing churn. Pushed to PR #7.
The root problem: the context-size estimators counted only message content and ignored the tool_calls payload. An assistant turn that only calls tools has empty content, so a tool-call-heavy session looked far smaller than it actually is on the wire. Three concrete consequences, all now fixed:
- Compaction fired late.
estimateChars (the trigger that decides when to trim the conversation) treated tool-call turns as ~0 chars, so a long tool-heavy turn could blow past the real budget before compaction kicked in — risking backend 400s and truncation. It now counts the tool-call payload. The change is additive, so messages without tool calls are unchanged (the existing exact-count test still holds).
- The
/context readout and fill nudge under-reported. summarizeContextUsage had the same blind spot, so the "window ~85% full, wrap up" nudge fired later than it should. Now it uses the accurate accounting.
- Summaries lost tool history.
buildSummaryTranscript skipped any assistant turn with empty content, which meant tool-call turns vanished from the LLM summary — the recap lost "who called what." It now renders (called write_file, …) so the compacted summary keeps the action history. That's a direct intelligence win for long sessions.
DRY: extracted context/message-size.ts with messageChars and skipLeadingToolMessages — the latter was duplicated verbatim in compaction.ts and summary-compact.ts (the orphaned-tool-window guard that keeps strict backends from 400ing).
Verification: 1481 tests pass (new tests for tool-call retention in summaries and tool-call counting in estimateChars), typecheck clean on core and app, exec smoke 10/10.
A candid note on where this is heading: four passes in, the high-value findings are getting sparser — I've now worked through essentially all the SAFE items across the prior audits (loop correctness, WWM, SSE, verify/plan bugs, MCP leak, and now compaction). The remaining flagged items are deliberate design tradeoffs (the verify recall taper) or genuinely RISKY refactors I've been avoiding on purpose because they'd threaten the "don't dip any quality" constraint — e.g., unifying all the JSON loaders despite their intentionally different throw-vs-fallback contracts, or migrating on-disk paths for the .naxil→.nxlite rebrand. If you want, I can take on one of those RISKY items carefully (with migration handling and tests), or shift to a different kind of improvement — but I'd rather tell you that plainly than invent low-value churn and risk regressing working code.