fix(backend): treat any non-end_turn stop as a failed side-channel call - #1368
Merged
Merged
Conversation
The side-channel summarizers only rejected stopReason == "max_tokens", so a guardrail stop, content-filter refusal or unknown reason was accepted as a valid result. For compaction that let a refusal become the checkpoint summary in the cacheable conversation history until the next cut. Accept only a positive completion signal and fall back through the paths that already exist: - compaction narrative + extraction: end_turn, or max_tokens (salvaged as before); anything else returns None -> truncation / plain compression - tool-batch summary and document abstract: end_turn only -> None - conversation title: end_turn, or max_tokens (the existing 50-char clip); anything else keeps the "New Conversation" placeholder Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The side-channel Converse calls only rejected
stopReason == "max_tokens". Any other non-completion stop (a guardrail stop, a content-filter refusal,tool_use, an unknown reason, or a missing reason) was accepted as a valid result. This change accepts a result only on a positive completion signal. Everything else goes through the fallback that site already has. No new fallbacks are added.compaction_summary._compress)end_turn,max_tokens(salvaged as before)None, then newest-first truncation (truncated_after_model/extract_then_truncate)extract_with_model)end_turn,max_tokens(complete lines kept as before)None, then the narrative alone (plain compression)tool_summaries/summarizer.py)end_turnNone, then the SPA's deterministic formatterfiles/document_digest.py)end_turnNone(digest without an abstract)inference_api/chat/service.py)end_turn,max_tokens(the existing 50-char clip)"New Conversation"placeholder, with no title write and nosession_titleeventWhy
Kaizen review 2026-09-25, Proposal 2 (Ship). A refused or guardrail-stopped compaction summary becomes the checkpoint in the cacheable conversation history, and it stays there until the next cut. That costs answer quality for the rest of the session and cannot be undone. The tool-summary, abstract and title outputs also persist (as
TSUM#rows, the digest and the session title), so a refusal's text would be shown or fed back to the model. We don't know exactly which stop reason Bedrock returns for a refusal, and this change makes that irrelevant.The
max_tokenssalvage added for compaction in PR 1353 is unchanged. The title keeps acceptingmax_tokensbecause its overrun handling (the 50-char clip) already exists and changing it is out of scope.Tests
guardrail_intervenedtest per site, parametrized withcontent_filtered,tool_use, an unknown reason andNonewhere relevant:max_tokenstests are unchanged and still pass, including all salvage tests. Added a title test confirmingmax_tokensoutput is still clipped.🤖 Generated with Claude Code