Repository navigation
Description
This body replaces the original report. That report said the stdio worker
"has no client" and recommended deletion. Both halves are wrong, and the
comments below record the readings that showed it. A reader should not have to
reconstruct the position from four comments, so this states it once.
The stdio worker is a shipped feature
nanopynix/pyproject.toml:43 declares
nanopynix-worker = "nanopynix.rpc.worker._worker:main", and
grpclib_transports.ssh.connect_ssh_stdio is its client.
That is the only SSH path that reaches a machine running OpenSSH.
connect_ssh opens a bare session and expects the far end to speak H2 on it,
which only serve_ssh's in-process demo server does (_DemoSSHServer,
ssh.py:181). connect_ssh_stdio runs a command and speaks over its stdin and
stdout, and the command it runs is nanopynix-worker.
grpclib-transports/tests/test_ssh.py:117 exercises that path.
What is missing is a client inside nanopynix. rpc/client/_pool.py reaches
its worker through multiprocessing_worker_with_backchannel and through
nothing else. The original report read "no caller inside nanopynix" as "no
client", and those are two different statements.
Three reasons to build it
1. It is the one seam with no multiprocessing singleton. #129 measured
that a forked child cannot start a forkserver worker at all: ensure_running
calls os.waitpid(self._forkserver_pid, WNOHANG) on a process that is not its
child, and raises ChildProcessError. #129 added spawn as the fork-safe
value. A stdio worker execs a fresh process, so it works from any process
state with no multiprocessing involved at all.
2. It can run a different Nix build per worker. That is item 3 of #76. The
forkserver preloads once, so one process gets one build for every worker it
starts. An exec chooses per worker, which is how a worker with no Boehm
collector would be selected per session rather than per process.
3. It is the only way to set an environment variable before Nix loads.
#94 landed Session(env=...), which serves every name Nix reads after
initLibStore. It cannot serve a name Nix reads while libnixstore loads,
because the forkserver preloads nanopynix.rpc.worker._worker and the library
is therefore loaded before any worker child exists. Those names are refused,
and nanopynix._env.READ_WHILE_LIBSTORE_LOADS lists them. An exec sets the
environment before the interpreter starts.
Where it plugs in, and what already exists
NanopynixSettings.worker_start is Literal["auto", "forkserver", "spawn"]
today. "stdio" is the fourth value, and this issue is what makes it
selectable.
Two halves of the transport are already there:
grpclib_transports.stdio_worker_with_backchannel
(grpclib-transports/src/grpclib_transports/stdio.py) already takes
env: Mapping[str, str] | None, andserve_stdio_with_backchannelis beside
it._stdio_maininrpc/worker/_worker.pystill calls the plainserve_stdio,
so it serves no backchannel and no RPC primop can reach the client.
Acceptance
worker_start="stdio"starts a worker withsys.executable -m nanopynix.rpc.worker._worker, and a session on it passes the same tests as
one onforkserver._stdio_mainserves the backchannel, so an RPC primop works on this start
method too.- The docstring of
mainnamesnanopynix.rpc.worker._worker. It names
nanopynix._workertoday, and that module does not exist. - A test at the
nanopynixlevel starts the console script and speaks to it.
Still open on the client side
worker_oom_score_adj.multiprocessing_workertakeson_process_start;
the stdio worker has no equivalent hook.- The worker exit status that
WorkerSignaledErrorreports. The pool reads it
from themultiprocessingprocess object. - The namespace. It travels today as a pickled
functools.partialover the
service factory, and an exec cannot pickle: it would have to travel as argv.
Out of scope, and why
A version field on InitRequest. The original report asked for one,
because a separately started worker can be a different version from its
client. That holds for connect_ssh_stdio against a remote machine. It does
not hold for this issue: the client here always execs the same installed
package, so skew cannot occur. State that reasoning in worker.proto, so the
next reader does not derive it again.
Resolved since the original report
run_worker is gone, and worker_child_teardown now runs in the
multiprocessing child (rpc/client/_pool.py:314). The comment below that found
"the live multiprocessing worker runs no teardown at all" no longer holds.
Findings F14 and Q4/Q5 of CODE_IMPROVEMENT_PLAN.md.
Activity
docs: turn the code improvement plan into issues and living documents
Lillecarl commentedon Aug 5, 2026
The premise of this issue is wrong: the client exists
This issue says the stdio worker "has no client", and recommends deletion. The
claim holds only inside
nanopynix. It does not hold for the library thatcarries the transport, and deletion would remove the far end of a shipped
feature.
grpclib_transports.ssh.connect_ssh_stdiois the client:grpclib-transports/tests/test_ssh.py:117exercises it.SSH mode does not replace stdio. SSH mode needs stdio.
There are two SSH client paths, and only one of them reaches a real machine:
connect_sshopens a bare session, and it expects the far end to speak H2 onthat session. The only server that does is
serve_ssh, which starts anasyncsshserver in the same process with a generated key and passwordauthentication (
_DemoSSHServer,ssh.py:181). A host that runs OpenSSHcannot answer it.
connect_ssh_stdioruns a command, and it speaks over the stdin and stdoutof that command. This is the only path to a remote host, and the command that
it runs is
nanopynix-worker, which ismain->_stdio_main->serve_stdio.So the stdio entry point is the remote half of the one SSH deployment mode that
works against a normal machine. This issue read "no caller inside nanopynix" as
"no client", and those are two different statements.
What is still true, and what this issue becomes
The evidence in the report stands on three points, and each one is a defect:
mainnamesnanopynix._worker. That module path does notexist. The real path is
nanopynix.rpc.worker._worker.nanopynixlevel starts the console script and speaks to it.InitRequestis absent, and a separately startedworker can be a different version from its client.
This issue therefore takes its own second branch -- "give it a client and a
test" -- and the deletion branch is withdrawn.
One more finding, from the same reading
run_worker(rpc/worker/_worker.py:657) has no caller anywhere: not innanopynix, not intests/, and not ingrpclib-transports. The pool reachesthe worker through
multiprocessing_worker_with_backchannel, whose child runs_run_multiprocessing_worker_with_backchannel._shutdown_workeris reachable only fromrun_workerand_stdio_main. Sothe live multiprocessing worker runs no teardown at all:
collector.close(),rpc_bridge.stop()andexecutor.shutdown(wait=True)never run in the childthat the pool actually starts. The child returns from
serve_h2and exits._exit_now_if_nix_will_not_stophas the same shape: it is called only frommain(), so the guard against a stuck Nix thread applies to the stdio pathalone. The multiprocessing child instead waits for the parent's
terminate()and then
kill().Refs #94, which needs the same deployment mode.
[-]Resolve the stdio worker: give it a client, or delete it[/-][+]Give the stdio worker its client and a test (do not delete it)[/+]Lillecarl commentedon Aug 7, 2026
Two things since this was written give the stdio worker a concrete reason to exist, and a place to be selected from.
It is the one seam with no
multiprocessingsingleton. #129 measures that a forked child cannot start a forkserver worker at all --ensure_runningcallsos.waitpid(self._forkserver_pid, WNOHANG)on a process that is not its child, and raisesChildProcessError. #129 addsspawnas the fork-safe value. A stdio worker execs a fresh process, so it works from any process state with nomultiprocessinginvolved.It can run a different Nix build per worker. That is item 3 of #76: the forkserver preloads once and copies its environment when it starts, so one process gets one build for every worker. An exec chooses per worker, which is how a non-GC worker would be selected per session rather than per process.
Where it plugs in. #129 adds
worker_start: auto | forkserver | spawntoNanopynixSettings.stdiois the third value, and the client this issue asks for is what makes it selectable.Refs #76, #129.
Lillecarl commentedon Aug 7, 2026
The load-time half of #94 is the second reason to build this client, and it names the shape.
envon a session now serves every variable Nix reads afterinitLibStore. It cannot serve one Nix reads whilelibnixstoreloads, because the forkserver preloadsnanopynix.rpc.worker._workerand the library is therefore loaded before a worker child exists. Those names are refused, andnanopynix._env.READ_WHILE_LIBSTORE_LOADSlists them.An exec sets the environment before the interpreter starts, so a stdio worker moves that whole set out of the refusal list. It would also make
Session(nix_conf=...)work on Nix 2.31, whichtests/support/nix_markers.py::NIX_CONF_FILE_IGNOREDcurrently skips three tests for.Two things are already in place:
grpclib_transports.stdio_worker_with_backchannel(grpclib-transports/src/grpclib_transports/stdio.py) already takesenv: Mapping[str, str] | None, andserve_stdio_with_backchannelis beside it._stdio_maininrpc/worker/_worker.pystill calls the plainserve_stdio, so it serves no backchannel and no primop can reach the client.NanopynixSettings.worker_startis the seam a third value goes in. It is aLiteral["auto", "forkserver", "spawn"]today.What is still missing on the client side:
worker_oom_score_adj(on_process_starthas no stdio equivalent), the worker exit status thatWorkerSignaledErrorreports, and the namespace path, which today travels as a pickledfunctools.partialand would have to travel as argv instead.[-]Give the stdio worker its client and a test (do not delete it)[/-][+]rpc: give the stdio worker a worker_start value, a client and a test[/+]feat(transports): let a caller reach the stdio worker process
docs: turn the code improvement plan into issues and living documents
feat(transports): let a caller reach the stdio worker process
feat(rpc): start a worker by exec, and serve its backchannel