Design: topology/pub-ack + topology/pub-complete#
Status: Phase 1 / 1.5 / 2 / 3 landed; this doc stays as the
authoritative spec for the shape.
Author: dwoz
Scope: salt/topology/, salt/client/__init__.py, salt/master.py
Target: master (Potassium)
Motivation#
Master-topology currently floods publishes to peer masters and waits for returns to arrive. The originating CLI has no deterministic way to answer two basic questions:
Who should I wait for? — peers independently match the target expression against their rosters; the originator never learns how many minions each peer accepted. The CLI falls back to "whatever minions returned so far" ∪ "whatever the master's own matcher found" — missing minions on remote peers are indistinguishable from unreachable ones.
Am I done? — Salt has no
salt/job/<jid>/completeevent (by design — see rationale below). The CLI's existingorder_masters+syndic_waitlogic infers completion from silence, which is a probabilistic bet with a one-size-fits-all grace period.
Syndic solved this for its own topology by letting the CLI grow its
expected-minion set as syndics self-reported minion lists, bounded
by a configurable syndic_wait. Master-topology has no equivalent;
peers are silent after accepting a flooded publish.
This design adds two authenticated topology frames —
topology/pub-ack and topology/pub-complete — that give the
originating CLI deterministic answers to both questions, with zero
new master-side job state and no change to Salt's publish-return
protocol semantics.
Non-goals#
No
job-completeevent on the master's local bus. Completion stays a client-side concept; the CLI remains the arbiter. This preserves the existing invariant that the master is a stateless message broker.No change to minion-side protocol. Minions see a normal publish and send a normal return; the new frames are strictly master-to-master.
No new target-expansion semantics. Publishes still flood; peers still match locally. The ACKs report local-match results, they don't decide them.
Wire format#
Both frames reuse the existing PeerMasterLink session (TCP 4521,
AES-signed envelope, breadcrumb-authenticated path). They slot into
the module-level _DISPATCH_TABLE at salt/topology/link_manager.py
alongside the current topology/pub / topology/ret / topology/evt
/ topology/sum tags.
topology/pub-ack#
Sent by each peer that accepts a flooded topology/pub, immediately
after it has matched the target against its local roster and
before dispatching to its own minions. One frame per peer per jid.
{
"cmd": "topology/pub-ack",
"tag": "topology/pub-ack",
"origin_cluster_id": <peer-cluster-id>, # SENDER cluster
"session_generation": <int>, # session continuity
"load": {
"jid": <str>,
"target_cluster_id": <str>, # ORIGINATOR cluster
"matched_minion_ids": [<str>, ...], # may be empty
"topology": {
"origin": <peer-cluster-id>,
"path": [<cluster-ids traversed>],
},
},
}
Semantics:
matched_minion_idsis the exact set the peer will publish to after this ack. If zero (compound didn't match anything locally) the peer sends an empty-list ack rather than silence, so the originator can distinguish "didn't match" from "peer unreachable."Fired from
_dispatch_pubon the receiving side, right afterrouter.forward_publishreturns its(links, local_match)tuple and before_publish_to_local_minionsdispatches. The scheduling pattern isasyncio.ensure_future(_send_pub_ack_fire_and_forget(...))immediately followed byawait asyncio.sleep(0)(seesalt/topology/link_manager.py~L1450-1459); the yield lets the ack coroutine run its first synchronous step — health-gate, envelope build, and theAsyncReqChannel.sendkickoff that hands the frame to the transport — before the awaited_publish_to_local_minionsbegins its local IPC fan-out. The real guarantee is therefore: the ack begins its wire send before the local publish fan-out begins; on-wire delivery ordering from that point is still best-effort. In practice this is enough for the originator to maintain the invariant thatexpected_setgrows beforereturned_set, because the local minions still have to execute the job and round-trip a return through the peer master after the fan-out starts. This is a fragile monotonic invariant: a future refactor that drops theawait asyncio.sleep(0)(or replacesensure_futurewith a construct that doesn't enter the coroutine body before the next await) would silently break the ordering without failing any functional test. It is pinned bytest_pub_ack_scheduled_before_local_publish_await.Transit peers also ack under flood: when the originator publishes with no explicit destination (
destinations is None), every peer in the flood tree sends apub-ackupstream for its own matched set, not just leaf peers. Under scoped routing (e.g.C@targeting specific clusters, sodestinationsis a non-empty set), a pure- transit peer that is not itself in the destination set haslocal_match=Falseand skips the ack path atsalt/topology/link_manager.py~L1415 — only destination peers ack. The originator therefore receives one ack per flood participant OR one ack per destination participant, respectively.
topology/pub-complete#
Sent by each peer when its local collection ends — either all locally-expected returns arrived or the peer's local job timeout fired. One frame per peer per jid.
{
"cmd": "topology/pub-complete",
"tag": "topology/pub-complete",
"origin_cluster_id": <peer-cluster-id>,
"session_generation": <int>,
"load": {
"jid": <str>,
"returned": [<minion-id>, ...], # subset of ack'd
"missed": [<minion-id>, ...], # ack'd but no return
"cancelled": <bool>,
"cancel_reason": <str>|null,
"topology": {
"origin": <peer-cluster-id>,
"path": [<cluster-ids traversed>],
},
},
}
Semantics:
missedis constructed by the emitter asexpected - returned(salt/topology/link_manager.py:2231), so under correct implementationsset(returned) ⊕ set(missed) == set(matched_minion_ids)from the priorpub-ackfor that jid. The originator does NOT re-verify this against the priorpub-ack— the invariant is emitter-enforced; a misbehaving peer could send disjointmissedand the originator would surface it as-is (fail-open).cancelledis reserved for future use. In Phase 1.5, the emitter (salt/topology/link_manager.py:_emit_pub_complete_once) hard-codescancelled=Falseandcancel_reason=None— no in-tree code sets it to True. Two eventual triggers are planned:topology/jid-cancelframe received (deferred to Tier 2).Parent peer master disappeared mid-job (not yet implemented).
For clean local-timeout, the peer always sets
cancelled: Falseand populatesmissedwith the un-returned minions.pub-completecarries no return payloads — those still flow astopology/retwith the per-minion return load.pub-completeis the metadata frame;topology/retis the data frame.Fire-and-forget. If delivery to the originator fails (link down), the frame is dropped; the originator falls back to its own
--timeoutand reconstructs completion fromtopology/retarrivals plus the priorpub-ack. Lossy by design — the frame is an optimization, not load-bearing.
Health gating#
Both frames are gated at PeerMasterLink._assert_sendable:
topology/pub-ack→ permitted only whenCONNECTED. A peer inQUIESCINGhas stopped accepting publishes, so it cannot have an ack to send.topology/pub-complete→ permitted onCONNECTEDandQUIESCING, same astopology/ret. Returns drain through quiesce; completes must drain with them.
Originator aggregation#
The CLI's LocalClient.get_cli_returns already handles the "expected
set grows over time" case under order_masters: True with
syndic_wait. We extend the same algorithm:
expected_set := publisher's own local matcher output
pub_ack_deadline := now + topology_wait (default 2.0s)
timeout_at := now + opts["timeout"]
loop:
drain pub-ack frames → expected_set |= frame.matched_minion_ids
peers_acked.add(frame.origin_cluster_id)
drain topology/ret → returned_set |= frame.load["id"]
drain pub-complete → peers_complete.add(frame.origin_cluster_id)
missed_by_peer[frame.origin] = frame.missed
if returned_set >= expected_set:
break # happy path: all back
if peers_complete >= peers_acked and now > pub_ack_deadline:
break # every peer reported done
if now > timeout_at:
break # global --timeout fires
Semantics vs. syndic:
topology_waitonly governs the window to collectpub-acks (expected-set stabilization). Once all ack'd peers have sentpub-complete, the loop exits immediately — no need to wait--timeoutjust because one unresponsive minion didn't return. Syndic can't do this because syndics never signal done.missed_by_peercarries into the CLI's final output: minions that peers themselves could not reach are reported as distinct from minions the CLI couldn't reach. Operator sees "peer east-sub timed out on 2 of its minions" vs. "CLI never heard from east-sub" as different conditions.
New opts#
# salt/config/__init__.py defaults
topology_wait: 2.0 # seconds; grace for pub-ack arrival
topology_pub_ack: true # emit/consume pub-ack+pub-complete
topology_pub_complete_timeout: 60.0 # peer's local collection timeout
Default-on. Peers running without the opt (or older code) simply
don't send the frames; the originator's loop falls back to the
pre-RFC behavior (silence-based inference, bounded by --timeout).
No breaking change to mixed deployments.
Rollout#
Phase 1 (land both frames, no CLI change): Add
topology/pub-ackandtopology/pub-completeto the dispatch table andPeerMasterLink.send_pub_ack/send_pub_completesenders. Originator discards the frames. Shippable alone; adds telemetry (operator cangrep /var/log/salt/masterfor ack latency), no behavioral change.Phase 2 (opt-in originator consumption): Add
topology_wait+ consumer logic inget_cli_returns. Gated ontopology_pub_ackopt; off-by-default initially.Phase 3 (flip default): After one release of real-world deployment, flip
topology_pub_ackdefault to True. Document the mixed-deployment behavior (older peers = silent-mode fallback).
Test plan#
Unit (
tests/pytests/unit/topology/):test_pub_ack_sent_before_local_publish— ack precedes_publish_to_local_minionsdispatch.test_pub_ack_empty_match_list— zero-match peer still acks.test_pub_complete_returned_plus_missed_equals_acked— conservation invariant.test_pub_complete_dropped_on_link_down_does_not_block— originator loop still terminates on--timeout.
Functional (
tests/pytests/functional/topology/):test_cli_sees_pub_ack_expected_set— 3-peer flood;expected_setmatches ∪ of per-peer matches.test_cli_terminates_on_pub_complete_before_timeout— all peers ack+complete under 1s; CLI exits in <1s regardless of--timeout.
Scenario (
tests/pytests/scenarios/topology/):test_pub_ack_backward_compatible_with_silent_peer— one peer older code (frames dropped), other peers new. CLI still works, falls back to silence-mode for the old peer.
Live-sandbox smoke at
agents/scratch/topology-sandbox/: firesalt --timeout=30 '*' test.pingfromtopo-east; grep master log forpub-ack from topology-east-sub-sub-1 matched=2; confirm CLI exits in <1s instead of the full 30s on the happy path.
Open questions#
Should
pub-ackcarrypeer_estimated_rttfor a future adaptive-timeout feature? Cheap to carry (one int), zero-cost to consumers that don't use it. Recommend yes: future-proof.Transit vs. leaf ack: a transit peer master that is itself forwarding to deeper peers — should it ack with its own matched set only, or also wait for deeper acks and roll them up? Recommend own set only: each peer acks for itself; the originator sees N acks for N peers in the flood. Rollup would centralize complexity in transits for no observable benefit.
Signature on ack frames: reuse existing per-envelope AES signature from the session (already does this on all topology/* frames) — no new auth path.
Non-adoption fallback#
If this design is rejected, the alternative is to live with syndic's
original design and copy syndic_wait as topology_wait. That
closes 80% of the gap for 20% of the work but leaves the
"ambiguous completion window" permanently. The visualizer's
synthesized job-complete fallback becomes the de-facto
"done" signal, which is a weaker but functional story.