8000 RPC: a worker exception arrives as the wrong class, and prose is the only identity on the wire · Issue #57 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

RPC: a worker exception arrives as the wrong class, and prose is the only identity on the wire #57

Closed

Description

@Lillecarl

The RPC boundary keeps the class of a Nix C++ exception and nothing else. Every
other exception a worker raises reaches the client as a NixError that carries
"TypeName: message" as prose.

Measured:

worker raises: SettingNotLiveError("Nix reads pure-eval only while constructing the evaluator, ...")
client gets:   NixError("[Unknown] SettingNotLiveError: Nix reads pure-eval only while ...")

convert_handler_errors (worker/_grpc_util.py:44) sends
f"{type(exc).__name__}: {exc}". A binding exception's Python name is its
Nix C++ name (nix_errors.cpp:109-183), so split_type_prefix plus
_NIX_EXCEPTION_TYPES recovers that one family. Nothing else is in that table,
so nothing else survives. from_response (exceptions.py:671) is typed
-> NixError, and a name it does not know falls through to message patterns
and lands on NixError.

Why it matters

A caller cannot write except SettingNotLiveError across the process boundary.
NixError is also the wrong family: its docstring says Nix produced the error,
and SettingNotLiveError's docstring says the opposite in as many words --
"Not a NixError, because Nix was never consulted".

docs/nanopynix/architecture-principles.md already makes this a rule: "The two
engines must agree on: exception class". Today rpc breaks that rule for every
exception Nix did not raise.

A client in another language is worse off still. It must split a string to
learn the class, and it reads a blanket Status.UNKNOWN for every failure.

What actually crosses this boundary

Measured, so that the fix is sized to the real 8000 set and not to the class
hierarchy:

  • Six builtins. RuntimeError, ValueError, TypeError, TimeoutError,
    KeyError and IndexError, raised throughout rpc/worker/ and
    _core/.
  • SettingNotLiveError, from settings.py:118,141, reached through
    CoreEvalState.configure. RPC: the worker does not enforce the construction-time settings guard #37 added it, which is what made this visible.
  • Whatever the bindings raise, which already works.

Three families need nothing:

  • Every ObjectLifetimeError subclass is raised client-side
    (rpc/client/_session.py, _pool.py, store.py). None crosses the wire.
  • Build errors are not exceptions on the wire. Both engines call
    build_error_from_result locally from a BuildResult.
  • WrongNixTypeError is defined, exported, and raised by nothing in
    nanopynix/src. Its __init__ is keyword-only, so it is also the one class
    that cannot be rebuilt from a message.

What this asks for

The error's class on the wire as a field, not as prose. gRPC's Status is
only the transport, and this repository already knows how to use it for this
exact job: rpc/_status_details.py carries a Nix error's structured detail in
the grpc-status-details-bin trailer, as Any-packed betterproto2 messages
inside a standard google.rpc.Status. The mechanism needs no new transport
concept.

The message

A new message in common.proto, beside NixErrorInfo:

message ErrorIdentity {
  // The Nix C++ exception class, when Nix raised the error. e.g.
  // "EvalError".
  string nix_type = 1;

  // The nanopynix or Python class, when Nix did not raise the error. e.g.
  // "SettingNotLiveError", "ValueError".
  string class_name = 2;
}

Two fields, two vocabularies, exactly one set. The worker picks the field the
same way translate_nix_exception picks its branch:
type(exc).__module__.startswith("nanopynix_bindings").

google.rpc.ErrorInfo was considered and rejected. It generates eight messages
this project never uses, and its reason field is specified as
UPPER_SNAKE_CASE, which needs a name-mapping table. _status_details.py
already promises that a foreign client needs "nothing from nanopynix beyond
common.proto", and a message there keeps that promise.

The status message does not change. The "TypeName: text" prefix stays, so
a peer with no support for the new detail behaves exactly as it does today.
That is what makes the degradation free.

Client resolution

