Repository navigation
Conversation
… per engine step `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. A Completions item carries no ids: the request's StreamBatch entries already did, and resending them at once queued every later step behind them on the Session's one HTTP/2 stream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ring preprocess, logprobs refused The Session's counterparts of Generate's review fixes: - A structured_output_error finish is a Rejected INTERNAL item, which atomesh answers with a 500 as HTTP chat does, not a Completions item. - A submit cancelled while preprocess runs (the Session ended) drops the seq the executor registers once it is made. - A RequestSpec asking for logprobs is refused INVALID: the Session's SamplingParams never carried them to the engine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # atom/entrypoints/grpc/server.py # tests/test_grpc_server.py
…e Session RPC Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # atom/entrypoints/grpc/server.py # tests/test_grpc_server.py
…e Session RPC # Conflicts: # atom/entrypoints/grpc/server.py
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical bugs allow cancelled preprocessing to corrupt requests after sequence-ID reuse and slow clients to exhaust shared-process memory through an unbounded output queue.
3 open issues
What changed in this PR
Adds the server-side Session RPC to ATOM’s gRPC interface, letting many requests share one stream with a StreamBatch per engine step. This builds on the Generate service and supports the later atomesh Session client.
Changes:
- Adds codecs for Session submission, abort, output, completion, and rejection messages.
- Implements per-Session sequence-ID windows, request admission, batching, and cleanup.
- Extends preprocessing for caller-assigned IDs and adds focused Session tests.
| File | Description |
|---|---|
tests/test_grpc_server.py |
Adds Session rejection and cancellation tests; updates callback fixtures. |
atom/model_engine/llm_engine.py |
Accepts caller-assigned sequence IDs and counts token-ID stops during structured-output admission. |
atom/entrypoints/grpc/session.py |
Manages Session ID windows, request lifecycle, and batched outputs. |
atom/entrypoints/grpc/server.py |
Implements Session admission and streaming; reserves separate API sequence IDs. |
atom/entrypoints/grpc/frames.py |
Encodes and decodes Session protocol messages. |
Review effort: Balanced
When the client's side of a Session ended, the reader first finished every admission in progress, and those waiting for a slot, before the Session ended and aborted its requests. A blocked admission held that teardown, and every request already running kept the GPU meanwhile, only for close() to abort what was admitted. The reader now ends at once: its admissions settle as a cancelled reader's do, and close() aborts what runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Client half-close during structured admission leaves other session requests consuming GPU time and KV-cache space; close the session before cancelling and draining admissions while preserving the settlement wait.
5 open issues
Drain admission tasks safely during server shutdown Close the session before draining pending admissions · New Add regression tests for sampling field presence and validation Cover SubmitBatch decoding, defaults, batching, and completion ordering Test explicit ID forwarding through both processor entry points
Review effort: Balanced
|
Fixes the admission-delay finding in 767c30d. A Session request's |
|
Fixes the teardown finding in 6a2f003. When the client's side of a Session ends, the reader no longer finishes the admissions in progress or waiting first: they settle as a cancelled reader's do, and |
…ssion RPC # Conflicts: # tests/test_grpc_server.py
… settle When the client's side ended, the reader cancelled its admissions and waited for them to settle before the Session closed. A structured admission blocked in its submission held that wait, and every request already running kept the GPU meanwhile. The reader now closes the Session first, aborting what runs, then lets each admission settle, which aborts its request once it is enqueued. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Cross-cutting session teardown and shared sequence-ID lifecycle changes require maintainer validation of cancellation, backpressure, and window reuse under live P/D GPU traffic.
4 open issues
1 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The cross-thread and asynchronous lifecycle interactions require human review of real-engine shutdown, backpressure, cancellation, and late-output behavior, which this snapshot cannot validate.
4 open issues
Review effort: Balanced
…ession RPC Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>



Part C of the 8 PRs proposed in #3657 (regrouped by function). No blocking issues.
Based on B, which it needs.
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.
What changed
frames.pyreads a SubmitBatch into requestspreprocesstakes, and an Abort into seq ids; it writes Ready, StreamBatch, Completions and Rejected. What it cannot serve as sent, including RequestSpec fields it does not read (arrive_time,trace), is INVALID.AtomEngine.Sessionadmits each request as Generate does; stop strings without ids, or anotherrequired_channelthan the server's, are INVALID. Client seq_ids lie below 2^24, matching atomesh'sSEQ_IDS; each request gets a new engine id from its Session's window (127 windows of 2^24), whose counter outlives the Session.RESOURCE_EXHAUSTED, its requests aborted and its reader cancelled once.preprocesstakes the caller'sseq_id; structured admission counts stop ids as stop strings;CoreManagerchecks rank hints before registering callbacks.Review focus
frames._sampling: how absent fields read.Session.send,Session.flushand_submit's failure paths: what holds a window, what is aborted.Testing
jasen/atom-grpc-c-session-server@ 404a7f3:tests/test_grpc_{frames,server,proto}.py,test_io_processor_fanout.pyandtest_dp_load_balance.py, 342 passed; ruff, black clean.Follow-ups
none
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
At a6c782d, CPU only: ruff and black (26.10.1) clean on the 4 changed .py files; the gRPC modules import.
The failure is the 30 s import-timeout test B's evidence describes; the collection error needs SGLang.
With A beneath it, the full CPU suite on this Python code ran against main cccc96a: 14,943 passed, its failures main's own or host-load timeouts that main hits too.
The integration branch's end-to-end tests, not part of this stack, ran against this Session server on CPU instances with a stub model runner:
test_frames11,test_grpc_session13,test_grpc_generate16,test_grpc_info16,test_grpc_structured_output4 andtest_grpc_refusals_pp_dcp4 passed. Measured there, the Session's step lag p99 at 1,024 concurrent requests is 1.2 ms at DP1 and 5.4 ms at DP4 with id-free Completions, against 2.6 and 42 ms with ids.🤖 Generated with Claude Code