8000 RPC: give the worker a typed state and a typed handle registry · Issue #43 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

RPC: give the worker a typed state and a typed handle registry #43

Closed

Description

@Lillecarl

The whole worker layer is Any to the type checker, so pyright --strict
verifies none of it.

Evidence

HandleRegistry.get_typed(handle, expected_kind) -> Any
(rpc/worker/_handle_registry.py:42). The kind tag is checked at runtime and
discarded statically.

EvalServiceHandler.__init__(self, state: Any)
(rpc/worker/_worker_eval.py:196), and StoreServiceHandler is the same.

The symptom is visible at rpc/worker/_worker.py:555-567, _shutdown_worker,
which carries nine suppressions on eight lines. Each says "cascade from
WorkerState Any attributes", although every attribute of WorkerState has a
concrete type.

Why it matters

pyright --strict reports zero errors over this code because it can see
nothing to check. Every handler body is the code that turns a wire message
into a Nix call, and it is unverified. That is the layer where a wrong handle
kind or a wrong attribute name becomes a TypeError in a subprocess.

Scope

Two mechanical changes, in this order:

  1. Type state as WorkerState on all three handlers. WorkerState is
    defined in _worker.py, and _worker.py imports the handlers, so move
    WorkerState to a neutral module rpc/worker/_state.py to break the
    cycle. AGENTS.md names that as the preferred correction.
  2. Replace get_typed with one typed accessor for each kind: get_store,
    get_eval_entry, get_value, get_locked_flake. There are four kinds,
    they do not change, and the call sites read better than a generic method.

Delete HandleRegistry.clear() (:65) at the same time. It has no caller,
and it resets _next = 1, so a use of it would reissue handle numbers that a
client still holds.

Files

rpc/worker/_state.py (new), _worker.py, _worker_eval.py,
_worker_store.py, _handle_registry.py.

Depends on

Phase 0 and Phase 1. Do not refactor under an unfixed defect.

Risk

Low. The change is mechanical, and pyright reports the mistakes.

Acceptance criteria

pyright stays at zero. The count of suppressions in
rpc/worker/_worker.py drops from 16 to fewer than 6. Count both before and
after.

Finding F7 of CODE_IMPROVEMENT_PLAN.md.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0