Repository navigation
3.x.x: a submitblock whose connect outlasts its budget fails as not sent, so its block is offered again (#762) - #797
Merged
Conversation
…s not sent, so its block is offered again (#762) submitblock runs under PRISM_BLOCK_SUBMIT_RPC_TIMEOUT_SECONDS (1 s by default), but the node client's connect timeout is 5 s. With no idle pooled connection and a slow connect (a lost SYN, a full accept queue, a slow name lookup), the request deadline fired during the connect. reqwest reports that as TimedOut, not is_connect(), so the call failed as a plain "transport failed", the offer was recorded as unknown, and a block that never left the frontend was never offered again. The change: - Rpc's client gets a connector layer. A connect started by a relaying call with its own deadline fails, as a connect error, at half that deadline. The instant is fixed when the call starts and reaches the connector through a task-local, because hyper starts the connect from the requesting task. - The not-sent boundary is unchanged: RpcNotSentError is still exactly hyper's Connect error kind (#522). hyper reports a failed connect only to a request it has not handed a connection. A request handed a pooled connection meanwhile goes on; the abandoned connect fails in the background, and the outcome stays the request's own. - The request deadline still bounds the whole call, connect included. Reads, calls without their own deadline, and node_client_builder() are unchanged, as is the 20 s idle-pool bound. Why not the other options in the issue: - Marking "connection established" in a connector layer is unsafe. hyper-util races the pool checkout against a new connect, so a request can be written on a checked-out connection while its own connect is still running. A deadline then would be taken for unsent. - The exact per-request marker (hyper-util's capture_connection) is unreachable: reqwest 0.12 does not pass request extensions to hyper. - A probe before submitblock is safe, but it costs a round trip on the block path. It also cannot guarantee that submitblock reuses the probed connection: another call can take it, or the node can close it. Tests: - rpc_not_sent: a submitblock whose TLS handshake never completes is RpcNotSentError ("timed out") at half its deadline. A read keeps the plain timeout. - rpc_not_sent: a submitblock written to a pooled connection while its own connect is stalled stays unknown. A full accept queue stalls the connect. - offer_not_sent_tests (PostgreSQL): the slow-connect row returns to pending, and the next claim lands the block with one submitblock. A deadline after the request was written stays unknown and is never offered again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the next call, and says why it was cut (#762) Review fixes for the #762 connect bound. - A relaying call with its own deadline still stops waiting for a new connection at its budget, relay_connect_budget(deadline): the first 1/RELAY_CONNECT_DIVISOR (half) of it. The connect itself no longer dies there. It runs in its own task, bounded by the client's 5 s connect timeout, and one established after its call stopped waiting is kept as the client's spare. - That covers a cut call, and a connect hyper moved to the background because its request took a pooled connection. The next connect the client starts takes the spare at once, if it is younger than the idle bound and a read finds the node has not closed it. So the re-offer after a cut finds its connection ready. The spare never carried a request, so the not-sent boundary is unchanged. - The cut's reason reaches RpcNotSentError and the offer's last_error: "no connection within 500ms, its share of the call's 1s deadline", instead of a generic "timed out". - The connect share is the named constant RELAY_CONNECT_DIVISOR, used by the code, the tests and the docs. Tests (rpc_not_sent): - a_connect_cut_at_its_budget_serves_the_next_call: after a cut connect gets through, the next submitblock goes out on its connection. - The pooled-connection test now also checks that hyper's background connect is not abandoned at the connect deadline. - The TLS-stall test: a second call, started after the first's whole deadline, gets its own budget. It also asserts the cut's reason, and times only with a lower bound plus a hang guard. - a_relaying_call_without_its_own_deadline_keeps_the_clients: submitblock and sendrawtransaction without their own deadline keep the client's deadline. - A kernel that does not drop SYNs to a full listen(0) queue now skips the accept-queue tests, saying why, instead of panicking. The README's PRISM_BLOCK_SUBMIT_RPC_TIMEOUT_SECONDS row and both runbook lines describe the connect share and the kept connect. 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0a7ea3d59
ℹ️ 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".
…open, and let a long deadline's cut win over the connect timeout (#762) Review fixes for d0a7ea3. - The spare's liveness check asks the kernel. A noop-waker poll_read reports Pending when the coop budget is spent, or before the reactor has seen a FIN that already arrived. A spare the node had closed could then be handed out, the submitblock written into it, and the offer left unknown. Now the client finds the spare's TCP socket once, when it parks it: the descriptor under /proc/self/fd whose addresses match the connection's HttpInfo. When a connect would take the spare, the client peeks at that socket with MSG_PEEK | MSG_DONTWAIT, below any TLS layer. Only EAGAIN hands the spare out. A FIN, any byte, an error, or a descriptor that no longer holds the socket drops it. Off Linux no spare is kept. - The spare is kept only while younger than the pool's idle bound (20 s by default, under qbitd's 30 s idle close). Its park time is now checked when it is taken, in place of the generation counter and the expiry task. - A request that fails on a spare before any byte is written stays unknown. hyper-util 0.1.20 knows that such a request on a new connection came back unwritten, but its error kind for it (Canceled) is private, so the call cannot prove it unsent. The check-to-write race is the same one the pool has. - relay_connect_budget caps the budget at 4.9 s, 100 ms under the 5 s connect timeout. Before, a deadline of 10 s or more raced the plain connect timeout, which could win and say only "connect failed". - The accept-queue tests fail, rather than skip, on a kernel that does not drop SYNs to a full queue, unless PRISM_TEST_ALLOW_SYN_SKIP=1 is set. Tests (rpc_not_sent): - a_spare_the_node_closed_is_never_handed_out: the node closes the spare while the runtime is blocked; the next call opens a new connection. - a_long_deadline_reports_its_cut_before_the_connect_timeout: a 10 s deadline reports its 4.9 s cut, on a paused clock. The README row and both runbook lines now say that a call that took a pooled connection meanwhile keeps that request's outcome. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 28, 2026
kiwidream
added a commit
that referenced
this pull request
Nov 11, 2026
…d is offered again, and the payout-revision listener reports its health (#816) Refs #816 (items 3 and 1; item 2, the lagging-node wake, is out of scope). Follow-up to #797/#762 and #795. One PR for both parts: they share no code, but each is small and both are 3.1.2 follow-ups to the same review (#811). Split commits would only cost the operator another hardware-key touch. ## Part A: a submitblock hyper hands back unwritten counts as not sent (#816 item 3) ### Problem `Rpc::call_timeout` mapped a send error to `RpcNotSentError` only when `error.is_connect()`. Suppose the node or a proxy closes the parked spare connection after `take_spare`'s kernel check but before hyper writes the request. hyper then hands the request back unwritten, and hyper-util doesn't retry it, because the spare is a new connection. The call failed as the plain `transport failed`, `classify_offer` recorded `OfferOutcome::Unknown`, and the block was never offered again although it never left the frontend. ### Change - `RpcNotSentError` is also returned when the send error's chain holds hyper-util's `Canceled` error (named by its `Display`, `client error (Canceled)`: the kind is private) directly over a canceled `hyper::Error`. Any other kind, source or text stays Unknown. Callers can tell the two cases apart through a new `stage: NotSentStage` (`Connect`, `Returned`). The connect message is unchanged. The new one reads `... transport failed before the request was sent: the connection closed before the request was written (<hyper's reason>)`. - **Source audit** (hyper 1.11.1, hyper-util 0.1.20, reqwest 0.12.28; no `h2` in `Cargo.lock`, so HTTP/1 only): - hyper's client builds a canceled error only with the request in hand, unwritten. There are three sites: `SendRequest::try_send_request` (connection not ready), the dispatch `Envelope` drop (the dispatcher went away with the request still queued), and `proto/h1/dispatch.rs` `recv_msg` (the dispatcher read a close or an error before it took the queued request). - The dispatcher takes a request out of the queue only to write it. Any failure after that is the connection's own error, never canceled. The only other canceled site, `OnUpgrade`, is not on the send path. - hyper-util wraps a canceled error as its `Canceled` kind only when `take_message()` returns the request, and retries it only on a reused connection. - reqwest's default retry policy acts only on HTTP/2 and HTTP/3 errors. - **Kept Unknown:** a close that hyper reads before hyper-util has handed the connection the request at all. hyper-util reports it as `SendRequest(IncompleteMessage)`, exactly like a close after a write, so it can't be proven unsent. - A tripwire test fails if hyper, hyper-util or reqwest change version, or `h2` enters the build, so the audit must be redone first. - Doc comments in `rpc.rs` (`RpcNotSentError`, `ConnectBoundLayer`), on `offer_not_executed` in `coordinator.rs` and on `release_unsent_offer` in `ledger/candidates.rs`, plus the #522 paragraph and the `offer_reserved` and `reconciliation` rows of `docs/prism-ledger-ops.md`, now describe the new case (prose only). - **Test seam:** a `#[doc(hidden)]` `SpareObserver` set through `Rpc::observe_spare`. It reports when a spare is parked and when one is handed out, before hyper has the request. When no observer is set, it costs one `OnceLock` read per spare hand-out. ### Tests (`tests/rpc_not_sent.rs`, `coordinator/offer_not_executed_tests.rs`) - `a_spare_the_node_closes_after_its_check_returns_the_submitblock_unsent`: - When the spare is handed out, the observer half-closes the node's end and waits for the kernel to report the FIN (a condition, not a sleep). The current-thread runtime's order then makes hyper's connection task read the close before it takes the queued request. - The call fails as `RpcNotSentError { stage: Returned }`, and the node's end reads 0 bytes before the client's own close. - The re-offer goes out on a new connection and the node takes the block exactly once. - It fails with the new rule disabled, and passed 30 of 30 repeats. - `a_spare_the_node_closes_after_reading_the_submitblock_may_have_been_sent`: the node reads the request off the spare and closes without replying. The outcome stays unknown (`transport failed`, not `RpcNotSentError`). - `the_not_sent_proof_covers_the_http_stack_in_the_lockfile`: the version tripwire above. - `land_a_cut_connect` now waits until the spare is actually parked instead of relying on a 100 ms sleep. `a_spare_the_node_closed_is_never_handed_out` also checks that the spare was never handed out. - `a_request_returned_unwritten_is_not_executed`: the offer path treats the new stage as not executed, so the reservation returns to `pending`. ## Part B: payout-revision listener health metrics (#816 item 1) ### Problem The #752 listener's only signal was a WARN, logged at most once a minute. A listener that is connected but hears nothing (for example through a transaction-pooling proxy) logged nothing at all. Such a frontend silently falls back to the blockpoll tick: after another frontend's block, its shares on new-tip work are refused `stale-job` until its next tick. ### Change - `qbit_prism_payout_revision_listener_up` (gauge): 1 from a successful LISTEN until the connection is lost or the probe fails. 0 before the first LISTEN, while reconnecting, and once the listener ends; a drop guard covers an aborted task. `Metrics` counts the listeners whose LISTEN holds, so a listener ending after a newer one began cannot clear the gauge. - `qbit_prism_payout_revision_announcements_heard_total` (counter): every notification the listener received, one per announced bump (a block's confirmation or settlement, a carry gate change, a fatal-state clear), so it is not a block count. - Both families are registered at 0 at startup and refreshed at every scrape, so a database outage that also stalls the health publisher still shows the listener down. - Documented in `docs/prism-native-metrics.md` (regenerated inventory plus a "Reading the payout-revision listener" section) and in `docs/prism-metrics-cardinality-privacy.md`. The pinned observability census is updated (106 families, 320 startup and 1004 populated series). - **No alert rule.** A frontend without its listener loses no block, credit or payout: each pool block costs it at most one tick of `stale-job` refusals. The gauge also drops to 0 on every reconnect, so a useful rule needs a dwell chosen from fleet data. The doc names a candidate (`listener_up == 0` for 10 m) for a later change through `generate_prism_alerts.py`. ### Tests - Lib: `the_listener_gauge_is_down_until_a_listen_holds_and_once_the_listener_ends` covers the guard and the counter. - `tests/revision_wake.rs`, `a_lost_listener_keeps_the_tick_and_wakes_again_once_it_reconnects`: - The gauge reads 1 with both listeners up, 0 once they are terminated, 1 after reconnecting, and 0 after the loops stop. - B's counter doesn't move for the announcement made while it was down, then moves by 1 for the next bump and by 1 for the late notification. - `a_bump_before_the_first_listen_still_wakes_the_refresh`: the gauge reads 0 before the first LISTEN and 1 after it. ### The CI failure of `a_lost_listener_keeps_the_tick_and_wakes_again_once_it_reconnects` (run 41467535602, 2026-11-02) - That run failed with `B republished at 2 without a listener or a tick`. - Cause: the test waited only for both LISTEN sessions, not for each loop's first refresh. B's first loop refresh could still be running when the "unheard" bump committed, read the new revision and publish it. - That run's log agrees: "A republished on its tick 66.9ms after the unheard announcement", although A's tick is 2 s. - The test now waits until each loop's first refresh has finished before it cuts the listeners. A's republish now comes on its real tick (2.00-2.03 s; once 8.0 s on this loaded host) in 6 local runs. ## Tests run locally (minidev-alex1, through the host gate) - `cargo test --locked -p qbit-prism-server --test rpc_not_sent`: 16 passed. The two new spare tests passed 30 of 30 repeats, and the not-sent test fails with the rule disabled. - `cargo test --locked -p qbit-prism-server --test rpc_idle_close --test rpc_deadlines`: 2 and 5 passed. - `test/prism-native-tests.sh cargo-args --locked -p qbit-prism-server --test revision_wake -- --nocapture` (private PostgreSQL 16): 7 passed. The two listener tests then passed 5 more times. - `test/prism-native-tests.sh cargo-args --locked -p qbit-prism-server --lib -- offer_not_sent_tests offer_not_executed_tests --test-threads=4`: 14 passed. - `cargo test --locked -p qbit-prism-server --lib -- revision_wake::tests offer_not_executed_tests metrics::registry::tests`: 12 passed. - `cargo test --locked -p qbit-prism-server --test observability`: 17 passed. - `cargo fmt --all -- --check`: clean. - `cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings`: clean, apart from the 3 known vendored `sqlx-core` warnings. - Guards: `python3 scripts/check_prism_pool_acquires.py`, `python3 scripts/generate_prism_metrics.py --check` and `python3 scripts/generate_prism_alerts.py --check` all pass. - No new PostgreSQL-gated test ids, so `test/prism-gated-tests.txt` is unchanged. ## CI must cover - The full lib suite, every gated shard (`revision_wake`, `offer_not_sent_tests`), and the gated-test manifest proof. This host runs in downgraded mode, so it can't prove the manifest. - Python tests. - The nightly load presets, through the `run-load` label. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Squashed commits: 332798a 3.x.x: a submitblock hyper hands back unwritten is not sent, and the revision listener gets a health gauge and counter (#816) ab9a006 3.x.x: revision_wake fills each frontend's ledger pool before the database refuses connections (#816) Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #762.
submitblock's deadline (PRISM_BLOCK_SUBMIT_RPC_TIMEOUT_SECONDS, default 1 s) is shorter than the node client's 5 s connect timeout. When no pooled connection exists and the connect is slow, reqwest reports a timeout that is not a connect error. The offer was recorded as unknown and the block was never offered again, although it never left the frontend.What changes
connector_layergives the connect of a relaying call that has its own deadline a budget ofdeadline / RELAY_CONNECT_DIVISOR(half), fixed per call and carried to the connector through a tokio task-local. A connect that misses its budget fails as hyper's Connect error kind, so it comes back asRpcNotSentError(3.x.x: a block found while qbitd refuses the connection is never offered again and is lost #522), andoffer_not_executedreturns the row to pending.last_errorsays the connect was cut ("no connection within 500ms, its share of the call's 1s deadline").Tests
tests/rpc_not_sent.rscovers: a stalled TLS connect ends not-sent within its budget; each call gets its own budget; a write to a pooled connection stays unknown; relaying calls without their own deadline keep the client's deadline; a cut connect serves the next call.offer_not_sent_tests: a slow connect returns the row to pending and lands the block once, and a deadline after the write stays unknown and is never re-offered.rpc_idle_close,rpc_deadlinesandoffer_not_executed_testspass.Spare liveness (31e03a7)
recv(MSG_PEEK | MSG_DONTWAIT)on its TCP socket, below any TLS layer. The socket is identified at park time by matching addresses and SO_TYPE, and re-checked before use. Only EAGAIN hands it out; a FIN, any byte or an error drops it. It is used only while younger than the idle bound (20 s, under qbitd's 30 s). Linux only; elsewhere no spare is kept.PRISM_TEST_ALLOW_SYN_SKIP=1. The spare recordsparked_atinstead of running an expiry task.a_spare_the_node_closed_is_never_handed_outanda_long_deadline_reports_its_cut_before_the_connect_timeout.rpc_not_sent13/13 (plus 15 repeats),rpc_idle_close,rpc_deadlinesand the gatedoffer_not_sent_tests7/7 pass.🤖 Generated with Claude Code