Skip to content
C.W.K.
Stream
Lesson 03 of 05 · published

Stale Guards Before Brain Spend

~12 min · optimistic-concurrency, hash, brain-spend, stale-write

Level 0Trace
0 XP0/36 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Remember the bytes that were read

A delegated edit reads source and returns after seconds or minutes of thought. Mobile sync or Dad may edit the same fragment meanwhile. A good result and a safe result are separate properties.

Capture the content hash when materializing the operand and store it as task base. Hash live bytes again immediately before apply. A mismatch keeps the revision as stale evidence for review against current source.

Check permission before spending too

Sending a protected fragment and rejecting only at apply still leaks content and spends tokens. Evaluate the matrix at queue, take, and operand read.

The check immediately before the brain call matters most because flags may flip while work waits. A queued task does not reserve future authority. Confirm both read and write rights.

Stale is not an invitation to auto-merge

A clean text merge does not prove semantic compatibility. The brain edited under an old premise while a new change may have replaced that premise. Automatic merge combines two judgments and falsifies provenance.

A narrow policy may allow mechanical non-overlap, but the default is a new task with current source and rebased instruction. Preserve the old revision as evidence without applying it.

Record cost in the failure

Repeated stale rejection signals a scope that is too broad or source that is too hot. Tokens spent, elapsed time, and base age help choose smaller fragments or quiescence.

Do not unsafe-apply to recover cost. Spent tokens are sunk; overwriting truth buys a far more expensive memory corruption.

Even an excellent revision cannot be applied directly when it was built from obsolete source. Check permission and base hash before and after spend, and preserve stale output as evidence only.

Code

An optimistic stale guard·python
from hashlib import sha256

def digest(text):
    return sha256(text.encode()).hexdigest()

read_source = "original"
base = digest(read_source)
current_source = "edited elsewhere"
revision = "improved original"
if digest(current_source) != base:
    status = "stale"
else:
    status = "apply"
assert status == "stale"

External links

Exercise

Add base-hash capture, pre-spend permission, and pre-apply hash check to one slow delegated task. Define the status and provenance of stale output.
Hint
Use a hash of actual bytes rather than an updated_at string.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.