Skip to content

transcript-sanitize extension defined but never loaded — tool_use/tool_result orphan crash #2955

@noetiqnoetiq

Description

@noetiqnoetiq

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

  1. repairToolUseResultPairing() runs via sanitizeSessionHistory() before limitHistoryTurns() — so the repair is done, then limitHistoryTurns re-introduces orphans by naive slicing
  2. dist/agents/pi-extensions/transcript-sanitize.js exists and would fix this on every context event (every API call), but it's never loaded in buildEmbeddedExtensionPaths() — dead code

Fix (applied locally, works)

  1. Load transcript-sanitize extension in buildEmbeddedExtensionPaths() — safety net on every API call
  2. Call sanitizeToolUseResultPairing() after limitHistoryTurns() in both attempt.js and compact.js

Files

  • dist/agents/pi-embedded-runner/extensions.js — add resolvePiExtensionPath('transcript-sanitize')
  • dist/agents/pi-embedded-runner/run/attempt.js — repair after limitHistoryTurns
  • dist/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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions