revert: remove trailing empty assistant message stripping

Reverts the sanitizer addition from PR #2466 (originally #2129).
We already have _empty_content_retries handling for reasoning-only
responses. The trailing strip risks silently eating valid messages
and is redundant with existing empty-content handling.
This commit is contained in:
Teknium 2026-03-22 04:55:34 -07:00
parent 5407d12bc6
commit 34be3f8be6
No known key found for this signature in database
8 changed files with 220 additions and 152 deletions

View file

@ -2443,18 +2443,6 @@ class AIAgent:
"Pre-call sanitizer: added %d stub tool result(s)",
len(missing_results),
)
# 3. Strip trailing empty assistant messages to prevent prefill rejection.
# These can leak from Responses API reasoning-only turns (Codex/MiniMax)
# where an empty assistant message is required by the Responses API but
# must NOT be sent to Chat Completions or Anthropic Messages API providers.
while (
messages
and messages[-1].get("role") == "assistant"
and not (messages[-1].get("content") or "").strip()
and not messages[-1].get("tool_calls")
):
logger.debug("Pre-call sanitizer: removed trailing empty assistant message")
messages = messages[:-1]
return messages
@staticmethod