anthropics / anthropics/claude-code
Orphaned advisor_tool_result after /compact makes the session permanently un-continuable (400)
- Dominant language
- Python
- Stars
- 145k
- Forks
- 23.1k
- PR merge metrics
- PR metrics pending
Description
## Summary
After `/compact`, a session that had previously used the **advisor** tool becomes permanently un-continuable: every subsequent request fails with a 400 naming an orphaned `advisor_tool_result` block. The only escape is `/advisor off`.
## Error
```
API Error: 400 messages.3.content.0: unexpected `tool_use_id` found in `advisor_tool_result` blocks:
srvtoolu_01RWdWPc9bkfPqFmB8bwC5K4. Each `advisor_tool_result` block must have a corresponding
`server_tool_use` block before it.
```
## Steps to reproduce
1. Start a long session with the advisor enabled.
2. Call the advisor a few times (it succeeds normally).
3. Run `/compact`.
4. Continue working.
From that point on, every request fails with the 400 above, always naming the same `srvtoolu_…` id and the same message index.
## What appears to be happening
The advisor is a server-side tool, so each call stores a `server_tool_use` block paired with an `advisor_tool_result`. Compaction rebuilds the message history, and it looks like the `advisor_tool_result` survives while the `server_tool_use` that produced it is dropped or summarised away — leaving an orphaned result block at a fixed index. The API validates the pairing on every subsequent request, so the failure is deterministic rather than transient.
## Impact
- **Not recoverable from inside the session.** The orphan is in the replayed history, so every retry fails identically. Retrying, waiting, or rephrasing does nothing.
- An active `/goal` loop retries on a timer and burns its attempts against the same 400, reporting only "the API returned an unexpected response", which does not point at the advisor at all. Diagnosing it takes reading the raw error.
- Work in flight is not lost, but the session cannot continue until the user finds `/advisor off` — which is not an obvious remedy from the error text.
## Workaround
`/advisor off`, then continue. The session recovers immediately.
## Expected
Compaction should keep an advisor call and its result together, or drop both — never emit an `advisor_tool_result` whose `server_tool_use` it discarded. Failing that, the client could detect the orphan and strip it rather than sending a request that cannot succeed.
## Environment
- Claude Code v2.1.273, macOS (darwin 27.0.0), zsh
- Model: Opus 5 (1M context)
- Advisor tool enabled, backed by Fable 5.1
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the /compact history rebuild and the advisor server_tool_use/advisor_tool_result pairing. Reproduce with advisor enabled, inspect the post-compaction history at the failing message index, and consider the issue done when compaction preserves both paired blocks or removes both, with subsequent requests succeeding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100