-
-
Notifications
You must be signed in to change notification settings - Fork 56.7k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Bug
During context truncation in long sessions (566+ messages, 4.6MB), limitHistoryTurns() can slice at user message boundaries, dropping an assistant(tool_use) while keeping its matching toolResult. This creates an invalid message sequence that the Anthropic API rejects on every retry.
Root Cause
repairToolUseResultPairing()runs viasanitizeSessionHistory()beforelimitHistoryTurns()— so the repair is done, thenlimitHistoryTurnsre-introduces orphans by naive slicingdist/agents/pi-extensions/transcript-sanitize.jsexists and would fix this on everycontextevent (every API call), but it's never loaded inbuildEmbeddedExtensionPaths()— dead code
Fix (applied locally, works)
- Load
transcript-sanitizeextension inbuildEmbeddedExtensionPaths()— safety net on every API call - Call
sanitizeToolUseResultPairing()afterlimitHistoryTurns()in bothattempt.jsandcompact.js
Files
dist/agents/pi-embedded-runner/extensions.js— addresolvePiExtensionPath('transcript-sanitize')dist/agents/pi-embedded-runner/run/attempt.js— repair after limitHistoryTurnsdist/agents/pi-embedded-runner/compact.js— same
Repro
Run a session past ~500 messages with heavy tool use until auto-compaction triggers. The session becomes unrecoverable with roles must alternate / incorrect role information errors.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working