Repository navigation
feat(server): align Anthropic Messages generation and stop semantics - #3696
Merged
Merged
Conversation
A generation the scheduler stops at the per-slot context bound (StopKind::ContextExhausted, finish_reason "length") now reports stop_reason model_context_window_exceeded on /v1/messages, streaming and non-streaming, not only when the route clamped max_tokens. Requests with media are never clamped, so this was the only way they could report it. The Messages response now always serializes stop_sequence, as null when nothing matched, so the non-streaming body and message_start match the API shape and the closing message_delta. Adds route tests through the scripted provider for a scheduler-matched stop sequence in both modes (reason, matched string, no leaked text), the null field, the context-exhausted stop, and the end-to-end max_tokens clamp including the context-shift exemption. The scripted provider gains a finish step with an explicit finish reason and stop kind. Documents /api/hello in the server feature table. Refs lablup#3625, lablup#3696
Member
Hardening reviewReviewed against #3625 (items 1-6) and the Messages API stop semantics. Items 1-6 are implemented and wired into both the streaming and non-streaming Fixes pushed in bf0fc4e:
Security: Merged current main (9ecd6df). Validation on Linux (CPU build): |
This was referenced Dec 2, 2026
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.
Align Anthropic Messages generation and stop semantics
Fixes #3625.
Claude Code can probe the server with GET or HEAD /api/hello. The probe returns an empty 200 and follows the normal API-key policy. Messages requests translate thinking.type and output_config.effort into the existing template controls; explicit template kwargs still take precedence.
Both JSON and SSE responses honor disable_parallel_tool_use. Text-only requests clamp the generation budget to the space left in the slot, unless context shifting is enabled. A length finish takes precedence over tool use or a stop sequence; only a response that actually reports stop_sequence includes the matched string. The OpenAI routes are unchanged.
Verification
On DGX Spark 2, the pre-review patch passed 122 focused Anthropic tests and workspace Clippy. A live CUDA Qwen3.5-4B-4bit server returned 200 for GET and HEAD /api/hello and emitted a thinking block only when enabled. The full test run failed on five targets; the clean base reproduced the same 70 named failures and two process aborts. The aborted binaries did not finish. These Spark runs preceded the final stop-sequence correction; the 123-test CPU run above includes it.