#9309: fix(sanitize): filter delivery-mirror messages to preserve tool ordering
agents
stale
Cluster:
Error Handling in Agent Tools
## What
Filters out delivery-mirror messages during context sanitization to preserve `tool_use` → `tool_result` ordering.
## Why
Fixes #9281 — When the `message` tool sends an outbound message, OpenClaw injects a delivery-mirror assistant message into the transcript. This message can be inserted between `tool_use` and `tool_result`, breaking Anthropic's strict requirement that `tool_result` must immediately follow `tool_use`. This causes 400 errors and bricks the session.
## How
- Added `filterDeliveryMirrorMessages()` helper that removes messages with `model="delivery-mirror"` and `provider="openclaw"`
- Called early in `sanitizeSessionHistory()` before tool_use/result repair runs
- Messages remain in JSONL transcript for UI/debugging, only filtered from API-facing context
## Testing
- All 131 pi-embedded-runner tests pass
- Added 2 new tests specifically for delivery-mirror filtering
- `pnpm build && pnpm check` ✅
---
🤖 *Built together with Claude. Fully tested, code reviewed and understood.*
Most Similar PRs
#8345: fix: prevent synthetic error repair from creating tool_result for d...
by vishaltandale00 · 2026-02-03
68.8%
#6687: fix(session-repair): strip malformed tool_use blocks to prevent per...
by NSEvent · 2026-02-01
66.8%
#21195: fix: suppress orphaned tool_use/tool_result errors after session co...
by ruslansychov-git · 2026-02-19
66.7%
#23698: fix: sanitize tool call IDs in agent loop for Mistral strict9 forma...
by echoVic · 2026-02-22
66.6%
#9248: Fix: Webchat UI goes grey/unresponsive after Slack message tool calls
by vishaltandale00 · 2026-02-05
66.6%
#14328: fix: strip incomplete tool_use blocks from errored/aborted messages...
by Kropiunig · 2026-02-12
66.3%
#4009: fix(agent): sanitize messages after orphan user repair
by drag88 · 2026-01-29
66.2%
#13831: fix(agents): include Anthropic in tool call ID sanitization
by lailoo · 2026-02-11
65.9%
#12487: fix(agents): strip orphaned tool_result when tool_use is sanitized ...
by skylarkoo7 · 2026-02-09
65.9%
#19094: Fix empty tool_call_id and function names in provider transcript pa...
by yxshee · 2026-02-17
65.8%