Skip to content

3.x.x: summarize the recovery evidence in parallel, byte-identical to the serial summarizer (cutover window) - #728

Merged
RobertClarke merged 3 commits into
3.x.xfrom
RobertClarke/parallel-evidence-summarizer
Oct 6, 2026
Merged

RobertClarke merged 3 commits into
3.x.xfrom
RobertClarke/parallel-evidence-summarizer

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

The recovery-evidence summarizer parsed every row of the export in one process, at about 29 MB/s on the 65.9M-share restore. That export is about 80 GB, so the summary took about 45 minutes. The migrated side's summary sits on the cutover's critical path. #721 made the database export parallel, but the summary stayed single-threaded.

This PR parses in parallel and keeps the output byte for byte what it was.

How it works

One state machine, shared by both paths. The summary's checks now live in _Summary: share order, the carry chains and head, candidate counts, integrity and completion ordering, and the final integrity checks.

  • summarize(lines), which the serial path (--jobs 1) and the existing tests call, feeds it line by line exactly as before.
  • The parallel path feeds the same object, so both paths run the same checks, raise the same errors and print the same notes.

Workers parse ranges. --jobs N worker processes (default: the CPU count, at most 8) each read a newline-aligned byte range of the file themselves. Each one decodes it as UTF-8 and splits it into lines as a text-mode read does (universal newlines), then parses and canonicalizes the rows with the same json.loads/json.dumps calls the serial path uses. What it returns, in order:

  • Kinds that are only hashed and counted (share hashes, sequences, audits and so on) come back as one run of canonical bytes per kind.
  • Share runs come back with their first and last sequence and their accepted sum. That covers only rows whose sequence is an integer that strictly increases within the run and whose accepted flag is a bool or int. Any other share row comes back as a record, with only the fields the checks read.
  • Every other row, the blocks, active carry, candidates, integrity, completion and unknown kinds, comes back whole.
  • A parse error comes back as the exception itself, at its position.

The parent replays in file order. It runs every check against those results: hashes[kind].update(run) is the serial path's per-row update, and a share run's first sequence is checked against the last one seen. So the first refusal in file order is the serial path's first refusal, with the same message.

Reading differences fall back to the serial reader. A range a worker cannot read exactly as text mode does, through invalid UTF-8 or a read error, is the case where the serial reader's 8 KB decoding blocks decide which error comes first. From that range on, the file is read by the serial reader from its start. Lines the workers' ranges already checked are read but not checked again, so even the UnicodeDecodeError message, with its block-relative position, is the serial one.

  • A refusal within 8 KB of an invalid byte past its range is summarized serially from scratch. That's the one case where the serial reader might decode the bad byte first.

Other guards.

  • A path that is not a regular file is summarized serially.
  • So is a module loaded without a sys.modules entry, whose _parse_range the forked workers could not find by name.
  • A host that can't create the pool or fork a worker (no POSIX semaphores, out of processes or memory) continues serially from the lines already checked, as does a worker that dies.
  • The last range is open: its worker reads to the end of the file, so a line still being written is never split.
  • The serial summarizer and the serial continuation go through one call into summarize(), so even an uncaught error's traceback (a RecursionError on absurdly nested JSON) has the serial frames. Python 3.14 reports the C stack used in that message, which varies with argv length even between two serial runs, so the test masks that one number.
  • The default --jobs follows the process's CPU affinity.

Proof

tests/test_prism_recovery_evidence_jobs.py (15 tests) runs the CLI with --jobs 1 and with --jobs 2..4 at chunk sizes of 1 byte (a range boundary after every line), 37 bytes, 300 bytes and 1 MiB. It compares the exit code, stdout and stderr exactly for:

  • a complete export with every kind, the 3.x.x: the legacy carry-forward integrity rule partitions by case-sensitive label, so self-check refuses union's ledger (5,506 false mismatches; money is per payout program) #708 note and raw UTF-8 text;
  • CRLF, lone CR and mixed line endings, a missing final newline and a BOM;
  • share order refusals at and inside range boundaries, plus non-integer sequences, string and missing flags, and non-object rows;
  • malformed JSON mid-file and on a truncated last line, an empty line, a missing kind or row, a JSON string record, an unhashable kind, an unknown kind, records after completion (malformed and valid), a missing completion marker, a duplicate integrity report, and accounting rows after the integrity report;
  • carry order, chain-break, as-issued and unexplained-finding refusals, and the integrity count checks;
  • invalid UTF-8 at the start, the middle and the end;
  • a missing file and a directory.

It also checks in-process:

  • the parallel path reads no line serially;
  • an unreadable range sends only the rest of the file through the serial checks;
  • one job is the serial summarizer;
  • a pool or fork failure summarizes serially;
  • ranges end after newlines, with the last one open, including for a file that grows after the ranges are cut;
  • an uncaught RecursionError prints the serial traceback.

The gated recovery harness (migration_rollback::the_parallel_evidence_export_prints_the_serial_export_byte_for_byte) now also summarizes the fixture export with --jobs 1, --jobs 3 --chunk-bytes 1 and --jobs 2 --chunk-bytes 4096. It requires identical exit codes, stdout and stderr, on a 2.x source and on its migrated three-partition ledger.

Speed

On a 3.25 GB export of 4M production-shaped share rows plus their header rows, on this build host (a shared 16-core Ryzen 9 9955HX):

--jobs Wall time Summary
1 (serial) 36.3 s; 38.5 s after the review fixes
4 10.3 s identical (cmp)
8 (default) 5.7 s; 5.9 s after the review fixes identical
12 4.4 s identical

