Repository navigation
3.1 dual-writer (4/5): dual-writer readiness and Stratum gating - #769
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. |
This comment has been minimized.
This comment has been minimized.
359539d to
7a2ea81
Compare
2daef48 to
6cc825b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c2eae8d28e
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd227caef6
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9549ef2907
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ae28d7ec58
ℹ️ 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".
4b1e8e5 to
21cf3ae
Compare
Rebased onto 3.x.x after #767 was squash-merged (44fd3e4), as one commit: the branch merged D3 heads, so a commit-by-commit replay conflicts. The tree is identical to the reviewed head 571fc6b. Co-Authored-By: Claude Opus 5.5 <[email protected]>
571fc6b to
2c5d7b8
Compare
The notes cover everything since v3.0.0-rc.6: #770's import-audits fix (#765) and #760's idle-connection bound (#759), which would have shipped as rc.7, and the 3.1 dual writer (#766, #768, #767, #769, #763), off by default. They describe the new settings, migrations 027, 028 and 031 (029 and 030 reserved), the upgrade from rc.6 with the migrate run while rc.6 serves, the rollbacks, and the dual writer's known limits. The migration guide's import-audits paragraph names this candidate in place of the skipped rc.7. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* 3.x.x: version 3.1.0-rc.1 VERSION, the workspace version and both lockfiles move to 3.1.0-rc.1. The fuzz lockfile also picks up hyper and hyper-util, which #769 added to the server without refreshing it. The 3.0.0 and development-line notes point at the new candidate; its own notes follow in this pull request. Co-Authored-By: Claude Opus 5.5 <[email protected]> * 3.x.x: 3.1.0-rc.1 release notes The notes cover everything since v3.0.0-rc.6: #770's import-audits fix (#765) and #760's idle-connection bound (#759), which would have shipped as rc.7, and the 3.1 dual writer (#766, #768, #767, #769, #763), off by default. They describe the new settings, migrations 027, 028 and 031 (029 and 030 reserved), the upgrade from rc.6 with the migrate run while rc.6 serves, the rollbacks, and the dual writer's known limits. The migration guide's import-audits paragraph names this candidate in place of the skipped rc.7. Co-Authored-By: Claude Opus 5.5 <[email protected]> * 3.x.x: 3.1.0-rc.1 notes: #773's pre-migrate tests Co-Authored-By: Claude Opus 5.5 <[email protected]> * 3.x.x: 3.1.0-rc.1 notes: the rollback to one writer stops and syncs the peer first Codex on #774: DOWNGRADE fences nothing, so the peer must be stopped, and its tail pulled, before the single-writer start; declare the tail lost only for a peer that never returns with its own database. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Caution
Do not merge: part of the 3.1 stack, teed up for review.
Stack position 4/5 of the PRISM 3.1 dual-writer stack: #766 (1/5, identity and peer sync), #768 (2/5, window cuts), #767 (3/5, carry owner), this PR, then #763 (5/5, E2E). Its base is #767's branch,
RobertClarke/p31-carry-owner, so this diff is the readiness work alone.PRISM 3.1 keeps mining online when either node of the pair dies by routing on readiness. This PR is what a frontend tells the balancer, and how its Stratum listeners follow it. It adds the
/healthzdual_writerobject, and gates readiness on the own-log latch and on a local writer. It also adds Stratum listeners that accept only while the frontend admits miners, the token-protected readiness-only endpoint the Hashbalancer checks, a liveness container healthcheck for dual mode, and their metrics.With
PRISM_DUAL_WRITERoff andPRISM_READINESS_PORTunset, the defaults,/healthz, the healthcheck and the Stratum listeners behave as in 3.0 and no readiness statement runs.The doc is
docs/prism-dual-writer-readiness.md. The Hashbalancer's routing on it is a separate PR in the balancer's repository.What changes
Readiness in dual mode (
coordinator.rs,readiness/dual_writer.rs).okandreadyalso need:PeerSyncStatus.own_log_caught_up), which a lost peer never clears;PRISM_NODE_INDEXin its never-copiedqbit_prism_node_identityrow, is not in recovery and is not read-only.statusnames the first that fails (own-log-behind, thenwriter-not-local), after 3.0'sruntime-stalledandjob-delivery-stalled./healthzgainsdual_writer: {node_index, carry_owner, own_log_caught_up, peer_sync, writer_path}.writer_pathislocal,remote(the row names the peer),unidentified(no row),read_onlyorunanswered. It comes from one statement on the frontend's own pool, reused for a second and bounded at two seconds, and it never reads the peer.Admission (
readiness/admission.rs):starting,admitting,grace,withdrawn.PRISM_READINESS_GRACE_SECONDS(default 10, 0 to 120), counted from the last publication that found the frontend ready, keeps admitting. Every new tip and payout revision causes such a dip.own-log-behindandwriter-not-localwithdraw at once.mining.get_healthincluded). The heartbeat runs as its own task, so publications keep coming./readyzturned503about 3 s later; with every ledger connection held busy, the writer stayslocal; 50 concurrent health calls share one refresh.Reported as
/healthzadmissionin dual mode or with the endpoint on.Stratum gating, dual mode only (
listen.rs,stratum.rs,server.rs). Each listener binds at startup, before the coordinator, as in 3.0, but listens only while the frontend admits:remote,unidentifiedorread_only) also closes established sessions. Each session finishes the request in hand, gets a 3 s drain, and only then is aborted, so no share lands in a database that is not this node's. After a not-ready or unanswered withdrawal, sessions carry on until the balancer closes them.The accept loop is shared with 3.0's listener, which is otherwise unchanged and is still what a single writer runs. The peer sync's own wait stays on the refresh and submit loops; the listeners follow admission alone, so there is one gate.
Readiness endpoint (
readiness/endpoint.rs). Settings:PRISM_READINESS_PORT(off by default),PRISM_READINESS_BIND(127.0.0.1),PRISM_READINESS_TOKENor_TOKEN_FILE(a group-readable0440file is fine).GET|HEAD /readyzwithX-Qbit-Healthcheck-Tokenanswers200 ready,503 not ready,401(the token is checked first) or404.no-store,Connection: close.Container healthcheck (
tools.rs). In dual modeqbit-prism-server healthcheckchecks liveness. Routing uses/readyz, and a converge must not time out while a node catches up after a restart, restore or rebuild.remote,unidentifiedorread_only(orunansweredonce admission has withdrawn), or readiness lost past the grace.self-checkkeep 3.0's readiness rule.Metrics:
qbit_prism_admission_admitting,_state{state}and_withdrawals_total{reason};qbit_prism_stratum_listener_accepting{listener};qbit_prism_dual_writer_writer_path{path},_node_indexand_carry_owner;qbit_prism_readiness_requests_total{result}.They are declared without samples unless dual mode or the endpoint exposes admission. In a stale snapshot
admission_admittingandstratum_listener_acceptingread 0, whileadmission_statekeeps the last decision. The inventory, metadata and observability contract are updated, and the pins are combined with the carry-owner families.Settings: five names in
config/native-settings.txt;check_prism_settings.pylearnsPRISM_READINESS_TOKEN_FILE;docs/prism-configuration.mddocuments them, and the HA reference's readiness contract points to the new doc.How it was tested
/code-review mediumrounds and a read-only fact-check of every doc claim against the code; findings fixed.cargo fmt --checkandcargo clippy --all-targets;check_prism_settings.pyandgenerate_prism_metrics.py --checkpass.tests/healthcheck_cli.rs: the healthcheck binary against canned/healthzanswers in both modes.tests/stratum_admission_gate.rs, at the socket level: refusal until admitted, refusal again after a withdrawal while an established session is served, closure when the decision goes stale, a definite fault closing established sessions (after answering a request in flight), and a silent database leaving them open.PRISM_TEST_REQUIRE_INTEGRATION=1:tests/dual_writer_readiness.rs: the latch and the identity at the coordinator (unidentified, thenlocal;remotefor a database personalised as the peer), a database turned read-only and back, the peer lost after the latch, the writer stayinglocalwith every ledger connection busy (it fails when pointed back at the ledger pool), a burst of 50 health calls sharing one refresh, a single writer's unchanged health.tests/readiness_frontend.rs, the server binary against the fake node:/readyzanswers503and401;200;200, and a rebuild held open keeps200for the whole default grace, turns503only after it, and is readmitted;200and accepts Stratum; with its database frozen behind a proxy it answers503within 10 s and refuses Stratum, and it is readmitted once the database answers again.carry_owner_postgres,carry_owner_adoption,dual_writer_windows) pass on it.test/prism-gated-tests.txt.Notes
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.