Skip to content

v0.21.11 — tail-cap undercount fix (GLM-4.7 32k truncate loop)

Choose a tag to compare

@TheArchitectit TheArchitectit released this 20 Aug 03:02
· 12 commits to master since this release

Fix

Tail-cap token undercount (2026-08-20 incident, attempt #8). applyTailCap estimated preserved-tail messages with text-only extraction while pi's convertToLlm ships assistant/toolResult messages verbatim (thinking blocks + toolCall arguments JSON included). A ~30k-token tail registered as ~5k tokens, passed the ~10.3k budget on a 32k-window model with a 20k output reserve, and overflowed the provider on both the original turn and pi's one-shot overflow retry → "Context overflow recovery failed after one compact-and-retry attempt."

New estimateAgentMessageBudgetTokens (extensions/mega-events/context-handler/headroom.ts) counts every block the provider receives, wired into both the fire path (applyTailCap) and replay path (recapReplayedTail). Failing-first regression tests reproduce the incident shape.

Docs

docs/LIVE_TRIM_AND_OVERFLOW_RECOVERY.md — end-to-end mechanism reference: pi emitContext chain, gate (fast/headroom/Phase H), replay cache + re-cap, thrash guard + debounce with headroom exemptions, tail-cap budget math, the verbatim-accounting invariant, how to validate future fixes, and known sharp edges. Registered in INDEX_MAP.md / HEADER_MAP.md.

Verification

  • 4505 tests / 0 fail, lint clean, regression 0 blocking, guardrails clean
  • Live: pi update --extensions → dashboard 0.21.11; GLM-4.7 32k session completes turns without output truncation

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com