8000 Docs: write down the ownership rules and the layering rules · Issue #53 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

Docs: write down the ownership rules and the layering rules #53

Open

Description

@Lillecarl

The rules below are what the code mostly follows. Where the code does not
follow them, the difference is work rather than taste. Nothing states them
today.

The rules for a native resource

  1. A CoreValue, a CoreEvalState and a CoreLockedFlake are confined to
    one evaluator thread. Every call reaches them through the
    NixThreadExecutor of that evaluator.
  2. A CoreStore is thread-safe, and the store pool may share it.
  3. Every native resource has exactly one owner, and the owner is the object
    that created it.
  4. Dropping the Python handle releases the native resource, on both engines,
    with no action by the caller. An explicit release() is the deterministic
    form of the same thing, and the close of the evaluator is the backstop.
    See inproc: a Nix value is never released when its Python handle is collected #40.
  5. A finalizer never calls Nix. A finalizer queues, and the next operation on
    the owning thread drains the queue.

The rules for layering

bindings -> _core -> {settings, stores, models, exceptions, protocols, logging} -> {inproc, rpc}

Dependencies point from the right to the left only. _core never imports an
engine. An engine never imports the other engine.

One exception is permanent, and it must stay documented at the import site:
rpc/client/_pool.py imports rpc/worker/_worker.worker_service_factory,
because the forkserver pickles it by module path.

Scope

Put the rules for a native resource in the module docstring of
_core/_objects.py. Put both sets in
docs/nanopynix/architecture-principles.md.

Section 4 of CODE_IMPROVEMENT_PLAN.md.

Activity

  1. Lillecarl commented on Aug 7, 2026

    @Lillecarl
    ContributorAuthor

    Half of this issue is already done

    Checked on 2026-08-07 against the tree.

    docs/nanopynix/architecture-principles.md -- complete

    The file carries both sets of rules that this issue asks for. The layering
    rule is there, in the shape this issue gives it:

    bindings  →  _core  →  {settings, stores, models, exceptions, protocols, logging}  →  {inproc, rpc}
    

    with Dependencies point right to left only, the two named rules
    (_core never imports an engine, An engine never imports the other
    engine), and the permanent worker_service_factory` exception.

    The five rules for a native resource are under ## Native resource ownership.

    The module docstring of _core/_objects.py -- three rules short

    nanopynix/src/nanopynix/_core/_objects.py has an 18-line docstring. It
    carries rule 1 and rule 2:

    The public inproc API may share a CoreStore across Store-pool
    threads, but each CoreEvalState and its values remain confined to one
    evaluator thread.

    The rest of the docstring explains why the class is named Core and not
    Local, which is worth keeping and is not one of these rules.

    Rules 3, 4 and 5 are not there:

    1. Every native resource has exactly one owner, and the owner is the object
      that created it. (The docstring says the objects "own L1 bindings", which
      is not the same statement.)
    2. Dropping the Python handle releases the native resource, on both engines,
      with no action by the caller.
    3. A finalizer never calls Nix. A finalizer queues, and the next operation on
      the owning thread drains the queue.

    What is left

    Add rules 3, 4 and 5 to the docstring of _core/_objects.py. Nothing else in
    this issue needs work.

    #40, which rule 4 refers to, is closed, so the behaviour that rule 4 states
    exists and is only undocumented at that site.

  • added
    source: nanopynix
    on Oct 19, 2026
  • 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