Back to blog

Your Agent Swarm's LeaderElection Class Is Guarding Against a Failure That Can't Happen

Sep 10, 2026
Series · Day 6
Distributed Systems in 30 Days
View all lessons →
Your Agent Swarm's LeaderElection Class Is Guarding Against a Failure That Can't Happen

Leader Election in Agent Swarms: A Solution Looking for Its Problem

Open your multi-agent framework's source and grep for `LeaderElection`. If you find one — terms, votes, heartbeat timeouts, the full Raft costume — it's standing guard against a failure your system cannot have, while the failure it has on every single run walks straight past it.

python
# seen (lightly disguised) in an agent orchestration framework
class AgentNode:
    def __init__(self, agent_id, peers):
        self.id = agent_id
        self.peers = peers
        self.term = 0
        self.state = "follower"
        self.voted_for = None
        self.leader_id = None

    def on_election_timeout(self):
        self.term += 1
        self.state = "candidate"
        self.voted_for = self.id
        votes = 1
        for peer in self.peers:
            if peer.request_vote(self.term, self.id):
                votes += 1
        if votes > len(self.peers) // 2:
            self.state = "leader"
            self.leader_id = self.id
            self.broadcast_heartbeat()

    def request_vote(self, term, candidate_id):
        if term > self.term and self.voted_for is None:
            self.term = term
            self.voted_for = candidate_id
            return True
        return False

Run the question Raft's own paper forces you to run: what failure does this actually recover from? Node crash? These "nodes" are function calls inside one Python process — nothing to crash independently. Network partition? There's no network between them to split; one control plane calls out to several model endpoints, sequentially or in parallel, and waits for the answers to land. Split-brain, where two nodes both believe they're leader because a partition cut them off from each other? Structurally impossible — there's exactly one process deciding who "leads," and it never loses contact with itself. Walk through every failure Raft's election protocol exists to survive, and the honest answer for this code is: none of them apply. It's cargo cult — the shape of consensus, borrowed without the conditions that ever made consensus necessary.

Day 5, in one line

Raft elects a leader so a cluster of independently-crashing, independently-partitioned machines can keep agreeing on one sequence of operations — it's a solution to a *physical* failure model: nodes die, networks split, messages get lost or arrive late.

The category error

Multi-agent orchestration, as almost everyone builds it today, carries no partition risk at all. It's one process — your orchestrator — making a set of API calls to LLMs and collecting what comes back. There's no cluster of peers that can lose contact with each other, because the "agents" aren't peers with independent state and independent failure — they're stateless function calls that happen to be slow, expensive, and probabilistic. What actually fails in a multi-agent system isn't the network. It's semantic agreement: two calls to the same model, or calls to two different models, come back with answers that contradict each other, and nothing about TCP, quorums, or terms tells you which one is right.

The election you actually need

Two coding subagents both report "tests pass, task done" — one ran the suite, the other hallucinated the run. Two research subagents pull different numbers for the same fact and both state them with total confidence. A planner agent and a critic agent disagree on whether a step is safe to execute. That's the real tie you need to break, and it isn't a liveness problem — every agent involved is alive and answering just fine. It's a correctness problem: which confident, well-formed, fully-available answer do you actually trust? Raft has nothing to say here, because Raft assumes every correct node that's up and connected converges on the same answer once you get the protocol right. LLM outputs don't converge like that — two "correct" agents, neither crashed, neither partitioned, can disagree on the substance and both sound completely sure of themselves.

Why the borrowed vocabulary is so tempting

Raft and Paxos are precise, peer-reviewed, battle-tested — borrow their vocabulary and your design doc instantly sounds more rigorous. It also lets you dodge the harder question. "Elect a leader" is a solved problem with a paper you can cite. "Decide whose answer wins on merit when both are plausible" has no canonical algorithm — it's a modeling problem specific to your domain, and it forces you to actually define what "correct" means for your task. Call it leader election, ship a class with a `term` field and a `voted_for` field, and you can convince yourself you've handled disagreement. You haven't. You've decided which agent gets to speak first — not which agent is right.

What to build instead

Swap the borrowed protocol for an explicit, named tie-break policy — something a teammate can read in a PR and push back on, not something buried inside a class called `LeaderElection`:

  • Confidence score — if your model or pipeline emits something calibrated (log-probs, self-reported certainty, a verifier score), take the higher one. Weak unless that score is genuinely calibrated, and most self-reported confidence isn't.
  • Judge model — a separate call, usually to a stronger or differently-prompted model, arbitrates between the two answers. Costs latency and money, but it scales to open-ended disagreement in a way a fixed rule can't.
  • Most-recent-context wins — if one agent's answer is grounded in fresher tool output (a re-read file, a re-run test) and the other's is stale, freshness beats confidence.
  • Structural authority — designate one agent role as the tie-breaker for a given decision type ahead of time (the test-runner's pass/fail beats the coder's self-report, always). Decided at design time, not improvised at runtime.
  • Human escalation — when the disagreement is high-stakes, or the methods above disagree with each other, surface it and stop. Cheap to build, expensive to run at scale — save it for the tail, not the median case.

Pick one. Name it in your code and your docs for exactly what it is — a tie-break policy — and make it inspectable. "We use a judge model with a fixed rubric when two subagents disagree on task completion" is a design decision you can defend in review. "We run leader election" is a decision you imported without checking whether it applies.

Where this goes next

Not every disagreement is binary, either. Sometimes you have three, five, a dozen agents each producing an answer, and you want to aggregate rather than pick a single arbitrator. That's quorum and voting — a different corner of the distributed-systems canon, and one that actually does map cleanly onto multi-agent agreement, unlike leader election. Day 7 draws that line: when "most agents agree" is a real signal of correctness, and when it's just several agents confidently making the same mistake together.

Flashcards
Check yourself

Extend your knowledge

  • Grep your own agent framework's codebase for 'leader', 'election', 'term', or 'quorum,' and check what failure each one is actually guarding against — you'll likely find at least one borrowed term with no matching risk.
  • Read the 'Safety' section of the original Raft paper (Ongaro & Ousterhout, 2014) for what it assumes about node and network failure, then compare it line by line against how your orchestrator actually runs.
  • Check how your framework — AutoGen, CrewAI, LangGraph, whatever you're on — currently handles conflicting subagent outputs, if it handles them at all. Is there an explicit policy, or does one answer just silently overwrite the other?
  • Next lesson: Day 7 — quorum and voting patterns for multi-agent agreement, and where 'most agents agree' is and isn't a valid correctness signal.
Test yourself on this lesson

Discussion

Chat with Chi Cong (AI) about this article. Your conversation is private to you — you can publish a summary for others when you're done.

Ask me anything about “Your Agent Swarm's LeaderElection Class Is Guarding Against a Failure That Can't Happen” — trade-offs, decisions, or the story behind it.