Skip to content

3.x.x: single-pass tee, chunk-parallel counted-share JSON and lean tip probes for the refresh (#275) - #502

Merged
djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b275-refresh-cpu
Sep 24, 2026
Merged

djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b275-refresh-cpu

Conversation

@djh58

@djh58 djh58 commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

The refresh's CPU path serialized the 400k accepted-share array twice (audit prefix and the WindowRef digest),
serialized the counted-share array twice (commitment leaf and audit suffix), folded it with two million
string clones on one thread and hashed the slice digest with four million tiny SHA updates; the two pipeline
lanes were balanced at ~606 and ~611 ms, so neither could shrink alone. This PR cuts both lanes without
changing a byte of any artifact, and trims two dead ledger probes on new tips.

Refs #275.

Byte-identical CPU cuts (builder only; verifiers stay serial and untouched):

  • qbit_prism::parallel (new): ordered chunk pipeline on one process-wide worker pool (¾ of the cores,
    at most 16 threads), write_array/write_array_frames (exactly serde_json::to_writer(&slice), each
    element still written by serde_json, chunks concatenated in order), and StructSplice, a serializer that
    keeps a struct's derived field order and skip rules but supplies one field's value bytes from a chunk-
    parallel writer. PrismRewardManifest's derive and AuditBundleRef::serialize_suffix remain the only
    definitions of the audit bytes; u128 fields reach serde_json's own serialize_u128 as before.
  • Tee: CanonicalAuditHashPrefix::new_with_share_digest serializes the accepted shares once and feeds both
    SHA states (prefix and WindowRef.snapshot_sha256), the second on its own thread over the same frames.
  • Counted-share JSON: the commitment leaf and the audit suffix serialize reward_manifest.shares in ordered
    chunks (reward_manifest_sha256, finish_with); with CTV the manifest is digested once for the leaf and
    the fan-out precommitments instead of twice.
  • Fold: compute_prism_window_parallel decides counted difficulties serially, builds CountedShare chunks
    on the pool, encodes each chunk's slice-digest bytes and entitlement partial sums there, and streams the
    digest on its own thread (one update per chunk). Eligibility/ordering and the per-share digest encoding
    are shared with the serial fold (eligible_window, update_slice_digest).
  • The compact-record capture no longer waits for the 130 MB counted-share drop; it runs on the blocking pool
    under the same build admission.

Lean-tip I/O (R5): probe #1 is skipped when the template fingerprint already differs (it includes
previousblockhash), probe #2 when the cached window's revision is below the one the chain-observation write
returned (every revision write is an increment), and the landing metric takes the anchor transaction's
revision. The same-template path is unchanged (probe #1 still precedes the fee RPC). The in-transaction save
fence and the lock-loop re-prove are untouched. AUDIT_BUILDER_VERSION is unchanged.

Method

Real processes: two qbit-prism-server frontends launched by qbit-prism-load at the production initial-job
admission (128), 2,000 Stratum sessions, a 400,000-share payout window, background shares at 1/s, 8 external
tips per run, runtime workers 8, pool 16. Both binaries carry the same diagnostic spans (scratch copies of
the trees; nothing in this PR is instrumentation); spans are aligned to the harness node's minted_at.
Order: A/A pair (base, base), then base A, candidate A, candidate B, base B. Every row is the median over a
run's 16 refreshes (8 tips × 2 frontends); every refresh took the delta share-acquisition path and served
2,000/2,000 sessions on both frontends. The host (22 cores, SHA-NI) was shared with other work; every heavy
step ran under one lock, and the A/A pair bounds the remaining noise.

Timing (on top of the merged fan-out work)

Base = origin/3.x.x b61747e (#499 fan-out C1+C2+A and #498 merged); candidate = this branch on b61747e
at its default pool size (4 threads). The branch was then moved onto 03f6347 (#501, delta across
retargets; one conflict in the refresh-trigger label, resolved to label a skipped probe from the parent
alone); a confirmation pair on that base (one run each, busier host): refresh 777 → 417 ms, tip→last notify 1061 → 678 ms, mean miner latency 979 → 610 ms, p99 1061 → 686 ms, publish→last 251 vs 252 ms, peak RSS 557 → 669 MiB, RSS after the tips 328–342 → 568–608 MiB; #501's refresh log shows the same trigger/acquisition mix on both binaries. Balanced A/B, base A / candidate A / candidate B / base B, eight
tips per run, medians over each run's 16 refreshes (8 tips × 2 frontends); every refresh took the delta
share-acquisition path and served 2,000/2,000 sessions on both frontends with reconciliation equal in
every phase and no refusals. A/A noise on this host (two base runs, earlier pair): refresh 2.7 ms, tip→last
13.5 ms, mean 12.2 ms, p99 19.3 ms.

metric saving pair A saving pair B median saving base range → candidate range
refresh 338.2 343.3 340.8 (46.0 %) 736–747 → 397–403
tip → last notify 385.3 331.2 358.3 (37.2 %) 955–973 → 587–624
mean miner latency 373.0 331.5 352.2 (39.1 %) 895–904 → 531–564
p99 miner latency 384.8 328.6 356.7 (37.0 %) 955–974 → 589–626
publish → last (post-publish tail) 5.4 -7.5 -1.1 (-0.5 %) 194–205 → 188–212
peak RSS per frontend (MiB) 49.6 -82.8 -16.6 (-2.6 %) 575–694 → 645–658

Hashrate loss at 60 s (1 − exp(−mean/60)): 1.5 % → 0.9 %. Share-ack latency (harness client_ack p99,
ms, warm-up / steady state): base 10.1 / 5.7 and 50.0 / 7.0, candidate 15.1 / 10.9 and 16.8 / 10.1: within
run-to-run spread. Lanes (ms, base → candidate): left (prefix + WindowRef digest) 309–311 → 121–125;
right body 388–396 → 215–220; finish (suffix) 225–227 → 90.

Pool-size trade-off (PRISM_REFRESH_BUILD_THREADS, same base pair, RSS per frontend after the eight
warm-up tips from the harness's rss_kib_last):

variant runs refresh median (ms) tip → last notify (ms) mean miner latency (ms) publish → last (ms) RSS after the 8 warm-up tips per frontend (MiB) peak RSS (MiB)
base b61747e 2 741 964 900 199 344–483 635
candidate, pool 16 (cases ab4-cand-A/B) 2 417 631 570 202 684–703 783
candidate, pool 8 2 420 612 554 194 663–677 754
candidate, pool 4 (new default) 2 400 606 548 200 542–585 651
candidate, pool 2 (one run) 1 437 687 623 213 535–541 604

The refresh stops getting faster above four threads (every stage is bounded by its consumer: the SHA-256
states and the fold's merge) while more threads retain more memory across allocator arenas, so four is the
default; eight saves almost nothing over sixteen, two starves the tee's producers. The retained excess over
base at the default is +100–240 MiB per frontend after the tips and converges (it does not grow with
further tips); PRISM_REFRESH_BUILD_THREADS=0 restores the serial builder.

Fault injection (real processes, same configuration)

Pool backends terminated mid-fan-out on tips 2 and 5 (16–32 backends), three own-block landings bumping the
payout revision while work was built and persisted, and a PostgreSQL fast restart during tip 3, each on the
candidate and on the base: every tip served 2,000/2,000 sessions on both frontends; reconciliation
offered = acknowledged = committed in every phase with zero missing, unexpected, unknown-outcome or
no-response commits and zero durability findings; the only refusals were the three stale job refusals
after landings (the existing revision fence). One existing offered candidate could not be processed … payout revision changed while observing chain state alert appeared once on a base run and once on a
candidate run; it is independent of this change.

Tests

  • tests/parallel_builder.rs (new): randomized windows (sizes 0–2,000, every string escape edge, u128
    difficulties at both ends, ineligible shares, credit policy, three orderings, CTV) × six thread/chunk
    geometries: identical body, canonical bytes, pipelined audit hash, share-array digest, reward-manifest
    digest and commitment leaf; the serial verifier accepts every parallel body and rebuilds its window; chunk
    boundaries 1–4,097; empty window; golden vectors for a fixed 2,048-share window recorded from the serial
    builders and re-derived on the untouched base tree.
  • parallel::tests: framing equality for every chunking, ordered consumption with bounded look-ahead,
    first-error propagation from either side, producer panic re-raised after draining, writer failures,
    struct splice equality and refusal of non-struct values, frames through the digest thread.
  • Existing overlapped_body_preserves_exact_serial_audit_bytes, the compute-pipeline admission/cancellation
    tests (now with the prefix→left hand-off), and the refresh-window deferral tests pass; tests force
    3 workers × 5-element chunks so the ordered path runs on any host.
  • cargo test for qbit-prism and qbit-prism-server (lib and every integration test, including the
    PostgreSQL-gated ones with the gate manifest checked), cargo clippy --workspace --all-targets -D warnings,
    cargo fmt --check: on the final tree (3.x.x 03f6347 plus this change) 3,948 passed, 0 failed, 60 ignored across the workspace (78 test binaries, PostgreSQL 16 and qbitd for the gated suites) with all 692 expected gated tests executed and the manifest check passing; clippy and fmt clean; scripts/check_prism_settings.py clean.

Independent review (no blockers, 8 minors) and dispositions

  • F1 pool re-entrancy (fixed). A builder that runs on a pool thread now runs ordered_chunks inline
    (thread-local flag set on every pool thread), as does a disabled pool or one whose threads failed to
    start; nested use cannot park the pool. Test: nested ordered_chunks inside a producer completes with
    correct order and takes the serial path.
  • F2 sizing and kill switch (fixed). PRISM_REFRESH_BUILD_THREADS (0 = serial builder, 1–64 = pool
    threads, empty = three quarters of the cores capped at 16) validated at startup, listed in the native
    settings inventory (scripts/check_prism_settings.py passes), documented in PRISM.md and .env.example,
    rejected out of range by the config CLI test. The thread arithmetic in the code comments now states the
    real shape: pool threads plus two lane threads and two digest threads per refreshing frontend, one pool
    per frontend process. Pool threads keep the process's priority (not changed).
  • F3 reused-window refresh stayed serial (fixed). The same-window rebuild (new template, same shares
    and revision) now uses the chunked fold, leaf, tee and suffix on its single lane; the benchmark's
    new-tip path is unchanged.
  • F4 landing-metric instant (restored). revision_work_observed is fed right after reconcile from the
    revision the chain-observation write returned (the instant the ledger probe used to feed it), and again,
    idempotently, from the anchor transaction and at window selection, so a bump between those points is still
    recorded at the later instant.
  • F5 deferred drop held the build permit in a queued blocking task (fixed). The permit is released
    before the counted-share drop is deferred.
  • F6 unwind-through-Drain untested (fixed). A consumer-panic test (20 rounds, 64 chunks) asserts every
    submitted job finished before the unwind reached the caller, none runs afterwards, and the pool still
    serves ordered work.
  • F7 pool thread spawn failure (fixed). A failed spawn keeps the threads that started; with none the
    builders run serially instead of leaking a half-started pool.
  • F8 contract docs (fixed). ordered_chunks states that producers must not block on the consumer or
    depend on the pool; BufferPool/spawn_hasher state the buffer-return bound.

Caveats

  • Peak RSS per frontend is +70 MiB at the default pool size (base runs vary by 120 MiB themselves) and the
    RSS retained after the tips is +100–240 MiB: glibc keeps freed memory per arena across the pool's threads;
    per-stage threads instead ratcheted RSS every refresh, which is why the pool exists. It does not grow
    across tips. The frontend that lands its own block peaks at 1.9–2.5 GiB while it publishes that block's
    audit bundle on base and candidate alike (pre-existing).
  • One unsafe (parallel::ordered_chunks): the per-chunk job's borrowed closure is lifetime-erased to run
    on the persistent pool; a drain guard waits for every submitted job on return and on unwind, and jobs never
    block. Covered by the producer-panic and consumer-panic tests; the independent review read the argument
    and added a 50-round unwind stress and a concurrent-callers test of its own (both passed).
  • No post-run verification of a landed block's published audit bundle was run against the harness cluster
    (discarded at run end); the byte identity is proven by the property/golden tests and the PostgreSQL-gated
    audit and landing tests.
  • Not done, as decided: prepared-record format change (R4) and incremental per-share fragments.

🤖 Generated with Claude Code


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

…p probes for the refresh (#275)

The refresh's CPU path serialized the accepted-share array twice (audit
prefix and WindowRef digest), the counted-share array twice (commitment
leaf and audit suffix), folded it with two million string clones on one
thread and hashed the slice digest with millions of tiny SHA updates; the
two pipeline lanes were balanced, so neither could shrink alone.

Builder-only, byte-identical cuts (verifiers stay serial and untouched):

- qbit_prism::parallel: an ordered chunk pipeline on one process-wide
  worker pool (PRISM_REFRESH_BUILD_THREADS; default three quarters of the
  cores, at most four, the measured knee; 0 runs the builder serially),
  write_array/write_array_frames (exactly serde_json::to_writer of the
  slice, every element still written by serde_json, chunks concatenated in
  order) and StructSplice, a serializer that keeps a struct's derived field
  order and skip rules while one field's value bytes come from a
  chunk-parallel writer. PrismRewardManifest's derive and
  AuditBundleRef::serialize_suffix remain the only definitions of the audit
  bytes; u128 fields reach serde_json's own serialize_u128 as before.
- CanonicalAuditHashPrefix::new_with_share_digest serializes the accepted
  shares once and feeds both SHA states, the WindowRef digest on its own
  thread over the same frames; finish_with writes the suffix with the
  reward manifest's shares in ordered chunks.
- The commitment leaf and, with CTV, the fan-out precommitments digest the
  reward manifest once through the same chunked writer.
- compute_prism_window_parallel decides the counted difficulties serially,
  builds the CountedShare chunks on the pool with their slice-digest bytes
  and entitlement partial sums, and streams the digest on its own thread.
  Eligibility, ordering and the per-share digest encoding are shared with
  the serial fold.
- The compact-record capture no longer waits for the counted-share drop;
  it runs on the blocking pool under the same build admission.

Lean tip probes: the ledger probe before the reuse check is skipped when
the template fingerprint already differs, the probe under the build permit
when the cached window's revision is below the one the chain-observation
write returned (every revision write is an increment), and the landing
metric takes the anchor transaction's revision. The same-template path,
the in-transaction save fence and the lock-loop re-prove are unchanged.
AUDIT_BUILDER_VERSION is unchanged.

Property tests build randomized windows through both paths at six
thread/chunk geometries and compare every byte and digest; golden vectors
for a fixed window were recorded from the serial builders and re-derived
on the base tree. At the #275 bar (two frontends, 2,000 sessions, 400k
window, background shares, eight tips per run, balanced A/B on the merged
3.x.x with the fan-out work) the refresh drops from 736-747 ms to
397-403 ms and tip-to-last-notify from 955-973 ms to 588-624 ms, with
the fan-out tail and share-ack latency unchanged; RSS per frontend after
the tips rises by 100-240 MiB (the pool's allocator arenas; it does not
grow with further tips) and peak RSS by about 70 MiB.

Refs #275

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@djh58

djh58 commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

@cursor review

@cursor cursor 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.

Stale Bugbot comment from a previous run.

… gating (#275)

The builder-threads test asserted that the detected parallelism is never
serial, which only holds on hosts whose pool has at least two threads:
builder_threads() is three quarters of the cores clamped to 1..=4, so a
two-core runner starts one thread and Parallelism::new(1, ..) is the
serial path. The test now asserts the relationship: the detected worker
count is the running pool's (at most eight) and it is serial exactly when
that count is one. Reproduced with the lib tests pinned to one and two
cores; the fixed test passes there and at the full core set. No other
test in this change reads the host's core count.

The coordinator's refresh probes were only covered indirectly. A new test
counts them alone (the memory ledger keeps that counter next to the state
reads that lease proofs and reuse fences also make): a same-template poll
probes once, a new tip whose transition bumped the revision probes not at
all and reads one snapshot, and a tip a peer already recorded probes once
under admission and reuses the cached window without a snapshot read.

Refs #275

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@djh58

djh58 commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

CI fix pushed as 74be188 (signed, on top; no amend).

Failure: parallel::tests::builder_threads_are_fixed_once_the_pool_runs asserted that the detected parallelism is never serial. On the 2-core runners builder_threads() is (2*3/4).clamp(1,4) = 1, and Parallelism::new(1, ..) is the serial path, so the assertion was host-dependent.

Fix (tests only): the test now asserts the relationship: detected workers == running.min(8) and is_serial() == (running == 1). Reproduced with the pushed binary pinned to 1 and 2 cores (fails) and at 22 (passes); the fixed lib tests pass at 1, 2 and 22 cores, as do the parallel_builder integration tests, the server config and refresh-window tests and the CLI config tests at 1 and 22 cores. No other test in this PR reads the host's core count. Clippy -D warnings, fmt and the settings check are clean.

Also in the commit: a test that pins the R5 probe gating by counting refresh probes alone in the memory ledger: a same-template poll probes once, a new tip whose transition bumped the revision probes not at all and reads one snapshot, and a tip a peer already recorded probes once under admission and reuses the cached window without a snapshot read.

The gated-test manifest is unaffected (no gated test added, expected list unchanged); the gate job re-proves it on this run.

@djh58

djh58 commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

@cursor review

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 74be188. Configure here.

@djh58

djh58 commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

Review ledger for head 74be188 (final)

CI 21/21 green on this head (the gated-test proof included); Cursor Bugbot reviewed 49f69bf and 74be188 and found no issues both times.

What was reviewed

  • Independent adversarial review before the PR (a separate Claude Fable session reading the full diff against 3.x.x): no blockers, 8 minors, all fixed before opening and dispositioned in the PR body (F1–F8: pool re-entrancy, operator sizing and kill switch, reused-window path, landing-metric instant, permit release, unwind-through-drain test, pool spawn failure, contract docs). That reviewer also added its own unwind stress and concurrent-callers tests, both passing.
  • Deep review on the PR: a code-review pass over all 28 files verifying byte identity of the parallel paths (array framing, struct splice, fold key order, overflow checks, slice-digest concatenation), the ordered_chunks unsafety argument (drain on return and unwind, no borrowed state after free, inline re-entrancy), and the probe skipping (revision read FOR UPDATE, every write is +1); an adversarial pass attacking chunk framing/escapes, the lifetime erasure and the R5 gates; a structure pass; Bugbot twice; CI.

Findings and dispositions

Fixed (in 74be188, tests only)

  1. builder_threads_are_fixed_once_the_pool_runs asserted the detected parallelism is never serial. On 2-core runners builder_threads() is (2*3/4).clamp(1,4) = 1, and one worker is the serial path, so CI failed. The test now asserts the relationship (workers == running.min(8), is_serial() == (running == 1)). Reproduced with the previous binary pinned to 1 and 2 cores; the fix passes at 1, 2 and 22 cores. No other test in the PR reads the host's core count.
  2. Test gap: nothing pinned the R5 probe gating. ledger_probes_run_only_where_they_can_keep_work counts refresh probes alone in the memory ledger: a same-template poll probes once, a new tip whose transition bumped the revision probes zero times and reads one snapshot, and a tip a peer already recorded probes once under admission and reuses the cached window without a snapshot read.

Rejected (with reasons)
3. Permit released before the deferred body drop lets the next admitted build overlap the previous body. Requested by review (F5) so the deferred drop does not extend the admitted window. The drop task is queued the moment the permit goes and frees in milliseconds while the next fold allocates over hundreds of milliseconds; the measured peak (+70 MiB per frontend at the default pool) includes it.
4. When the prefix lane fails, the window is no longer cached (base cached it and failed at reservation). The prefix writes into SHA states that cannot fail and serializes types whose Serialize cannot error; the path is unreachable, and failing the capture there caches nothing half-built. The compute.rs prefix-error test asserts the new behavior.
5. prepare_refresh_body_with repeats the pipeline's three steps for the reused-window path. The pipeline splits those steps across two lanes with an admission hand-off; the reuse path composes them on one lane. Sharing one composition would serialize the pipeline or add a lane abstraction for a single caller.
6. The adversarial pass found no refutation of the byte-identity, lifetime-erasure or probe-gating claims beyond the items above.

Deferred as follow-ups (approved by the maintainer; a follow-up issue collects them)
7. Same-window rebuild (prepare_refresh_body_with) calls new_with_share_digest and discards the share-array digest: one extra SHA-256 pass over the share array on a spawned hasher thread per new template on the same window (about 90 ms CPU, off the critical path, bytes unaffected). Fix: a prefix-only parallel constructor.
8. Four public body builders (coinbase/CTV, serial/parallel) with 9–12 positional parameters each; a builder-options struct would remove the serial delegators and the too_many_arguments allows.
9. qbit_prism::parallel holds three concerns (worker pool, ordered pipeline, struct-splice serializer) in one file; split into three modules.
10. refresh_parallelism() uses a compile-time test branch to force small chunks; replace with a fixture override.

No production code changes remain open on this PR.

@kiwidream

Copy link
Copy Markdown
Member

Post-merge workstream A review (read-only at 49f69bfb): approve — byte identity, tee digest consistency, verifier parity and both probe removals verified. Four low-severity follow-ups filed as #509 (pool drain soundness, retained memory, a discarded share digest on the reused-window rebuild, refresh trigger label priority).

djh58 added a commit that referenced this pull request Sep 24, 2026
…-paging

Both sides add metric families. Conflicts resolved by hand in the census
tests only: `tests/observability/cardinality.rs` re-derived from the merged
registry (60 families; 241 startup and 675 populated series: #504's four
families and six series plus this branch's three unlabeled gauges), and
`tests/observability/contract.rs` keeps both sides' gauge names. #502 and
#507 touch no metrics files. The auto-merged registry, metrics, coordinator,
ledger, metadata, inventory and gated-test list were checked: every family
and constant from both sides is present, the metadata names all resolve in
the registry, the inventory is regenerated, and the gated list is byte-sorted
with no duplicates.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
djh58 added a commit that referenced this pull request Sep 24, 2026
…ld, trigger precedence, retained memory (#509) (#512)

* 3.x.x: #502 follow-ups: pool drain state in an Arc, prefix-only rebuild, trigger precedence, retained memory (#509)

F1, soundness. ordered_chunks kept its drain state (the ready map, the
error, the outstanding count and their condvar) on the caller's frame and
lent it to every job through a lifetime-erasing transmute. A job's last
actions are decrementing outstanding and unlocking the mutex, and the
drain waiter can see zero and return between the unlock's swap and its
futex wake, so that wake could run on a freed frame. The state now lives
in an Arc<Shared> cloned into each job; only produce stays borrowed, and
a job's last use of it is inside catch_unwind, before the decrement. The
twelve parallel unit tests pass under Miri.

F3, hot path. The reused-window rebuild (prepare_refresh_body_with)
called new_with_share_digest and discarded the digest, spawning a hasher
thread and hashing the whole share array a second time on every same-tip
template churn. CanonicalAuditHashPrefix::new_with hashes the prefix
alone; a thread-local probe counts the digests computed, and tests in
both crates pin that the rebuild computes none and that its hashes are
the pipelined refresh's.

F4, observability. A new template on the same tip runs no ledger probe
at entry since #502, so the refresh trigger label was always template
there even when the revision, balances, reanchor, shares or fee changed.
The label is now named on that path from the window the rebuild used, by
the same precedence (classify_refresh) as the probed path; a coordinator
test drives a same-tip template change with a revision bump and reads
revision, then template alone, from the metric.

F2, resources. docs/prism-storage-sizing.md records the per-frontend
retained-memory change with #502's numbers and the knobs that bound it
(PRISM_REFRESH_BUILD_THREADS, MALLOC_ARENA_MAX) and the build slot no
longer bounding live counted-share bodies exactly. No code change.

No artifact byte changes: the byte-identity suites, golden pins, frozen
corpus and audit_cli goldens are untouched and pass.

Closes #509

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* 3.x.x: drop the jobs' untaken chunks on the calling thread (#509 review)

With the drain state in an Arc, a chunk the consumer never took (a
producer or consumer error, or a consumer panic unwinding through the
drain) stayed in the shared state and was dropped by whichever thread
released the last Arc clone, which can be a pool thread after
ordered_chunks has returned. C is generic and may borrow the caller's
frame: the counted-share fold's chunks are keyed by &str into a caller
local. No current chunk type dereferences its borrow on drop, but the
SAFETY invariant that justifies the transmute did not hold for them.

Drain::settle now waits for the jobs and takes the first panic, the first
error and the untaken chunks under the lock, on the calling thread, on
the return path (Drain::finish) and on the unwind path (Drop) alike, so a
clone of the shared state that outlives the call owns only empty
containers. Found independently by the adversarial and code-review lanes
of the review.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
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.

2 participants