Skip to content

Add a teaching demo that separates lease expiry from fencing - #1

Draft
namp wants to merge 1 commit into
mainfrom
cursor/lease-vs-fencing-demo-7fa3
Draft

namp wants to merge 1 commit into
mainfrom
cursor/lease-vs-fencing-demo-7fa3

Conversation

@namp

@namp namp commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a small, stdlib-only teaching demo under lease_vs_fencing/. It is isolated from the scanner driver: no scanner files are changed, and the demo does not join make check.

The demo makes two mechanisms concrete:

  • A coordinator lease can be acquired, renewed, and dropped when its TTL elapses. Expiry only clears that exclusive hold. The previous holder still has the fencing token it was given.
  • An effect sink accepts or rejects writes by comparing fencing tokens. FencedSink rejects a token older than one it has already observed. UnfencedSink stores every write.

The shared timeline expires Alice's lease, grants Bob a newer token, and then lets Alice write again. The fenced sink rejects that stale write. The unfenced sink stores it. A separate case writes after the TTL with no newer token presented, and the fenced sink still accepts it, so expiry is not treated as a fence.

How to run

From the repository root:

python3 -m lease_vs_fencing
python3 -m unittest lease_vs_fencing.test_lease_vs_fencing
Open in Web Open in Cursor 

The coordinator TTL only drops an exclusive hold. A fenced sink rejects a stale write after it observes a newer token, and an unfenced sink still accepts that write.

Co-authored-by: Nicholas <n.ampazis@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants