Skip to content

[ATOM gRPC] The Session RPC: many requests on one stream, one message per engine step - #3674

Open
Jasen2201 wants to merge 56 commits into
jasen/atom-grpc-b-proto-serverfrom
jasen/atom-grpc-c-session-server
Open

Jasen2201 wants to merge 56 commits into
jasen/atom-grpc-b-proto-serverfrom
jasen/atom-grpc-c-session-server

Conversation

@Jasen2201

@Jasen2201 Jasen2201 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

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.py reads a SubmitBatch into requests preprocess takes, 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.Session admits each request as Generate does; stop strings without ids, or another required_channel than the server's, are INVALID. Client seq_ids lie below 2^24, matching atomesh's SEQ_IDS; each request gets a new engine id from its Session's window (127 windows of 2^24), whose counter outlives the Session.
  • Each engine step gives a Session one StreamBatch, then id-free Completions or Rejected items for those it ended. Arrival is when read, token times when delivered. An Abort, or the client's side ending, aborts its requests at once, admissions settling after, as HTTP teardown does.
  • A seq that reached the engine keeps its window until its terminal output; a failed submission aborts its seq. Past 4096 unread messages the Session fails with RESOURCE_EXHAUSTED, its requests aborted and its reader cancelled once.
  • preprocess takes the caller's seq_id; structured admission counts stop ids as stop strings; CoreManager checks rank hints before registering callbacks.

Review focus

  1. frames._sampling: how absent fields read.
  2. Session.send, Session.flush and _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.py and test_dp_load_balance.py, 342 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. 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.

pytest tests/entrypoints tests/test_grpc_proto.py <the files importing llm_engine, engine_core, block_manager, SpeculativeConfig or the API server>
    7314 passed, 1 failed, 380 skipped, 1 collection error

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_frames 11, test_grpc_session 13, test_grpc_generate 16, test_grpc_info 16, test_grpc_structured_output 4 and test_grpc_refusals_pp_dcp 4 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

… 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>
Jasen2201 and others added 9 commits November 22, 2026 13:36
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>
Jasen2201 added a commit that referenced this pull request Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jasen2201
Jasen2201 added this pull request to stack #3735 November 23, 2026 07:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread atom/entrypoints/grpc/session.py Resolved
Comment thread atom/entrypoints/grpc/session.py Resolved
Comment thread atom/entrypoints/grpc/server.py Resolved
Copilot AI balanced review requested due to automatic review settings November 24, 2026 05:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because a blocked admission can delay session teardown after stream EOF, leaving an active request consuming GPU/KV resources.

4 open issues

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>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 06:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because pending structured submissions can delay session closure after client input ends, allowing other running requests to continue consuming GPU time.

4 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 24, 2026 06:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Review effort: Balanced

Comment thread atom/entrypoints/grpc/server.py Resolved
@Jasen2201

Copy link
Copy Markdown
Collaborator Author

Fixes the admission-delay finding in 767c30d. A Session request's arrive_time is now stamped when the Session reads its Submit, before it waits for an admission slot or runs preprocess, as the HTTP routes start their clock before tokenizing; until now it was the seq's own, stamped in preprocess. The seq's arrive_time, which the scheduler orders by, is unchanged. Test: test_a_session_request_arrives_when_read_not_when_admitted (one request held in preprocess, one waiting for its slot; both report the read time).

@Jasen2201

Copy link
Copy Markdown
Collaborator Author

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 close() aborts the running requests at once. Test: test_the_end_of_the_client_s_side_aborts_without_waiting_for_an_admission. The four open issues listed are the ones already answered in their threads.

Jasen2201 and others added 2 commits November 24, 2026 07:58
…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>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 08:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Copilot AI balanced review requested due to automatic review settings November 24, 2026 08:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 14:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human review is needed for cancellation and teardown across shared engine state and reusable ID windows, because this review did not validate those lifecycle paths on real engines.

4 open issues

Review effort: Balanced

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 11:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch has not been deployed

No deployments
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.

3 participants