Skip to content

api: keep content on blocking replies that open with a refusal prefix (#172) - #205

Merged
AzeezIsh merged 1 commit into
mainfrom
fix/blocking-refusal-keeps-content
Oct 27, 2026
Merged

AzeezIsh merged 1 commit into
mainfrom
fix/blocking-refusal-keeps-content

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

Fixes #172.

What

When a blocking (non-streaming) reply's text opened with a known refusal pattern and no tool call fired, build_choice_message moved the text into refusal and set content: null. Streaming replies keep the text, so the two paths disagreed: in #172, 27 of 200 blocking replies came back with no content. Most of them were answers that only opened with a hedge ("I cannot verify that source. Here is what the paper says: ...").

Now the refusal classifier still fills refusal, and content keeps the text, so blocking matches streaming.

Tests

🤖 Generated with Claude Code

…ix (#172)

The blocking chat path moved the first sentence into `message.refusal` and
set `content` to null whenever the reply opened with one of the 23 prefixes
in refusal.rs, dropping the rest of the answer. The streamed path sends every
content piece and appends the refusal at the end, so the same prompt gave a
full answer streamed and `content: null` blocking (27/200 on the issue's
GLM-5.3 run). The classifier is a prefix heuristic, so a reply such as
"I cannot verify that source. Here is ..." lost real content.

Blocking now matches streaming: `refusal` is still populated, `content` is
kept. ATLAS_DISABLE_REFUSAL_DETECTION=1 is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

This fix covers more than the OpenAI endpoint. I traced which readers depended on the old content = None:

  • ir::Choice.refusal is read only by openai/encode.rs, which puts it on the chat-completions wire.
  • Anthropic /v1/messages (blocking) goes through chat_completions_inner, then ChatOutcome::Blocking(ir), then MessagesResponse::from(ir). anthropic/translate.rs builds text blocks from c.content alone and never reads refusal. Before this PR, a reply that opened with a refusal prefix came back with no text block at all: just thinking/tool blocks, or an empty content: []. After this PR it carries the full text, the same as the streaming /v1/messages path already did.
  • Streaming chat and /v1/responses streaming keep the text and append a refusal delta/done event. This PR does not change them.

🤖 Generated with Claude Code

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

I ran an adversarial review on this PR (Qwen3.8-Max). Here is what I checked for each concern:

  • Double emission (content + refusal): the only reader of Choice.refusal is openai/encode.rs. Anthropic /v1/messages builds blocks from content only (see my earlier comment). Streaming chat already sends every content piece and then a refusal delta. So blocking now has the same shape as streaming, and no adapter emits the text twice.
  • Strict response_format / JSON schema: strict output is grammar-constrained, so the model emits JSON. A refusal prefix ("I cannot…") cannot match inside a JSON object. Unconstrained json_object was never validated server-side on the blocking path (chat_blocking_choice.rs validates tool calls only).
  • tool_choice: required: the refusal classifier already requires msg_tool_calls.is_none(), and required-tool enforcement keys on tool calls, not on content.
  • "The strip was acting as redaction": it was not. The streaming path never stripped, so the same text has always reached streaming clients.
  • Divergence from OpenAI's content: null on refusal: this is real and intentional. Atlas's classifier is a prefix heuristic, not a model-side refusal channel, and Blocking chat reply nulls content and drops the rest of the answer when it opens with a refusal prefix (streamed path keeps it) #172 showed it nulling real answers 27 times in 200. refusal stays set for clients that branch on it.

🤖 Generated with Claude Code

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Live gate, part 1: BFCL golden ST-995 = 87.44 / 87.32 (n=995, run-1792760075267807876). This was on sparky (GB10), FP4-Local, recipe profile, on a binary built from main 504063a + #205 + #206 at their PR heads (sha256 64bbdec27bd2ffea). That is identical to main's 87.44 / 87.32, so the change is accuracy-neutral. The serve log over the run has only the five standard startup WARNs and 0 ERROR lines. The agentic-webserver 50-iteration leg on the same server is running now, and I'll post it here.

🤖 Generated with Claude Code

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Live gate, part 2: agentic-webserver, 50 iterations, passes: 50/50 webserver_ok, 50/50 followed_directions, 12.344 s/turn, Σwall 4,705 s (run-1792764782219366004). Same server and binary as the BFCL leg (main 504063a + #205 + #206). For comparison, main on the same profile measured 12.43 s/turn. The combined gate passes on both legs: BFCL unchanged at 87.44 / 87.32, agentic 50/50.

🤖 Generated with Claude Code

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Riding integration train #212 (integ/train-2026-10-27, merged --no-ff at this PR's current head). It's being gated on sparky (GB10) now: control vs main, then agentic-webserver 50 + BFCL ST-995 on FP4-Local. The plan is to merge the train once both legs pass and CI shows only the repo-wide reds, which merges this PR. Results will land on #212 and in the campaign log (#211).

@AzeezIsh
AzeezIsh merged commit cf6f9d2 into main Oct 27, 2026
20 of 23 checks passed
AzeezIsh added a commit that referenced this pull request Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blocking chat reply nulls content and drops the rest of the answer when it opens with a refusal prefix (streamed path keeps it)

1 participant