Repository navigation
Lease results to the session in place with typed-lease - #464
Draft
johnsabath wants to merge 4 commits into
Draft
johnsabath wants to merge 4 commits into
johnsabath wants to merge 4 commits into
Conversation
The contract for typed-lease: the setting's new value, what a session gets as a result's arrays, BlockFull, and how kept arrays count against the slot's volume. The link does not implement it yet. Signed-off-by: John Sabath <john@reactor.inc>
With REACTOR_MODEL_SERVER_CODEC=typed-lease, the model server writes each array of a result into its own span of the output block. The session gets read-only arrays over those spans and copies nothing. When the last view of an array is gone, the session sends a release, and the model server can write that span again. A result that finds no free span within 2 seconds fails with BlockFull. The request fails alone, and the link goes on. A release the session cannot make, or a leased array in a request, closes that link. The session's reader thread no longer keeps the last message while it waits for the next one, so a result its caller dropped is freed at once. Signed-off-by: John Sabath <john@reactor.inc>
- A leased array still alive at interpreter exit is not released, so an exit handler can still read it. - The session's lease reader takes a reentrant lock, so a collection that runs inside it cannot deadlock on a release. - The model server applies a release frame all or none. - A release frame stays inside the link's frame limit. - A release that cannot be sent closes the session's link. - A refused lease leaves no live array counted. split_echo now runs under any REACTOR_MODEL_SERVER_CODEC: each half registers the echo's step types. The model server probe reports the result spans it holds. With typed-lease, they must stay below one burst after every cycle, because echo keeps a partial burst of frames. Signed-off-by: John Sabath <john@reactor.inc>
…tests rely on Signed-off-by: John Sabath <john@reactor.inc>
Contributor
Author
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Dec 5, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why
With
REACTOR_MODEL_SERVER_CODEC=typed, the session copies each array of aresult out of the model server's shared memory. For large results, that copy
is most of the step's round trip. This PR adds an opt-in mode that skips it.
What Changed
REACTOR_MODEL_SERVER_CODEC=typed-lease, set on the model server and on everysession runtime, works as
typed, except for results. The model serverwrites each array of a result into its own span of its output block. The
session gets read-only arrays over those spans. When the last view of an
array is gone, the session sends a release, and only then can the model
server write that span again. Requests are still copied.
A result that fits the block, but finds no free span within 2 seconds, fails
with
BlockFull. That request fails alone, and the link goes on. A releasethe session cannot make, or a leased array in a request, closes that link.
ModelClient's reader thread no longer keeps the last message while it waitsfor the next one, so a result its caller dropped is freed at once.
REACTOR_MODEL_SERVER_CODECpickleortypedtyped-leasereactor_runtime.model_server.BlockFullModelClient.step()withtyped-leaseModelClient.step()resulttyped-lease, non-empty arrays are read-onlyrr.ShmHellorr.ShmLeaseHelloandrr.Release, sent only intyped-leasemodetyped-leasereactor_runtime.ipc.leaseSpans,leased_array,LeaseReaderAn end in
typed-leaseagainst an end in any other mode, or against an olderruntime, fails at connect with the variable named.
Side effects
An application that keeps results keeps the model server's memory. Size
model.resources.sessions.shared_memory.outputfor what it keeps, or keepnp.array(x)copies. Echo keeps up to 29 frames for its burst. An array keptpast the link's close keeps that block in the slot's volume. An in-place op
on a tensor made with
torch.from_numpyends the session process.split_echonow runs under any codec, and withtyped-leaseit requiresfewer held spans than one burst after each cycle. CI still runs it with the
default codec.
How it was proved
Each invariant has a test, and each guard was checked by mutation: 17
mutations, each failed a test. The reader-thread test fails without its fix.
A 15-cycle
split_echorun withtyped-leasepasses, and fails when themodel server ignores releases. An older runtime is simulated by unregistering
the new hello, not run.
Round trip in one CPU-only Linux container, 1,000 steps, median p50 of 3 runs (µs):
Authored lines: 646 in
src(code and docstrings), 777 in tests and the endurance suite.