Repository navigation
3.x.x: refuse an unmeasurable memory floor, find pg_stat_statements as .dylib and surface why a managed cluster did not start (#485) - #514
Conversation
…s .dylib and surface why a managed cluster did not start (#485) qbit-prism-load on macOS (#447) ran with three silent gaps: - --min-mem-available-mib read MemAvailable from /proc/meminfo and did nothing when it could not, so the run proceeded unguarded. A floor the host cannot measure is now refused at entry, naming the flag and --min-mem-available-mib 0 for a run without one (EP-CONFIG). A phase's side report counts the checks at which MemAvailable could not be read mid-run (mem_available_unread_checks), so a floor that lapsed does not read as having held (EP-OBSERVABILITY). - pg_stat_statements was preloaded only when pkglibdir held pg_stat_statements.so; Homebrew ships pg_stat_statements.dylib. Either name is accepted. - The cluster root under macOS's default TMPDIR put PostgreSQL's socket at 107 bytes, over the 103 it accepts, and the harness exited with "pg_ctl failed" and no reason, because the log went with the root. The root's random part is 12 hex digits instead of 32, which fits that TMPDIR; a base too deep for the socket is refused before anything is created, naming TMPDIR and the platform limit; and a server that does not start reports the last lines of its own log beside pg_ctl's output. The README records macOS as supported for smoke runs, with the memory floor, peak-RSS and TMPDIR caveats. A new gated test starts a cluster PostgreSQL refuses and checks the error carries the server's reason; its id is added to test/prism-gated-tests.txt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. |
kiwidream
left a comment
There was a problem hiding this comment.
Review by a delegated agent on behalf of workstream A (head d68320e).
Verdict: approve. Nothing blocks the merge. The entry refusal happens before any side effect, and no existing Linux invocation now refuses. The socket limits match PostgreSQL 16; I checked them on a real server at 107 and 108 bytes. The gated test proves the log-tail path. The findings below are low-severity gaps in tests and docs. The stale note in tests/quorum_replication.rs should be fixed in this PR.
Findings
Low
crates/qbit-prism-load/tests/quorum_replication.rs:9 — the TMPDIR=/tmp note is now wrong.
The note says macOS's default temp directory is too deep for the 103-byte limit, so the test should be run with TMPDIR=/tmp. With the 12-hex root, the socket under the default /var/folders/<2>/<30>/T/ is 87 bytes, so the default works. Suggested wording: "The managed cluster puts its Unix socket in a prism-load-<12 hex> root under the process temp directory. Under macOS's default TMPDIR that is 87 bytes, inside the 103-byte limit. A TMPDIR deeper than 64 bytes (68 on Linux) is refused by TempRoot::create before anything is created, naming the limit." This is documentation only, so no test applies.
crates/qbit-prism-load/src/run.rs:696 — no test covers the call that wires the entry refusal.
a_memory_floor_the_host_cannot_measure_is_refused_at_entry calls measure::verify_memory_floor directly. If the verify_memory_floor(...) line in execute were deleted, all five new tests would still pass, and macOS runs would again go unguarded. That fails EP-VALIDATION: the test does not prove the entry claim. execute reads the hard-coded MEMINFO_PATH, so on Linux no test can reach the refusal. Test that would catch it: give execute a way to take the meminfo source (for example a crate-private execute_with_meminfo(args, &Path)). Drive it with a nonexistent path and the default floor, then assert the error names --min-mem-available-mib and that --out was not created.
crates/qbit-prism-load/src/run.rs:2054 and :2253 — mem_available_unread_checks has no test, and zero does not always mean guarded.
(a) Removing the += 1 at :2253, or the initial u64::from(...is_none()) at :2054, fails no test. (b) The initial value counts the phase-start read. That read is not a floor check, since nothing is compared against the floor at phase start, yet the field doc at :1990 and the README describe the counter as counting "once-a-second floor checks". (c) A phase shorter than one second, or one that breaks out of the loop early, makes no floor check at all and reports 0. The README says "a non-zero count means the phase was not guarded throughout", but the reverse does not hold. Under EP-OBSERVABILITY an unknown should not look like healthy. Failure scenario: a sub-second phase reports mem_available_unread_checks: 0 and min_mem_available_kib set from the start read, and reads as guarded without ever being checked. Suggested fix: also report the number of floor checks made (mem_available_checks), or state in the doc that zero means "no failed read", not "guarded". Test: a drive_phase run with a fake meminfo that fails once, asserting the count, plus a sub-second phase asserting the checks total is 0.
Other answers on this counter. It lives in PhaseOutcome, which is built fresh in each drive_phase, so it resets per phase. It is serialised in the side report's phases[] (not in the capacity artifact, so the server's validator is unaffected). It is documented in the README's quiet-host paragraph. On Linux it can be non-zero without a missing file: read_to_string fails with EMFILE when the harness exhausts its raised RLIMIT_NOFILE, and with ENOMEM under memory pressure, which is exactly when the floor matters. Permissions and containers are not a realistic cause: /proc/meminfo is mode 0444, and lxcfs and gVisor both provide MemAvailable.
crates/qbit-prism-load/src/cluster.rs:431 — no boundary test for the socket-length check.
The test uses a base that is MAX_SOCKET_PATH_BYTES bytes deep, far past the limit. Changing <= to < would refuse a valid 107-byte path, and no test would catch it. Test that would catch it: create_in with a base sized so the widest socket is exactly MAX_SOCKET_PATH_BYTES bytes is accepted (then clean up), and one byte deeper is refused. I confirmed the real boundary on PostgreSQL 16.15 on Linux: a 107-byte socket path starts, and a 108-byte one logs Unix-domain socket path "…" is too long (maximum 107 bytes) and then FATAL: could not create any Unix-domain sockets.
Nit
crates/qbit-prism-load/README.md:87,crates/qbit-prism-load/src/cluster.rs:392—<28>should be<30>. The per-user component of macOS'sTMPDIRis 30 characters (for examplek3n2y0yd5hs2_4nq2f4w0m8h0000gn). The test's sample path uses 30, and the 107 and 87 figures only hold with 30; with 28 they would be 105 and 85. The test comment says "49 bytes"; the sample is 48 without the trailing slash.crates/qbit-prism-load/README.md:95— the only full command uses Linux paths and no--min-mem-available-mib. Copied onto macOS, it is refused with a message that names the fix, so nothing breaks. A macOS smoke-run line would save a round trip, e.g.--pg-bin-dir "$(brew --prefix postgresql@16)/bin" --min-mem-available-mib 0. The macOS bullet above it does say to pass0.crates/qbit-prism-load/src/cluster.rs:617— the call site is not tested.pg_stat_statements_is_found_as_a_shared_object_or_a_dylibtests the helper. If the call site reverted to.join("pg_stat_statements.so"), the test would still pass. This is low risk because the change is one line.
Answers to the owner's questions
- Entry refusal.
run::executehas one caller,src/main.rs.Args::validateis unchanged. The commands indocs/prism-throughput-measurements.md(--min-mem-available-mib 6144) run on Linux, whereMemAvailableis readable, so they are unaffected. CI never runs the binary: tests calldrive_phasewith--min-mem-available-mib 0, or parseArgs, and never callexecute.examples/ha_qualification.rsandtests/quorum_replication.rscallManagedPostgres::startdirectly and skip the check. The refusal comes right aftervalidateand beforeresolve_bin_dir,claim_out_dir,create_dir_all(log_dir),gitand any cluster, so it has no side effect. The README's macOS bullet tells the reader to pass--min-mem-available-mib 0. There is no macOS example command (see Nit). - Socket limit constants. Both are correct. PostgreSQL 16 defines
UNIXSOCK_PATH_BUFLENassizeof(sun_path)insrc/include/libpq/pqcomm.h(notport.h). The buffer size counts the terminator, andStreamServerPortrefuses whenstrlen(path) >= UNIXSOCK_PATH_BUFLEN. The longest accepted path is therefore 107 on Linux (108 − 1) and 103 on macOS and the BSDs (104 − 1). I confirmed 107 accepted and 108 refused on 16.15.not(target_os = "linux")→ 103 is conservative on platforms whosesun_pathis larger..s.PGSQL.65535is the right worst case: five digits is the widest port, and the.lockfile beside it is a regular file with nosun_pathlimit. The standby started byReplication::Async/Syncuses the same-k <root>as the primary (cluster.rs:707), so the one check covers both sockets. - Root creation. With
create_dir, a missing temp directory now fails ascreate cluster root <path>: No such file or directory. Previouslycreate_dir_allwould have createdTMPDIRitself. I think the new behaviour is better. The first 12 characters of a v4 simple UUID are all random (the version nibble is character 13), which gives 48 random bits. A collision fails withEEXISTand is not retried; it is never shared.keepand removal on drop are unchanged. Nothing depends on the 32-hex name:scripts/prism_ha_qualification.py:91,186,examples/ha_qualification.rs:575andtests/test_prism_ha_qualification.pymatch only theprism-load-prefix. The qualification script'sTMPDIRis/tmp/b281-XXXXXXXX, well inside the limit. - Failure reporting.
log_tailreads the whole file. That file is the log of a freshlyinitdb'd cluster's firststart(primary) or first start afterpg_basebackup(standby), so in practice it is small, andstarthas no other callers. After a failed primary start, the?atcluster.rs:630drops theTempRoot, which removes the root unlesskeep. After a failed standby start,managed.stop()runs, and droppingManagedPostgresdrops the root. The error text ("removed with the cluster root unless --keep-artifacts") matches.max_connections=0fails inside the server, not inpg_ctl: I ran it by hand on 16.15.pg_ctlprints onlywaiting for server to start.... stopped waiting / pg_ctl: could not start server / Examine the log output., and the log holdsFATAL: 0 is outside the valid range for parameter "max_connections" (1 .. 262143). The assertionerror.contains("max_connections")can therefore only be satisfied by the log tail. On the base, the test would fail on bothPostgreSQL did not startandmax_connections. (Pre-existing and out of scope: ifpg_ctl -t 120times out while the postmaster is still starting,runningstays false, sostopskips it and the root is removed under a live server.) - The unread-checks counter. See the finding above.
- Tests.
- Four of the five cannot compile on the base, because they call new API:
verify_memory_floor,mem_available_kib_at,pg_stat_statements_library,TempRoot::create_in,log_tail. - On behaviour,
…too_deep…refused_before_it_is_createdwould fail on the old code for the stated reason: the real root name's length is 43 before, 23 now. a_failed_start_carries_the_end_of_the_server_logcovers the helper's tail, empty and missing cases.- The gated test would fail on the base for the stated reason (item 4).
- The memory-floor and
pg_stat_statementstests prove their helpers, not the wiring (findings above). - The
quorum_replication.rsnote is wrong now (first finding).
- Four of the five cannot compile on the base, because they call new API:
Command log
Run on a Linux host at the PR head, toolchain 1.98.1:
cargo build --locked -p qbit-prism-load: passed.cargo clippy --locked -p qbit-prism-load --all-targets -- -D warnings: passed, no warnings.cargo test --locked -p qbit-prism-load: passed. The harness had 132 passed and 0 failed. In this run the gated test skipped through the gate (PRISM_TEST_PG_BIN_DIR is unset) and was reported as ok.test/prism-native-tests.sh cargo-args --locked -p qbit-prism-load --test harness(PostgreSQL 16.15): passed, 132 passed and 0 failed. The manifest readsexecuted qbit-prism-load::harness::a_managed_cluster_that_fails_to_start_reports_the_servers_own_reason.python3 scripts/check_gate_env_reads.py: passed ("no direct reads … in 317 Rust files").- By hand with PostgreSQL 16.15
initdbandpg_ctl:-c max_connections=0:pg_ctlexit 1, and the reason appears only in the server log.-kso the socket path is 107 bytes: started.- 108 bytes: refused,
maximum 107 bytes.
- Path arithmetic: the macOS sample base is 48 bytes, the socket is 87 bytes with 12 hex and 107 with 32. The deepest base that fits is 64 bytes on macOS and 68 on Linux.
- Not run: anything on macOS;
scripts/check_gate_manifest.pyagainst the full CI manifest. CI's default mode runs--workspace --all-targets, so the new gated test will execute inprism-native-postgres, but I did not check that here.
Brings in #470, #512, #513, #514 and #515. #515 opens the share append's transaction through AppendConnection::begin, which records BEGIN completion so that a future cancelled before the reply retires the connection instead of returning it to the pool; this branch opens the same transaction with "BEGIN; SET LOCAL plan_cache_mode = force_generic_plan" so the share_id probe is planned once per connection. Resolution keeps both: AppendConnection::begin takes the opening statement and the append passes APPEND_TRANSACTION_BEGIN. SQLx reads every reply of that simple query through its ReadyForQuery before begin returns, so the guard records completion only once the whole batch is in. ledger_cancelled_begin now cancels the append on the custom BEGIN, and a new case holds only the batch's closing ReadyForQuery (the execution proxy gains pause_statement_ready) and proves the connection is still retired. The pool-acquire inventory, the gated-test manifest and the #482 ops notes follow the new call sites. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Addresses review on #564. A counted run whose phases count any mem_available_unread_checks (#514) went unguarded for a while, whatever its other readings said, so it now fails the memory floor. A harness older than #514 counts none and is held to its readings alone, so comparisons against 5d0042f still read. The smoke test asserts a real report counts none. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… wait out descendants that outlive SIGKILL (#511) Addresses review on #564. legacy-flags.json gains report_fields, the side-report fields added after 5d0042f with the commit that added each (mem_available_unread_checks at 8c3e0ac, #514). The driver records in the manifest which of them each build's history predates, and the comparator requires the count in every phase of every other build, so a newer candidate that drops it fails rather than passing on its readings alone. The driver's descendant sweep no longer gives up ten seconds after SIGKILL: it keeps killing and waiting, locks held, until nothing is left below it, and says what it is waiting for. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #485 (workstream A, #261; found when #447 ran on macOS). Harness only:
crates/qbit-prism-load. No server change.Three portability gaps, each silent before:
--min-mem-available-mibreadMemAvailablefrom/proc/meminfoand did nothing when it could not, so the run proceeded unguarded with onlymin_mem_available_kib: nullto show for it. A floor the host cannot measure is refused at entry, naming the flag and--min-mem-available-mib 0for a run without one (EP-CONFIG). Each phase's side report also carriesmem_available_unread_checks, the once-a-second checks at which the read failed mid-run, so a lapsed floor does not read as having held.pg_stat_statements. It was preloaded only whenpkglibdirheldpg_stat_statements.so; Homebrew shipspg_stat_statements.dylib, so on macOS every lock-statement column readn/a. Either name is accepted.TMPDIRthe cluster root put PostgreSQL's socket at 107 bytes, over the 103 it accepts, and the harness exited withpg_ctl failedand no reason because the log went with the root. The root's random part is 12 hex digits instead of 32 (87 bytes there); a base too deep for the socket is refused before anything is created, namingTMPDIRand the platform limit; a server that does not start reports the last 20 lines of its own log besidepg_ctl's output.README: macOS is supported for smoke runs, with the memory-floor, peak-RSS and
TMPDIRnotes; the Tests section lists the gated tests.Tests (
tests/harness.rs): the entry refusal with an injected meminfo path; the library under either suffix; a root too deep for the socket refused before creation; the log tail; and one gated test that starts a cluster PostgreSQL refuses (max_connections=0) and checks the error carries the server's own reason. Its id is added totest/prism-gated-tests.txt.Not covered. No macOS run: (1) and (3) are exercised on Linux by injection and a forced deep base (the limit is 107 there, 103 on macOS). No
--work-dirflag; the shorter root plus the entry refusal covered the problem.tests/quorum_replication.rsstill carries a doc note advisingTMPDIR=/tmpon macOS, now stale.Verification.
cargo fmt --all --check;cargo clippy --locked --workspace --all-targets -- -D warnings;scripts/check_gate_env_reads.py;scripts/check_prism_settings.py;cargo test --locked -p qbit-prism-load(132 harness tests); the new gated test executed undertest/prism-native-tests.sh(manifest: executed);--test quorum_replicationunder the same script starts a real primary and standby under the shorter root. Written by a delegated worker; reviewed and re-verified by the coordinator.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.