Skip to content

Fix stale CONFIG apply silently regressing cluster state machines - #70718

Closed
dwoz wants to merge 2 commits into
saltstack:3008.xfrom
dwoz:dwoz/backport/3008.x-staleconfig
Closed

dwoz wants to merge 2 commits into
saltstack:3008.xfrom
dwoz:dwoz/backport/3008.x-staleconfig

Conversation

@dwoz

@dwoz dwoz commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Backport of two commits from the master-topology work on master. Both land correctness fixes for clustered masters on 3008.x.

  • MembershipStateMachine.apply unconditionally wrote self._version = index for every CONFIG entry, including stale ones replayed via log truncation or recovery. A stale entry re-delivered after a snapshot-install or follower truncation would silently overwrite the committed voter set — potential split-brain shape.
  • Same unconditional pattern existed in the three sibling state machines (RingConfigStateMachine, RingRegistryStateMachine, RoutingStateMachine). Ring policy, ring registry, and routing-table state could all be silently regressed by a stale entry.

Fix: short-circuit apply when index <= self._version. The _version field already round-trips through each SM's snapshot envelope, so the gate survives snapshot install.

Test plan

  • pytest tests/pytests/unit/cluster/consensus/ — 394 passed
  • Four new regression tests (one per SM) added alongside the fix

dwoz added 2 commits November 6, 2026 22:07
… apply

`MembershipStateMachine.apply` unconditionally overwrote the SM's
voter / learner view every time a CONFIG command was applied.
`Node.on_config_change` is gated by `_applied_config_index=M` so the
callback only fires on the newest-index CONFIG, but the SM state
itself was not gated: a stale CONFIG re-applied after log truncation
(leader stomps a divergent follower tail) or during recovery replay
could silently revert the authoritative voter view.  Downstream
readers of `membership_sm.voters` / `.learners` (ring bring-up,
routing) then saw the wrong set until the next real CONFIG.

Fix: short-circuit the apply when the incoming log index is at or
below the SM's `_membership_version`.  The existing field already
round-trips through get_snapshot / restore_snapshot as the ``version``
key, so the gate survives snapshot install.  `index == -1` (the
no-index default used by test harnesses that don't care about replay
safety) still always applies, preserving pre-existing behavior.

Regression framing originally captured at
`agents/scratch/bug-025/NOTES.md` lines 40-50 and 43-50 --- flagged
during BUG-025 QA as a pre-existing risk in master, now addressed
here.  Two unit tests added: the hot-path short-circuit
(`test_stale_config_apply_does_not_regress_voters`) and the
snapshot-restore round-trip
(`test_stale_config_skip_survives_snapshot_roundtrip`); both
confirmed RED on pre-fix HEAD via `git stash`.

Note: RingRegistryStateMachine.apply and RoutingStateMachine.apply
have the same "overwrite + set version on every apply" shape and
need the same gate, but the fix there warrants a separate per-SM
callsite audit; flagged in agents/scratch/bug-028/NOTES.md as
follow-up.
The stale-CONFIG regression fix in MembershipStateMachine.apply left the
three sibling SMs in salt/cluster/consensus/raft/log.py with the identical
"overwrite unconditionally + set version on every apply" pattern:

- RingConfigStateMachine.apply (log.py:911)
- RingRegistryStateMachine.apply (log.py:1047)
- RoutingStateMachine.apply (log.py:1189)

Same truncation/replay regression risk applied to ring policy, ring
registry, and routing-table state: a stale entry re-delivered via log
truncation or recovery replay silently overwrote the authoritative SM
state.

### Fix

Each sibling SM gets the same short-circuit used by MembershipStateMachine:

    if (
        index >= 0
        and self._version >= 0
        and index <= self._version
    ):
        log.debug(...)
        return

The index=-1 escape hatch for test harnesses still always applies.  The
_version field already round-trips through each SM's snapshot envelope
as "version" so the gate survives snapshot install.

### Audit

All production callers in salt/ pass index=entry.index
(salt/cluster/consensus/raft/node.py:840, :857; and
salt/runners/cluster.py:258), so no caller relies on pre-fix no-index
re-apply semantics.

### Regression tests

Added to tests/pytests/unit/cluster/consensus/test_raft_log.py, one per
sibling SM.  All four verified RED pre-fix (via git stash) and GREEN
post-fix.  Full cluster unit suite: 585 passed.
@dwoz
dwoz requested a review from a team as a code owner November 7, 2026 05:30
@dwoz dwoz added the test:full Run the full test suite label Nov 7, 2026
@dwoz dwoz added this to the Argon v3008.7 milestone Nov 7, 2026
@dwoz dwoz mentioned this pull request Nov 9, 2026
3 tasks done
@dwoz

dwoz commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #70755 which combines all five cluster-correctness backports into a single PR.

@dwoz dwoz closed this Nov 9, 2026

This branch was previously deployed

1 inactive deployment
ci — 447d048f Deployed Nov 7, 2026 by dwoz via Build Onedir Packages / DEB (x86_64) #28599
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant