Fix: map Anthropic compaction finish_reason to stop instead of length

When Anthropic's context compaction triggers with pause_after_compaction=True,
the API returns finish_reason "compaction". This was incorrectly mapped to
"length", which signals output truncation due to max_tokens and causes
downstream consumers to retry or attempt continuation. Compaction means the
context was summarized and the model paused naturally, so "stop" is the
semantically correct mapping.

Fixes #25165

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
kaiisfree 2026-04-05 07:34:44 +00:00
parent d251238bd7
commit 3cc452a54c
2 changed files with 2 additions and 2 deletions

View file

@ -65,7 +65,7 @@ _FINISH_REASON_MAP: dict[str, OpenAIChatCompletionFinishReason] = {
"max_tokens": "length",
"tool_use": "tool_calls",
"refusal": "content_filter",
"compaction": "length",
"compaction": "stop",
# Cohere
"COMPLETE": "stop",
"ERROR_TOXIC": "content_filter",

View file

@ -66,7 +66,7 @@ class TestMapFinishReasonAnthropic:
("end_turn", "stop"),
("max_tokens", "length"),
("tool_use", "tool_calls"),
("compaction", "length"),
("compaction", "stop"),
("content_filtered", "content_filter"),
],
)