Skip to content

[ATOM gRPC] atomesh: the Session link to an ATOM instance - #3678

Open
Jasen2201 wants to merge 53 commits into
jasen/atom-grpc-f-mesh-chat-renderfrom
jasen/atom-grpc-g-mesh-session-link
Open

Jasen2201 wants to merge 53 commits into
jasen/atom-grpc-f-mesh-chat-renderfrom
jasen/atom-grpc-g-mesh-session-link

Conversation

@Jasen2201

@Jasen2201 Jasen2201 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Part G of the 8 PRs proposed in #3657 (regrouped by function). No blocking issues.

Based on F, the PR below it; it needs E, uses none of F's code, and at runtime calls the Session RPC that C serves.

Why

atomesh had no client for ATOM's Session RPC, so every request to an ATOM worker needed a Generate stream of its own.

What changed

  • AtomSessions (engine/atom/session.rs) keeps one Session call per ATOM instance, shared by its ranks, on a connection, thread and runtime of its own; opening is bounded at 10 s and holds no lock.
  • A writer sends queued requests as one SubmitBatch, then one Abort; a reader routes outputs by seq_id.
  • A SessionStream carries what Generate would send, timing included, so AtomStream reads either; outputs and unsent prompts are bounded.
  • A dropped request sends Abort and keeps no ids; a broken call fails its requests and is reopened. An instance without registered workers has its Session released; its last handle ends the call.
  • Nothing routes over it until H, so two items carry a dead-code allowance.
Limits and failure handling
  • Opening fails with DEADLINE_EXCEEDED after 10 s. Requests waiting for one instance share its opening, and an opening no request waits for ends its call and thread at once.
  • A stream left unread past 4096 outputs fails with RESOURCE_EXHAUSTED and is aborted once; the reader never waits, and the other requests are unaffected.
  • A Complete's TTFT, TPOT and latency come from the Completion's times, measured as Generate measures them.
  • Seq ids stay below 2^24; SEQ_IDS names the Python _SEQ_ID_SHIFT it must equal.
  • AtomSessions::releasing_removed(registry) checks at most once a second; running requests keep their Session to their end.
  • The ATOM client decodes messages of any size, as ATOM's server sends them without a limit.
  • Past 256 MiB of requests (prompt and RequestSpec) the writer has not taken, a request gets 503, and one larger than 256 MiB alone gets 400; one cancelled before it is taken sends nothing and holds its bytes until the writer discards it.

Size: over 1,000 lines, half of them tests: the link is one unit, testable only whole.

Review focus

What a request's stream carries, how long a seq_id stays held, and which messages fail the whole Session.

Testing

Against an in-process Session stub: ranks share one Session, outputs reach only their request, rejections map to HTTP statuses, drops abort, and a broken Session reopens. Also: a missing Ready, an abandoned opening, an unread stream, timing, a 5 MiB message, a released Session, dropped ids, a full queue, an oversized request.

jasen/atom-grpc-g-mesh-session-link @ 6885945: all tests pass, with and without atom-engine; fmt clean; clippy adds none.

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

In atom/mesh (rustc and clippy 1.100.0), at 6885945: cargo fmt --check passes, and cargo clippy --all-targets, with and without atom-engine, warns on none of the lines this PR adds.

cargo test --features atom-engine --lib            1568 passed, 0 failed
cargo test --features atom-engine --test <each>    304 passed, 0 failed
cargo test --lib                                   1563 passed, 0 failed
cargo test --test <each>                           304 passed, 0 failed

test_load_counter_performance, a throughput check in an untouched file, fails now and then on this shared host (load average 50-140); it passes alone, with and without atom-engine.

🤖 Generated with Claude Code

Each ATOM instance gets one Session, shared by its ranks and opened by its
first request. Outputs are split by seq_id into one stream per request that
carries what a Generate call sends, so `AtomStream` turns it into token
chunks; a dropped request sends Abort, a broken Session fails its requests
and the next request opens a new one, a Ready of another protocol version
is refused, and seq ids stay below 2^24. Nothing routes requests over it until
`--atom-grpc-session`.

A non-streaming request's ids are kept from its StreamBatch entries for
its Complete, since a Completions item carries none, and each Session runs
on a connection, thread and runtime of its own, off the router's runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jasen2201 and others added 8 commits November 22, 2026 13:44
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e atomesh Session link

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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jasen2201 added a commit that referenced this pull request Nov 23, 2026
mod.rs, stream.rs and session_test.rs under engine/atom keep this branch's
version: it already holds the Session link's change to them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jasen2201
Jasen2201 changed the base branch from jasen/atom-grpc-e-mesh-discovery-pd to jasen/atom-grpc-f-mesh-chat-render November 23, 2026 07:59
@Jasen2201
Jasen2201 added this pull request to stack #3735 November 23, 2026 07:59
Copilot AI balanced review requested due to automatic review settings November 23, 2026 09:12

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

