Skip to content

2.x.x: replace PRISM builder pipe polling with readiness waits - #237

Merged
kiwidream merged 4 commits into
2.x.xfrom
fix/prism-236-pipe-transport-20260906
Sep 6, 2026
Merged

kiwidream merged 4 commits into
2.x.xfrom
fix/prism-236-pipe-transport-20260906

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

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:

  • Current head 8ce64bb: independent Linux full discovery passed 3,327 tests (2 skipped), and GitHub CI passed on Python 3.14.
  • Current 65-test transport module: two serial and four concurrent reviewer runs passed; 286 related tests passed. Polling-failure regressions use deterministic fake clocks.
  • Real Rust daemon parity gate: 7 tests passed.
  • Local Python 3.14/macOS transport, window pipeline and lease-monitor suites: 129 tests run, OK (2 skipped). A broader run hits five existing Linux os.splice assumptions, reproduced against the unchanged base.
  • git diff --check passed.

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.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Alex and others added 2 commits September 6, 2026 08:37
#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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-06T13:29:03.597822Z 8ce64bb New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread lab/prism/bundle_compiler.py Resolved
Alex and others added 2 commits September 6, 2026 09:21
…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
@kiwidream
kiwidream merged commit 43fef00 into 2.x.x Sep 6, 2026
11 checks passed
@kiwidream
kiwidream deleted the fix/prism-236-pipe-transport-20260906 branch September 6, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant