Repository navigation
Description
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
8000
fix is sized to the real set and not to the class
hierarchy:
- Six builtins.
RuntimeError,ValueError,TypeError,TimeoutError,
KeyErrorandIndexError, raised throughoutrpc/worker/and
_core/. SettingNotLiveError, fromsettings.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
ObjectLifetimeErrorsubclass 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_resultlocally from aBuildResult. WrongNixTypeErroris 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.
nix_typeknown ->refine_withinit, then
cls(error_type, msg, raw=raw, info=info). The refinement must stay.
The worker's class is authoritative but coarse: Nix reports both1 + "a"
and a hash mismatch as plainnix::EvalError, and the client narrows those
toNixTypeErrorandEvalHashMismatchErrorby message. Treating the wire
name as final would be a regression.class_namein an explicit allowlist ->cls(msg), or the step-1
construction when the class is aNixErrorsubclass.- 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 SettingNotLiveErrorcatches a worker-raisedSettingNotLiveError.- Each of the six builtins arrives as itself.
- An engine-parity test asserts that both engines raise the same class for the
same misuse. ObjectMisuseErrorarrives withFAILED_PRECONDITION, and the four
argument-shaped builtins withINVALID_ARGUMENT.- A name the client does not allow degrades to the present behaviour, and a
test pins that. - The
NixErrorInfodetail 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
ErrorIdentitydetail, 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'stest_the_worker_refuses_a_hand_built_configure_request
records today's loss in its docstring and assertsNixError. It becomes
SettingNotLiveError.
Out of scope
- The reverse direction. A client-side primop raising
PrimopErrorbecomes
GRPCError(INTERNAL, str(exc))atrpc/client/_manager.py:112, reaches Nix
through the worker's primop bridge, and returns as anEvalError. Separate
boundary, separate shape. - The worker raising the wrong class at the source.
_core/_objects.py:97,416,572,694raiseRuntimeError("local value has been released")where inproc raisesValueReleasedError. 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
fix(core): make the worker enforce the construction-time settings guard
[-]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[/+]fix(core): make the worker enforce the construction-time settings guard
feat(rpc): carry a worker exception's class on the wire