Repository navigation
Description
The log path and Nix's forward progress share fate. A caller who blocks their
own event loop stops the evaluation.
The chain, measured
The back-pressure is not one buffer. It is four, linked:
LogCollector.callback(logging.py:90) does a blockingsync_q.puton a
queue of 10 000. The C++ logger calls it on the Nix thread.WorkerServiceHandler.subscribe_logs(_worker.py:445) consumes
collector.stream()and yields each event straight onto the gRPC
response. Each yield becomesgrpclib.server.Stream.send_message, which
awaits the HTTP/2 flow-control window. Verified in the grpclib source.- The client's
_forward_worker_logs(_pool.py:412) reads that stream and
callsCallbackBus.emit, which is synchronous and never blocks. So the
client stops reading only when its event loop stops running. LogCapture.events(logging.py:256) is an unbounded list, and
WorkerClient.log_stream(_pool.py:390) opens its memory object stream
withmax_buffer_size=math.inf. Neither has a cap.
Hops 1 and 2 push back, and the caller's event loop is the last consumer. An
event loop is not a real-time consumer, and Nix must not depend on one.
Two further defects, from the same reading
- A lost
request_finalizedmarker is a permanent hang.
LogCapture.__aexit__(logging.py:320) awaitswait()inside
anyio.CancelScope(shield=True)with no bound. One missing marker parks
that await for the life of the process, and a cancellation cannot reach it.
The path already exists:WorkerClient._teardowncancels_log_taskafter
_LOG_DRAIN_TIMEOUT_SECONDSwhile the worker still emits. log_stream's buffer ismath.inf. A caller who iterates it slowly
grows the client process without limit. The same defect asLogCapture,
one layer down.
The rule to write down
A log event may be lost. Nix's progress may not be delayed. Exactly one hop
in each process is lossy, it sits at the process boundary, and every hop
above it is guaranteed to drain. A control event is never lost.
A control event is a request_finalized marker or the stream sentinel. A
log line is diagnostic; a marker is protocol.
| hop | rule |
|---|---|
| Nix thread → collector | never blocks. put_nowait; on a full queue, drop and count |
| collector → relay task | always drains. The relay's only job is to move events |
| relay → outbox | lossy. Bounded; discard the oldest log line, never a control event |
| outbox → wire | may park on flow control, which is correct: it backs up into the outbox only |
| wire → client bus | already always drains |
bus → LogCapture |
bounded, discard the oldest |
The oldest, not the newest, at every cap: nanopynix_helpers/build.py:78 and
ekn/src/ekn/eval.py:356 both scan a capture for the fixed-output hash
mismatch Nix prints next to the failure, so the end of a log is the part worth
keeping.
Scope
LogCollector.callbacknever blocks.request_finalizedand the sentinel
take the place of the oldest queued event rather than joining the drop
count.stats()reportsdropped, which the SIGUSR1 dump already prints.- A new
LogOutbox: the worker's bounded hand-off from the relay to
SubscribeLogs. Same policy, one hop on. - A relay task, started by
worker_service_factory, that drains the collector
unconditionally. LogCapturegainsmax_eventsandwait_timeout, plustruncated,
dropped_eventsandunfinalized_request_ids.wait()is bounded and
records;wait_for_requestraises.- The loss reaches the caller. A new
nix.common.EventsDroppedvariant in
theLogEventoneof says how many events the producer discarded, at the
point in the stream where it happened. Without it a caller reads a short log
and cannot tell. Both engines send it, soLogCapture.dropped_eventsmeans
the same thing on each.
Acceptance criteria
- An operation that emits more than
maxsizeevents into a consumer that
never drains completes, andstats()["dropped"] > 0. - An evaluation completes while the client's event loop is held closed.
- A capture whose events were capped reports
truncated. - A capture that lost events upstream reports
dropped_events, on both
engines. - A finalize marker that never arrives ends the block and appears in
unfinalized_request_ids, instead of hanging.
Finding F11 of CODE_IMPROVEMENT_PLAN.md.
Activity
fix(logging): stop a stalled log consumer from stalling Nix