_grpc_call (rpc/client/_pool.py:110) consults a widened resolver first and
falls back to from_response, which keeps its -> NixError type for its Nix
callers.

  1. nix_type known -> refine_within it, then
    cls(error_type, msg, raw=raw, info=info). The refinement must stay.
    The worker's class is authoritative but coarse: Nix reports both 1 + "a"
    and a hash mismatch as plain nix::EvalError, and the client narrows those
    to NixTypeError and EvalHashMismatchError by message. Treating the wire
    name as final would be a regression.
  2. class_name in an explicit allowlist -> cls(msg), or the step-1
    construction when the class is a NixError subclass.
  3. Neither -> today's behaviour.

Do not import or evaluate a name that came off the wire. The payload selects a
key in a table the process built at import; it never names a module.

The allowlist is derived from the class objects in nanopynix.exceptions plus
the six builtins, minus an exclusion set that gives a reason for each entry. A
test pins the resulting key set as a literal, so a new exception class cannot
be added without deciding whether it crosses the wire.

Status codes

convert_handler_errors sends a blanket UNKNOWN. A client in another
language reads the code, and today it reads nothing else. Two families get a
real code:

Exception Code Why
ObjectMisuseError FAILED_PRECONDITION the object's state is wrong for the call, which is what the code means
ValueError, TypeError, KeyError, IndexError INVALID_ARGUMENT the request named something the worker cannot use
everything else UNKNOWN unchanged

Every NixError and every Nix C++ error stays UNKNOWN. A Nix failure is a
failure of the requested work, not of the request, and gRPC has no code for
that. DEADLINE_EXCEEDED and UNIMPLEMENTED stay unused on purpose: both mean
something specific to gRPC middleware that a worker-internal TimeoutError or
a nix::UnimplementedError is not.

The trim path eats the new detail

_trim_to_budget (_status_details.py:267) returns a Status with no
details at all
when any detail is not a NixErrorInfo. Adding a second
message without changing this drops the class identity on exactly the errors
with the deepest traces.

Partition the details. Never trim the identity, which is a few dozen bytes and
is the most valuable thing in the trailer. The give-up path keeps it.

Acceptance criteria

  • except SettingNotLiveError catches a worker-raised SettingNotLiveError.
  • Each of the six builtins arrives as itself.
  • An engine-parity test asserts that both engines raise the same class for the
    same misuse.
  • ObjectMisuseError arrives with FAILED_PRECONDITION, and the four
    argument-shaped builtins with INVALID_ARGUMENT.
  • A name the client does not allow degrades to the present behaviour, and a
    test pins that.
  • The NixErrorInfo detail still arrives, and the identity survives a trim
    that empties it.

Tests

  • A round trip for each allowed class through a real worker: raise it, catch
    it by class on the client.
  • A malformed or unknown ErrorIdentity detail, proving the degradation.
  • Both messages riding the same trailer.
  • The identity surviving an oversized NixErrorInfo, and surviving the
    give-up path.
  • The status-code table.
  • The allowlist key set, as a literal.
  • test_config_flow.py's test_the_worker_refuses_a_hand_built_configure_request
    records today's loss in its docstring and asserts NixError. It becomes
    SettingNotLiveError.

Out of scope

  • The reverse direction. A client-side primop raising PrimopError becomes
    GRPCError(INTERNAL, str(exc)) at rpc/client/_manager.py:112, reaches Nix
    through the worker's primop bridge, and returns as an EvalError. Separate
    boundary, separate shape.
  • The worker raising the wrong class at the source.
    _core/_objects.py:97,416,572,694 raise RuntimeError("local value has been released") where inproc raises ValueReleasedError. This issue transports
    faithfully whatever the worker raised. Making the worker raise the right
    class is RPC: give the worker a typed state and a typed handle registry #43.
  • EngineError, the fourth family in the taxonomy table, is API: the public surface disagrees with itself #44.

Found while fixing #37. #37 accepts the degradation deliberately: its acceptance
criterion is that the worker refuses, and the refusal and the message both
survive today.

Activity

  1. changed the title [-]RPC: a worker exception arrives as the wrong Python class[/-] [+]RPC: a worker exception arrives as the wrong class, and prose is the only identity on the wire[/+] on Jul 30, 2026
  2. added
    source: nanopynix
    on Oct 19, 2026
  3. added theissue type on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: nanopynix

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0