Skip to content

fix(spec): a used spec number stays spent, kernel lock for reserve - #1261

Merged
tieubao merged 3 commits into
masterfrom
l312-spec
Dec 2, 2026
Merged

tieubao merged 3 commits into
masterfrom
l312-spec

Conversation

@tieubao

@tieubao tieubao commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

What

A spec number that was used stays used, and reserving a number no longer deadlocks on Ubuntu 26.04.

  1. lib/spec/spec-next.sh promotes a realized reservation in place to a permanent anchored SPENT record, so a later reserve never hands the number out again.
  2. reserve is serialized by the kit's kernel lock (lib/goal/goal-lock.sh, flock; perl flock on macOS) instead of mkdir-as-lock, which deadlocked under uutils mkdir (CI run 46362536895).
  3. A lock directory left by a killed older copy is reclaimed when its owner is dead; a live holder still refuses. CRLF lines read correctly. A killed reserve frees the lock at once. The lock wait is 60 s.
  4. commands/mega.md states the contract: a number becomes permanently SPENT once it is realized and seen by a later reserve; an unused reservation is still released after its TTL.

Demo

Two worktrees racing reserves, 20 rounds under load: no number issued twice.

Proof

docs/verification/spec-number-stays-spent.md

  • Verdict: works: no duplicate numbers, no deadlock, and a stale lock from an older copy no longer blocks.
  • Proof: tests/test-spec-next-spent.sh 114/114 and tests/test-spec-reserve.sh 70/70 on bash 5.3, bash 3.2, GNU tools first and a Linux flock shim; the Ubuntu deadlock reproduced locally before the fix; planted faults red; one fresh review with real races and SIGKILL runs, its blocker and three risks fixed.
  • Risk: an older installed copy refuses to reserve while a new-style lock exists, until it is updated with install.sh; undo with a revert.
  • Needs Han: nothing.

Bookkeeping

no-board-row: leftover audit slice tracked on the devkit leftovers item

Promote realized reservations in lib/spec/spec-next.sh to permanent SPENT records in the same ledger, counted with no TTL and anchored repo scoping. Replace the home-made mkdir mutex with lib/goal/goal-lock.sh kernel flock so concurrent worktrees serialize safely on Ubuntu 26.04 uutils coreutils.
Reclaim dead-owner or empty mkdir-lock dirs before goal_lock while refusing live holders and non-empty dirs fail-closed; strip trailing CR in SPENT and RESERVE parsing/dedupe; close fd 9 inside command substitutions so SIGKILL releases the flock immediately; default GOAL_LOCK_TIMEOUT to 60 inside reserve; clarify commands/mega.md spent contract.
@tieubao
tieubao merged commit 45d1587 into master Dec 2, 2026
4 checks passed
@tieubao
tieubao deleted the l312-spec branch December 2, 2026 09:42
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.

1 participant