Skip to content

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

Merged
kiwidream merged 1 commit into
3.x.xfrom
harness-485-macos-portability
Sep 24, 2026
Merged

kiwidream merged 1 commit into
3.x.xfrom
harness-485-macos-portability

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

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:

  1. Memory floor. --min-mem-available-mib read MemAvailable from /proc/meminfo and did nothing when it could not, so the run proceeded unguarded with only min_mem_available_kib: null to show for it. A floor the host cannot measure is refused at entry, naming the flag and --min-mem-available-mib 0 for a run without one (EP-CONFIG). Each phase's side report also carries mem_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.
  2. pg_stat_statements. It was preloaded only when pkglibdir held pg_stat_statements.so; Homebrew ships pg_stat_statements.dylib, so on macOS every lock-statement column read n/a. Either name is accepted.
  3. Socket path. Under macOS's default TMPDIR the cluster root 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 (87 bytes there); a base too deep for the socket is refused before anything is created, naming TMPDIR and the platform limit; a server that does not start reports the last 20 lines of its own log beside pg_ctl's output.

README: macOS is supported for smoke runs, with the memory-floor, peak-RSS and TMPDIR notes; 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 to test/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-dir flag; the shorter root plus the entry refusal covered the problem. tests/quorum_replication.rs still carries a doc note advising TMPDIR=/tmp on 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 under test/prism-native-tests.sh (manifest: executed); --test quorum_replication under 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


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

…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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 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-24T17:38:23.475434Z d68320e PR opened
ℹ️ 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.

@kiwidream kiwidream left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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's TMPDIR is 30 characters (for example k3n2y0yd5hs2_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 pass 0.
  • 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_dylib tests 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

  1. Entry refusal. run::execute has one caller, src/main.rs. Args::validate is unchanged. The commands in docs/prism-throughput-measurements.md (--min-mem-available-mib 6144) run on Linux, where MemAvailable is readable, so they are unaffected. CI never runs the binary: tests call drive_phase with --min-mem-available-mib 0, or parse Args, and never call execute. examples/ha_qualification.rs and tests/quorum_replication.rs call ManagedPostgres::start directly and skip the check. The refusal comes right after validate and before resolve_bin_dir, claim_out_dir, create_dir_all(log_dir), git and 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).
  2. Socket limit constants. Both are correct. PostgreSQL 16 defines UNIXSOCK_PATH_BUFLEN as sizeof(sun_path) in src/include/libpq/pqcomm.h (not port.h). The buffer size counts the terminator, and StreamServerPort refuses when strlen(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 whose sun_path is larger. .s.PGSQL.65535 is the right worst case: five digits is the widest port, and the .lock file beside it is a regular file with no sun_path limit. The standby started by Replication::Async/Sync uses the same -k <root> as the primary (cluster.rs:707), so the one check covers both sockets.
  3. Root creation. With create_dir, a missing temp directory now fails as create cluster root <path>: No such file or directory. Previously create_dir_all would have created TMPDIR itself. 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 with EEXIST and is not retried; it is never shared. keep and removal on drop are unchanged. Nothing depends on the 32-hex name: scripts/prism_ha_qualification.py:91,186, examples/ha_qualification.rs:575 and tests/test_prism_ha_qualification.py match only the prism-load- prefix. The qualification script's TMPDIR is /tmp/b281-XXXXXXXX, well inside the limit.
  4. Failure reporting. log_tail reads the whole file. That file is the log of a freshly initdb'd cluster's first start (primary) or first start after pg_basebackup (standby), so in practice it is small, and start has no other callers. After a failed primary start, the ? at cluster.rs:630 drops the TempRoot, which removes the root unless keep. After a failed standby start, managed.stop() runs, and dropping ManagedPostgres drops the root. The error text ("removed with the cluster root unless --keep-artifacts") matches. max_connections=0 fails inside the server, not in pg_ctl: I ran it by hand on 16.15. pg_ctl prints only waiting for server to start.... stopped waiting / pg_ctl: could not start server / Examine the log output., and the log holds FATAL: 0 is outside the valid range for parameter "max_connections" (1 .. 262143). The assertion error.contains("max_connections") can therefore only be satisfied by the log tail. On the base, the test would fail on both PostgreSQL did not start and max_connections. (Pre-existing and out of scope: if pg_ctl -t 120 times out while the postmaster is still starting, running stays false, so stop skips it and the root is removed under a live server.)
  5. The unread-checks counter. See the finding above.
  6. 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_created would 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_log covers 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_statements tests prove their helpers, not the wiring (findings above).
    • The quorum_replication.rs note is wrong now (first finding).

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 reads executed 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 initdb and pg_ctl:
    • -c max_connections=0: pg_ctl exit 1, and the reason appears only in the server log.
    • -k so 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.py against the full CI manifest. CI's default mode runs --workspace --all-targets, so the new gated test will execute in prism-native-postgres, but I did not check that here.

@kiwidream
kiwidream merged commit 8c3e0ac into 3.x.x Sep 24, 2026
21 checks passed
@kiwidream
kiwidream deleted the harness-485-macos-portability branch September 24, 2026 18:34
djh58 added a commit that referenced this pull request Sep 25, 2026
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]>
Anatolie added a commit that referenced this pull request Sep 30, 2026
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]>
Anatolie added a commit that referenced this pull request Oct 1, 2026
… 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]>
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