Context compaction corrupts server-side tool pairs (advisor_tool_result without server_tool_use)

Resolved 💬 1 comment Opened Jun 3, 2026 by PJ-lima Closed Jul 7, 2026

Bug Report

Description

When context compaction runs (auto or /compact) near the context limit, it drops server_tool_use blocks but retains the corresponding advisor_tool_result blocks. This produces an unrecoverable 400 error on every subsequent API call, including /compact itself — the session is permanently broken.

Error

API Error: 400 messages.33.content.0: unexpected `tool_use_id` found in `advisor_tool_result` blocks: srvtoolu_01V9UBu9fGvyetuqkNtMsUkM. Each `advisor_tool_result` block must have a corresponding `server_tool_use` block before it.

Reproduction pattern

  1. Long session with multiple advisor() calls
  2. Context fills to ~100%
  3. /compact runs (or is triggered automatically)
  4. Compaction truncates history at a point that orphans an advisor_tool_result
  5. All subsequent API calls return 400 — session unrecoverable, --resume also fails

Impact

  • Session permanently broken, cannot recover with --resume
  • /compact itself also fails with the same error (no escape)
  • All work in context is lost

Environment

  • Claude Code CLI (Linux)
  • Session ID: e3c2492a-3d2c-4031-b831-0a53ba32190f
  • Context: 100% at time of failure

Expected behavior

Compaction should either preserve complete tool use/result pairs or drop both sides atomically.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