Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions commands/mega.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,12 @@ no new binary or `lib/` file. Full depth + a worked dry-run: the skill's
4. **Front-load clarifications ONCE**, over the whole union -- Step 2's beat, reused
verbatim, just framed against the union rather than one mega.
5. **Spec-number block reserve + release.** Reserve via `bash lib/spec/spec-next.sh reserve`
(the spec-numbering mkdir-mutex reservations ledger, the same mechanism the wavefront dispatch
already uses at Step 4). This kit has no separate `release` verb: an unclaimed reservation
self-expires on its own stale-reclaim TTL, so "release the old megas' unused numbers" is a
no-op here, not a command to run -- the ledger prunes them without an operator step.
(the spec-numbering kernel-flock reservations ledger, the same mechanism the wavefront dispatch
already uses at Step 4). This kit has no separate `release` verb: an unrealized reservation
still expires after the TTL, and a number becomes a permanent `SPENT` record once it is
realized in a spec file, branch, or commit and seen by a later `reserve`, after which it does
not come back on its own (to reclaim one burnt by mistake, delete its
`| SPENT | spec=<NNN> repo=<REPO>` line from `spec-reservations.log`).
6. **Provenance per sub-goal.** Every consolidated sub-goal records `from: <mega-A>/SG-<N> +
<mega-B>/SG-<M>` on its roadmap line and in its goal file. Done imports keep their own
single origin + PR.
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh
| `/kit:design` | `[H/I]` | Opt-in interactive solution-design beat between /think and /spec. Use when the operator wants to shape HOW to build after the idea passed /… | SPEC-003, SPEC-004, SPEC-005 +162 | test-anomalies-advisor.sh, test-board-mirror-cleanup.sh, test-ceremony-fits-diff.sh +40 |
| `/kit:devs-team` | `[H/I]` | Parallel multi-lens critique of a solution design (the active spec if present, else the decision brief). Dispatches 5 engineering lenses, m… | SPEC-016, SPEC-018, SPEC-019 +14 | test-gate-vocab-recording.sh, test-meta-review-verifiers.sh, test-meta-spec-depth.sh +1 |
| `/kit:dispatch` | `[H/I]` | Fire several disjoint VALIDATED specs concurrently, each in its own worktree, then converge. Cross-goal fan-out behind a disjointness gate … | SPEC-002, SPEC-016, SPEC-017 +114 | test-advisor.sh, test-agent-effectiveness.sh, test-attempt-state-race.sh +52 |
| `/kit:docs` | `[H/I]` | Update all project documentation to match the current codebase. Cross-references the diff against every doc file and fixes drift. | SPEC-001, SPEC-002, SPEC-003 +292 | conform.sh, test-active-spec-pick.sh, test-adapters.sh +162 |
| `/kit:docs` | `[H/I]` | Update all project documentation to match the current codebase. Cross-references the diff against every doc file and fixes drift. | SPEC-001, SPEC-002, SPEC-003 +292 | conform.sh, test-active-spec-pick.sh, test-adapters.sh +163 |
| `/kit:draft-agent` | `[H/I]` | Meta-agent agent-builder. From a one-line description, generates a new subagent definition OR a mega-goal sub-goal file and (by default) in… | SPEC-089, SPEC-108, SPEC-139 +1 | test-agent-effectiveness.sh, test-command-emit-sweep.sh, test-meta-agent.sh +1 |
| `/kit:execute` | `[H/I]` | Whole-spec execution with verification. Dispatches one builder for the whole spec, verifies every task's criteria once at the end, retries … | SPEC-001, SPEC-003, SPEC-004 +82 | test-board-work.sh, test-break-it.sh, test-config-registry.sh +29 |
| `/kit:explain` | `[H/I]` | Turn a merged change into a literate-diff explainer a human READS to understand: background -> goal + intuition -> a prose-ordered diff -> … | SPEC-050, SPEC-060, SPEC-094 +25 | test-boundary-lint.sh, test-clean-room.sh, test-command-emit-sweep.sh +13 |
Expand All @@ -29,8 +29,8 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh
| `/kit:greenlight` | `[H/I]` | Post-push CI-green lane: snapshots an open PR's checks via gh, classifies each failure real vs flaky, fixes real ones via the kit:fix-agent… | SPEC-019, SPEC-217, SPEC-369 | test-audit-verdict-grammar.sh, test-gate-ledger-actions.sh, test-ql-verdict.sh |
| `/kit:grill` | `[H/I]` | Universal intake interview: one type-shaped question at a time, each with a recommended answer, until the task is actually understood. Answ… | SPEC-058, SPEC-059, SPEC-063 +27 | test-anomalies-advisor.sh, test-ceremony-lens.sh, test-config-stamp.sh +17 |
| `/kit:kit-health` | `[H/I]` | Run a self-assessment of the kit against its own philosophy. Checks file count, hook performance, source citations, and structural health. | SPEC-001, SPEC-002, SPEC-004 +18 | test-command-emit-sweep.sh, test-meta-docs-registry.sh, test-meta-goal-ledger.sh +4 |
| `/kit:mega` | `[H/I]` | Turn a multi-objective destination into a sequenced roadmap of dependent sub-goals: decompose, front-load every clarification once, set the… | SPEC-034, SPEC-036, SPEC-088 +53 | test-adapters.sh, test-advisor.sh, test-bin-forwarders.sh +44 |
| `/kit:next` | `[H/I]` | Pick up the next undone task from the spec. Loads context, shows acceptance criteria, lets you drive the implementation. | SPEC-001, SPEC-002, SPEC-003 +146 | smoke.sh, test-active-spec-pick.sh, test-adapters.sh +95 |
| `/kit:mega` | `[H/I]` | Turn a multi-objective destination into a sequenced roadmap of dependent sub-goals: decompose, front-load every clarification once, set the… | SPEC-034, SPEC-036, SPEC-088 +53 | test-adapters.sh, test-advisor.sh, test-bin-forwarders.sh +45 |
| `/kit:next` | `[H/I]` | Pick up the next undone task from the spec. Loads context, shows acceptance criteria, lets you drive the implementation. | SPEC-001, SPEC-002, SPEC-003 +146 | smoke.sh, test-active-spec-pick.sh, test-adapters.sh +96 |
| `/kit:onboard` | `[H/I]` | Guided first-run: detect the install mode, offer /kit:adopt for this repo, pick modules, capture the consumer knobs that make them work, di… | SPEC-199, SPEC-213, SPEC-232 +3 | test-clean-room.sh, test-command-emit-sweep.sh, test-onboard-detect.sh |
| `/kit:pitch` | `[H/I]` | Assemble an outward buy-in doc from what a gated run already produced: the spec, the proof-of-done, the implementation-notes, and the gate … | SPEC-140, SPEC-141, SPEC-193 +7 | test-gate-validate-round.sh, test-outcome-emit-sweep.sh, test-pitch.sh +2 |
| `/kit:prototype` | `[H/I]` | Opt-in throwaway-spike beat beside /kit:design. Builds throwaway code that answers ONE design question: a logic/state model driven by hand … | SPEC-075, SPEC-206, SPEC-207 +3 | test-picture-section.sh |
Expand All @@ -40,7 +40,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh
| `/kit:review` | `[H/I]` | Paranoid code review. Security, architecture, regressions, missing tests, edge cases. Produces actionable TODOS. | SPEC-001, SPEC-002, SPEC-003 +155 | smoke.sh, test-adopt.sh, test-advisor.sh +90 |
| `/kit:ship` | `[H/I]` | Ship: review gate, tests, version bump, changelog, conventional commit, docs update, PR. Complete pipeline from done to merged. | SPEC-001, SPEC-002, SPEC-003 +111 | test-active-spec-pick.sh, test-adopt.sh, test-board-mirror.sh +64 |
| `/kit:spec-validate` | `[H/I]` | Adversarial review of a spec before implementation. 7 specialist lenses attack the spec from different angles (6 advisory, 1 blocking on th… | SPEC-002, SPEC-003, SPEC-004 +70 | test-command-emit-sweep.sh, test-design-record.sh, test-every-step-review.sh +10 |
| `/kit:spec` | `[H/I]` | Generate a development spec from a feature idea or decision brief. Creates docs/specs/ with structured requirements. | SPEC-001, SPEC-002, SPEC-003 +241 | test-active-spec-pick.sh, test-audit-verdict-grammar.sh, test-bin-forwarders.sh +110 |
| `/kit:spec` | `[H/I]` | Generate a development spec from a feature idea or decision brief. Creates docs/specs/ with structured requirements. | SPEC-001, SPEC-002, SPEC-003 +241 | test-active-spec-pick.sh, test-audit-verdict-grammar.sh, test-bin-forwarders.sh +111 |
| `/kit:start` | `[H/I]` | Detect project state and suggest the right next command. The entry point for any session. | SPEC-002, SPEC-003, SPEC-004 +94 | test-anomalies-advisor.sh, test-audit-cadence.sh, test-board-add.sh +96 |
| `/kit:test-plan-review-team` | `[H/I]` | Parallel multi-lens adversarial critique of a spec's test plan (the ## Test plan section), with a bounded revise loop that tightens it. Dis… | SPEC-031, SPEC-052, SPEC-062 +14 | test-meta-docs-registry.sh, test-meta-review-verifiers.sh, test-meta-vmodel-dispatch.sh +3 |
| `/kit:test-plan` | `[H/I]` | Derive a test-case coverage matrix from a spec's acceptance criteria before /kit:execute. Writes a `## Test plan` section into the active s… | SPEC-004, SPEC-016, SPEC-018 +38 | test-ceremony-lens.sh, test-e2e.sh, test-gate-ledger-inherit.sh +15 |
Expand Down
165 changes: 165 additions & 0 deletions docs/verification/spec-number-stays-spent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Verification: spec-number-stays-spent

Headless shell library fix (`l312-spec`, off `origin/master` `74475fb1`): no UI surface.

Fixes two core defects and four review findings (B1, R1, R2, R5, plus spent contract 2b option a) in `lib/spec/spec-next.sh`:

1. **Realized spec numbers stay spent permanently**: `_prune_reservations` previously dropped a `RESERVE` line once its number appeared in `docs/specs/`, branches, or recent commits; deleting the spec file or branch later let `next` and `check` treat the number as free again. A realized reservation for the calling repo is now promoted once in place to `<iso> | SPENT | spec=<NNN> repo=<REPO>` in the same reservations ledger, counted by `_spent` / `_numbers` / `check` with no TTL and anchored `repo=` scoping.
2. **Kernel flock replaces mkdir-as-lock (Ubuntu 26.04 uutils fix)**: `reserve` previously serialized via a home-made `mkdir "$RES_LOCK"` + owner-file mutex, which deadlocked `tests/test-spec-reserve.sh` T20 on Ubuntu 26.04 (`uutils coreutils 0.10.0`, `uutils/coreutils#16344`: racing non-recursive `mkdir` exits 0 on `EEXIST`, allowing concurrent entry and self-deadlock on the owner PID). `reserve` now serializes via `lib/goal/goal-lock.sh` (`flock(2)` on fd 9), eliminating `mkdir`-as-lock, owner files, and PID/TTL reclaim races.
3. **B1 (stale old-code mkdir-lock dir migration)**: before calling `goal_lock "$RES_LOCK"`, if `$RES_LOCK` is a directory, `reserve` checks `$RES_LOCK/owner` (stripping CR and suffix after `.`) and reclaims it via `rm -f "$RES_LOCK/owner" && rmdir "$RES_LOCK"` when the owner PID is missing/dead, while leaving live old-code holders and non-empty unexpected directories untouched so `goal_lock` refuses fail-closed.
4. **R1 (CRLF resilience)**: `sub(/\r$/,"")` runs first in `_spent` and the prune dedupe `awk`, and `line="${line%$'\r'}"` runs after each `read -r line` in `_reservations` and `_prune_reservations`, so hand-edited CRLF lines never fail open as free or duplicate on promotion.
5. **R2 (no orphaned fd 10 hold on SIGKILL)**: `n="$(exec 9>&-; next)"`, `realized="$(exec 9>&-; _scan_numbers)"`, and `exec 9>&-` inside `tail`/`date` command substitutions close fd 9 inside the subshell instead of redirecting the function call (which made bash save fd 9 to fd 10 and leak the lock to orphaned children).
6. **R5 and 2b option (a)**: `GOAL_LOCK_TIMEOUT="${GOAL_LOCK_TIMEOUT:-60}"` inside `reserve` (matching or exceeding the old mutex patience under contention), and `commands/mega.md` states accurately that a number becomes permanently `SPENT` once realized and seen by a later `reserve` while unrealized reservations keep TTL expiry.

## Readers audited

All readers of `spec-reservations.log` / `SPEC_RESERVE_FILE` in `lib/`, `bin/`, `hooks/`, and `tests/` were searched (`rg -n "spec-reservations|SPEC_RESERVE|RESERVE" lib/ bin/ hooks/ tests/`):

- `lib/spec/spec-next.sh`: filters `RESERVE` lines by `*"| RESERVE |"*` and reads `SPENT` lines via anchored `_spent`, stripping trailing CR in both paths.
- `tests/test-spec-reserve.sh`: T6 checks `count 'num=006'` (0, unaffected by `spec=006`); T11 checks expired foreign pruning for nonexistent `repo=some-other-repo` (passes because `[ ! -d "$r" ]`); T9/T14/T15/T16/T17/T18/T25 verify kernel `flock(2)` semantics via `lib/goal/goal-lock.sh` (T18 verifies non-empty unexpected directory at `$RES.lock` is refused safely).
- `tests/test-spec-find.sh` and `tests/test-spec-next-pr-scan.sh`: call `spec-next.sh` CLI only; no direct ledger parsing.
- `commands/mega.md`: updated lines 539-545 to document kernel flock, permanent `SPENT` records once realized and seen by a later `reserve`, TTL release for unrealized claims, and line deletion for reclaiming a burnt number.

## Root cause and RED baselines

### 1. Reproducing the Ubuntu 26.04 T20 failure locally (uutils `mkdir` TOCTOU on `origin/master`)

```text
Command: bash -c '<T20 5-round probe under uutils mkdir stub against origin/master lib/spec/spec-next.sh>'
Exit: 0
Output:
round 1: total=1 distinct=1 lock=free
wa err: spec-next: open PR heads not scanned (SPEC_NEXT_NO_PR_SCAN=1) spec-next: open PR heads not scanned (SPEC_NEXT_NO_PR_SCAN=1)
wb err: spec-next: open PR heads not scanned (SPEC_NEXT_NO_PR_SCAN=1) spec-next reserve: could not acquire lock after 20 tries (<tmp>/repo/res-1.log.lock)
```

### 2. Initial RED baseline on `origin/master` (`e75b5b2d`)

```text
Command: bash tests/test-spec-next-spent.sh
Exit: 1
Output:
=== T1: realized file deleted -- number stays spent ===
FAIL T1 check 006 stays TAKEN after file deletion (missing 'TAKEN' in: ... SPEC-006 is free rc=0)
FAIL T1 next does not reissue deleted 006 after 007 expires (want '007' got '006')
=== T17: kernel flock exclusion and immediate SIGKILL release ===
FAIL T17 reserve succeeds immediately after holder SIGKILL (006) (want '006' got '')
=== Results ===
Passed: 49 / 100
51 assertions failed.
```

### 3. Fix-round RED-first baseline on `86c181b0` (before B1, R1, R2, and `mega.md` wording)

```text
Command: timeout -k 5 90 bash tests/test-spec-next-spent.sh | tail -n 65
Exit: 0 (suite exit 1 before pipe)
Output:
FAIL T14 commands/mega.md states SPENT happens when seen by a later reserve
FAIL T18a stale mkdir lock dir with dead owner is reclaimed (006) (want '006' got '')
FAIL T18a lock path migrated to regular file (want 'file' got 'other')
FAIL T18b empty stale mkdir lock dir is reclaimed (006) (want '006' got '')
FAIL T19 CRLF SPENT 010 reads as TAKEN (SPEC-010 is free rc=0)
FAIL T19 CRLF live RESERVE 011 reads as TAKEN (SPEC-011 is free rc=0)
FAIL T19 next advances past CRLF SPENT 010 and RESERVE 011 (012) (want '012' got '006')
FAIL T19 reserve after CRLF ledger returns 012 (want '012' got '011')
FAIL T20 next reserve succeeds after SIGKILL mid-scan (006) (want '006' got '')
FAIL T20 orphaned child held lock after SIGKILL (got='', 2s)
Passed: 104 / 114
10 assertions failed.
```

## Green runs

### 1. Shellcheck and 5-configuration verification matrix (bash 5.3, `/bin/bash` 3.2, GNU tools first on `PATH`, Linux `flock(1)` shim)

```text
Command: shellcheck -S warning lib/spec/spec-next.sh tests/test-spec-reserve.sh tests/test-spec-next-spent.sh && <5-config matrix of test-spec-next-spent.sh, test-spec-reserve.sh, test-spec-next-pr-scan.sh>
Exit: 0
Output:
SHELLCHECK OK
=== bash 5 (default PATH) ===
Passed: 114 / 114 (spec-next-spent green.) | Passed: 70 / 70 (spec-reserve green.) | Passed: 8 / 8 (spec-next-pr-scan green.)
=== /bin/bash 3.2 (default PATH) ===
Passed: 114 / 114 (spec-next-spent green.) | Passed: 70 / 70 (spec-reserve green.) | Passed: 8 / 8 (spec-next-pr-scan green.)
=== bash 5 (GNU tools first) ===
Passed: 114 / 114 (spec-next-spent green.) | Passed: 70 / 70 (spec-reserve green.) | Passed: 8 / 8 (spec-next-pr-scan green.)
=== /bin/bash 3.2 (GNU tools first) ===
Passed: 114 / 114 (spec-next-spent green.) | Passed: 70 / 70 (spec-reserve green.) | Passed: 8 / 8 (spec-next-pr-scan green.)
=== bash 5 (GNU + Linux flock shim) ===
Passed: 114 / 114 (spec-next-spent green.) | Passed: 70 / 70 (spec-reserve green.) | Passed: 8 / 8 (spec-next-pr-scan green.)
```

### 2. Changed-scope suites (`bin/test-affected --base origin/master`)

```text
Command: bash bin/test-affected --base origin/master
Exit: 0 (29 pass, 0 fail, 1 timeout under load 77.9)
Output:
PASS tests/test-advisor.sh
PASS tests/test-docs-wiring.sh
PASS tests/test-hooks.sh
PASS tests/test-kri-wiring.sh
PASS tests/test-mega-gate-head.sh
PASS tests/test-mega-reconcile.sh
PASS tests/test-meta-agents-commands.sh
PASS tests/test-meta-docs-registry.sh
PASS tests/test-meta-goal-ledger.sh
PASS tests/test-meta-plugin-hooks.sh
PASS tests/test-meta-review-verifiers.sh
PASS tests/test-meta-vmodel-dispatch.sh
PASS tests/test-precedent.sh
PASS tests/test-registry-freshness-guard.sh
PASS tests/test-registry-verbs.sh
PASS tests/test-shared-lookups.sh
PASS tests/test-spec-active.sh
PASS tests/test-spec-depth.sh
PASS tests/test-spec-drift-guard.sh
PASS tests/test-spec-find.sh
PASS tests/test-spec-index.sh
PASS tests/test-spec-next-pr-scan.sh
PASS tests/test-spec-next-spent.sh
PASS tests/test-spec-reserve.sh
PASS tests/test-spec-states.sh
PASS tests/test-spec-task-done.sh
PASS tests/test-test-affected.sh
TIMEOUT tests/test-wrap-land.sh (limit 600s; CI-only suite blocked standalone by branch-guard)
PASS tests/test-wrap-merge.sh
PASS tests/test-wrap-rebase.sh
test-affected: 30 selected, 29 pass, 0 cached, 0 fail, 1 timeout, 1 uncovered
```

## Negative control and planted faults (isolated scratch copy)

All negative control probes ran in temporary scratch copies without mutating the workspace, each capped by `timeout -k 5`:

```text
Command: bash -c '<12 planted-fault negative control probes in isolated scratch copies>'
Exit: 1
Output:
Mutant [M0-origin-master] (test-spec-next-spent.sh): Exit=124 (baseline direct run: Exit=1, Passed: 49 / 100, 51 assertions failed)
Mutant [M1-no-goal-lock] (test-spec-reserve.sh): Exit=1 | Passed: 58 / 70 12 assertions failed.
Mutant [M2-drop-spent-from-numbers] (test-spec-next-spent.sh): Exit=1 | Passed: 69 / 100 31 assertions failed.
Mutant [M3-drop-foreign-dir-guard] (test-spec-next-spent.sh): Exit=1 | Passed: 98 / 100 2 assertions failed.
Mutant [M4-no-promo-dedupe] (test-spec-next-spent.sh): Exit=1 | Passed: 99 / 100 1 assertions failed.
Mutant [M5-unanchored-promo-dedupe] (test-spec-next-spent.sh): Exit=1 | Passed: 99 / 100 1 assertions failed.
Mutant [M6-no-x-number-anchor] (test-spec-next-spent.sh): Exit=1 | Passed: 98 / 100 2 assertions failed.
Mutant [M7-no-unterminated-read] (test-spec-next-spent.sh): Exit=1 | Passed: 98 / 100 2 assertions failed.
Mutant [M8-piped-check] (test-spec-next-spent.sh): Exit=1 | Passed: 99 / 100 1 assertions failed.
Mutant [M9-no-b1-dir-reclaim] (test-spec-next-spent.sh): Exit=1 | Passed: 111 / 114 3 assertions failed.
Mutant [M10-no-r1-cr-strip] (test-spec-next-spent.sh): Exit=1 | Passed: 109 / 114 5 assertions failed.
Mutant [M11-no-r2-exec-close] (test-spec-next-spent.sh): Exit=1 | Passed: 112 / 114 2 assertions failed.
Verdict: RED
```

## Rollback

Revert the commits on this branch (`git revert <sha>`). Existing `| SPENT |` lines in `spec-reservations.log` are harmlessly ignored by older `spec-next.sh` (which only parses `| RESERVE |` lines); any regular lock file at `spec-reservations.log.lock` can be removed (`rm -f <kit-log-dir>/spec-reservations.log.lock`) if rolling back to the old `mkdir`-lock implementation. To reclaim an individual burnt number without rolling back, delete its exact `| SPENT | spec=<NNN> repo=<REPO>` line from `spec-reservations.log`.

## Not proven

- Native Ubuntu 26.04 kernel/uutils runner execution and real util-linux `flock(1)` (reproduced locally via the `uutils/coreutils#16344` `mkdir` stub, GNU coreutils/gawk/gnu-sed first on `PATH`, and a `flock(1)` shim; full Ubuntu matrix runs in CI).
- `tests/test-wrap-land.sh` standalone rerun (timed out at 600s during `bin/test-affected` under load 77.9 and is blocked standalone locally by `branch-guard`; runs on CI).
- Live GitHub open-PR scanning (`SPEC_NEXT_NO_PR_SCAN=0`).
- Pre-existing `ledger.location = "isolated"` per-worktree ledger split (R4, explicitly out of scope).
- Spec numbers created without `reserve` or deleted before any later `reserve` observes realization are not recorded as `SPENT` (documented per lead decision 2b option a).
Loading
Loading