Repository navigation
[ATOM gRPC] atomesh: structured output to ATOM gRPC workers; answers as ATOM's HTTP routes give them - #3677
[ATOM gRPC] atomesh: structured output to ATOM gRPC workers; answers as ATOM's HTTP routes give them#3677Jasen2201 wants to merge 94 commits into
Conversation
…as ATOM's HTTP routes give them For a chat served by ATOM gRPC workers, atomesh sends ATOM the chat's structured-output input with the request: tools, tool_choice and response_format as the client sent them, each message's own tools in `message_tools_json`, the merged template kwargs the prompt was rendered with (`merged_template_kwargs`), and whether the rendered prompt ends in one of the worker's reasoning markers. SGLang and vLLM requests are unchanged. For a model with an ATOM gRPC worker, the gRPC routers answer 400 `unsupported_media` to a chat or `/generate` carrying image, video, audio or embedding input, before preparing it, since ATOM receives only the rendered token ids; the regular gRPC router answers 501 `unsupported_api` to `/v1/responses` for such a model, and `/v1/messages` keeps its 501. SGLang and vLLM workers serve media and Responses as before. atomesh records how long a gRPC request's chat template and encode take, as `mesh_prepare_stage_seconds` by stage, beside the HTTP ingress's own. atomesh's gRPC `/generate` stream decodes each chunk through the request's stop decoder, as the chat stream and the unary response do, and flushes it when the stream completes, so a character split across chunks is no longer lost and both `/generate` and `/v1/completions` streams join to the unary text; the streamed text also honours stop, stop_token_ids, skip_special_tokens and no_stop_trim. The generate SSE goldens are re-recorded with the restored spaces. The unary chat answer and the streamed usage chunk report the prefix-cache hit ATOM sends on each Complete in `usage.prompt_tokens_details.cached_tokens`, as ATOM's HTTP chat does. The protocol crate's chat `Usage` has no field for it, so `render::with_cached_tokens` adds it to the answer's JSON. An ATOM worker ends an output where a stop string's own ids match, and ATOM's HTTP routes return all of it. atomesh decodes the output of an ATOM worker, or an ATOM D, with none of the request's stops (`drop_stops_for_atom`), so a stop string the model writes with other ids no longer cuts the text, inside reasoning or content, where ATOM's HTTP chat keeps it. A gRPC chat answer always carries `message.content`, "" when the output has none, and a streamed chat opens on the engine's first message with a delta carrying the role and `"content": ""`, as ATOM's HTTP chat does. The chat SSE goldens are re-recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t and render Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and render Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…omesh structured output and render Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… workers ATOM's Generate carries no logprobs, so a chat with `logprobs` or a /generate with `return_logprob` came back with null logprobs where ATOM's HTTP chat route returns them. For a model with an ATOM gRPC worker, the regular and P/D gRPC routers now answer such a request 400 `unsupported_logprobs`, beside the media refusal. /v1/completions keeps its null logprobs, as ATOM's HTTP /v1/completions answers them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…put and render Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s end The MiniMax parser holds a trailing partial namespace token or `<tool_call>` outside a call until more text arrives. At end of input nothing released it, so a streamed ATOM reply ending in `The prefix is <tool_c` lost `<tool_c`, which the unary reply keeps. Its `end_of_input_text` now returns that text outside a call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…as streamed The unary read of an ATOM reply took any bare `<function=NAME>...</function>` for a call, so prose such as `The format is <function=YOUR FUNCTION NAME></function>.` became a call named `YOUR FUNCTION NAME`, while the streamed reply, which reads a bare call only when it names a declared tool, kept it as text. The unary read now asks the same of a bare call; the reply's text ends at the first call it keeps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The unary read of an ATOM reply ended its text at the first call, so `Before <function=get_weather>...</function> After` answered `Before ` and dropped ` After`, which the streamed reply and ATOM's HTTP chat keep. As ATOM reads a reply, its text is now all of it outside the calls kept (a wrapped call's from its `<tool_call>`); SGLang's and vLLM's replies read as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed output and render Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Verified streaming-parser defects can turn prose into unintended tool invocations and corrupt or omit arguments when handling multiple calls.
7 open issues
Wrapped ATOM calls skip follower validation · New Quoted tool-call marker truncates wrapped unary content · New Parameter parsing crosses into the next bare call · New Earlier parameterless calls lack empty JSON arguments · New Parse bare-function ATOM XML replies as tool calls Seed parser with the resolved initial reasoning state Use native model parsers for native tool-call output
3 resolved since last review
Review effort: Balanced
| // A bare one is a call only when it names a tool and call syntax | ||
| // follows; else it is prose, and so is its `<function=...>`. | ||
| if self.bare_call { |
There was a problem hiding this comment.
main's Qwen parser reads this input the same way: streamed, it announces get_weather, drops the prose, and get_unstreamed_tool_args sends {}; unary returns the text. This PR's recovery does not reach it (end_of_input_closers is None when prose follows the name). Checking a wrapped call's name before announcing it is a separate change to the shared parser.
| /// parameter may be cut off in its name, which is then no parameter. | ||
| static WRAPPED_OR_BARE_CALLS: LazyLock<Regex> = LazyLock::new(|| { | ||
| let pattern = concat!( | ||
| r"(?s)<tool_call>\s*(.*?)\s*</tool_call>", |
There was a problem hiding this comment.
main's Qwen parser returns the same unary content, Use , for this input: its extractor also matches from the quoted <tool_call>. Anchoring the wrapped match on a function header is a separate change to the shared parser; this PR only changes the streamed read, which keeps the sentence.
… output and render Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Verified parser defects can misinterpret prose as tool calls, overwrite arguments between streamed calls, and discard surrounding text.
8 open issues
Wrapped ATOM calls skip follower validation Preserve text after a recovered call’s closing tag · New Earlier parameterless calls lack empty JSON arguments Parameter parsing crosses into the next bare call Quoted tool-call marker truncates wrapped unary content Parse bare-function ATOM XML replies as tool calls Seed parser with the resolved initial reasoning state Use native model parsers for native tool-call output
Review effort: Balanced
| if !self.bare_call { | ||
| closers.push_str(self.tool_call_end_token); | ||
| } |
There was a problem hiding this comment.
Fixed in f544044: end_of_input_closers no longer appends </tool_call> when text follows the call's </function>, so the unary reply keeps After, with the call read at </function>. Streamed, the reply reads as main's parser reads it; ending a wrapped call at </function> while streaming is a separate change to the shared parser. Test: text_after_a_cut_off_wrapper_s_function_is_not_closed_into_the_call.
The streamed Qwen XML parser read parameters from its whole buffer, so
two calls arriving in one delta both took the later call's values, and a
call with no parameters closed with an empty argument string instead of
`{}`. It now reads parameters only up to the open call's end tag and
streams `{}` for a call that closes without any, unary as streamed, for
bare and wrapped calls alike.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…/function> For `Before <tool_call><function=f>...</function> After`, appending `</tool_call>` at end of input made both reads drop ` After` into the call. `end_of_input_closers` now returns no closers when text follows the call's `</function>`, so the unary reply keeps that text (the call still read at `</function>`, as ATOM's HTTP parser ends it) and the streamed one reads as on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Verified parser bugs drop prose or emit spurious tool calls, while model-wide capability checks incorrectly restrict supported requests in mixed-backend pools.
6 open issues
Wrapped ATOM calls skip follower validation Preserve text after a recovered call’s closing tag Quoted tool-call marker truncates wrapped unary content Parse bare-function ATOM XML replies as tool calls Seed parser with the resolved initial reasoning state Use native model parsers for native tool-call output
2 resolved since last review
Review effort: Balanced
…al into structured output and render Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Qwen streaming parsing can consume a valid nested function header as prose and omit a tool call that unary parsing recognizes.
9 open issues
Restart parsing at nested function headers in ATOM replies · New Wrapped ATOM calls skip follower validation Append generated tokens directly to the aggregate string · New Avoid cloning the full response to add timing fields · New Preserve text after a recovered call’s closing tag Quoted tool-call marker truncates wrapped unary content Parse bare-function ATOM XML replies as tool calls Seed parser with the resolved initial reasoning state Use native model parsers for native tool-call output
Review effort: Balanced
…eads it Streaming read `Example <function=NAME ... <function=get_weather></function>` as one header named `NAME ... <function=get_weather`, so the call was lost, while the unary pattern (`<function=[^<>]*>`) skips the quoted header and finds it. A bare header's name now ends at a `<` as on unary: the text up to it is prose, and the parser reads on from the nested `<function=`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`process_chunk_tokens` collected each decoded piece in a Vec only to concatenate them, and `run_generate_stream` passes it a Complete's whole unstreamed suffix. It now appends each piece to one String; only the chat's reasoning path keeps the pieces. Both share the decoding loop (`decode_chunk`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… tree An ATOM worker's timed reply was turned into a serde_json Value, its text and every output id copied, only to add three timing keys to each meta_info. A Serialize wrapper now flattens the timing (`MetaInfoTiming`) after the meta_info's fields, writing the same bytes; the completions adapter reads it back through the same type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔵 Needs a closer look
The router applies ATOM restrictions based on any registered worker rather than the eligible producer, incorrectly rejecting supported SGLang requests and silently clearing completion logprobs.
6 open issues
Wrapped ATOM calls skip follower validation Preserve text after a recovered call’s closing tag Quoted tool-call marker truncates wrapped unary content Parse bare-function ATOM XML replies as tool calls Seed parser with the resolved initial reasoning state Use native model parsers for native tool-call output
3 resolved since last review
Review effort: Balanced
…sh structured output and chat render Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Streaming delimiter handling can misclassify answers as reasoning, while counting HTTP-only ATOM workers as gRPC-capable causes incorrect request rejections and disables completion logprobs.
8 open issues
Wrapped ATOM calls skip follower validation HTTP-only workers incorrectly satisfy the gRPC model check · New Split closing-tag tokens misclassify answer text as reasoning · New Preserve text after a recovered call’s closing tag Quoted tool-call marker truncates wrapped unary content Parse bare-function ATOM XML replies as tool calls Seed parser with the resolved initial reasoning state Use native model parsers for native tool-call output
Review effort: Balanced
| workers | ||
| .iter() | ||
| .any(|worker| worker.metadata().runtime_type == RuntimeType::Atom) |
| let result = pieces | ||
| .iter() | ||
| .try_fold(ParserResult::default(), |mut read, piece| { | ||
| let piece = parser.parse_reasoning_streaming_incremental(piece)?; |
Main keeps a chat's body as sent for the routers whose render reads fields the typed request drops (RouterTrait::sent_chat_body, route_chat_as_sent). The ATOM gRPC routers now take the message tools and `thinking` from that body instead of a second raw-body route: route_chat_body and the raw part of into_native_parts go, sent_chat_body also keeps the body for a model with an ATOM worker, and prepare_chat_with reads MessageTools and read_thinking from it (prepare_chat_declaring and execute_chat_declaring fold into prepare_chat_with and execute_chat_with). A model with ChatControls renders with its encoder and names its own opener; the template path keeps per-message tools through render_chat_messages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Critical parser bugs discard quoted or trailing prose and misclassify answer content as reasoning.
10 open issues
Preserve trailing prose after an incomplete tool-call wrapper · New Wrapped ATOM calls skip follower validation Avoid token-vector allocations when reasoning parsing is disabled · New Split closing-tag tokens misclassify answer text as reasoning HTTP-only workers incorrectly satisfy the gRPC model check Preserve text after a recovered call’s closing tag Quoted tool-call marker truncates wrapped unary content Parse bare-function ATOM XML replies as tool calls Seed parser with the resolved initial reasoning state Use native model parsers for native tool-call output
Review effort: Balanced
| if self.in_tool_call && self.current_tool_name_sent { | ||
| return String::new(); | ||
| } |
| let (pieces, _stopped) = process_chunk_pieces(&mut stop_decoder, &token_ids); | ||
| let chunk_text = pieces.concat(); |


Part F of the 8 PRs proposed in #3657 (regrouped by function). No blocking issues.
Based on E, which it needs.
Why
A chat to an ATOM gRPC worker reached ATOM without its structured-output input. Its answers also differed from ATOM's HTTP ones in stops, end-of-sequence text, reasoning, forced tool calls, usage and stream endings.
What changed
AtomOutput, shared with main's bridge ([atomesh] Rust frontend down to LLMEngine, replacing the Python standalone service #3698). No stop cuts it, the end ids are hidden, the prompt's reasoning opener (or the model's implicit one) is read first, and the worker's parsers apply.content: "", the opening empty delta, and ATOM's usage fields (render/atom_usage.rs), streamed where the worker'susage_on_finishputs them. A forcedtool_choiceis parsed in the model's syntax.prepare_chatfills aStructuredOutput, with every message's tools andthinkingread from the chat's body as sent (prepare::sent_chat_body, kept also for a model with an ATOM worker). Media and/v1/responsesare refused; a completion's logprobs answer null.Size: over 1,000 lines and 15 files: one unit, a chat to ATOM answered as ATOM's HTTP chat answers it.
Review focus
AtomOutputkeys on the producing worker's runtime, or on aPipelinebuilt withreading_output_as_atom.prepare::sent_chat_bodykeeps a chat's body as sent for a model with an ATOM worker too;prepare_chat_withreads its message tools andthinkingfrom it.Testing
Each change has a test that fails without it; see Evidence.
jasen/atom-grpc-f-mesh-chat-render@ f2453c2: all tests pass; fmt clean; 5 new clippy warnings.Follow-ups
none
What changed, in detail
AtomOutput(grpc/pipeline.rs): none of the request's stops cut the reply; theeos_token_idsGetModelInfo lists are hidden stop ids unlessignore_eos;ResponseContext.prompt_openeris thereasoning_open_markersentry the prompt ends on, fed to the reasoning parser before the reply (unary replies over 64 KiB are parsed piece by piece); parsers are the router's flags, else the worker's, else the model-name mapping.render/atom_usage.rs: unary chat: cached tokens andttft_s/tpot_s/latency_s; streamed chat: cached tokens on a usage chunk sent after the finish chunk,include_usageor not; unary completion: timing (carried in/generate's meta_info, serialized throughMetaInfoTimingwithout rebuilding the reply); n>1: the prompt and its cached tokens once, the slowest timing,num_choices.ToolParser::end_of_input_closers; Qwen XML and MiniMax), as ATOM's HTTP parser keeps such a call; a<tool_call>is not closed past text that follows its</function>. In an ATOM worker's reply only (ToolParser::read_as_atom), atomesh's Qwen XML parser also reads a bare<function=...>call outside a<tool_call>wrapper, as ATOM's HTTP parser does, whole or cut off after its declared name, in a parameter's name or in a tag after a closed parameter; a bare header's name ends at a<, as the unary pattern reads it; one that prose quotes, or that names no declared tool, stays text, and so does a<tool_call>no<function=follows; the reply's text is all of it outside its calls. Text the parser holds at end of input as the start of a call that never came is sent as content (ToolParser::end_of_input_text; Qwen XML and MiniMax), so the streamed reply's text is the unary one's. SGLang's and vLLM's replies read as on main, except that, for every backend, streamed Qwen XML calls arriving in one delta each carry their own arguments,{}for a call without parameters.MessageTools::readon the body as sent, sent inmessage_tools_json, given to the template per message, and added to the tool list the reply is parsed against. A named or requiredtool_choicestill needs a top-level tool (ingress validation, all routers).Stack
ATOM serves
atom.grpc.v1.AtomEnginebeside its HTTP server (token ids in, token ids out, ATOM's P/D flow unchanged), and atomesh routes to ATOM gRPC workers over a Generate call per request or one Session per instance. One linear stack, merged bottom to top: A, B, C, D, E, F, G, H; each PR's base is the one before it.Evidence
In
atom/mesh(rustc and clippy 1.100.0), at f2453c2:cargo fmt --checkandcargo clippy --all-targetswith and withoutatom-enginepass.Clippy against E (warnings matched by message and file):
The five:
result_large_erron three functions returning aResponseerror, as their neighbours do, and twofield_reassign_with_defaultin render tests. The fixes at f2453c2 add none.test_load_counter_performance(untouched file) and the fixed-portrouting_testsfail now and then on this shared host at load average 50-140; each passes on rerun.Tests that fail without their change:
atom_output_tests(stops kept, end ids hidden, the worker's parsers under an alias),f_atom_reasoning_opener, the ATOM and SGLang usage tests inrender/tests.rs(n=2 included) andh_completion_adapter,test_streaming_atom_output_without_text_opens_with_an_empty_content,g_complete_suffix,h_atom_native_tool_calls(cut-off and bare calls, the streamed text matching the unary one, and bare calls read as text for other backends, included), the Qwen XML parser'sa_quoted_wrapper_before_a_bare_call_stays_text,calls_in_one_delta_stream_their_own_arguments,text_after_a_cut_off_wrapper_s_function_is_not_closed_into_the_call,a_held_opener_no_call_followed_is_text_at_end_of_input,a_bare_call_naming_no_declared_tool_is_text,a_call_after_an_unclosed_bare_header_is_readandtext_between_and_after_calls_is_text, MiniMax'sa_held_partial_marker_is_text_at_end_of_input,a_long_reply_arriving_in_its_complete_alone_is_split_as_when_streamed(a closer cut at the 256th id),an_atom_chat_carries_the_tools_a_message_of_any_role_declares, the refusal table run through ATOM's request builder, andk_cache_reconcile.test_generate_aggregator_appends_atom_s_timing_to_meta_infopins a timed/generatereply's bytes, before and after its serialization changed.🤖 Generated with Claude Code