agentsclimarketplace

Lease epoch fencing token monotonic guard

Skill kjuhwa/skills-hub/skills/algorithms/lease-epoch-fencing-token-monotonic-guard

Reject stale leader writes using a monotonic epoch/fencing token rather than just liveness checksFrom its SKILL.md

Install
npx -y skills add kjuhwa/skills-hub --skill lease-epoch-fencing-token-monotonic-guard

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

1.7 KB, 284 tokens by cl100k_base, as published. Nobody here has run it

lease-epoch-fencing-token-monotonic-guard

When building leader-election visualizations, the naive "only the leader can write" rule breaks under partition-heal scenarios: an old leader that didn't notice it lost the lease still thinks it's leader and keeps issuing writes. The fix is a fencing token — a monotonically increasing integer assigned on each leader election. Every write carries the token; the state machine rejects any write whose token is less than the highest seen.

class StateMachine {
  apply(op, token) {
    if (token < this.maxToken) return { rejected: 'stale-leader' };
    this.maxToken = token;
    this.state = reduce(this.state, op);
  }
}

This pattern generalizes far beyond leader election: any resource with exclusive access under partial failure benefits (distributed locks, cache invalidation epochs, config version pins, optimistic concurrency versions). The key insight is that liveness checks alone ("is the leader still alive?") race against the network — a write that was authorized when sent may arrive after authority transferred. Attaching a monotonic token moves the check to the receiver at apply time, eliminating the race entirely. For visualizations, showing the rejected write with its stale token next to the current token makes the failure mode legible in a way that abstract "split-brain" diagrams don't.

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,835. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.