Skip to content

[ATOM gRPC] gRPC server: the Session RPC and its engine_v1 frames codec (5/14) - #3662

Closed
Jasen2201 wants to merge 1 commit into
jasen/atom-grpc-04-serverfrom
jasen/atom-grpc-05-session
Closed

Jasen2201 wants to merge 1 commit into
jasen/atom-grpc-04-serverfrom
jasen/atom-grpc-05-session

Conversation

@Jasen2201

@Jasen2201 Jasen2201 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

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

Why

With Generate, every request holds its own stream, so a step of 1,024 streaming requests leaves an instance as 1,024 messages. The Session carries an instance's requests on one stream as engine_v1 messages, one StreamBatch per engine step, and ATOM answered it UNIMPLEMENTED.

What changed

  • frames.py: decode_client turns a SubmitBatch into one request per entry in the form preprocess takes, and an Abort into seq ids; encode_ready, encode_stream, encode_completions and encode_rejected write the server's messages.
  • Absent sampling fields read as the HTTP routes fill omitted ones; a request the Session cannot serve as sent comes back INVALID, and another protocol version raises FrameError.
  • AtomEngine.Session admits each request as Generate does, under a per-Session seq_id window (session.py: 127 windows of 2^24 ids; the API process's own ids wrap below them).
  • Each engine step gives a Session one StreamBatch, then its ended requests' Completions or Rejected items (INVALID for a 4xx, OVERLOADED for 503, INTERNAL otherwise). An Abort, or the end of the call, aborts its requests as the HTTP stream teardown does.
  • preprocess takes the caller's seq_id, and structured-output admission counts stop ids as stop strings, as it counts a chat's stop strings over HTTP.

Review focus

  1. frames._sampling: how absent fields read.
  2. Session.flush: what a StreamBatch entry and a Completions item carry.
  3. Windows, taken first-freed-last (Sessions.open).

Testing

jasen/atom-grpc-05-session @ 97da97b: the full CPU suite on this PR's Python code, parts 6 to 13 on top (they change no Python), fails only where main fails; 14,943 passed. ruff, black clean.

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

At 97da97b: ruff check and black --check (26.10.1) on the 4 changed .py files, clean.

The full CPU suite (pytest tests/ --ignore=tests/plugin --ignore=tests/entrypoints/test_openai_server.py --ignore=tests/test_atomesh_mooncake_store.py) on this PR's Python code, with parts 6 to 13 on top (they change no Python), against main cccc96a:

main  14936 passed, 10 failed, 1571 skipped
top   14943 passed,  9 failed, 1571 skipped, 8 errors
  • The 9 failures are main's: seven Engram host-path tests (no GPU), a Mooncake Store lookup timeout, and a multiprocess-metrics restart test.
  • The 8 errors are test_simulated_tp on its fixed port 29591, held by main's run beside it; alone, 9 passed.
  • Main's tenth failure is test_server_entrypoints_initialize_native_storage_before_import, whose 30 s budget covers an import that takes 27 to 41 s here on main and on the top alike.
  • The top adds 14 tests, all passing.

The integration branch's end-to-end tests, not part of this stack, ran against this branch on CPU instances with a stub model runner (ATOM's own server, CoreManager, EngineCore, Scheduler and BlockManager; atomesh's routers left out): test_frames 11, test_grpc_session 13, test_grpc_generate 16, test_grpc_info 16, test_grpc_structured_output 4, test_grpc_refusals_pp_dcp 4 and test_proto 5 passed, 118 in all with the stub's own tests.

After frames.py lost the client half the dropped tests used (encode_submit, encode_abort, decode_server and their helpers), at 97da97b the gRPC modules import and tests/test_grpc_proto.py passes; at the stack's top fb4f090, tests/entrypoints with the stack's own tests: 3,390 passed, 0 failed.

🤖 Generated with Claude Code

…ec (5/14)

`AtomEngine.Session` carries many requests on one bidirectional stream of
engine_v1 messages. `atom/entrypoints/grpc/frames.py` turns a SubmitBatch
into one request per entry in the form `InputOutputProcessor.preprocess`
takes, and an Abort into seq ids; it writes Ready, StreamBatch, Completions
and Rejected, with buffers read through their refs, little-endian data and
a protocol version check. Missing sampling fields read as the HTTP routes
fill omitted ones; media, n above 1, negative prompt ids and
kv_transfer_params engine_v1 cannot express come back as INVALID
rejections.

Each request is admitted as Generate admits one, under a per-Session
seq_id window (`session.py`: 127 windows of 2^24 ids, with the API
process's own ids wrapping below them). Each engine step is answered with
one StreamBatch, then the step's Completions or Rejected items (INVALID
for a 4xx, OVERLOADED for 503, INTERNAL otherwise). An Abort, or the end
of the call, aborts its requests as the HTTP stream teardown does; a
window returns once its last request ends. `preprocess` takes the
caller's seq_id, and structured-output admission counts stop ids as stop
strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jasen2201

Copy link
Copy Markdown
Collaborator Author

Superseded by #3674 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