Skip to content

3.x.x: settle the SIGTERM drain's block before the next fault, so a settlement-lock hold cannot start ahead of the landing's revision bump (#686) - #691

Merged
RobertClarke merged 3 commits into
3.x.xfrom
ci/faults-sigterm-drain-settle
Oct 6, 2026
Merged

RobertClarke merged 3 commits into
3.x.xfrom
ci/faults-sigterm-drain-settle

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Fixes the flake in #686. Follow-up: #692. Test-only: the harness changes and the server doesn't.

Why

faults_under_load_drain_an_offer_in_flight_and_outlast_a_settlement_lock_holder failed three times: twice on PRs, once on a 3.x.x push. Each time:

settlement-lock: 0 of 60 offered in the first 3.0 s of the hold were accepted (refusals: {"stale-job": 60})

sigterm-drain leaves its found block for the relaunched frontend to land.

  • The landing confirms the block and bumps the payout revision.
  • Until work at the new revision is published, every share on the old work is refused stale-job. That window is normally 1–2 s.
  • The harness started the next fault as soon as the frontend answered /healthz, whatever state the block was in.
  • When the bump came just before settlement-lock took SETTLEMENT_LOCK, the holder also blocked the republication. So every share in the first half of the hold was refused.

#686 has the full analysis.

What

  • SigtermDrain::poll_settle. Modelled on the SIGKILL fault's landing wait and 3.x.x: pause the session load's shares around scenario 2's own blocks, and start each replayed transcript after earlier blocks land (#631, #632) #640's gate. Once the frontend serves again, it:

    1. polls the block's candidate row until it is submitted;
    2. reads qbit_prism_cluster.payout_revision and every frontend's /healthz until each one is ok, publishes payout_state_generation equal to that revision, and reports authorized_missing_current_work == 0.

    The fault's recovery window, and so the next fault's gap, waits for it. The wait is bounded by DRAIN_SETTLE_WAIT (60 s).

  • A new sigterm-drain check: "the relaunch landed the block and every frontend served work at its revision". It fails the drain if the settle didn't finish. Without it, a block that never landed would pass, and the next fault would measure the missing bump.

  • Evidence: the landing time, the settle time, the last candidate row and the last reading.

  • Docs: the README's fault table, the scenario criteria in test/e2e-scenarios.toml, and the test's module doc.

  • Unit test: the current() predicate.

Evidence

Loops of 20 runs each on the build host. Every run was pinned with taskset to 2 CPUs, like the CI runner, and used a managed PostgreSQL 16 cluster.

Loop Before (3.x.x 186903df) After (e41c7a80)
cargo test -p qbit-prism-load --test faults, the per-PR test 20 of 20 passed 20 of 20 passed
The same plan with the hold started 3 s earlier (baseline=0), run through the harness binary 12 of 20 passed 20 of 20 passed

Before, forced:

  • All 8 failures were CI's message: "0 of 60 … (refusals: {"stale-job": 60})".
  • One run that passed had 59 of 60 accepted.

After, forced:

  • Every hold accepted every retained-work share: 60 of 60, or 61 of 61, with no refusal.
  • The block landed 0.5–3.3 s, and every frontend's work was current 2–6 s, after the frontend served again.
  • So the drain's recovery runs at most about 2 s past its 4 s window.

Why the forced loop is the comparison: on the stock schedule the race is rare. It hit 3 of the roughly 50 CI runs sampled in #686, and none of 27 local runs. The intermediate head 5edc4411 also passed 20 of 20 on both loops.

Not changed

  • The server.
  • The settlement-lock verdict and its 90% criterion.
  • The presets' timings.

🤖 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.

…ettlement-lock hold cannot start ahead of the landing's revision bump (#686)

The drain leaves its found block for the relaunched frontend to land.
The landing confirms the block and bumps the payout revision, and until
work at the new revision is published every share on the old work is
refused stale-job. The harness started the next fault once the frontend
answered /healthz, whatever state the block was in. When the bump
landed just before faults-pr-smoke's settlement-lock took
SETTLEMENT_LOCK, the holder also blocked the republication, so every
share in the first half of the hold was refused (#686: 3 CI failures).

SigtermDrain now has a settle step, like the SIGKILL's landing wait and
#640's gate. Once the frontend serves again, it polls the block's row
until it is submitted, then reads qbit_prism_cluster.payout_revision and
every frontend's /healthz until each is ok, publishes
payout_state_generation equal to that revision, and has delivered that
work to every authorized session. The recovery window, and so the next
fault, waits for it, bounded at 60 s. A new sigterm-drain check fails
the drain when the settle did not finish, because without it a block
that never landed would pass and the next fault would measure the
missing bump. The evidence reports the landing and settle times and the
last reading.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 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-10-06T01:07:52.362036Z e41c7a8 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5edc441190

ℹ️ 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".

Comment thread crates/qbit-prism-load/src/fault/mod.rs Resolved
- The faults phase's bound adds DRAIN_SETTLE_WAIT for a drain, as it adds
  the lease wait for a SIGKILL, so a slow settle reads as a settle failure
  rather than a truncated phase.
- A candidate that goes terminal without landing (abandoned, orphaned), or
  whose row is gone, ends the settle at once instead of polling for 60 s.
- A block the shutdown itself landed counts as landed before the exit, and
  the check now says "the block landed" rather than crediting the relaunch.
- A settle read whose task was lost is replaced (Spawned::lost) instead of
  holding the wait to its bound. The last read's error is cleared by a
  later good read, so a passing settle carries no stale error.
- The detail prints its timings as sentences, not Option debug output.
- One reqwest client for the settle, and every frontend's /healthz read at
  once with a 2 s limit, after the revision.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke

Copy link
Copy Markdown
Member Author

Ran a high-effort code review on 5edc441. It made eight findings: seven are fixed in 7994150, and one is a follow-up.

Fixed:

  • Phase bound. The faults phase's bound now adds DRAIN_SETTLE_WAIT for a drain, as it adds the lease wait for a SIGKILL. A slow settle now shows as a settle failure, not as a truncated phase with the next fault "never started". the_phase_bound_covers_every_window_and_allowance covers it.
  • Terminal rows. A candidate that goes abandoned or orphaned without landing, or whose row is gone, ends the settle at once instead of polling for 60 s. The check's detail names the state.
  • Shutdown landings. A block the draining process landed itself, with row_after_exit already submitted, counts as landed before the exit. The check is renamed "the block landed and every frontend served work at its revision", so it no longer credits the relaunch.
  • Lost reads. A settle read whose task was lost is replaced, via the new Spawned::lost(), instead of holding the wait to its bound.
  • Stale errors. The last read's error is cleared by a later good read.
  • Detail text. The timings print as plain numbers instead of Some(…).
  • Health reads. The settle uses one reqwest client. It reads every frontend's /healthz at once with a 2 s limit, after reading the revision.

Follow-up:

A work read that started just before DRAIN_SETTLE_WAIT ran out and
finished after it could record success, reporting a settle past the
bound as within it. It now counts only while the bound holds; otherwise
the settle reports that it did not settle in time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke merged commit c95febb into 3.x.x Oct 6, 2026
34 checks passed
@RobertClarke
RobertClarke deleted the ci/faults-sigterm-drain-settle branch October 6, 2026 01:26
RobertClarke added a commit that referenced this pull request Oct 6, 2026
… a quiet cluster, whichever fault landed a block before it (#692) (#699)

#691 made the SIGTERM drain wait until its block had landed and every
frontend served work at the payout revision the landing committed. Other
faults land a block too, frontend-sigkill, block-failover and
candidate-backlog, and none waits for the republication. A
settlement-lock straight after one took SETTLEMENT_LOCK while the
landing's work was unpublished, blocked that publication too, and every
retained-work share in the first half of its hold was refused stale-job,
the same failure as #686.

The settlement-lock fault now waits, from the start of its injection,
until every frontend is ready, publishes payout_state_generation equal to
the cluster's payout_revision and has delivered that work to every
authorized session, with no backend holding or waiting for
SETTLEMENT_LOCK, so the holder is not queued behind a settlement still
under way. The wait is bounded at 60 s, included in the phase's time
bound; a cluster that never goes quiet gets the lock at the bound. A
found block still to land does not hold the wait: every bump of the
payout revision takes SETTLEMENT_LOCK, so none can happen under the lock.

The holder reads the payout revision in its own transaction once it has
the lock, and the fault reads every frontend's /healthz once more before
the hold starts. A new check passes only if, under the lock, every
frontend was ready and publishing work at that revision, so a tip that
reached the frontends after the last reading fails the hold instead of
passing it. The evidence records when the cluster was quiet, the last
reading before the lock, the revision under the lock and the reading
under it; the hold's ACK summary is now taken from the lock's
acquisition. The wait is the drain's work half, moved into a
WorkCurrentWait both faults use, with unit tests for its states.

Locally, pinned to two CPUs, a preset copy running
frontend-sigkill,settlement-lock with baseline=0 failed the
settlement-lock fault in 8 of 8 runs before, each with "0 of 60 accepted
(stale-job 60)". With the quiet wait it passed in all 36 runs, 10 of 10
at the final head, where the lock queued at most 0.02 s behind a quiet
reading and the hold's ACK p99 was 9-19 ms. On the real node, with two
frontends and 500 sessions, pool-exhaustion then settlement-lock passed
with the cluster quiet at once and every frontend serving the locked
revision.

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