Skip to content

Add a bounded heap census, allocator control, and the RSS soak bound (#226 part 2) - #234

Merged
kiwidream merged 1 commit into
2.x.xfrom
bound-coordinator-heap-growth
Sep 4, 2026
Merged

kiwidream merged 1 commit into
2.x.xfrom
bound-coordinator-heap-growth

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Part 2 of #226. Part 1 (#232) landed the always-on telemetry that discriminates
retention from fragmentation. This adds the operator-triggered census that names
a retention site when there is one, puts the glibc allocator under deliberate
control, and turns "RSS is bounded" into a check rather than an observation.

Stacked on #232, which is its merge base. Review that first. Two PRs for
#226 is deliberate: splitting the always-on telemetry out let it land ahead of
this and of #233, so all three extend a settled metrics.py and family-set test
instead of racing one.

What the census found

Locally it names nothing retained. sys.getallocatedblocks() returns to its
pre-storm count once the storm's objects are released — 169,729 before, 169,653
after — and the type histogram is the coordinator's own bookkeeping (function,
tuple, dict, wrapper_descriptor, weakref.ReferenceType). The storm leaves
no live Python objects behind.

The evidence points at glibc per-thread arena fragmentation, and the storm
instrument reproduces the mainnet shape exactly.
A 64-thread allocation probe
takes the process from 5 to 64 arenas and from 9 to 72-73 anonymous regions in
the 4-64 MiB band — the same band the mainnet capture reported 658 of 943
regions in — while malloc_in_use_bytes stays flat at 10 MB. That is precisely
the "RSS rises over a flat in-use" signature #226 described, reproduced from a
cold start on a test host.

So no retention fix is invented; the allocator settings are the fix. What cannot
be settled from here is whether retention also sits underneath the
fragmentation on the mainnet process — only a census on that process can answer
that, which is what this ships.

What changed

The census. SIGUSR1 produces a bounded report: a type histogram over
gc.get_objects(), optionally tracemalloc top-N by file, written to a file.
Off unless PRISM_HEAP_CENSUS is set at startup, because tracemalloc has a
standing cost and a full heap walk on a 17.7 GB process must not be reachable by
accident. Bounded three ways — top-N, an output byte cap with payload halving,
and a wall-clock cap that stops mid-walk and records that it did. Never
reachable from a request path
, pinned by a test. The signal handler only writes
to a self-pipe; the walk runs on the census worker thread, so nothing heavy
executes in handler context.

The allocator. MALLOC_ARENA_MAX defaults to 2 in the image, argued in
the Dockerfile, and is passed through compose.yaml along with the census and
trim switches so it can be changed without a rebuild. malloc_trim is exposed on
SIGRTMIN+1, off by default, rate-limited, and reports its arena and RSS deltas
through part 1's gauges. It takes every glibc arena lock in turn, so it is an
operator action rather than a periodic one. Where a platform has no SIGRTMIN
the trim signal is simply not armed.

The bound. An RSS soak check reads a sample series and fails when RSS exceeds
a stated multiple of baseline. The operator command exits 0 on pass, 1 on fail,
2 on bad input, so a soak asserts the bound instead of a human reading a graph.

Safety and rollout

  • Census and trim are both off by default; only the allocator setting changes
    behaviour out of the box, and it is a documented default with a rationale.
  • The census cannot be triggered by a request, cannot run unbounded, and cannot
    be enabled at runtime — only at startup.
  • Every switch is passed through compose.yaml and documented in .env.example,
    so a diagnosis window is a restart, not a rebuild. This was a review finding:
    the first draft documented an --env-file workflow that silently did nothing,
    and claimed compose needed no passthrough for a variable glibc reads directly.
    It does.
  • Part 1's gauges are how the trim's effect is read, so there is no new
    measurement surface to trust.

Review findings addressed

/code-review raised seven, and re-verifying on macOS surfaced three more. All
ten are fixed. The ones that mattered:

  • MALLOC_ARENA_MAX never reached the container, and the docs asserted it did
    not need to. An operator would have run the experiment and reasoned from a
    setting that was never applied.
  • PRISM_HEAP_CENSUS* and PRISM_MALLOC_TRIM_* had no passthrough either.
  • Census file retention sorted on (mtime_ns, name) with an unpadded
    sequence
    , so several censuses inside one mtime tick tie-broke lexicographically
    and -10 sorted before -9: the newest report could be deleted while an older
    one survived. The sequence is now zero-padded and ordering no longer depends on
    filesystem timestamp granularity.
  • The malloc_info bin parser matched fastbin rows as well, so bin_bytes
    double-counted fast_bytes and top_bytes clamped to 0 — corrupting the exact
    free-bytes split the docs tell an operator to use when deciding whether
    malloc_trim will help.
  • The type histogram overwrote rather than merged same-named types, which
    would have hidden the very retention the census exists to find.
  • signal.SIGRTMIN is Linux-only and was evaluated at class scope, making the
    test module unimportable on macOS; and the rss-sample test asserted the Linux
    /proc outcome unconditionally. The production code already handled both
    correctly.

Verification

Run locally on macOS (Darwin 25.4.0, Python 3.14.3) on this branch:

touch .env
git ls-files '*.sh' | xargs bash -n
git ls-files '*.sh' | xargs docker run --rm -v "$PWD:/mnt:ro" -w /mnt \
    koalaman/shellcheck:stable -x
python3 -m compileall -q docker lab tests examples scripts
GIT_CONFIG_GLOBAL=/dev/null python3 -m unittest discover -s tests -p 'test_*.py'

bash -n, shellcheck and compileall clean. The suite is 3217 tests, failures=2
errors=3 skipped=8
; the five failures are the documented macOS os.splice set
in test_prism_job_builder, identical to this branch's merge base. The extra
skips are the glibc-only and SIGRTMIN-only cases skipping correctly.

Not verified here, and deliberately left to the operator: the census on
union-mainnet, the 24 h testnet soak, and the allocator experiment on a testnet
coordinator all need a live host, and nothing in this change was run against
production. What ships is the instrument, the runbook (in
docs/prism-capacity-readiness.md and docs/mainnet-deployment.md), and the
threshold check. The arena and region figures above are host-specific
measurements on an 8-core Linux box with glibc 2.39 — the mechanism is what
reproduces, not the absolute numbers.

#185's post-storm drain measurement was re-run on this build and is reported in
the commit body.

Closes #226

2.x.x is not the default branch, so this will not auto-close. #226 needs
closing by hand after both this and #232 have merged.


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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 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-04T19:25:34.368565Z dbd4391 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.

…226 part 2)

Part 1 landed the always-on telemetry that discriminates retention from
fragmentation. This adds the operator-triggered instrument that names a
retention site when there is one, puts the glibc allocator under deliberate
control, and turns "RSS is bounded" into a check rather than an observation.

The census. SIGUSR1 produces a bounded report: a type histogram over
gc.get_objects(), optionally tracemalloc top-N by file, written to a file and
never reachable from a request path. It is off unless PRISM_HEAP_CENSUS is set
at startup, because tracemalloc has a standing cost and a full heap walk on a
17.7 GB process must not be reachable by accident. The walk is bounded by
top-N, by an output byte cap with payload halving, and by a wall-clock cap that
stops mid-walk and says so. The signal handler only writes to a self-pipe; the
walk runs on the census worker thread.

The allocator. MALLOC_ARENA_MAX defaults to 2 in the image, argued in the
Dockerfile, and is passed through compose along with the census and trim
switches so an operator can change it without rebuilding. malloc_trim is exposed
on SIGRTMIN+1, off by default, rate-limited, and reports its arena and RSS
deltas through part 1's gauges. Where the platform has no SIGRTMIN the trim
signal is simply not armed.

The bound. An RSS soak check reads a sample series and fails when RSS exceeds a
stated multiple of baseline, with the operator command exiting 0 on pass, 1 on
fail and 2 on bad input, so a soak asserts the bound instead of a human reading
a graph.

What the census found. Locally it names nothing retained:
sys.getallocatedblocks() returns to its pre-storm count once the storm's objects
are released (169,729 before, 169,653 after), and the type histogram is the
coordinator's own bookkeeping. The evidence points at glibc per-thread arena
fragmentation instead, and the storm instrument reproduces the mainnet shape
exactly: a 64-thread allocation probe takes the process from 5 to 64 arenas and
from 9 to 72-73 anonymous regions in the 4-64 MiB band -- the same band the
mainnet capture reported 658 of 943 regions in -- while malloc_in_use_bytes
stays flat at 10 MB. That is the "RSS rises over a flat in-use" signature, so no
retention fix is invented; the allocator settings are the fix. Whether retention
also sits underneath the fragmentation on the mainnet process can only be
settled by a census on that process, which is what this ships.

