Repository navigation
2.x.x: replace PRISM builder pipe polling with readiness waits - #237
Merged
Merged
Conversation
#236) The --serve daemon transport and the one-shot writer drive the builder's pipes non-blocking so cancellation, supersession and the absolute deadline are checked between syscalls, and they slept a fixed 20 ms after every EAGAIN. On Linux that is one sleep per drained 64 KiB pipe capacity, so a multi-megabyte window exchange paid orders of magnitude more in idle sleeps than in copying: measured here, the 90 MiB request write of a cold 210k-share prepare_window spent 26.9-27.6 s in 1,327-1,362 sleeps, and the raw helpers moved 3-6 MiB/s. A small readiness waiter now takes the sleep's place. One instance serves one transport operation, registers the descriptor lazily (an operation satisfied from buffered bytes or by syscalls that never block costs no selector) and closes the registration on every exit path. Each wait is bounded by BOTH the remaining absolute deadline and the retired sleep's 20 ms cancellation-check cadence, so a waiting build wakes the moment the pipe can progress and still re-checks its control signals on the old schedule when nothing happens. EINTR is retried after the control checks without waiting; readiness the selector reports may be spurious and is resolved by retrying the syscall; a descriptor the selector refuses degrades to the old bounded sleep. Nothing else about the loops changes: exact raw-payload lengths, bytes buffered after an envelope newline, short reads and writes, EOF and broken-pipe classification, exactly-once crash accounting, timeouts that leave the failure to the one-shot fallback, supersession before and after a fault, Linux splice with the portable fallback, and spool poisoning without ever replaying a partially sent prefix. The line reader also stops rescanning the whole buffer for the newline after each chunk. Measured with tests/perf/window_builder_pipe_latency.py against the baseline module extracted from e59bda3 and the real release daemon: the raw helpers reach 30-215 MiB/s with byte-exact digests; a cold 210k prepare_window drops from 39.8-43.8 s to 12.2-13.8 s with the request write at 0.13-0.15 s and identical digests and canonical bytes. The residual is elapsed daemon-side time plus the whole-request encoding PR 2 targets, neither attributed here; see the report for what the numbers do and do not establish. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_012HydbXko45T99GQ4yi6yMB
Full discovery failed once in the new one-shot writer test: a slowly paced child does not guarantee EAGAIN while json.dump emits small fragments, so "the writer blocked at least once" was a scheduling assumption, and the same assumption sat under several real-pipe tests. Every remaining wait-count assertion now holds by construction. Real-pipe and one-shot peers are gated: a peer thread waits on an event, a child process polls for a marker file, and the recording waiter releases them on the transport's first blocked wait, so at that moment the pipe is empty (reads) or full (writes) whatever the scheduler did. The scripted timeout tests drive the module's clock through a hand-advanced fake instead of letting 20 ms of real time elapse, and assert the exact wait count and remaining slack. Where no gate is possible -- a real deadline on an idle pipe, the fake daemon's parse time -- the wait count is no longer asserted and the byte, framing, classification and cleanup assertions remain. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_012HydbXko45T99GQ4yi6yMB
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4252b175a1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This was referenced Sep 6, 2026
…ered pipe (#236) A selector can accept a builder pipe's registration and still refuse to poll it -- SelectSelector over a Windows pipe handle is the known case, a descriptor torn down under the registration another. The readiness waiter only guarded registration, so a select-time failure propagated out of the transport loop instead of reaching the bounded-sleep fallback the waiter documents (PR #237 review). A failed poll now releases the selector exactly once, marks the descriptor unwatchable for the rest of the operation so no selector is rebuilt on later waits, and finishes the same wait with the sleep over whatever budget the failed poll left: the remainder of the cancellation slice, and never past the absolute deadline, so a wait that already spent its budget inside the failed poll returns at once. EINTR from the poll stays what it was, a plain wakeup that keeps the selector and hands control back to the loop's cancellation and deadline checks. Regression coverage uses a deterministic selector fake that registers and then raises at select, with a hand-advanced clock: single release and no recreation across waits, the remainder-of-slice and deadline bounds, a deadline spent inside the failed poll, EINTR kept distinct, and a line read completing over the fallback through the real helper. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_012HydbXko45T99GQ4yi6yMB
The detach-once test asserted two positive sleeps against the real clock, so a >20 ms deschedule during the failed poll would have made the waiter's correct no-sleep return look like a failure. It now runs on the existing fake-clock helper and asserts the two full-slice sleeps exactly, the same way its sibling budget tests already do. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_012HydbXko45T99GQ4yi6yMB
6 tasks
Closed
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Large PRISM builder requests repeatedly hit pipe backpressure and then sleep for a fixed 20 ms, extending cold payout-window preparation. Replace those sleeps with readiness waits that return as soon as the pipe can progress, while retaining the existing deadline and cancellation-check cadence.
The change covers daemon reads, writes and spool splices, plus the one-shot writer. It also avoids rescanning already checked response bytes for a newline. Selector cleanup, partial progress, EOF, broken pipes, EINTR, cancellation and supersession are covered by regression tests; unsupported selector registration or polling falls back to bounded sleeps within the original slice and deadline.
On the shared Linux benchmark host, a cold 210,000-share daemon preparation fell from 39.8–43.8 seconds to 12.2–13.8 seconds, with identical canonical bytes and digests. Request writing fell from 26.9–27.6 seconds to 0.13–0.15 seconds. These measurements cover the daemon exchange on Python 3.12, not production-image or end-to-end Stratum recovery. The on-demand benchmark and its limitations are included in
tests/perf/window_builder_pipe_latency.md.Validation:
8ce64bb: independent Linux full discovery passed 3,327 tests (2 skipped), and GitHub CI passed on Python 3.14.os.spliceassumptions, reproduced against the unchanged base.git diff --checkpassed.The 400,000-share benchmark fell back in both variants and remains unresolved in this change. The separate Rust paging allocation defect is tracked in #240. Production-image validation, end-to-end recovery and the combined lease-monitor latency target remain release checks for the broader issue.
Part of #236; the database decoding and serialization changes are separate work.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.