The parent's own work is hashing the canonical bytes and replaying the checks. It stays well below the workers' parsing, so 8 jobs gives about 6.5×. At the restore's 29 MB/s serial rate, that's the 45-minute summary in about 7 minutes. Peak memory is about 230 MB per process at 8 jobs.

Review

The high-effort review raised nine findings; eight are fixed in the second commit.

  • Declined: after a refusal or a fallback, the pool's shutdown still waits for the ranges already being parsed. That's at most one range per worker, about a second at the restore's rate, before an exit or a serial pass that takes minutes.
  • Not done: cgroup CPU quotas aren't read. Size --jobs on a quota-limited host, as the runbook says.

Scope

This is tooling only: the summarizer script, its tests, the gated harness's comparison, and the runbook paragraphs in docs/prism-ledger-ops.md and docs/prism-rust-migration.md. There's no server code. It lands after rc.4's tag, as a pinned tooling commit, as #721 did with rc.2.

🤖 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.

RobertClarke and others added 2 commits October 6, 2026 10:26
… the serial summarizer

The summarizer parsed every row in one process at about 29 MB/s, about
45 minutes for the 65.9M-share export, and its migrated-side run sits on
the cutover's critical path. #721 parallelised only the database export.

Worker processes now parse and canonicalize newline-aligned byte ranges
of the export, and the summarizing process applies every check to their
results in file order: the rows of kinds only hashed and counted arrive
as runs of canonical bytes, share runs with their sequence bounds and
accepted sum, and every other row whole. The checks themselves are one
state machine that the serial path (--jobs 1) and the parallel path
share, so the summary, its notes and every refusal are the serial ones
byte for byte. A range a worker cannot read as a text-mode read does
(invalid UTF-8, a read error) sends the rest of the file through the
serial reader from the start, and a refusal next to an invalid byte is
summarized serially from scratch, so decoding errors are the serial ones
too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lit a growing line, and keep tracebacks serial

From the high-effort code review:
- A host that can't create the process pool or fork a worker (no POSIX
  semaphores, out of processes or memory) now summarizes serially from
  the lines already checked, instead of failing a valid export.
- The last range is open, read to the end of the file by its worker, so
  a line still being written is never split between two ranges.
- The decode window for a refusal next to an invalid byte comes from the
  interpreter's TextIOWrapper chunk size, kept to at least 1 MiB, rather
  than a copy of CPython's 8 KiB.
- The default job count follows the process's CPU affinity.
- The serial summarizer and the serial continuation share one call into
  summarize(), so even an uncaught error's traceback is the serial one.
- Runs accumulate into one bytearray; the test harness's summarize()
  delegates to summarize_with(); --jobs refuses with the parallel
  export's wording.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 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-10-06T15:18:15.568974Z 9a1fe94 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.

@RobertClarke
RobertClarke merged commit 811a22f into 3.x.x Oct 6, 2026
40 checks passed
@RobertClarke
RobertClarke deleted the RobertClarke/parallel-evidence-summarizer branch October 6, 2026 15:38
RobertClarke added a commit that referenced this pull request Oct 8, 2026
Set VERSION and [workspace.package].version to 3.0.0-rc.5: rc.4 plus
#737's fixes in #742 (fatal-state clear accepts a tip that only grew,
takes --timeout-seconds, and runs the integrity report under its own
statement timeout) and #744 (migration 026: the report computes each
set once); the deferred share-hash backfill in #743 and #746 (migrate
--defer-share-hashes, then the throttled backfill-share-hashes after
go-live); #745 (migrate --offline-indexes, which composes with
--defer-share-hashes); the cutover tooling merged after rc.4's tag
(#728, #732, #736, #740); and #747, a test-only fix for #724. Both
Cargo.lock files move only their workspace-member entries.

doc/release-notes-3.0.0-rc.5.md, dated 2026-10-08, covers:
- the changes, with the report's estimated 57 to 29 s since 026, the
  migrate --defer-share-hashes command measured on the pair at
  5 min 06 s (539d6c9, before #745), backfill-share-hashes' throttle,
  record of 2 and safe rerun, the evidence scripts' changes, and the
  offline index builds' estimated gain;
- upgrading: migrate is needed again (a binary-only upgrade refuses
  "missing migration(s) 26", and this export refuses a database without
  026), the cutover's migrate step with both flags, and finishing the
  backfill after go-live under #738's snapshot rule, with self-check
  only at low share rates. Rolling back to rc.4 at fence 2 goes only by
  finishing the backfill first or from the pre-migrate backup or
  physical copy, and each rc.4 refusal is quoted where it applies: a
  start meets the cursor first and says to run migrate, which rc.4's
  migrate refuses. The rules still in force: #737's statement timeout
  for rc.4's tools, 026 or not, #738's snapshot rule, and fatal-state
  clear --timeout-seconds, whose bound ends before the commit;
- the same evidence set as rc.4's, with each PR's merge SHA, the pair's
  serving evidence carried, and the rehearsal's full measurements left
  to the cutover's go/no-go record;
- the known issues: rc.4's, minus #737's F1, F2, F4 and F5, plus
  #737's open part, #738 (its fix planned for rc.6), #739, #741, #731
  and #734, with #582 closed and #712 and #724 updated.

docs/prism-rust-migration.md now says how earlier candidates refuse a
database at fence 2: a start with the backfill's own refusal, whose
advice to run migrate holds only for this release, and their migrate,
or a start with PRISM_POSTGRES_INIT_SCHEMA=1, with the fence. The
development-line notes name 3.0.0-rc.5, and they and the 3.0.0 notes
link all five candidates' notes.

Co-Authored-By: Claude Opus 5.5 <[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.

1 participant