Test-portability and correctness fixes from review: SIGRTMIN is Linux-only and
was evaluated at class scope, making the module unimportable elsewhere; the
rss-sample test asserted the Linux /proc outcome unconditionally; census file
retention sorted on (mtime_ns, name) with an unpadded sequence, so within one
mtime tick the newest report could be deleted -- the sequence is now zero-padded
and the ordering no longer depends on filesystem timestamp granularity; the
malloc_info bin parser counted fastbin rows twice; and the type histogram
overwrote rather than merged same-named types, which would have hidden the very
retention the census hunts.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@kiwidream
kiwidream force-pushed the bound-coordinator-heap-growth branch from 8d7a4e3 to dbd4391 Compare September 4, 2026 19:20
@kiwidream
kiwidream merged commit e4e7764 into 2.x.x Sep 4, 2026
11 checks passed
Anatolie added a commit that referenced this pull request Sep 11, 2026
… review)

The resident-set bound prose said the awk command "refuses a series
shorter than the soak". It does not: `last - t0 < 82800` refuses a series
spanning less than 23 hours from its first sample to its last, exactly as
the retired Python evaluator's RSS_BOUND_DEFAULT_MIN_SPAN_SECONDS did
(23 * 3600, measured from the first sample after re-basing). The
threshold and the expression are unchanged; a 23 h floor is parity with
the tool this runbook qualified under, and 86,400 s from t0 would reject
an honest 24 h soak whose last 5-minute sample lands just short.

The one-hour slack is the reason the Python source recorded on the
constant ("a 24 h soak with an hour of tolerance for a late first
sample", #234); the prose now says so and keeps step 2's 24 h run.

Verified with the unchanged awk program on synthetic 300 s-cadence
series: 82,800 s exits 0, 82,500 s exits 2.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_013yFEcAtVPzfzMiwYmFskLD
Anatolie added a commit that referenced this pull request Sep 14, 2026
… review)

The resident-set bound prose said the awk command "refuses a series
shorter than the soak". It does not: `last - t0 < 82800` refuses a series
spanning less than 23 hours from its first sample to its last, exactly as
the retired Python evaluator's RSS_BOUND_DEFAULT_MIN_SPAN_SECONDS did
(23 * 3600, measured from the first sample after re-basing). The
threshold and the expression are unchanged; a 23 h floor is parity with
the tool this runbook qualified under, and 86,400 s from t0 would reject
an honest 24 h soak whose last 5-minute sample lands just short.

The one-hour slack is the reason the Python source recorded on the
constant ("a 24 h soak with an hour of tolerance for a late first
sample", #234); the prose now says so and keeps step 2's 24 h run.

Verified with the unchanged awk program on synthetic 300 s-cadence
series: 82,800 s exits 0, 82,500 s exits 2.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_013yFEcAtVPzfzMiwYmFskLD
Anatolie added a commit that referenced this pull request Sep 14, 2026
… review)

The resident-set bound prose said the awk command "refuses a series
shorter than the soak". It does not: `last - t0 < 82800` refuses a series
spanning less than 23 hours from its first sample to its last, exactly as
the retired Python evaluator's RSS_BOUND_DEFAULT_MIN_SPAN_SECONDS did
(23 * 3600, measured from the first sample after re-basing). The
threshold and the expression are unchanged; a 23 h floor is parity with
the tool this runbook qualified under, and 86,400 s from t0 would reject
an honest 24 h soak whose last 5-minute sample lands just short.

