Skip to content

Fix LocalClient KeyError on cluster_retry sentinel from clustered masters - #70721

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

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

Conversation

@dwoz

@dwoz dwoz commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Backport from master-topology work (LocalClient portion only; the RemoteClient companion fix depends on master-only PR #70656 and will follow once that lands on 3008.x).

When Raft is still forming on a clustered master, _cluster_is_ready returns False and the receiver returns {"enc": "clear", "load": {"ret": False, "cluster_retry": True}} with no jid key. LocalClient.pub / pub_async previously crashed with KeyError: 'jid' (wrapped by cmd_async as the opaque SaltClientError: 'jid'), confusing operators who were just hitting a cold-start race.

Fix: receive path detects the cluster_retry sentinel and raises a clean SaltClientError with an actionable message telling the operator the cluster is still forming and to retry.

Test plan

  • pytest tests/pytests/unit/client/ tests/pytests/unit/test_client.py — 242 passed, 12 skipped
  • New regression test pins both the crash shape and the clean-error raise

Observed on the 24-master clustered sandbox: every
CLI publish failed with::

    SaltClientError: 'jid'

Trace:

    File "salt/client/__init__.py", line 2162, in pub
        return {"jid": payload["load"]["jid"],
                "minions": payload["load"]["minions"]}
    KeyError: 'jid'

### Root cause

ReqServerChannel.handle_message at salt/channel/server.py:452
short-circuits with::

    {"enc": "clear", "load": {"ret": False,
                                 "cluster_retry": True}}

when _cluster_is_ready() is False (Raft not yet a committed
voter / leadership flapping).  No jid key in the load.  The
minion-side AsyncReqChannel._crypted_transfer knows about the
cluster_retry sentinel (salt/channel/client.py:253-266),
but LocalClient.pub / pub_async do not -- they both end
with::

    return {"jid": payload["load"]["jid"],
            "minions": payload["load"]["minions"]}

which KeyErrors on the missing jid.  cmd_async then
re-raises as SaltClientError: 'jid', which tells the operator
nothing about the real condition.

The cluster_retry sentinel was introduced in commit
97d78d3 (May 2026, "consensus: gate minion/CLI traffic
until node is a committed Raft voter").  Gate was never taught to
the LocalClient publish path.

### Fix

LocalClient.pub and LocalClient.pub_async now detect the
cluster_retry key in the returned load and raise::

    SaltClientError(
        "Master is not ready; cluster consensus still forming. "
        "Retry the command once the cluster is ready."
    )

### Follow-up flagged, not in this commit

Secondary gate-latch bug: MasterPubServerChannel._signal_cluster_ready
installs a one-shot on_ready callback on the RaftService.  When
RaftService restarts (observed on topo-west-1 across terms 6-9),
the callback never re-arms and the gate latches closed
permanently.  Needs separate fix (re-arm on RaftService restart,
or switch from one-shot to continuous).

### Regression test

tests/pytests/unit/client/test_init.py::test_pub_raises_clean_error_on_cluster_retry: mocks the
ReqChannel to return the cluster_retry payload shape and
asserts SaltClientError("cluster consensus still forming")
is raised (not KeyError('jid')).  Verified FAIL pre-fix /
PASS post-fix.
@dwoz
dwoz requested a review from a team as a code owner November 7, 2026 05:31
@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
Pre-commit black hook flagged this file during CI; running the hook
locally and committing the reformat.
@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 — 10cde86b Deployed Nov 7, 2026 by dwoz via Build Onedir Packages / macOS (x86_64) #28652
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