Repository navigation
Export always-on heap and component-cardinality telemetry (#226 part 1) - #232
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c87e72fb0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| enabled = getattr(port, "malloc_telemetry_enabled", None) | ||
| if enabled is None: | ||
| try: | ||
| enabled = env_malloc_telemetry() |
There was a problem hiding this comment.
Read the validated malloc switch from the config snapshot
When PrismCoordinator is constructed with an explicit CoordinatorConfig, the validated value exists only at config.lifecycle.malloc_telemetry_enabled; the coordinator never copies it to malloc_telemetry_enabled. Consequently this lookup falls through to the ambient process environment, so a caller passing a snapshot with telemetry disabled can still execute mallinfo2 (and a valid environment change between startup and the first render overrides the startup-validated value). Read the lifecycle snapshot through port.config or publish that value on the coordinator.
Useful? React with 👍 / 👎.
| "# HELP qbit_prism_process_gc_pending_objects Objects tracked by the cyclic collector since its generation was last collected (gc.get_count), by generation.", | ||
| "# TYPE qbit_prism_process_gc_pending_objects gauge", | ||
| *[ | ||
| f'qbit_prism_process_gc_pending_objects{{generation="{generation}"}} {int(count)}' | ||
| for generation, count in zip(PRISM_GC_GENERATIONS, sample.gc_pending) |
There was a problem hiding this comment.
Do not report GC collection counts as pending objects
In the shipped Python 3.14 image, gc.get_count() exposes collection-trigger counters—principally allocations minus deallocations—not the number of objects tracked in each generation; Python 3.14 also no longer has generation 1. Labeling these samples gc_pending_objects{generation=...} makes the operational guidance interpret internal trigger state as retained objects and recommends using the generation-2 value as a backlog signal, which can produce incorrect heap-leak conclusions. Rename and document the values according to their actual collection-counter semantics.
Useful? React with 👍 / 👎.
8c87e72 to
cbd5696
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cbd5696518
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| `qbit_prism_process_malloc_in_use_bytes` against | ||
| `qbit_prism_process_resident_memory_bytes`. All three rising together is | ||
| retention: something is holding objects. RSS rising while allocated blocks | ||
| and in-use bytes stay flat is fragmentation. |
There was a problem hiding this comment.
Include mmapped allocations in the retention check
When a retained allocation is large enough for glibc to serve it via mmap (for example, a native buffer that grows in place), mallinfo2 records its bytes in hblkhd, exported here as qbit_prism_process_malloc_mmapped_bytes, rather than in uordblks/qbit_prism_process_malloc_in_use_bytes. RSS can therefore rise while both quantities recommended here remain flat, causing this runbook to diagnose fragmentation—or later blame pymalloc/the child—even though this process is retaining mmapped chunks. Include the mmapped gauge in this decision before drawing that conclusion.
Useful? React with 👍 / 👎.
Issue #226 recorded a coordinator growing about 390 MB/h of RSS across 45 h with a memory map shaped like glibc per-thread arenas over 64 threads, and nothing on /metrics could say whether that was live Python objects, pymalloc fragmentation, or glibc arena fragmentation. This lands the cheap, fixed cardinality instrument for that question, and the component gauge list #185 asked for, ahead of the census and allocator work in the second part. lab/prism/process_telemetry.py (new) collects sys.getallocatedblocks(), gc.get_count() and gc.get_stats() per generation, threading.active_count(), and glibc mallinfo2 arena/in-use/free/mmapped bytes through ctypes. The mallinfo2 binding is resolved once per collector and an absent or broken symbol is remembered without logging; it renders as an availability gauge at 0 with every byte gauge at -1, never as zero bytes, so musl, macOS, and pre-2.33 glibc read as unavailable rather than empty. The older int-typed mallinfo is deliberately not used as a fallback: its 32-bit fields wrap on a multi-gigabyte heap, which is exactly this issue's heap. The collector never walks the heap: no gc.get_objects(), no tracemalloc. lab/prism/metrics.py renders eleven process families (only the GC families carry a label, the closed three-value generation set) and two component families, qbit_prism_component_entries and qbit_prism_component_bytes, over a closed component label set covering the payout window and its serialization cache, job contexts and the bundle cache, the evicted-job graveyard, the candidate lanes and every hash-keyed candidate registry, reconcile flights, the pending-share floor, and the daemon mirror. Component reads are direct attribute loads on the shipped owners so a renamed field fails loudly. There is no hashrate-rollup gauge: the rollup folds in PostgreSQL and retains no in-process buffer. The cached payout window is accounted exactly once so the byte family can be summed for attribution. Its two backings are mutually exclusive, so a mirror-backed window (the Rust path, which is what mainnet runs) reports only under daemon_window_mirror_*, and a page-backed window only under payout_window_*. Which pair is non-zero is how an operator reads the active backing. share_window_serialization_spool is labelled in HELP and in the docs as an on-disk temporary file rather than resident bytes, so it is not mistaken for RSS. lab/prism/coordinator_config.py adds PRISM_MALLOC_TELEMETRY (default on, strict boolean validated at startup through LifecycleConfig) gating only the mallinfo2 call, which walks glibc free lists under each arena lock and is the one reading that is not a plain counter load. The renderer resolves it once at construction and falls back to the shipped default if the value has become invalid since startup: a telemetry switch must not be able to take the coordinator down from a metrics thread. compose.yaml passes it through and .env.example documents it, so the compose stack can turn it off with a restart. tests/test_prism_metrics.py pins the exact family sequences, the unavailable rendering, the shipped-owner reads, the closed label set under growth, the no-double-count property stated as a sum, and the no-heap-walk contract, and extends the frozen parity reference in the same commit. tests/test_prism_process_telemetry.py pins the collector and the switch. docs/prism-capacity-readiness.md documents the families, the glibc-only statement, the switch and how to set it in each deployment, the single accounting of the window, and what to read first when RSS climbs. Co-Authored-By: Claude Fable 5.1 <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
cbd5696 to
e8f5e60
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8f5e604fd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| the shape #226 captured. Arena flat while RSS rises points at pymalloc or at | ||
| the Rust daemon child, which this process's gauges do not see. |
There was a problem hiding this comment.
Remove the child daemon from coordinator RSS diagnosis
When the coordinator's RSS rises while its arena gauge stays flat, the Rust daemon child cannot explain that rise: process_resource_metrics() reads /proc/self/statm, which includes only the coordinator process, while the daemon is launched as a separate subprocess.Popen. This guidance can therefore send an incident investigation toward a process that is provably outside the plotted RSS; recommend checking the child only against its own RSS metric or removing it from this branch of the diagnosis.
Useful? React with 👍 / 👎.
Summary
Issue #226 recorded the mainnet coordinator at 17.69 GB RSS after 45 h of ordinary
load, growing about 390 MB/h from a 125-145 MiB startup baseline, with nothing on
/metricsable to say whether that growth is live Python objects, pymallocfragmentation, or glibc arena fragmentation. This lands the always-on instrument
that discriminates between those hypotheses, plus the component-cardinality gauge
list.
This is part 1 of 2 for #226, and that split is deliberate. The telemetry lands
first so the census, the allocator experiment and the eventual fix (part 2) build on
a settled
metrics.pyand a settled family-set test, and so the concurrentmonitor-stall work for #227 extends the same reference test rather than racing it.
Expect a second PR against #226.
These gauges are also the acceptance instrument #185 asked for: its component list
is covered in full, item by item, in
docs/prism-capacity-readiness.md.What changed
lab/prism/process_telemetry.py(new) collectssys.getallocatedblocks(),gc.get_count()andgc.get_stats()per generation,threading.active_count(),and glibc
mallinfo2arena / in-use / free / mmapped bytes throughctypes. Thebinding resolves once per collector; an absent or call-time-broken symbol is
remembered and never re-probed or logged. The collector never walks the heap — no
gc.get_objects(), notracemalloc— which is pinned by a test that patches bothto raise.
The older int-typed
mallinfois deliberately not used as a fallback: its32-bit fields wrap on a multi-gigabyte heap, which is precisely this issue's heap.
lab/prism/metrics.pyrenders 13 new families: 11 process families (only the GCones carry a label, the closed three-value
generationset) andqbit_prism_component_entries/qbit_prism_component_bytesover a closedcomponentlabel set. Component reads are direct attribute loads on the shippedowners, so a renamed field fails a test loudly instead of reporting a silent zero.
lab/prism/coordinator_config.pyaddsPRISM_MALLOC_TELEMETRY(default on, strictboolean, validated at startup) gating only the
mallinfo2call.compose.yamlpasses it through and
.env.exampledocuments it.Why, citing the issue's production evidence
The map shape in #226 — 943 anonymous regions totalling 23.4 GB, of which 658 are
in the 4-64 MiB band across 64 threads, plus one 3.9 GB
[heap]— is theglibc per-thread-arena signature (
HEAP_MAX_SIZEis 64 MiB), not a few largebuffers. Neither the image nor the deployment sets
MALLOC_ARENA_MAXorPYTHONMALLOC. Distinguishing that from ordinary retention needs arena bytes nextto in-use bytes and a live allocation count, which is exactly what the heap block
exports;
docs/prism-capacity-readiness.mdgives the four-step reading order.qbit_prism_process_allocated_blocksrising with RSS is retention;arena_bytes - in_use_bytesrising with a high thread count is glibc arenafragmentation, the shape #226 captured.
Safety and rollout
mallinfo2, which is the sole reason the switch exists.name. A test grows jobs, tips, candidate hashes, generations and workers by five
each and asserts the series set is byte-identical before and after.
qbit_prism_process_malloc_info_available 0with all four byte gauges at-1,never
0— a zero arena on a 17 GB process is a lie an operator would act on. Thefamily set is identical on every platform so one dashboard serves both. Verified
on macOS, which genuinely lacks the symbol.
PRISM_MALLOC_TELEMETRYonce atconstruction and falls back to the shipped default if the value has become invalid
since startup. The strict reader exits the process, which is right at startup and
wrong on a metrics thread: an observability knob must not be able to cause an
outage.
accessors, so
prism_coordinator.pyis untouched.its own configuration rather than from
.env, so turning the switch off thereneeds the same variable added on that side.
Review findings addressed
/code-reviewraised seven issues on the first draft; all seven are fixed in thisbranch. The substantive ones:
payout_window_*anddaemon_window_mirror_*, so summingqbit_prism_component_bytesfor RSS attribution counted the window twice — on theRust path, which is what mainnet runs. The window is now accounted exactly once,
and the property is pinned as a sum so a future backing cannot reintroduce it.
Which pair is non-zero is now also how an operator reads the active backing.
SystemExitreachable from the metrics thread on an invalid switch value —fixed as described above.
share_window_serialization_spoolis a temporary file, not RSS; HELP text and docs now say so.
getattrthat broke the fail-loudly promise, a docstring claiming O(1)reads where one is O(pages), and the switch missing from
.env.exampleand thecompose allowlist.
Refuted during implementation
There is no in-process hashrate rollup buffer to gauge, so no gauge was invented
for one.
hashrate_rollup_maintenance_loopfolds each batch inside PostgreSQLthrough
advance_hashrate_rollupsand retains nothing between passes; the publichashrate series cache from #218/#219 lives in a separate process. The docs record
why the family is absent.
Two registries stand out as census targets for part 2 and were deliberately not
changed here:
_block_candidate_terminal_outcomes, whose own docstring records312,000 entries after one testnet4 storm and describes its bound as a target rather
than a ceiling, and
_accepted_block_preview_acceptance_monotonic, which keeps atombstone per observed hash by design. Both are now exported.
Verification
Run locally on macOS (Darwin 25.4.0, Python 3.14.3), on this branch rebased onto
c3ca8bb(#225, itself on top of #230):bash -n, shellcheck and compileall are clean. The suite is 3191 tests, failures=2errors=3 skipped=4: the five failures are the documented macOS
os.spliceset intest_prism_job_builder(test_daemon_splice_failure_poisons_spool_and_one_shot_recovers,test_mid_stream_splice_failure_poisons_spool_for_later_builds,test_splice_failure_poisons_spool_and_falls_back_to_pipe,test_spool_creation_failure_falls_back_to_pipe_writes,test_spool_feeds_builder_and_is_written_once_per_generation), which pass on LinuxCI and are identical to this branch's merge base. Two of the four skips are the
glibc-only collector tests skipping correctly on macOS.
Independently checked beyond the suite: the rendered family count goes 240 to 253
with nothing removed, and a macOS render shows
malloc_info_available 0with allfour byte gauges at
-1while the interpreter gauges stay real.Not verified here: behaviour on musl; the cost of
mallinfo2on a fragmentedmulti-gigabyte heap with 64 arenas (the pinned test asserts the mechanism, not a
duration, because timing absolutes are host-specific); and any value on a live
coordinator — nothing in this change was run against production.
Closes #226