#7767: fix: enable turn validation for all non-OpenAI providers to prevent role ordering errors
agents
stale
Cluster:
Tool Call ID Sanitization
## #7693
Third-party OpenAI-compatible providers (e.g., Kimi/Moonshot, DashScope/Qwen) configured with `api: "openai-completions"` were encountering API errors:
- `"roles must alternate between 'user' and 'assistant'"`
- `"incorrect role information"`
These errors resulted in the user-facing message: **"Message ordering conflict - please try again."**
## Root Cause
In [agents/transcript-policy.ts](cci:7://file:///c:/Users/reddragon/Documents/open-source/openclaw/src/agents/transcript-policy.ts:0:0-0:0), the [validateAnthropicTurns](cci:1://file:///c:/Users/reddragon/Documents/open-source/openclaw/src/agents/pi-embedded-helpers/turns.ts:76:0-118:1) flag was only enabled for Anthropic providers:
```typescript
validateAnthropicTurns: !isOpenAi && isAnthropic,
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR changes transcript policy resolution so `validateAnthropicTurns` is enabled for all non-OpenAI providers (previously only non-OpenAI Anthropic), aiming to prevent role-ordering errors from OpenAI-compatible third-party providers.
The change affects how session history is sanitized/validated before use in the embedded runner (both run and compaction flows) via `resolveTranscriptPolicy` → `sanitizeSessionHistory` → optional `validateGeminiTurns`/`validateAnthropicTurns`.
<h3>Confidence Score: 4/5</h3>
- Likely safe to merge, but the renamed semantics of the validation flag deserve a second look.
- The PR is a small, localized change that broadens when a validation step runs; main risk is behavioral mismatch/overreach (applying an Anthropic-specific fixer to other providers) rather than correctness regressions across the codebase.
- src/agents/transcript-policy.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#12812: fix(transcript-policy): sanitize tool call IDs for all non-OpenAI p...
by justin-nevins · 2026-02-09
80.8%
#13831: fix(agents): include Anthropic in tool call ID sanitization
by lailoo · 2026-02-11
78.4%
#15197: fix: allow OpenAI auth profiles for OpenAI-compatible providers
by bufordtjustice2918 · 2026-02-13
77.8%
#17179: fix: validateAnthropicTurns handles consecutive system messages for...
by Limitless2023 · 2026-02-15
77.3%
#13976: fix(anthropic): include Anthropic in tool call ID sanitization
by omair445 · 2026-02-11
76.8%
#2806: [AI-Assisted] Fix: Repair tool_use/tool_result pairing for Claude o...
by Arthur742Ramos · 2026-01-27
76.3%
#14187: fix: add Moonshot AI to non-standard provider detection
by shad0wca7 · 2026-02-11
75.5%
#23549: fix: extend repairToolUseResultPairing and allowSyntheticToolResult...
by imjszhang · 2026-02-22
74.9%
#19451: fix(errors): surface provider hint for role-ordering failures
by rafaelipuente · 2026-02-17
74.9%
#22194: fix(agent) Moonshot/Kimi kimi-k2.5 returns ROLE_UNSPECIFIED
by ShengFuC · 2026-02-20
74.6%