The one-hour slack is the reason the Python source recorded on the
constant ("a 24 h soak with an hour of tolerance for a late first
sample", #234); the prose now says so and keeps step 2's 24 h run.

Verified with the unchanged awk program on synthetic 300 s-cadence
series: 82,800 s exits 0, 82,500 s exits 2.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_013yFEcAtVPzfzMiwYmFskLD
Anatolie added a commit that referenced this pull request Sep 15, 2026
…nd guard lab/prism doc references (#318)

* 3.x.x: re-anchor the capacity-readiness runbook to native telemetry (#303)

docs/prism-capacity-readiness.md documented and told the operator to run
lab/prism/metrics.py and lab/prism/process_telemetry.py, which #244 deleted;
lab/prism/ holds only Dockerfile on this line. Decide per section instead of
deleting wholesale:

- Retire the Python-specific material: the interpreter/allocator and
  component-cardinality families, the heap census, malloc_trim, and the
  MALLOC_ARENA_MAX storm instrument. Each keeps a short past-tense note that
  it applied to the retired Python coordinator and names what replaces it or
  who owns the gap (#278 registry, #279 inventory).
- Re-anchor what is runtime-independent on the #308 registry: the process
  block (process_resident_memory_bytes, the collector_* state, runtime_*
  gauges, the #277 snapshot block), the RSS reading order, the 2.0x
  resident-set bound as one awk pass over the sample CSV, and the 24 h soak
  runbook using docker exec, /proc/1/status, and curl against the audit
  listener on 3341. Every command parses and resolves on this branch.
- Mark the Validate Qualification Evidence gate deferred: the native
  validator exists, but no producer on this branch emits the v2 file and the
  strict key set still requires three retired settings. #288 re-keys the
  validator; #291 produces the first native artifact.

tests/test_docs_lab_prism_references.py guards the recurrence: no runnable
python -m lab.* / python lab/*.py command in docs/ may target a module absent
from the branch, and every lab/prism path or lab.prism module reference must
resolve against git ls-files, except GitHub URLs pinned to a commit SHA. The
pre-existing residue in prism-overload-alerts.md, prism-coordinator-refactor/
and prism-rust-migration.md is ratcheted at today's counts; the test fails
when a file grows or when it improves without lowering its ceiling.
Discovery picks the module up in the existing CI shards.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_014VHcDK2anZJPx8Gu1LZvuN

* 3.x.x: correct the signal and #278 scope claims in the capacity runbook (#303)

The native server is PID 1 in the shipped container with no init and
installs handlers for SIGTERM and SIGINT only, so the kernel drops SIGUSR1
rather than terminating the process. Thread and open-file-descriptor gauges
fell outside #278's cutover-minimum scope, and #288's docs CI check is still
to land.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* 3.x.x: join shell continuations before scanning doc commands (#318 review)

`dead_commands` matched each physical line on its own, so a documented
`python3 -m \` + `lab.prism.deleted` (or `python3 \` + `-m lab.x`,
`python3 -u \` + `-m lab.x`, `python3 \` + `lab/x.py`) slipped past the
guard even though the fence runs the deleted module. Join backslash
continuations into logical shell lines first and report the command at
its first physical line. `dangling_references` and the RATCHET ceilings
are untouched; no wrapped `python ... lab` command exists in docs/ today.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YH4dPMQC6xqq9dreB1puTb

* 3.x.x: keep the warm-up boundary sample in the RSS-bound baseline (#318 review)

The Python evaluator this awk pass replaced put a sample taken exactly
warmup seconds after the first one into the warm-up (`t <= warmup_seconds`)
and judged only later samples against the bound (`t > warmup_seconds`).
The awk used a strict `<`, so with the runbook's regular 300 s cadence a
transient peak landing exactly at hour one fell out of the baseline and
could turn a pass into a fail. Use `<=` so the verdict is the Python
tool's, and say so in the prose.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016PioJBmGucLpZZ9HhQgUj1

* 3.x.x: state the RSS-bound span floor the check actually enforces (#318 review)

The resident-set bound prose said the awk command "refuses a series
shorter than the soak". It does not: `last - t0 < 82800` refuses a series
spanning less than 23 hours from its first sample to its last, exactly as
the retired Python evaluator's RSS_BOUND_DEFAULT_MIN_SPAN_SECONDS did
(23 * 3600, measured from the first sample after re-basing). The
threshold and the expression are unchanged; a 23 h floor is parity with
the tool this runbook qualified under, and 86,400 s from t0 would reject
an honest 24 h soak whose last 5-minute sample lands just short.

The one-hour slack is the reason the Python source recorded on the
constant ("a 24 h soak with an hour of tolerance for a late first
sample", #234); the prose now says so and keeps step 2's 24 h run.

Verified with the unchanged awk program on synthetic 300 s-cadence
series: 82,800 s exits 0, 82,500 s exits 2.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_013yFEcAtVPzfzMiwYmFskLD

* 3.x.x: parse real CPython option forms in the doc-command guard (#318 review)

The command regexes accepted only single-letter switches between the
interpreter and `-m` or a script path, so `python3 -OO -m lab.prism.deleted`
or `python3 -X dev -m lab.prism.deleted` ran deleted code while passing
contract (a). Share one interpreter-plus-options sub-pattern that follows
`python3 --help`: clustered flag letters, `-W`/`-X` with an attached or
following argument, and `--check-hash-based-pycs <mode>`. `-c cmd` stays
excluded because it runs its argument and ends the option list; CPython
rejects the `=` spelling of the long option, so none is accepted. Also scan
version-suffixed interpreters (`python3.12`), as the CI images name them.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FcDKnhKaUD45rfBYeYTGH4

* 3.x.x: record the image Compose resolved from the soak env files (#318 review)

Step 1 of the testnet soak runbook built the coordinator image through
Compose with the deployment's env files, then inspected
`${PRISM_COORDINATOR_IMAGE:-qbit-lab-prism-coordinator:local}` as a
standalone shell expansion. An operator who sets
`PRISM_COORDINATOR_IMAGE` only in an env file, without exporting it,
would build the configured image and inspect the default one instead.

Substitute the env files once, in a `compose` function, and let the same
invocation build the image and resolve its name through
`config --format json`, reading the `prism-coordinator` service record
with `python3`. `config --images prism-coordinator` is not used because
it prints the images of the services the coordinator depends on as well
(`postgres:16-alpine` and the qbitd image), one per line and in varying
order, so `docker image inspect` would receive one multi-line argument
and fail; `docker compose config` has no `--no-deps`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JWTB41CrR7dJ353fGub6HL

* 3.x.x: match quoted and ./-relative targets in the doc-command guard (#318 review)

A ratcheted doc could swap one dangling `lab/prism/...` mention for a
runnable `python3 -m 'lab.prism.deleted'` or `python3 ./lab/prism/deleted.py`
command: rule (b) still counted the path, so the ceiling held, and rule (a)
required an unquoted module or `lab/` straight after whitespace, so it saw no
command. Both command rules now share one `quoted` sub-pattern that accepts a
target in matching single or double quotes, the script rule accepts `./`
prefixes, and the reported missing path is the normalised one.

`-m` may also close a flag cluster and take its module attached. On CPython
3.12 `-mjson.tool`, `-Im json.tool`, `-OOm json.tool`, `-Imjson.tool` and
`-m'json.tool'` all run the module, so those spellings are matched; `-Wm`
and `-Xm` hand `m` to `-W`/`-X` and stay unmatched, as does `-c`. A
mismatched quote is a shell syntax error, runs nothing and matches nothing;
the prose rule still sees the reference.

The module docstring now states the contract's limit: rule (a) is a lexical
check of direct python invocations and does not follow `cd`, `PYTHONPATH`,
aliases or shell variables.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YL7EVncHtFRE74z559dGFf

* 3.x.x: reject malformed RSS rows in the bound check (#318 review)

The `awk` port of the resident-set bound skipped every row with fewer
than two fields under the same rule that skipped `#` comments, so a
sample lost during an RSS excursion (a truncated line in the CSV)
disappeared silently and a valid late sample could still pass the soak.
The deleted `read_rss_samples` raised on any non-blank, non-comment line
that was not `seconds,rss_bytes`, and the `rss-bound` CLI turned that
into exit 2. A non-numeric RSS field was worse than skipped: `abc > n`
compared as strings and reported a breach.

Skip only comment and blank lines, require a numeric first and second
field on every other row (extra trailing fields stay tolerated, as they
were in the Python tool) and report the offending row as unusable input
with exit 2. `exit` inside a main rule still runs `END` in every awk,
so the failure is recorded in a variable that `END` checks before any
verdict logic; verified on the macOS awk (20200816). `-1` samples are
still ignored, after validation.

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

* 3.x.x: sort RSS samples by time before the bound check (#318 review)

The deleted `evaluate_rss_bound` sorted the series by time before it
re-based on the first sample; the `awk` port took the origin from the
first physical row. A nonmonotonic file, such as two partial soak logs
concatenated with the later one first, put a late sample at the origin,
so the warm-up window swallowed every earlier sample (including a
post-warm-up excursion), the baseline rose to the excursion and the
verdict flipped or the span check refused the file.

Sort the file numerically on the first field with `sort -t, -k1,1n`
before the `awk` pass, so the origin is the earliest sample as it was in
the Python tool. Comment and blank lines sort as zero and are skipped
wherever they land, a malformed row is still caught after sorting, and
the pipeline exits with awk's status. Verified with the macOS sort
(2.3-Apple) and awk (20200816) against the deleted evaluator: a
breaching series with its hour-5 sample moved before the hour-0 rows now
fails as the Python tool failed it, where the previous command refused a
24 h file for its span and passed a 28 h one.

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

* 3.x.x: capture the runtime and pool series the RSS reading order cites (#318 review)

Item 3 of "What to look at first when RSS climbs" names
`qbit_prism_runtime_task_stalled{task}`,
`qbit_prism_runtime_poll_lag_seconds{task}` and
`qbit_prism_database_pool_acquire_seconds` as the evidence that a climb is a
blocked worker holding buffers rather than a leak. The five-minute capture
loop kept only the stall gauge, so the poll lag and pool wait at a breach
could not be read back: the full snapshots are taken at hour 1, hour 24 and
the breach itself, and cannot recover what those series showed at an earlier
sample.

Add both families to the `grep -E` filter. The poll-lag gauge renders with
its `task` label and matches the existing `[ {]` anchor as it is. The pool
histogram never renders under its bare family name: the registry emits
`..._bucket{result=...,le=...}`, `..._sum{result=...}` and
`..._count{result=...}`, as the observability tests assert, so the pattern
names those three suffixes explicitly and keeps the anchor after them. The
sentence after the loop now says the log carries the reading order's
runtime and pool series, so a breach is read at its own sample rather than
the nearest hourly snapshot.

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

* 3.x.x: match quoted interpreter names in the doc-command guard (#318 review)

A ratcheted doc could swap one dangling `lab/prism/...` mention for a
runnable `"python3" -m lab.prism.deleted` command: the shell strips the
matching quotes and runs Python, rule (b) still counted the module so the
ceiling held, and rule (a) required whitespace straight after a bare
interpreter name, so it saw no command. The interpreter now goes through
the same `quoted` sub-pattern as the target, bare or in matching single or
double quotes, with the quote in its own named group because `re` rejects
one group name used twice in a pattern.

The word boundary before `python` is kept, so `/usr/bin/python3` and
`env python3` still match. Inside `sh -c "python3 -m lab.x"` no quote
closes right after the name, so the interpreter quote backtracks to empty
and the inner command is read as before; a mismatched quote around the
name is a shell syntax error, runs nothing and matches nothing, and the
prose rule still sees the reference. No ratchet ceiling changed: the
tracked docs contain no such command today.

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

* 3.x.x: pin the deleted-test map's retired module paths to their last commit (#318 CI)

`docs/prism-deleted-test-map.md` landed on 3.x.x with #322 after this
branch's merge-base, and it names three `lab/prism/*.py` modules that #244
removed: `candidate_window.py`, `bundle_compiler.py` and
`endpoint_registry.py`. The reference guard this branch adds scans every
tracked doc on the merge ref, so CI's "Python unit tests (shard 1)" failed
on those three lines while the same test passed on the branch alone.

The guard's contract offers two ways to name retired code: describe it in
words or link a commit-pinned GitHub URL, which is stable history and
exempt. The three mentions are now links to the files at `700fae0`, the
last commit before #244 deleted them, with the module basename as the link
text so the visible path no longer claims to exist on the branch. The
table's wording is otherwise unchanged.

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

* 3.x.x: pin candidate_window.py to the commit that last carried it (#318 CI)

`lab/prism/candidate_window.py` was removed before #244, so the link 4d6d0c8
added at `700fae0` pointed at a commit without the file. The other two
modules did exist there; this one now links to `^`, the last
commit before its own deletion. Verified with `git cat-file -e` on the
pinned tree.

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

* 3.x.x: pin candidate_window.py to v2.0.2, where the module lives (#318 CI)

bd35536 rewrote the `candidate_window.py` link with a malformed revision
(`blob/^/`), which the reference guard no longer recognised as a
commit-pinned URL. The module never existed on the 3.x.x line; it was
added on the 2.x line by the v2.0.0 consolidation (#246) and is present at
v2.0.2, `504846c`, the same pinned commit the guard's own tests use as
their example. The link now points there, checked with `git cat-file -e`
against that tree before committing. The guard passes on the merged tree.

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

* 3.x.x: gate the soak pre-check on a fresh metrics body (#318 review)

The soak pre-check matched any x-prism-metrics-state value, so a stale or
unavailable body whose cached process gauge still read 1 printed two lines,
grep exited 0, and the prose told the operator the RSS series was
trustworthy. Every gauge in the body is a scrape-time render of cached
observations, and the header is what says whether that render is current.

Replace the grep with an awk verdict in the style of the RSS bound check:
it sets a flag on the exact `x-prism-metrics-state: fresh` line and on the
process collector gauge at 1, prints `ready` and exits 0 only when both are
present, and otherwise names the failed condition and exits 1. The sentence
after it now says both lines are required, that a stale or unavailable body
can still carry a cached gauge at 1, and that the run must not start until
the check passes. The step-3 capture loop is unchanged; it records the state
header whatever its value on purpose.

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

* 3.x.x: require a runnable entry point for -m targets in the doc-command guard (#318 review)

The doc-command guard accepted a `python -m lab.pkg` command when only
`lab/pkg/__init__.py` was tracked, because it reused the prose contract's
candidate list and took its first two entries. CPython does not run such a
package: on 3.14, `python3 -m lab.pkg` against an `__init__.py`-only package,
or against a bare directory, prints "No module named lab.pkg.__main__;
'lab.pkg' is a package and cannot be directly executed" and exits 1. It runs
the package only when `lab/pkg/__main__.py` exists, and it runs
`lab/auxpow/vardiff.py` even though `lab/auxpow` has no `__init__.py`.

Commands now resolve through a separate `runnable_candidates` helper that
admits only `<relative>.py` or `<relative>/__main__.py`; the prose contract
keeps `module_candidates`, so a `lab.prism.pkg` mention of an
`__init__.py`-only package is still not dangling. A dead `-m` command reports
both paths joined by `or`, so a reader is not told to create `lab/pkg.py`
beside a tracked package that merely lacks `__main__.py`. The docstring
states the new rule, the passing fixtures gain `lab/pkg/__main__.py`, and
tests cover the four package shapes and the prose exemption.

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

* 3.x.x: pin the B8 parity record's retired module paths to the commit it cites (#318 CI)

`docs/prism-b8-miner-parity.md` landed on 3.x.x with #313 after this
branch's last merge of the base, and its reference line names
`lab/prism/tip_refresh.py` and `lab/prism/job_delivery.py`, which #244
removed. The reference guard this branch adds scans every tracked doc on
the merge ref, so CI's "Python unit tests (shard 1)" failed on that line
while the test passed on the branch alone.

The line already anchors itself to a 2.x.x commit; the two module mentions
are now links to those files at `95ffe06`, checked with `git cat-file -e`
against that tree, with the basenames as link text so the visible path no
longer claims to exist on the branch. The guard treats a commit-pinned
GitHub URL as stable history. The sentence is otherwise unchanged.

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

* 3.x.x: parse quoted option arguments in the doc-command guard (#318 review)

The doc-command guard read a `-W`, `-X` or `--check-hash-based-pycs`
argument only as a bare non-whitespace word, so `python3
--check-hash-based-pycs 'always' -m lab.prism.deleted` and `python3 -X 'dev
mode' -m lab.prism.deleted` ran and yet were not reported: the quoted mode
broke the `always|default|never` match, and the space inside the quotes
ended the `-X` argument early. The bare word also swallowed an unterminated
quote, so `python3 -X 'dev" -m lab.prism.x`, which bash rejects before
Python starts, was reported as a dead command. On CPython 3.14, `-X 'dev'`,
`-X "dev mode"`, `-X'dev'`, `-X"dev mode"`, `-W 'error'`, `-W"error"`,
`-W 'error'::DeprecationWarning` and `--check-hash-based-pycs "always"` all
run `json.tool` exactly as their bare spellings, because the shell strips
matching quotes, attached or not, before CPython sees them.

An option argument is now a shell word: runs of unquoted characters
alternating with matching-quoted strings, non-empty, ending at whitespace.
The runs and strings alternate rather than nest, so one word has a single
parse and a long argument cannot backtrack exponentially. `-W` and `-X`
take that word attached or after whitespace; `--check-hash-based-pycs`
reuses `quoted()` around its three modes with its own group name, since the
command patterns already use that group for the interpreter and the target.
An unquoted run holds no quote character, so a mismatched quote matches no
option and the line is left to the prose contract. Tests cover each quoted
form against missing and existing targets, a wrapped form, and the
mismatched forms.

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

* 3.x.x: accept -R and the -- terminator in the doc-command guard (#318 review)

`PYTHON_FLAG` listed every single-letter option but `-R`, so `python3 -R -m
lab.prism.deleted` ran and was not reported. On CPython 3.14 the option
lines of `python3 --help` are `-b -B -c -d -E -h -i -I -m -O -OO -P -q -R
-s -S -u -v -V -W -x -X`, with `-h : print this help message and exit (also
-? or --help)`; `-R` was the only letter missing, and `python3 -R -m
json.tool --help` and `python3 -Rm json.tool --help` both run the module,
so `-Rm` joins the adjacent `-m` spellings. Separately, the standard `--`
terminator before a script path evaded `SCRIPT_COMMAND`: `python3 --
s.py`, `python3 -O -- s.py` and `python3 -OO -- ./s.py` run the script.

`R` is in the flag class and `SCRIPT_COMMAND` accepts an optional `--`
followed by whitespace before the script target. `MODULE_COMMAND` does not:
after `--` CPython takes `-m` as a script name, and `python3 -- -m
json.tool` fails with "can't open file '.../-m'", so that line runs nothing
and stays with the prose contract, which a test asserts. Tests cover `-R`
and `-ER -X dev` in the option table, `-Rm`, and `--` before a script with
missing and existing targets, in a wrapped form, and with `./`.

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

* 3.x.x: invalidate the soak when the coordinator restarts (#318 review)

`compose.yaml` gives `prism-coordinator` `restart: on-failure`, so a
coordinator that exits mid-soak is started again by Compose inside the same
container, and the step-3 capture loop, which only read `/proc/1/status`,
would go on sampling the new PID 1 without a word. The CSV would then splice
several short lifetimes into one 23 h span, each restart's low RSS and reset
share counters would hide the growth, and the bound, which assumes one
process, could pass.

The loop now reads `docker inspect` for the container's status, `StartedAt`
and `RestartCount` once before it starts and again before every sample,
appends each reading to `soak-process.log`, and on any change prints both
readings with the time to stderr and stops. The container is the same across
a Compose restart, so `$c` stays the handle and `docker inspect` on it is the
right probe. The prose says the bound is evidence about one process, why the
restart policy would otherwise hide a restart, that the log lets a later
reader show the run was one process, and that a change invalidates the run:
keep the message and the log, attach `docker logs "$c"`, and start over from
step 2. Step 6 gets one sentence saying such a run is not judged. Verified
against a throwaway container with the same restart policy, where two policy
restarts moved `StartedAt` and took `RestartCount` from 0 to 2, and with a
stub `docker` that changes `StartedAt` on the second iteration.

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

* 3.x.x: invalidate the soak when an RSS sample is missing (#318 review)

The step-3 capture loop piped `/proc/1/status` straight into `awk`, so when
`docker exec` failed transiently, or the body had no `VmRSS:` line, the awk
printed nothing and exited 0 and the loop went on without a word. The bound
check only enforces the overall 23 h span from the first sample to the last,
so two successful samples 82,800 s apart pass it while the missing
five-minute samples between them can hide an excursion, and the judge's
malformed-row rule cannot catch this because no row is written at all.

Each iteration now writes exactly one `seconds,bytes` row or stops the run.
The body is read into a variable first and its exit status kept, because the
block is pasted into an operator's bash or zsh and a pipeline's status is its
last command's without `pipefail`; the awk prints a row only when the body
carries exactly one `VmRSS:` line in kB; and an empty or malformed result
prints the time, the exec's exit status when it was non-zero, and the body
that was read to stderr, then breaks, in the restart guard's style. The
variable is `body`, not `status`, because `status` is read-only in zsh. The
prose says a missing sample invalidates the run for the same reason a
restart does, that a transient `docker exec` failure is therefore not
skipped, and that the operator starts over from step 2; step 6 now says a
run stopped on a missing sample is not judged. Verified with `sh -n`,
`bash -n` and `zsh -n` on the extracted loop, with a stub `docker` in sh,
bash and zsh that returns a normal body, then a body without `VmRSS:` or a
non-zero exit, where each run wrote one row and stopped with the message, and
with a live throwaway container, where the exec line produced one row and,
after the container was removed, an empty body with exit status 1.

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

* 3.x.x: tokenize shell-quoted targets in the doc-command guard (#318 review)

The command contract accepted a `-m` target or script path that was entirely
bare or entirely inside one pair of quotes, so a target the shell assembles
from several pieces slipped through: `python3 -m "lab.prism."deleted`,
`python3 -m lab."prism".deleted` and `python3 "lab/prism/"deleted.py` all run
the missing target (bash 3.2 and CPython 3.14 run `python3 -m "json."tool`
exactly as the bare spelling), yet the scanner reported nothing, and the
prose rule saw only `lab.prism`, which resolves to the tracked directory.

The target is now read as a whole shell word: the tokenizer that already
parsed quoted option arguments is generalised to `SHELL_WORD` and used for
the `-m` target and the script path as well. `dead_commands` removes the
matching quotes, strips any `./` prefixes from a script path, and only then
reads the word against the target grammar and resolves it, reporting the
normalised target. A word that then names no `lab` module or script, such as
`$VAR`, another package, or `"lab.prism."` with nothing after the dot (which
CPython answers with "No module named lab.prism."), is not a `lab` command.
An unterminated opening quote still matches nothing. `quoted()` stays for
the interpreter name and the `--check-hash-based-pycs` mode, whose values
are fixed words with nothing to concatenate.

A word ends at whitespace, at a bash metacharacter (`;`, `|`, `&`, `(`, `)`,
`<`, `>`), at a backtick, or at a quote that opens no string, so the forms
the previous `\b` boundary caught keep being caught: `` `python3 -m lab.x` ``
in inline code, `python3 -m lab.x; ...`, `$(python3 lab/x.py)` and the inner
command of `sh -c "python3 -m lab.x"`. Backslash escapes are out of scope and
the docstring now lists them with the other things the lexical check does not
follow.

`dangling_references` is unchanged: the prose rule is about mentions, and
`"lab.prism."deleted` in prose is not a mention of a module, while the
runnable form is now caught by the command rule.

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

* 3.x.x: skip patch and diff files under docs/ in the reference guard (#318 CI)

The guard read every tracked file under `docs/`, and #320 (22bd1a2) added
`docs/prism-alert-rules-qbit-tools.patch`, a unified diff of qbit-tools'
Ansible monitoring role. Its line 991 is a `-` line quoting a comment that
used to name `lab/prism/block_candidates.py` in that other tree, so the
prose contract reported it as a dangling reference on this branch. The
mention is quoted history, not this repository's prose: the patch records
another tree's text before and after a change, editing a line of it would
break the patch, and neither contract has anything to say about it.

Both contracts now skip tracked files under `docs/` whose suffix is in
`QUOTED_HISTORY_SUFFIXES` (`.patch` and `.diff`). The selection is factored
into `documented(paths)`, which `setUpClass` filters to files, so the rule
is testable without git: a new test checks that a patch and a diff are left
out while `.md`, `.json` and `.yaml` paths stay in, and that no selected
doc carries a skipped suffix. The scope is not narrowed to Markdown: every
other suffix is still read. The module docstring states the exemption. With
the skip in place the real-docs tests pass again, `dead_commands` over the
59 documents in scope is empty, and every RATCHET count equals its ceiling.

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

* 3.x.x: tokenize the interpreter word in the doc-command guard (#318 review)

The command contract accepted an interpreter name that was wholly bare or
wholly inside one pair of quotes, so a name the shell assembles from pieces
slipped through: bash 3.2 runs `"python"3 -m json.tool`, `'pyth'on3 -m
json.tool`, `python"3" -m json.tool` and `"/usr/bin/pyth"on3 -m json.tool`
exactly as `python3`, yet the scanner reported nothing for `"python"3 -m
lab.prism.deleted`, `'pyth'on3 -m lab.prism.deleted` and `python"3"
lab/prism/deleted.py`, while `/usr/bin/python3 …` and `env python3 …` were
caught and `mypython3 …` was correctly not.

The interpreter is now read as a whole shell word, the way 43609d1 reads
the target. `dead_commands` strips the matching quotes, takes the basename
after the last `/`, so `/usr/bin/python3` keeps matching, and accepts the
word only if it is wholly `python`, `python3` or `python3.N`; `mypython3`,
`cpython3`, `python2` and `python3x` are other programs and are not
commands, while the prose contract still sees their reference. Option
parsing, the `-m` and script handling and the target tokenizer are
untouched: `SHELL_WORD`, `PYTHON_OPTION` and `MODULE_OPTION` are the same
strings as before, and the same 21 commands are found across the tracked
documents by the old and the new grammar.

Two details make reading a word from every position of a line sound.
First, a word may start right after a closing quote, so `"/usr/bin/"python3`
is one candidate and its tail `python3` another: the command patterns are
lookaheads that consume nothing, and `python_commands` drops a candidate
that starts inside the interpreter word of the one before it, whether or
not that word named Python, so `"/usr/bin/"python3 lab/prism/x.py` is
reported once and `"my"python3 -m lab.prism.x` (`mypython3` to bash) not at
all. Second, the interpreter word's quoted pieces hold no whitespace: a
program name is one word, and with arbitrary quoted pieces `"$c" sh -c
"python3 …` read from `$c` would pair the closing quote of `"$c"` with the
opening quote of the `sh -c` string and hide the `python3` inside it. A
word starts where no unquoted word character precedes it, so `env python3
…`, `docker exec "$c" python3 …`, `sh -c "python3 …"`, inline-code
`python3 …` and `$(python3 …)` are caught as before, and a mismatched
interpreter quote still matches nothing. The docstring and the grammar
comments now cover the interpreter alongside the target.

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

* 3.x.x: invalidate the soak when a metrics sample fails or is stale (#318 review)

The step-3 capture loop piped the `/metrics` scrape through `tr`, `grep`
and `sed` straight into `soak-metrics.log`, so when the `curl` failed, the
body carried none of the expected families, or its header said `stale` or
`unavailable`, the trailing `sed` still exited 0 and the loop went on
without a word. The correlated series is what reads an RSS excursion back
at its own five-minute sample, so the log could omit exactly the interval
where RSS breached while the run stayed eligible for judgment, and the
step-2 gate could not catch it because it proves the body fresh once, at
the start.

Each iteration now appends the filtered lines or stops the run, in the RSS
guard's style. The response is read into a variable first and the exec's
exit status kept; the `\r` strip runs as a second step on the variable
rather than in the same pipeline, because the status of a command
substitution is its last command's without `pipefail`, which not every
operator shell sets. An awk then requires, in order, that the exec
succeeded, that the body carries exactly the line
`x-prism-metrics-state: fresh`, and that the RSS gauge family
`qbit_prism_process_resident_memory_bytes`, the series the reading order
starts from, is present; the other families in the filter are not
required, since a histogram bucket or a `runtime_task_stalled{task}`
series can legitimately be absent from a scrape. On any failure the loop
prints the time, the condition that failed (the exit status, the state
header actually seen, or the missing family) and the header lines to
stderr, then breaks. The `grep -E` filter and the `sed` timestamp prefix
are unchanged; the restart guard and the RSS-sample guard are untouched.
The prose holds the metrics sample to the missing-sample rule and says the
step-2 gate proves freshness only once, and step 6 now lists a failed or
non-fresh scrape among the reasons a run is not judged.

Verified with `sh -n`, `bash -n` and `zsh -n` on the extracted loop, and
with a stub `docker` and a stub `sleep` in sh, bash and zsh that serve a
normal `/proc/1/status` body to the `cat` call and, for the `curl` call, a
fresh body (two samples, eight rows, no message), then from the second
sample a `curl` exit 7, a `stale` header, or a fresh header without the
RSS gauge: each of the nine failure runs wrote the first sample's four
rows and stopped with its message. `python3 -m unittest
tests.test_docs_lab_prism_references -v` passes (56 tests).

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

* 3.x.x: normalise ANSI-C quoted words in the doc-command guard (#318 review)

bash treats $'…' (ANSI-C quoting) and $"…" (locale quoting) as quoted
strings and strips them like plain quotes: on bash 3.2, `python3 -m
$'json.tool'`, `python3 -m $'json.'tool`, `python3 -m $"json.tool"` and
`$'python3' -m json.tool` all run json.tool. The word grammar read the `$`
as an unquoted character, so `unquote` produced `$lab.prism.deleted`, which
matched no target, and the guard reported nothing for a command that runs a
deleted module.

A quoted piece may now carry the `$` prefix, in both the target word and the
interpreter word, and `unquote` strips it with the quotes, so
`$'lab.prism.'deleted` reads as `lab.prism.deleted` and `$'python3'` as
`python3`. A `$` directly before a quote belongs to the quoted piece and is
never an unquoted character, which keeps the split of a word unique and the
alternation free of ambiguous nesting; a `$` before anything else is an
ordinary character, so `$VAR` words behave as before. Backslash escapes stay
out of scope as the docstring says: `$'lab\x2eprism.deleted'` keeps its
backslash, names no target and is not reported. Tests cover the evading
module, script and interpreter forms, the same forms with existing targets,
the escape and unterminated-quote cases, and a wrapped form at its line.

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

* 3.x.x: invalidate the soak on a failed process collection (#318 review)

The step-3 capture loop accepted a `/metrics` scrape when the exec exited
0, the body carried exactly `x-prism-metrics-state: fresh` and the family
`qbit_prism_process_resident_memory_bytes` was merely present. The header
proves less than that check assumed. `metrics_snapshot.rs` describes only
the age of the last snapshot publication and says a fresh failed probe is
still fresh, and the collector families are overlaid at scrape time by
`Metrics::overlay_collections`: when the process collector's last success
is absent or older than `COLLECTOR_STALE_AFTER` (30 s),
`snapshots::invalidate` renders
`qbit_prism_collector_available{collector="process"} 0` and
`qbit_prism_process_resident_memory_bytes -1`, the rendering the registry
test `process_collector_reads_real_input_and_distinguishes_failure_from_zero`
asserts for a failed read. Such a body passed the loop, so it recorded a
correlated sample with no RSS value, the series the reading order starts
from, instead of invalidating the soak. The step-2 gate already requires
the gauge at exactly 1, but proves it once, at the start.

The awk now requires, in order, that the exec exited 0, the exact line
`x-prism-metrics-state: fresh`, the exact line
`qbit_prism_collector_available{collector="process"} 1`, and an RSS sample
whose value is a nonnegative integer, so `-1` is rejected. On failure it
prints the first condition that failed in the existing style: the exit
status, the state header seen or its absence, the collector gauge line
seen or its absence, or the RSS line seen or its absence. The surrounding
shell is unchanged. The prose states the new conditions and why the header
alone is not enough, and step 6 lists an unavailable process collector and
an unusable RSS value among the reasons a run is not judged. Step 2, the
RSS `/proc/1/status` guard and the restart guard are untouched.

Verified with `sh -n`, `bash -n` and `zsh -n` on the extracted loop, and
with a stub `docker` and a stub `sleep` in sh (bash 3.2), bash 3.2 and zsh
5.9. The stub serves a normal `/proc/1/status` body to the `cat` call and,
for the `curl` call, a fresh body with the gauge at 1 and RSS at 4194304
first, then the case under test: the gauge at 0 with RSS `-1`, the gauge
at 1 with RSS `-1`, no gauge line, and a `stale` header. Each of the
twelve failure runs wrote the first sample's five rows to
`soak-metrics.log` and stopped with its own message; the second sample's
RSS row still lands in `soak-rss.csv`, since that read precedes the
scrape. The three control runs, with the second body also good and the
stub `sleep` ending the loop, wrote ten rows and no message. The awk
program gives the same answer for every case under macOS awk 20200816,
busybox 1.37.0, gawk 5.3.2 and mawk 1.3.4. `python3 -m unittest
tests.test_docs_lab_prism_references` passes (60 tests).

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

* 3.x.x: require exactly two fields in the soak judge (#318 review)

The `awk` bound check refused a row with fewer than two fields but read
any row with more, so `82800,300,000` judged as 300 bytes and
`0,100,garbage` set the baseline, and corrupted input could suppress a
breach while the prose promised an exact `seconds,rss_bytes` format. The
deleted Python evaluator had the same looseness (`read_rss_samples` at
`1398bbc^` took the first two comma-separated fields and ignored the
rest), so the port was faithful to it and wrong with it.

The predicate is now `NF != 2`: a row with a third field, including a
trailing comma, is unusable input (exit `2`) like a truncated one. The
capture loop writes exactly two fields, so a row with more was corrupted
somewhere between the loop and the judge and is refused rather than read.
The prose says the field count is exact and names the tightening over the
Python tool.

Verified with the judge fence extracted from the doc and run under `sh`
with BSD awk: a flat 24 h series passes (exit 0), `0,100,garbage`,
`82800,300,000`, `100,200,` and a one-field row each exit 2 with the row
named, `-1` samples, comments and blank lines are still skipped, a
post-warm-up breach still exits 1, and whitespace around a field still
counts as two fields; the `NF < 2` form exited 0 on both three-field
rows. `python3 -m unittest tests.test_docs_lab_prism_references` passes
(60 tests).

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

* 3.x.x: write each soak run into its own directory (#318 review)

The step-3 capture loop appended every sample to `soak-process.log`,
`soak-rss.csv` and `soak-metrics.log` in the working directory with `>>`,
and nothing truncated them or moved them aside. The restart rule says an
invalid run is started over from step 2, so a second run appended to the
first run's files, and the judge, which sorts by timestamp before it
reads, then took its first hour, and so its baseline, from the earlier
run, judged the later run against that baseline, and satisfied the span
floor with the earlier run's first sample and the later run's last.
Truncating instead would have destroyed the evidence the restart rule
says to keep.

Every run now writes into its own directory, `soak-<UTC start time>`,
and the loop is chained to the `mkdir` that creates it with `&&`: `mkdir`
without `-p` refuses a name that already exists, and on that refusal the
loop does not run at all, so a run can never append to another run's
files and never writes anything the operator did not name. The share-ack
histogram and the `/metrics` snapshots in steps 3 and 4 go into the same
directory, step 6 judges the run's own `soak-rss.csv`, step 7 records the
run directory, and the restart rule keeps the directory rather than "the
log". The bound section says the sort applies to partial logs of one run
and points at the per-run directory as the reason two runs never share a
file.

Verified with `sh -n`, `bash -n` and `zsh -n` on the loop extracted from
the doc, and with a stub `docker`, `sleep` and `date` in sh, bash and zsh:
a fresh run created its directory and wrote two RSS rows, three process
readings and eight metrics lines before the stub flipped the process
state and the restart guard stopped it; a second run under the same
start time was refused by `mkdir`, the loop did not run, the first run's
files were byte-identical afterwards and nothing was written at top
level; a third run under a later start time created a second directory
and left the first untouched. `python3 -m unittest
tests.test_docs_lab_prism_references` passes (60 tests).

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

* 3.x.x: leave -h and -V out of the doc-command guard's prefix options (#318 review)

`PYTHON_FLAG` listed `h` and `V` among the option letters that may sit
between the interpreter and its target, so the guard read `python3 -V
lab/removed.py` and `python3 -h -m lab.removed` as commands that run the
missing target and would have failed CI on a diagnostic that never
reaches it. CPython prints the help text for `-h` and its alias `-?`, and
the version for `-V`, and exits before it reads the target, so such a
command runs nothing; the comment above the class already excluded `-c`
for the same reason.

The class is now every single-letter option other than `-c`, `-m`, `-h`
(with `-?`) and `-V`. Because `PYTHON_FLAG` also builds the `-W`/`-X`
cluster form and the `-m` cluster (`MODULE_OPTION`), `-hW error`, `-VX
dev`, `-hm lab.x` and `-Vm lab.x` are no longer read as options either,
which is what CPython does with them. The comment names the letters, the
behaviour and the spellings checked, and a new `ScannerTests` case covers
`-h`, `-?`, `-V`, `-VV`, `-OO -h`, `-Oh`, `-hOO`, `-V -X dev`, `-VX dev`
and `-hW error` before a missing module (bare and quoted) and a missing
script, `-V --` before a script, and the clusters `-hm`, `-Vm`, `-Ohm`,
`-hIm` and `-VVm` with the module attached or following; each is not a
command, and the prose contract still sees the reference.

Verified on CPython 3.14.6 with `lab/gone.py` and `gone.py` that raise
`SystemExit("RAN")`: every spelling above printed the help text or the
version and exited 0 with neither file run, while `python3 -m lab.gone`
and `python3 gone.py` printed `RAN`. Mutation check: with the old class
restored in a copy of the module, the new test fails in ten of its
subtests (every one but `-?`, which was never in the class). `python3 -m
unittest tests.test_docs_lab_prism_references` passes (61 tests).

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

* 3.x.x: invalidate the soak on a gap between samples (#318 review)

The step-3 capture loop never compared one sample's time with the
previous one's, and the `awk` judge's span floor reads only the first
and last timestamps. A host suspended for an hour, or a `docker inspect`
or `docker exec ... cat` that stalled for one (neither call is bounded;
only the `curl` carries `--max-time`), therefore left a hole in the
series that nothing reported: the iteration after the stall wrote a
valid row, the loop went on, and the judge passed a file in which an
excursion could have risen and drained unseen. The deleted Python
evaluator (`evaluate_rss_bound` in `lab/prism/process_telemetry.py` at
`1398bbc^`) had no gap rule either, so the port was faithful to it and
wrong with it.

The judge now takes `max_gap=360` and refuses a series in which two
consecutive usable samples are more than 360 s apart as unusable input
(exit 2), naming the interval and both timestamps. The rule sits after
the `-1` skip, so a hole bridged by `-1` rows is still a hole, and a
single `-1` row between two cadenced samples opens a 600 s gap; the loop
never writes one, and the prose says so. The loop keeps the previous
iteration's `now` and, before anything is written, stops the run as
invalid when more than 360 s have passed since it, printing the interval,
its own timestamp and the last sample's. The tolerance is the 300 s of
sleep plus a minute for the three reads. The prose explains the rule in
the bound section as a tightening over the Python tool of the same kind
as the exact field count, adds a step-3 paragraph on the interval check
beside the missing-sample one, and lists a gap among the reasons step 6
does not judge a run.

Verified with the judge fence extracted from the doc under macOS awk
20200816, and under busybox 1.37.0, gawk 5.3.2 and mawk 1.3.4 in an
alpine container, all agreeing: a flat 300 s series passes (exit 0); a
3900 s hole after hour 2, the same hole bridged by `-1` rows, a 2.5x
excursion that drained inside the hole, the hole in shuffled input and a
hole inside the warm-up each exit 2 with the gap named; a 360 s interval
passes and a 361 s one exits 2; a breach still exits 1, and a malformed
row, a short span, comments and blank lines behave as before. The
unchanged judge at the previous HEAD passed every hole case. The loop,
extracted from the doc, passes `sh -n`, `bash -n` and `zsh -n`, and with
a stub `docker`, `sleep` and `date` under sh (bash 3.2 in POSIX mode),
bash 3.2 and zsh 5.9: a control run in cadence wrote three RSS rows
before the stub's process flip ended it; a run whose second `date +%s`
is 3900 s after the first stopped with the gap message after exactly one
row, one process line and one metrics sample; a 360 s interval continued
and a 361 s one stopped. `python3 -m unittest
tests.test_docs_lab_prism_references` passes (61 tests).

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

* 3.x.x: stop the soak when an append to the run's files fails (#318 review)

The step-3 capture loop appended its process reading, RSS row and
metrics lines with `>>` and never looked at the status. The operator's
shell is not under `set -e`, so when the run directory filled or its
filesystem returned an I/O error the loop went on reading and failing to
write, and once the rows already on disk spanned the 82,800 s the judge's
floor asks for they would have passed it, with the hours after the disk
filled, and the process readings and metrics lines that should explain
them, missing from the record. The gap rule cannot see this: the series
simply ends.

Each of the three appends is now checked and the first that fails stops
the run as invalid, naming the file and the sample time, in the style of
the other stop paths. The metrics lines are read into a variable before
they are appended, as the body and the response already are: the status
of the pipeline would be `sed`'s, and what a failed write does to that is
each implementation's own affair, whereas the builtin `printf` reports one
as `1` in `sh`, `bash` and `zsh` alike. The grep pattern is unchanged. The
prose adds the rule beside the missing-sample and gap paragraphs, and
step 6 lists a failed append among the reasons a run is not judged.

Verified with the loop extracted from the doc: `sh -n`, `bash -n` and
`zsh -n` pass, and with the stub `docker`, `sleep` and `date` under sh
(bash 3.2 in POSIX mode), bash 3.2, zsh 5.9, busybox 1.37.0 sh and dash
0.5.13, the control and gap runs behave as before; with the stub `sleep`
replacing `soak-rss.csv`, `soak-process.log` or `soak-metrics.log` by a
directory after the first iteration, the second iteration stops with the
append message naming that file and nothing further is written. In an
alpine container, `echo x >> /dev/full` and `printf '%s\n' x >> /dev/full`
return 1 in busybox sh, dash, bash 5.3.9 and zsh 5.9, and `if !` and `||`
take the failure branch while the shell keeps running. `python3 -m
unittest tests.test_docs_lab_prism_references` passes (61 tests).

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

* 3.x.x: record why a soak is invalid and return nonzero (#318 review)

Every stop path of the step-3 capture loop printed its message to stderr
and left the loop with `break`, whose status is 0, and wrote nothing to
the run directory to say the run was cut short. The iteration that finds
a bad metrics sample has already written its RSS row, so a stop after 23
hours left a directory whose CSV satisfies the span floor and nothing, in
the directory or in the status, to say it was invalid: a wrapper that ran
the fence as a script, or an operator who kept the directory and lost the
shell's scrollback, would have judged and passed it.

The fence now defines `invalid`, which copies what it is piped to
`$run/soak-invalid` and to stderr, and `capture`, a function that holds
the loop and is called at the end of the fence. Every stop path writes
its message through `invalid` and returns 1 from `capture`; `mkdir
"$run" || return` keeps the per-run-directory guard and returns `mkdir`'s
status before the loop runs. The loop body is otherwise unchanged. The
fence is pasted into the operator's interactive shell, which steps 4 to 7
read `$run` from, so the stop paths `return` rather than `exit`, and
`run=` and `c=` stay outside the function. The prose describes `capture`,
says the directory now records why it is invalid and that the only way
`capture` returns by itself is an invalidation, notes that `tee` still
delivers the message to stderr when the disk itself is the fault, and
step 6 refuses to judge a directory that holds `soak-invalid` whatever
its CSV would say; the restart rule points at the marker for the message.

Verified with the fence extracted from the doc: `sh -n`, `bash -n` and
`zsh -n` pass, and with the stub `docker`, `sleep` and `date` under sh
(bash 3.2 in POSIX mode), bash 3.2, zsh 5.9, busybox 1.37.0 sh and dash
0.5.13: the control, gap and three append-failure runs write the same
rows as before, `capture` returns 1 on each, `soak-invalid` holds exactly
the stop message (`cmp`-identical to the stderr text for the control and
gap runs), and `$run` is still set afterwards; a refused `mkdir` returns
its status, runs nothing and writes no marker. In an alpine container,
`tee -a /dev/full >&2` still delivers its input to stderr and exits 1
with busybox and coreutils tee, through `invalid` in busybox sh, dash,
bash 5.3.9 and zsh 5.9. `python3 -m unittest
tests.test_docs_lab_prism_references` passes (61 tests).

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

* 3.x.x: read quoted option words in the doc-command guard (#318 review)

The guard read the interpreter and the target as whole shell words and
unquoted them, but matched the option words between them with a regex
on the raw line, so the hyphen and the letters had to be bare. bash
strips the quotes of an option word before CPython sees it, so `python3
"-O" -m lab.prism.deleted`, `python3 '-m' lab.prism.deleted`, `python3
"-m"lab.prism.deleted`, `python3 $'-OO' -m …`, `python3 "-"O -m …`,
`python3 "-X" dev -m …` and `python3 "--" lab/prism/deleted.py` all run
the deleted target and were reported as nothing, and in a ratcheted
document such a spelling could replace a dangling mention without moving
the count.

The option regexes and the `quoted` helper are replaced by a tokenizer.
`INTERPRETER_CANDIDATE` finds each candidate interpreter word as before;
`command_target` then reads the words after it one shell word at a time
with `NEXT_WORD`, unquotes each, and applies the option grammar to the
unquoted word in order: a flag cluster is skipped; a `-W`/`-X` cluster
takes its argument attached or as the next word; `--check-hash-based-pycs`
takes the next word, which must be one of its three modes; a `-m` cluster
names the module attached or as the next word; `--` makes the next word
the script; any other word is the script, so `-c…`, `-h…`, `-?`, `-V…`
and long options still end the command at a word that names no lab
target. A word with a mismatched quote is no shell word, so the command
ends there, as bash rejects the line. `dead_commands` reports the same
`(first line, command, missing path)` rows, with the command sliced from
the interpreter word to the target word; the only observable change is
that a module and a script command on one line now report in source
order. `PYTHON_FLAG` and the target grammar are unchanged; the comments
describe the tokenizer and the spellings checked.

Verified on bash 3.2 and CPython 3.14.6 that every spelling above runs
`json.tool` or a `lab/gone.py` that raises exactly as its bare form,
that `'-h'`, `"-hm"`, `"-V"`, `"-Wm"`, `"-Xm"`, `"--check-hash-based-pycs"
sometimes` and `'--' -m` still run nothing, and that `"-O'` and `-X "dev'`
are rejected by bash before Python starts. Five new `ScannerTests` cover
the quoted, concatenated and ANSI-C option words before missing and
existing module and script targets, the wrapped form at the right line,
the quoted non-command options, and mismatched option-word quotes.
Mutation check: with the scanner at the previous HEAD, the new tests fail
in 16 places. Over the 59 docs in scope the old and new scanners read the
same 17 Python commands with identical kind and target. `python3 -m
unittest tests.test_docs_lab_prism_references` passes (66 tests).

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

* 3.x.x: cover quoted --check-hash-based-pycs modes in the doc-command guard (#318 review)

A review of the regex scanner noted that `python3 --check-hash-based-pycs
$'always' -m lab.prism.deleted` and `python3 --check-hash-based-pycs
alwa"ys" -m lab.prism.deleted` were read as no command, while bash hands
CPython the bare mode and the missing target runs. The tokenizer that
replaced the regexes in a1c542a unquotes every word after the interpreter
before the grammar sees it, the mode included, so both spellings are
reported there; this adds the test that says so.

`test_quoted_hash_mode_arguments_are_read_as_shell_words` covers
`$'always'`, `alwa"ys"`, `'never'`, `$"default"`, `de'fault'` and
`"al"ways` before a missing module and a missing script, and the same
before an existing module, and checks that `"sometimes"`, `$'some'times`
and two mismatched-quote spellings are no command while the prose
contract still sees the reference.

Verified on bash 3.2 and CPython 3.14.6 that each of the six spellings
runs `json.tool`, and that `$'some'times` is rejected with
"--check-hash-based-pycs must be one of 'default', 'always', or 'never'"
before anything runs. `python3 -m unittest
tests.test_docs_lab_prism_references` passes (67 tests).

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

* 3.x.x: re-read the coordinator identity after each soak sample (#318 review)

The step-3 `capture` function checked the coordinator's identity before
each sample's reads and nowhere else. A restart between that check and
the `/proc/1/status` and `/metrics` reads recorded the replacement's RSS
and metrics under the original identity in `soak-process.log`; every
later iteration's check would catch it, but the last iteration of a
valid run has no later iteration, since the operator ends the run after
24 h, so a restart in that window on the last sample left a directory
with no `soak-invalid` that read as a single-process run.

The identity is now read again after the two reads, after the metrics
append and before the sleep, and a change ends the run as invalid
through `invalid` and `return 1` like every other stop path, printing the
sample time and both readings. The pre-sample check and the one
`soak-process.log` line per sample are unchanged. That sample's rows are
already in the files, which is fine because the marker keeps the
directory from being judged, as step 6 says. The step-3 intro names the
second check and the restart paragraph explains the window.

Verified with the fence extracted from the doc, `sh -n`, `bash -n` and
`zsh -n` passing, and with the stub `docker`, `sleep` and `date` under sh
(bash 3.2 in POSIX mode), bash 3.2 and zsh 5.9, where the stub's inspect
answer flips `RestartCount` at a chosen call: flipping at the post-read
check of the second sample stops the run with the new message after two
RSS rows, two process lines at the original identity and eight metrics
lines; flipping at the first sample's post-read check stops it after one
row; flipping at the second sample's pre-check still stops with the
existing message; with no flip, five samples run with no identity or gap
message and the run ends on a gap sentinel. In every case `capture`
returns 1 and `soak-invalid` is byte-identical to stderr. `python3 -m
unittest tests.test_docs_lab_prism_references` passes (67 tests).

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

* 3.x.x: fetch the pinned qbit through a cached, two-route, digest-checked installer (#318 CI)

Run 34857720110 lost the native PRISM job before any Rust test started:
the release download route on github.com answered 504 for the whole of
curl's seven-second --retry 3 window (an eleven-second first attempt, then
three instant 504s carrying github.com's own error page), so the install
step exited 22 and the gate-manifest proof failed for want of a manifest.
The run four minutes earlier fetched the same asset in seven seconds.

Replace the inline curl with .github/scripts/install-prism-qbit.sh, which
keeps the version, asset id and digest pinned in one place and takes the
tarball from the first source that verifies:

- a cached copy (actions/cache keyed on the script's hash, so a pin bump
  rotates the key); a cached file with the wrong digest is deleted, and a
  cache-service error is only a warning;
- the release download route, with five retries under a bounded
  ninety-second retry timer plus connect and stall timeouts;
- the release-asset API route on api.github.com, which fronts the same
  storage through a different tier and needs no token for a public repo.

Nothing is extracted before its sha256 matches the pin, whichever source
delivered it, and QBITD_BIN is still written to the job environment.

tests/test_install_prism_qbit.py drives the real script against a loopback
server scripted per route: fallback after a gateway error, rejection of
wrong-digest bytes from a route or the cache, failure when every source is
unusable, a verified cache hit making no request, and the workflow calling
the script with only the cache directory configured.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H5oqbzF1nZ43sn7454ezH5

* 3.x.x: end the soak from the capture loop and gate the judge on its marker (#318 review)

The step-3 `capture` loop returned only through its `invalid` paths; a
valid run was "ended by the operator after 24 h". So a SIGHUP from a
closed terminal, a SIGTERM from a host going down or an interrupt after
the CSV spanned the judge's 82,800 s floor but before 24 h ran no stop
path, wrote no `soak-invalid`, and left a directory that step 6 judged
and the floor passed, indistinguishable from a valid run.

The loop now keeps the time of its first sample and ends the run itself:
after the first sample taken 86,400 s or more after it, once that
sample's reads, appends and both identity checks have passed, it writes
one line to `$run/soak-complete.tmp`, renames it to `$run/soak-complete`
and returns 0. The rename publishes the marker whole or not at all: a
redirect straight to the marker's name would create the file before the
write, and a write that then failed on a full disk could keep `invalid`
from writing `soak-invalid` on the same disk, leaving an empty marker
and no invalid marker. A failed write or rename ends the run as invalid
through `invalid` like a failed append; an interruption between the two
leaves only the temporary file, which nothing reads. The `mkdir` rule
already keeps `capture` out of an existing directory, so a marker is
only ever written by the loop that took every sample in it.

Step 6 gains an executable gate, `completed`, that refuses a directory
holding `soak-invalid` or lacking a regular-file `soak-complete`, and
prints the completion line otherwise; the bound check runs only after
it. The awk judge is unchanged. The prose that said the operator ends a
valid run is reworded, the judge's hour of slack is tied to the marker,
and the marker joins step 7's record.

`tests/test_prism_soak_capture.py` extracts the capture, gate and judge
fences from the doc and runs them under sh (dash) and bash with shell
functions for `date`, `sleep` and `docker`, where `sleep` advances a
file-backed clock: a full run completes with 289 samples, the marker,
no stderr and a passing gate and judge; a SIGTERM at 23 h leaves a CSV
the judge alone accepts and a directory the gate refuses; an identity
change on the final sample's post-read check writes `soak-invalid` and
no marker; a marker write onto /dev/full with an unwritable
`soak-invalid` publishes nothing and the gate still refuses; a SIGTERM
between the write and the rename leaves only the temporary file; an
existing directory is not written into; and the gate refuses a directory
with both markers, a directory as the marker, or only the temporary
file. Mutating the gate to ignore the marker, or the fence back to a
direct redirect, fails the corresponding tests. `python3 -m unittest
tests.test_prism_soak_capture tests.test_docs_lab_prism_references`
passes (75 tests).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01B3vaLLrCSvBv4qzDEiX6Dj

* 3.x.x: hold each soak sample's end to the previous one's before completing the run (#318 review)

`capture` stamped every row with the `now` it read before the sample's
reads, and its completion check used that same `now`. A `docker inspect`
or `docker exec ... cat` that stalled inside the final sample's reads was
therefore invisible: on any other sample the next iteration's start-time
gap check would have seen it, but the sample that completes the 24 h has
no next iteration, so a stall of an hour passed both identity checks,
published `soak-complete` claiming the samples span 0..86400 s for a
process observed at 90000, and returned 0.

Read the clock again after the post-read identity check and hold each
sample's end to the previous sample's end with the same 360 s tolerance
the start-time check and the judge's `max_gap` use, before the completion
block can run. The 300 s sleep lies inside that interval, so the reads
get the same minute on the final sample that the start-time check leaves
them on every other one; a read that overruns it ends the run through
`invalid` with the sample's time, when its reads ended and how far behind
the previous sample's that was, publishes no marker and returns 1. The
start-time check stays for a hole in the sleep, and the marker is still
written to `soak-complete.tmp` and renamed.

Cover it on the fake clock: the final pre-read inspect advancing the
clock from 86400 to 90000 with the identity and both bodies healthy now
returns 1, records that message, leaves no marker, and is refused by the
gate although the bound check alone would pass the CSV; a 60 s overrun on
the final sample still completes, and a 61 s one is rejected on the final
sample as it already was on an ordinary one.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kfm1tpNt7zHUJGa9sQKv22

* fix: reject failed soak process identity probes (#318)

* fix: recognize non-identifier Python module targets

* fix: preserve quoted literal module targets (#318)

* fix: require fresh share-ack soak snapshots (#318)

* fix: preserve literal script targets in documentation guard (#318)

* fix: validate and atomically publish full soak snapshots (#318)

* fix: invalidate soak captures on backward clock readings (#318)

* fix: skip shell comments in documentation command guard (#318)

* fix: schedule soak snapshots during capture (#318)

* fix: resolve complete prose references in documentation guard (#318)

* fix: normalize lab script paths in documentation guard (#318)

* fix: reject failed RSS reads during soak capture (#318)

* docs: mark retired soak settings for the native guidance guard (#318)

* test: avoid redundant full-soak identity fault simulations (#318)

* fix: distinguish shell data from executable documentation commands (#318)

* test: publish supervisor fixture readiness atomically (#318)

* fix: require accepted-share progress throughout the soak (#318)

* fix: recognize compound-shell documentation commands (#318)

* fix: consume shell option arguments before command strings (#318)

* fix: consume sudo chdir arguments in doc commands (#318)

* fix: exclude sudo edit mode f…
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