-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
bug: compaction preserves orphaned tool_use blocks after request timeout, permanently breaking session #93321
Copy link
Copy link
Closed
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.ClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.Good issue quality with a plausible reproduction path needing some confirmation.staleMarked as stale due to inactivityMarked as stale due to inactivity
Description
Metadata
Metadata
Assignees
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.ClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.Good issue quality with a plausible reproduction path needing some confirmation.staleMarked as stale due to inactivityMarked as stale due to inactivity
Type
Fields
Priority
None yet
Description
When an LLM request times out mid-turn while the agent has pending parallel tool calls (tool_use blocks without corresponding tool_result blocks), OpenClaw's compaction mechanism preserves the orphaned tool_use blocks in the compacted history. This causes every subsequent API call to be permanently rejected with a
ValidationException: messages.N: tool_use ids were found without tool_result blockserror, rendering the agent completely unresponsive.Steps to Reproduce
web_fetch+memory_searchcalls)[assistant turn failed before producing content]on every subsequent messageRoot Cause
In OpenClaw's compaction logic, when the session history is truncated/summarized, there is no validation that every
tool_useblock in the retained history has a correspondingtool_resultblock immediately following it.The Anthropic API (and AWS Bedrock's Claude endpoint) strictly requires that every
tool_useblock be immediately followed by itstool_resultin the next message. When compaction truncates at a boundary that splits a(tool_use → tool_result)pair, the orphanedtool_useblock poisons the entire session permanently.Observed in session
a7c86c90-f74b-41a9-980b-70a4c6fb8570(wukongim agent):2026-06-15T09:04(context: ~118k tokens, provider request timeout)toolu_dc61dfdd…,toolu_b0bb3eae…,toolu_9088da77…10:53,11:04,11:13— each time re-embedding the same broken blocks17:36onward (~6 hours of failed retries)Expected Behavior
Compaction should validate
tool_use/tool_resultpairing integrity before finalizing the compacted history. If a truncation boundary would leave atool_useblock without itstool_result, the compaction should either:tool_useblock along with any partial context around it), ortool_resultwith an error/cancelled status so the message sequence remains validThis would prevent a single LLM timeout from permanently corrupting a session.
Suggested Fix
In the compaction module, after generating the truncated/summarized message list, add a post-processing validation pass:
Alternatively, detect orphaned
tool_useblocks at request-build time and strip them before sending to the provider, logging a warning.Workaround
Delete or reset the agent's
sessionIdinsessions.jsonand restart the gateway. This forces a fresh session on the next message, discarding the corrupted history.Environment
anthropic-messagesAPI)anthropic/ml4.6-plus(claude-sonnet-4-6)truncateAfterCompaction: truewas configured inagents.defaults.compactionbut did not prevent the corruption (the timeout happened before compaction could cleanly reset the context)