Roadmap lock
File-level locking with TTL, heartbeat, and stale lock detection for multi-session roadmap coordinationFrom its SKILL.md
npx -y skills add joestein/on-loop --skill roadmap-lockAssembled 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
6.5 KB, as published. Nobody here has run it
Roadmap Lock Management
This skill manages file-level locking for multi-session coordination during roadmap execution. Locks prevent multiple sessions from working on conflicting steps simultaneously.
Lock Storage
Locks are stored in two places:
- Step-level locks: In
roadmap/.state/<feature>.jsonunderlocksand within stepassigned_sessionfields - Global coordination: In
roadmap/.state/_global.jsonfor cross-feature concerns
Lock Schema
Step Lock (in feature state file)
{
"locks": {
"<step-key>": {
"session_id": "<uuid-v4>",
"session_label": "<human-readable label, e.g. 'Alice laptop'>",
"phase": 1,
"step": 3,
"files": ["path/to/file.py", "path/to/other.py"],
"acquired_at": "<ISO 8601>",
"last_heartbeat": "<ISO 8601>",
"ttl_minutes": 60
}
}
}
Global Lock File
roadmap/.state/_global.json:
{
"version": "1.0",
"migration_lock": null,
"active_sessions": {
"<session-id>": {
"session_label": "<human-readable label>",
"feature": "<feature-slug>",
"phase": 1,
"step": 3,
"started_at": "<ISO 8601>",
"last_heartbeat": "<ISO 8601>",
"pid": "<process identifier if available>"
}
}
}
Operations
Generate Session ID
When a new session starts (any command invocation that needs coordination):
- Generate a UUID v4 using
python3 -c "import uuid; print(str(uuid.uuid4()))" - Store it for the duration of the session
- Optionally accept a
session_labelfrom the user for human readability
Acquire Lock
When /on-continue picks up a step:
- Read the feature state file
- Read the global lock file
- Check for conflicts:
a. If the step has
exclusive: true, verify no other steps in the phase arein-progressb. If the step hasconflicts_withIDs, verify none of those steps arein-progressc. If any target files overlap with files locked by another session, the lock cannot be acquired - Check for stale locks on the target step:
a. If a lock exists, check
last_heartbeatb. Iflast_heartbeatis more than 10 minutes old, the lock is stale and can be reclaimed c. Log a warning when reclaiming a stale lock - Write the lock:
a. Add entry to
locksin the feature state file b. Add entry toactive_sessionsin the global lock file c. Setlast_heartbeatto current timestamp - Verify lock (read-after-write): a. Re-read the state file b. Verify the lock belongs to this session c. If another session overwrote the lock (race condition), back off and retry once d. If retry fails, report that the step is unavailable
Release Lock
When a step completes, fails, or /on-pause is invoked:
- Read the feature state file
- Verify the lock belongs to the current session (by
session_id) - Remove the entry from
locks - Remove the entry from
active_sessionsin the global lock file - Write both files
Heartbeat
While a session is actively working on a step:
- Every 5 minutes, update
last_heartbeatin both:- The lock entry in the feature state file
- The session entry in the global lock file
- Use current ISO 8601 timestamp
- The heartbeat should be written at natural checkpoints (e.g., between agent phases)
Implementation note: Since Claude Code sessions are not long-running daemons, the heartbeat is written at key milestones during step execution rather than on a timer. Each agent dispatch within /on-continue should update the heartbeat.
Detect Stale Locks
When checking lock availability:
- Read the lock entry
- Parse
last_heartbeatas ISO 8601 - Compare to current time
- If the difference exceeds 10 minutes, the lock is stale
- Stale detection formula:
now - last_heartbeat > 10 minutes
Use this Python snippet for comparison:
python3 -c "
from datetime import datetime, timezone, timedelta
last = datetime.fromisoformat('<heartbeat_value>')
now = datetime.now(timezone.utc)
stale = (now - last) > timedelta(minutes=10)
print('stale' if stale else 'active')
"
Reclaim Stale Lock
When a stale lock is detected and a session wants to acquire the step:
- Log a warning:
[timestamp] WARNING: Reclaiming stale lock on phase <N> step <M> from session <old-session-id> (last heartbeat: <timestamp>) - Remove the old lock entry
- Remove the old session from
active_sessions - Proceed with normal lock acquisition
- Note the reclamation in the step's state for auditability
Release All Locks (for /on-pause)
When /on-pause is invoked:
- Read the feature state file
- Find all locks belonging to the current session (by
session_id) - For each lock:
a. If the step is
in-progress, leave it asin-progress(another session can reclaim via stale detection, or the same session can resume) b. Remove the lock entry - Remove the session from
active_sessionsin the global lock file - Write both files
Conflict Detection
File-Level Conflicts
Two steps conflict at the file level if their files arrays have any intersection:
Step A files: ["src/api.py", "src/models.py"]
Step B files: ["src/models.py", "src/utils.py"]
Conflict: "src/models.py" is in both -> cannot run concurrently
Annotation-Based Conflicts
Steps can declare conflicts explicitly:
exclusive: true-- This step cannot run while any other step in the same phase is in-progressconflicts_with: [1, 4]-- This step cannot run while steps 1 or 4 are in-progressparallel: true-- This step can run concurrently with otherparallel: truesteps (unless file conflicts exist)
Conflict Resolution Priority
- Check
exclusiveflag first (most restrictive) - Check
conflicts_withlist - Check file-level overlaps
- If no conflicts, the step is eligible
Error Handling
- Lock file missing: Create it with empty state
- Lock file invalid JSON: Back up the corrupt file, create fresh
- Session ID mismatch on release: Log warning, do not release (prevents accidental release of another session's lock)
- Concurrent write detected: Read-after-write check; back off and retry once
Global Lock File Initialization
If roadmap/.state/_global.json does not exist, create it:
{
"version": "1.0",
"migration_lock": null,
"active_sessions": {}
}
The migration_lock field is reserved for future use (e.g., schema migrations that need exclusive access).