Repository navigation
Add a typed codec that rebuilds a message without running code - #462
Draft
johnsabath wants to merge 1 commit into
Draft
johnsabath wants to merge 1 commit into
johnsabath wants to merge 1 commit into
Conversation
reactor_runtime.ipc.typed encodes an object as a tree of typed values: None, bool, int, float, str, bytes, numpy arrays and scalars of a fixed dtype list, list, tuple, dict, and the dataclasses and enums registered with @payload_type. Arrays go into the writer's SharedSlot as they do with pack(), or inline when there is no slot. The reader builds only those types. It checks every length against the frame, every array's shape against its bytes, every span against the block, and the nesting depth, and it refuses an unregistered type by name. pickle imports any class a frame names and calls what the frame tells it to, so a reader that must not trust its writer cannot use it. Nothing uses the codec yet; the model server's link takes it in the next change. Signed-off-by: John Sabath <john@reactor.inc>
Contributor
Author
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
A split model's link pickles every message, and unpickling runs whatever code a
frame names. This PR adds a reader to
reactor_runtime.ipcthat builds data andruns no code, so a fault in a session runtime cannot run code in the model
server. The next PR lets the link use it.
What Changed
reactor_runtime.ipc.typedencodes an object as typed values:None,bool,int,float,str,bytes, numpy arrays and scalars of a fixed dtype list,list,tuple,dict, and dataclasses and enums registered withpayload_type. Arrays go into the writer'sSharedSlot, as withpack().The decoder runs no code from the types it builds: records are filled field
by field without
__init__, enums are looked up by member name, dict keys areplain values (by exact type, to a bounded depth), and registration refuses a
field that is a data descriptor. It checks each length against the frame, each
array's shape against its bytes, each span against the block, the nesting
depth, and that one frame copies no more bytes out of the block than the block
holds. A malformed frame raises
TypedFrameError.Pickle carries some values that this codec refuses at encode with a
TypeErrorthat names the type: torch tensors, object or structured arrays,sets, subclasses of builtins, and a combined
Flagvalue (send itsint). Abytearrayarrives asbytes, and a non-contiguous array arrives as aC-contiguous copy.
Interface: new module
reactor_runtime.ipc.typed; new exportsreactor_runtime.ipc.payload_typeandTypedFrameError; new propertySlotReader.size. Nothing calls the codec yet. About 535 lines are source and496 are tests.
How it was proved
Round trips of nested records, tuples, optional arrays, enums, dicts of lists of
arrays and numpy scalars compare types as well as values. Fifteen hostile
frames, a pickle that writes a file, and a frame that names one span three
times are each refused, and no file appears. Every prefix of two sample frames
and 6,000 randomly changed frames decode or raise one of the documented errors.
With the shape check, tuple decoding or the depth check broken, 3, 2 and 1
tests fail.