Two critical request-ID reuse bugs can abort replacement requests through stale stream drops or reordered queued messages, requiring lifecycle and batching fixes with regression tests.

2 open issues
What changed in this PR

Adds atomesh’s client-side Session link, allowing requests to an ATOM instance’s ranks to share one gRPC call. This prepares the transport for opt-in routing in #3679; production routing remains unchanged here.

Changes:

  • Adds per-instance Sessions with batched submissions, output routing, cancellation, and reconnection.
  • Generalizes AtomStream to consume either Generate or Session responses.
  • Adds tests for shared-rank routing, completion tokens, rejection statuses, cancellation, and Session failures.
File Description
atom/​mesh/​src/​routers/​grpc/​engine/​atom/​stream.rs Supports Generate and Session response streams.
atom/​mesh/​src/​routers/​grpc/​engine/​atom/​session.rs Implements shared Sessions and per-request lifecycle management.
atom/​mesh/​src/​routers/​grpc/​engine/​atom/​session_test.rs Tests Session behavior with an in-process server.
atom/​mesh/​src/​routers/​grpc/​engine/​atom/​pair.rs Exposes the client helper within the parent module.
atom/​mesh/​src/​routers/​grpc/​engine/​atom/​mod.rs Registers the Session module and adds the client RPC method.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 23, 2026 09:18
Copilot AI balanced review requested due to automatic review settings November 24, 2026 17:12

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.

🟢 Approval recommended

No active review issues were identified for the client-side Session link changes.

2 open issues

Review effort: Balanced

…dmission into the Session link

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

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.

🟢 Approval recommended

No active review issues remain for the client-side Session transport changes.

2 open issues

Review effort: Balanced

…ervative cut-off close into the Session link

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

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.

🟢 Approval recommended

No active review issues remain for the client-side Session transport addition.

2 open issues

Review effort: Balanced

…on a last worker's removal into the Session link

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

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

Session eviction can leave the dedicated thread, runtime, and connection alive indefinitely because response reads lack a shutdown signal when the last Session owner drops.

2 open issues

Review effort: Balanced

Jasen2201 and others added 3 commits November 24, 2026 21:37
Releasing the last Session handle ended only the client's half of the call: the
reader kept reading ATOM's half, and with it the thread, runtime and connection,
until ATOM ended the call. The handles now own a signal the reader races against;
on it the reader returns, ending the call, whose requests ATOM then aborts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A sent request that does not stream keeps its route, and its seq_id, until its
Completion after the Abort its drop sends; until then each step's ids were still
collected for a Complete no one reads. They are now released once its stream is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and timing fixes into the Session link

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

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

Concurrent opening, cancellation, and transport-backpressure races in the cross-runtime Session lifecycle require Python Session integration validation that this environment cannot perform.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@Jasen2201

Copy link
Copy Markdown
Collaborator Author

Fixes both open issues of this review:

  • Reader shutdown (r4677247175): 0cc0acb. The Session handles own a signal the reader races against; when the last one drops, the reader ends the call, whose requests ATOM aborts. a_session_is_released_once_no_worker_of_its_instance_is_registered now checks both halves end (assert_ends) while ATOM keeps its half open; it fails without the change.
  • Ids of a cancelled request (r4677247216): 65e78f9. A dropped unstreamed request keeps its route and seq_id until its Completion, but no ids. Test: a_dropped_request_that_does_not_stream_keeps_its_seq_id_but_no_ids.

…ession link

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

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

Cancelling a non-streaming request after tokens accumulate leaves its output buffer allocated until further ATOM activity, requiring immediate buffer cleanup and a regression test that verifies cleanup without another step.

1 open issue

Review effort: Balanced

Comment on lines +764 to +770
if routes
.open
.get(&self.seq_id)
.is_some_and(|route| route.tx.is_closed() && !route.overflowed)
{
let _ = self.session.commands.send(Command::Abort(self.seq_id));
}
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 14:31

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

Cancelling an already-sent non-streaming request retains accumulated output IDs until further peer output arrives, risking prolonged memory retention under backpressure, and the regression test misses this case.

1 open issue

Review effort: Balanced

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