← Back to PRs

#9309: fix(sanitize): filter delivery-mirror messages to preserve tool ordering

by whoknowsmann open 2026-02-05 03:44 View on GitHub →
agents stale
## 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