Skip to content

[ATOM gRPC] atomesh: gRPC chat and stream output as ATOM's HTTP routes give it (12/14) - #3669

Closed
Jasen2201 wants to merge 1 commit into
jasen/atom-grpc-11-mesh-chat-fieldsfrom
jasen/atom-grpc-12-mesh-render
Closed

Jasen2201 wants to merge 1 commit into
jasen/atom-grpc-11-mesh-chat-fieldsfrom
jasen/atom-grpc-12-mesh-render

Conversation

@Jasen2201

@Jasen2201 Jasen2201 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Part 12/14 of the stack proposed in #3657. No blocking issues.

Why

atomesh's gRPC generate stream decoded each chunk's ids alone, so a streamed completion read "disa do sedu" where the unary one read "di sa do se du". atomesh also cut an ATOM worker's text at the first stop string it decoded, which ATOM's HTTP routes keep. A chat ending in its reasoning had no content key, and none reported cached tokens.

What changed

  • The /generate stream decodes through the request's stop decoder and flushes it on Complete (generate_streaming::run_generate_stream), as the chat stream does. /v1/completions diffs that text, so both streams join to the unary text, for every gRPC backend.
  • An ATOM worker's output, or an ATOM D's, is decoded with none of the request's stops (drop_stops_for_atom): ATOM ends it where a stop's own ids match, as over HTTP.
  • A chat answer always carries message.content ("" when empty), and a chat stream opens with the role and "content": "", as ATOM's HTTP chat does.
  • The unary chat answer and the streamed usage chunk carry usage.prompt_tokens_details.cached_tokens from each Complete; render::with_cached_tokens adds it, as the protocol crate's chat Usage has no such field.

Review focus

  1. The eight SSE goldens are re-recorded: generate's pinned a per-chunk "Helloworld", and chat's gain the opening content chunk, for SGLang and vLLM too.
  2. A Partial whose text the decoder holds still gets its event, so its output_ids reach the client.

Testing

Streams sent token by token join to the unary text; an ATOM output keeps its text past a stop string, an SGLang one is cut.

jasen/atom-grpc-12-mesh-render @ 05a919b: with atom-engine, 1408 lib and 303 integration tests passed. cargo fmt clean; clippy's four new warnings are of kinds these files already carry.

Follow-ups

none

Stack

ATOM serves atom.grpc.v1.AtomEngine beside 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. Bottom to top:

  1. [ATOM gRPC] Token-id prompts reuse block-hash chains; an idle EngineCore waits for input (1/14) #3658 Token-id prompts reuse block-hash chains; an idle EngineCore waits for input
  2. [ATOM gRPC] atomesh: share ATOM's P/D rank mapping and prefill-info parsing (2/14) #3659 atomesh: share ATOM's P/D rank mapping and prefill-info parsing
  3. [ATOM gRPC] The atom.grpc.v1 proto and its generated Python modules (3/14) #3660 The atom.grpc.v1 proto and its generated Python modules
  4. [ATOM gRPC] gRPC server: --grpc-port, info RPCs, Generate, Abort, structured output (4/14) #3661 gRPC server: --grpc-port, info RPCs, Generate, Abort, structured output
  5. [ATOM gRPC] gRPC server: the Session RPC and its engine_v1 frames codec (5/14) #3662 gRPC server: the Session RPC and its engine_v1 frames codec
  6. [ATOM gRPC] atomesh: compile ATOM's protos in every build (6/14) #3663 atomesh: compile ATOM's protos in every build
  7. [ATOM gRPC] atomesh: an ATOM gRPC client (7/14) #3664 atomesh: an ATOM gRPC client
  8. [ATOM gRPC] atomesh: discover ATOM gRPC workers, their model info and DP ranks (8/14) #3665 atomesh: discover ATOM gRPC workers, their model info and DP ranks
  9. [ATOM gRPC] atomesh: ATOM P/D over gRPC (9/14) #3666 atomesh: ATOM P/D over gRPC
  10. [ATOM gRPC] atomesh: the Session link to an ATOM instance (10/14) #3667 atomesh: the Session link to an ATOM instance
  11. [ATOM gRPC] atomesh: chat structured output to ATOM; refuse media and Responses (11/14) #3668 atomesh: chat structured output to ATOM; refuse media and Responses
  12. [ATOM gRPC] atomesh: gRPC chat and stream output as ATOM's HTTP routes give it (12/14) #3669 atomesh: gRPC chat and stream output as ATOM's HTTP routes give it
  13. [ATOM gRPC] atomesh: route ATOM requests over the Session (13/14) #3670 atomesh: route ATOM requests over the Session
  14. [ATOM gRPC] The Session's step delivery: Completions without ids, atomesh's Session on its own thread (14/14) #3671 The Session's step delivery: Completions without ids, atomesh's Session on its own thread

1 and 2 stand alone; 6 to 13 need only part 3 of the Python side; 14 changes both sides of the Session.

Evidence

In atom/mesh (rustc and clippy 1.100.0), at 05a919b:

cargo fmt --check                                         ok
cargo clippy --all-targets                                ok
cargo clippy --all-targets --features atom-engine         ok
cargo check --features ext-proc --tests                   ok
python3 proto/vendor_ext_proc.py --check                  ok
cargo test --features atom-engine --lib                   1407 passed, 1 failed, 7 ignored
cargo test --features atom-engine --test <each> -- --test-threads=1
                                                          303 passed, 0 failed, 1 ignored

Clippy against main cccc96a (warnings matched by message and file):

[clippy] base 108, branch 114, new 6, gone 0
  NEW x3: src/routers/render/tests.rs: warning: field assignment outside of initializer for an instance created with Default::default()
  NEW x1: src/routers/render/chat_aggregator.rs: warning: the `Err`-variant returned from this function is very large
  NEW x2: src/atom_engine/wire.rs: warning: using `chunks_exact` with a constant chunk size
[clippy-ae] base 110, branch 114, new 4, gone 0
  NEW x3: src/routers/render/tests.rs: warning: field assignment outside of initializer for an instance created with Default::default()
  NEW x1: src/routers/render/chat_aggregator.rs: warning: the `Err`-variant returned from this function is very large

Against the PR below (part 11):

[clippy] base 110, branch 114, new 4, gone 0
  NEW x3: src/routers/render/tests.rs: warning: field assignment outside of initializer for an instance created with Default::default()
  NEW x1: src/routers/render/chat_aggregator.rs: warning: the `Err`-variant returned from this function is very large
[clippy-ae] base 110, branch 114, new 4, gone 0
  NEW x3: src/routers/render/tests.rs: warning: field assignment outside of initializer for an instance created with Default::default()
  NEW x1: src/routers/render/chat_aggregator.rs: warning: the `Err`-variant returned from this function is very large

The lib run's one failure, policies::tree::tests::test_tree_structure_integrity_after_stress (main's radix-tree stress test, untouched here), came under host load; it passed 3 of 3 reruns, and a full lib rerun passed 1408 of 1408.

The four new clippy warnings: one result_large_err in chat_aggregator.rs, whose two other Result<_, Response> functions main already flags, and three field_reassign_with_default in render/tests.rs, which main flags 35 times.

Reverting the drop_stops_for_atom calls makes test_an_atom_output_keeps_what_atom_returned_past_a_stop_string fail with "" for "test test test".

🤖 Generated with Claude Code

…s give it (12/14)

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>
@Jasen2201

Copy link
Copy Markdown
Collaborator Author

Superseded by #3677 after regrouping by function (see #3657).

@Jasen2201 Jasen2201 closed this Nov 21, 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.

1 participant