Chapter 07
How agreement happens
Consensus, epochs, trust scores and Byzantine fault tolerance — agreement without a boss.
Imagine five friends trying to agree on which restaurant to visit. There's no leader. They can't all be in the same room. They send messages back and forth. Eventually, four of them agree on “Italian place on 5th street.” The fifth friend was stuck in traffic and missed the message.
Did they reach consensus? Yes — because four out of five agreed. The one who missed out will catch up when they reconnect.
This is what Legion does, but with data instead of restaurants. And it needs to work reliably even when devices are unreliable or, in extreme cases, actively malicious.
Epochs — numbered rounds of agreement
Legion organizes agreement into epochs — think of them as rounds in a game. Each epoch has a number (0, 1, 2, 3…) and contains a list of commands (actions, data changes, etc.) that all nodes agree on.

When a node wants to add a new action to the group's shared state (like “user sent this message”), it proposes the action. The group then agrees on it within the current epoch. Once agreed, the epoch is closed and the next one begins.
Each epoch is cryptographically linked to the previous one — like a chain. If someone tries to change a command in an old epoch, the chain breaks and everyone knows.
How commands get ordered
Every command in an epoch gets a sequence number — 0, 1, 2, 3… This ensures everyone sees commands in the same order. Order matters because in a shared system, if two people edit the same document, the order of edits determines the final result.
When a new command is added:
- The system assigns it the next available order number.
- It computes a hash (a unique fingerprint) of the command's content plus its order number.
- The command, its order, and its hash are stored in the epoch log.
- Other nodes verify the hash to ensure nothing was tampered with.
Trust scores — keeping track of who's reliable
Not all nodes behave the same way. Some are always available. Some go offline frequently. Some send correct data. Some send wrong data.
Legion tracks this using trust scores — a number between 0.0 and 1.0 for each peer:
| Score | What it means |
|---|---|
| 0.9 | Fully trusted (verified identity, always reliable) |
| 0.7 | Known peer (verified identity, mostly reliable) |
| 0.5 | Unknown peer (just met, unverified) |
| 0.0 | Blocked or revoked |
Trust scores start at 0.5 for new peers and adjust over time:
- Successful interaction (+0.01): The peer responded correctly. Small boost.
- Failed interaction (-0.05): The peer failed or sent bad data. Bigger penalty.
- Time decay (-1% per cycle): Trust slowly fades if there's no recent activity, but never drops below 0.1. (Think of it like a friendship — if you don't talk for years, you're not necessarily enemies, just strangers again.)

The poison detection system
If the average trust score of all peers drops below 0.5, the epoch is considered poisoned. This means something is seriously wrong — too many unreliable or misbehaving nodes are in the group.
When an epoch is poisoned:
- New commands are paused.
- The system flags which peers are dragging down the average.
- The least-trusted peers may be removed from the group.
- A clean epoch begins.
This is like a health check for the entire network. If the network is sick, it stops processing and figures out why.

Byzantine Fault Tolerance — when things go really wrong
Sometimes, a node doesn't just make mistakes. It actively tries to cheat. It might:
- Send different messages to different peers (equivocation)
- Try to insert fake commands
- Try to block the group from reaching agreement
This is called a Byzantine fault — named after a classic computer science problem called the “Byzantine Generals Problem.” Imagine generals surrounding a city, each leading their own army. They need to agree on whether to attack or retreat. But some generals might be traitors who send conflicting messages. How do the honest generals reach agreement?
Legion handles this using a protocol inspired by Tendermint, a well-known consensus algorithm. It works in three phases:
- Propose: One node (the proposer, chosen by rotation) suggests a value (a set of commands to include in this round).
- Pre-vote: All nodes vote “yes” or “no” on the proposed value.
- Pre-commit: If enough nodes (more than 2/3) voted “yes,” nodes make a firm commitment to that value.
Once 2/3+ of nodes commit, the value is accepted. The system is guaranteed to reach agreement as long as fewer than 1/3 of nodes are acting maliciously.

Operating modes
BFT is powerful but also resource-intensive. Legion lets you choose how strictly to use it:
| Mode | What it does |
|---|---|
| Observation | BFT runs in the background, watching but not deciding. Regular commands use the simpler epoch system. |
| Hybrid | Regular commands use epochs. Critical commands (like changing group settings) use BFT. Best balance of speed and safety. |
| Full BFT | Every command goes through BFT. Maximum safety, maximum overhead. |
For most use cases, hybrid mode is the sweet spot. You get the speed of simple epochs for everyday operations and the security of BFT for important decisions.
What happens if agreement can't be reached?
Sometimes a group gets stuck. The proposer is offline. Too many nodes are unreliable. The network is slow.
Legion handles this with liveness timeouts:
- If no progress is made in 30 seconds, the system falls back to hybrid mode.
- If a specific round gets stuck, the round number is forced forward.
- Timeouts increase exponentially (like a backoff) to avoid flooding the network.
This ensures the system always makes some progress, even under adverse conditions.
Trust and consensus in practice
Here's how trust and consensus work together in a real scenario:
- Your smartphone sends a message to the AI assistant.
- The orchestrator node receives it and proposes a command in the current epoch.
- Other nodes verify the command's signature and hash.
- Trust scores determine whether the orchestrator's proposal is accepted or scrutinized.
- If BFT is active for this command type, a full voting round occurs.
- Once agreed, the command is recorded in the epoch and the result flows back to your smartphone.
You, the user, don't see any of this. You just see: you typed something, and got a response. But underneath, a whole system of agreement, trust, and verification made that possible.
Summary
| Concept | Simple explanation |
|---|---|
| Epoch | A numbered round of agreement |
| Command | An action or data change |
| Hash chain | Cryptographic link between epochs — prevents tampering |
| Trust score | How reliable each peer is (0.0 to 1.0) |
| Poisoned epoch | The group's average trust dropped too low |
| BFT | A protocol for agreement when some nodes can't be trusted |
| 2/3+ rule | You need more than two-thirds agreement to decide |
| Liveness timeout | If the group is stuck, force progress |
What comes next
Now you understand how devices agree on data. But how do you actually deploy and run a Legion network? Read Running the platform to learn about deployment, servers, and providers.