Repository navigation
fix(#906): checkout release must prove holder identity - #907
Merged
admarble merged 7 commits intoAug 7, 2026
Merged
Conversation
`CheckoutLock.release()` skipped the holder-identity check entirely when the lock carried `skipPidCheck` — which every /fullsolve lock does. Acquire and release were asymmetric in exactly the scenario #901 exists for: a second session's acquire was correctly refused while the holder was fresh, but its release succeeded and removed the holder's lock. Every halt branch in the skill runs the release contract, so the losing session finishing first was the common path. Ownership is now one ordered predicate, `isCheckoutOwner`, shared by acquire and release so they cannot disagree about who the holder is: 1. cross-host -> refuse (first, unconditional) 2. both sessionIds present -> equality decides, no fall-through 3. pid+hostname match -> release (live-process self-release) 4. skipPidCheck lock && caller issue === holder issue -> release 5. otherwise refuse Rule 4 restores for a constant-filename lock the property `releaseExternal` gets for free from its issue-keyed *filename*: naming the issue is the proof. It is a courtesy check against the accident (a blocked session carries a different issue), not a security boundary — `clear --force` exists. Also closed here: - `clear()` now unlinks an unparseable checkout.lock. Reachable via the create-then-write window (#856 group-SIGKILL); it was previously unclearable by any command while the hook blocked on it forever. - All three refusal messages recommend `clear --force`; plain `clear` refuses a fresh holder, and a leaked skill lock reads fresh for 6h. - CLI: `locks checkout release --issue`, and refusal is distinguishable from a no-op (exit 1, names the holder's issue and the recovery command). /fullsolve SKILL.md (all three mirrors): --issue on every release site; duplicated per-issue acquire block deleted; Phase 0 declared unconditional on resume; Phase 5.0 branch gate releases before exiting; release contract no longer names two branches that continue to Phase 5; SEQUANT_ISSUE exported so the hook stops blocking the holder with its own lock. Three tests asserted the bug as the contract and are corrected. The fullsolve gate test is rewritten per-site: its count-based pairing (`8 >= 7`) already tolerated deleting a release site. Fixes #906
…sees it `test-tautology-detector` resolves helper indirection only through block-bodied arrow consts, so a `function` declaration made every test calling it read as import-less. These tests spawn the real dist CLI. Pre-existing blind spot, measured: on origin/main this file already reads 17/19 (89%) tautological; the 17 that remain are #901's `function runHook` tests, untouched here.
Two QA findings on my own diff. 1. The AC-12 guidance was wrong. The PreToolUse hook runs outside and before the command's shell, so it reads Claude Code's environment — not anything a skill bash block exports. Verified live: this very run was HOOK_BLOCKED by its own #906 lock, and re-running with `export SEQUANT_ISSUE=906` prepended to the same block changed nothing. The previous text told readers to set it "in that same block", which does not work either. Replaced with what does: the `git -C "$SEQUANT_WORKTREE"` form, and the literal-path caveat on path-restore (the exemption does not resolve `$VARS`, so `git checkout -- "$F"` is refused where a literal path is allowed). AC-12's stated consequence is not achievable by this mechanism at all — it needs holder identity surviving a shell boundary, which Design v2 itself rules out of scope. Flagged, not papered over. 2. The gate's whole-file negative anchored on `npx `, so a site written as bare `sequant locks checkout release` would have passed. Now scans bash fences instead of anchoring on the runner — which also keeps the §5.5 prose that merely names the command from matching. Mutation-verified: the bare-`sequant` form now fails the gate.
…d paths Closes the two gaps QA left open. 1. AC-12 for real. `SEQUANT_ISSUE` could never identify the holder interactively: PreToolUse runs outside and before the command's shell, so nothing a skill bash block exports reaches it, and the one path that does export it (`sequant run`) also sets SEQUANT_ORCHESTRATOR, where the guard stands down. The fallback was unreachable in every real flow and the holder was routinely blocked by its own lock. The hook does see both the acquire and every later command of the same session, and session_id survives the shell boundary that kills the acquiring PID. It now records the session->issue binding when it observes `locks checkout acquire --issue=N`, and consults it as the last rule in the holder check. Clearing happens only on a release that names the session's OWN issue -- a refused release must not strip the real holder's identity. 2. Path-restore exemption. `git checkout -- "src/foo.ts"` was blocked while the unquoted form was allowed. My earlier claim that this was about shell variables was WRONG, and the correction matters: an unquoted `$F` always worked. The cause is quoting -- `emit_segments` drops double-quoted regions, leaving the segment as `git checkout --` with no trailing space, and the exemption required `-- `. Now `--( |$)`. `--detach` still does not match, and quoted branch names (`git checkout "main"`) are still blocked. SKILL.md prose replaced: it described the pre-fix world and told readers to work around a gap that no longer exists. 12 new integration tests against the real hook. The identity tests write a lock with NO sessionId -- the shape production actually writes, since acquire never passes --session-id -- because the default fixture stamps one and would let the sessionId rule decide every case, passing them vacuously.
The gate flagged 31/54 (57.4%) of this PR's test blocks. Measured on origin/main, checkout-lock.integration.test.ts already read 17/19 (89%) and checkout-lock.test.ts 7/20 -- every one a false positive. Both files drive real production code. The earlier commit dodged this by reshaping one helper into an arrow const, which left the gate at exactly 50.0%, one test away from re-tripping. Three blind spots, each with a measured effect: 1. Only arrow-const helpers were extracted, so a `function` declaration made every test calling it read as import-less. Added, but NOT by widening the regex: a greedy return-type subpattern ran past the body and anchored on the next declaration's brace, silently attributing somebody else's code as the helper body -- it made the numbers look right for the wrong reason. Now the regex stops at the closing paren and a deterministic walk picks the body brace, stepping over an object return-type annotation. The object-return-type test pins exactly this. 2. Handles were seeded only on helpers that spawn the build output, so a factory like `makeLock()` returning `new CheckoutLock(...)` did not count. Now an imported production function seeds a handle too. 3. "Production" meant `dist/` only. The checkout-lock suite spawns the real .claude/hooks/pre-tool.sh -- the enforcement half of the feature under test. Project scripts (hooks/*.sh, scripts/**) now count; spawning a system binary like `git` still does not. Diff now reads 0/60. All 60 pre-existing detector tests unchanged and passing; 7 added, including two negatives proving the widening did not switch the detector off (a helper that reaches nothing, and a helper that only spawns `git`, are both still flagged).
Mutation testing found the pattern unexercised: the runHook case reaches
production through the collected HOOK variable, so removing
PROJECT_SCRIPT_PATTERN failed nothing. The inline-literal form
(spawnSync('npx', ['tsx', 'scripts/migrate.ts'])) is the shape it
actually guards. M11 now fails exactly this test.
…T_ISSUE claim The original entry credited the SEQUANT_ISSUE export with unblocking the holder. It never did -- corrected, and the three new entries describe what actually closes it.
admarble
deleted the
feature/906-fix-locks-checkout-release-ignores-holder-iden
branch
August 7, 2026 13:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CheckoutLock.release()skipped the holder-identity check entirely whenever the lock carriedskipPidCheck— which every/fullsolvelock does. Acquire and release were asymmetric in exactly the two-session scenario #901 exists for: a second session's acquire was correctly refused while the holder was fresh, but its release succeeded and removed the holder's lock. Since every halt branch in the skill runs the release contract, the losing session finishing first was the common path — and the next session was then waved straight through thepre-tool.shguard while the first was still mid-run.Implements Design v2, plus the gaps found while validating it. Ownership is now one ordered predicate,
isCheckoutOwner, shared by acquire and release so the two cannot disagree about who the holder is:sessionIds present → equality decides, no fall-throughpid+hostnamematch → release (live-process self-release)skipPidChecklock and caller issue === holder issue → releaseRule 4 restores for a constant-filename lock the property
LockManager.releaseExternalgets free from its issue-keyed filename: naming the issue is the proof of ownership. It is a courtesy check against the accident — a blocked session carries a different issue by construction — not a security boundary;clear --forcealready exists.Everything else this closes
The guard now recognizes the holder across the shell boundary.
SEQUANT_ISSUEwas supposed to identify the holder topre-tool.shand never could:PreToolUseruns outside and before the command's shell, so nothing a skill bash block exports reaches it — not even an export prepended to the same block as the guarded command — and the one path that does export it (sequant run) also setsSEQUANT_ORCHESTRATOR, where the guard stands down. The holder was routinely refused in its own tree, with a message naming itself as the blocker. Observed live while building this PR. The hook now records the session→issue binding when it observeslocks checkout acquire --issue=<N>, keyed onsession_id— the one identity that survives the shell boundary killing the acquiring PID — and consults it as the last rule. Clearing happens only on a release naming the session's own issue, so a refused release cannot strip the real holder's identity.Path-restore is exempt whether or not the path is quoted.
git checkout -- "src/foo.ts"was refused while the unquoted form passed. My first diagnosis of this was wrong and is corrected here: it is not about shell variables — unquoted$Falways worked.emit_segmentsdrops double-quoted regions, leaving the segment asgit checkout --with no trailing space against an exemption requiring--. Now--( |$).--detachstill doesn't match; quoted branch names are still blocked.A corrupt
checkout.lockwas unclearable by any command. Reachable — the file is created and written in two steps and a group-SIGKILL lands between them (#856).clearread it, saw nothing, returnedno-lockwithout unlinking (--forceonly ever reached the staleness check, never the read), while the hook blocked on it forever.All three refusal messages recommended a bare
clear, which refuses a fresh holder — and a leaked skill lock reads fresh for its full 6h TTL.The tautology detector reported whole suites of real tests as tautological. Three blind spots, each measured on
mainrather than assumed:checkout-lock.integration.test.tscheckout-lock.test.tsIt extracted only arrow-const helpers (so
functiondeclarations made every caller read as import-less); seeded handles only on helpers that spawn build output (somakeLock()returningnew CheckoutLock(...)didn't count); and treateddist/as the only production code, excluding the hook scripts these very tests drive. Guard rails are explicit and tested: a helper reaching no production code, and one that only spawnsgit, are both still flagged./fullsolve's Phase 0.3 is corrected alongside:--issueat every release site, the duplicated per-issue acquire block deleted (a literal second acquire halts the session against its own lock —LockManagerhas no reentrancy check), Phase 0 declared unconditional on resumed runs, the Phase 5.0 branch gate now releasing before it exits, and the release contract no longer naming two branches that actually continue to Phase 5.locks checkoutships in no released version, so failing closed costs no compatibility.Test plan
npm test— 240/240 files, 5140 passed, 1 expected-fail, 2 skippednpm run build,npm run lint(0 warnings),lint:skill-sync(44 synced, 0 diverged)Mutation verification (per CLAUDE.md)
Eleven mutations, tree restored clean after each. The gate test was rewritten because its predecessor's count-pairing (
8 >= 7) stayed green when a release site was deleted.skipPidCheckrelease bypass--issuefrom one release sitesequant …withoutnpx--function-declaration helper extractionTwo process notes I'd rather state than bury
A
git checkout --during mutation testing wiped uncommitted work. Reverting a mutation reverted my not-yet-committed detector fixes with it. Caught only because the next "baseline" run failed 5 tests instead of passing. Reapplied, committed, then re-mutated — and the isolated re-run immediately showed the earlier batch had been measuring a corrupted baseline.One fix looked right for the wrong reason. My first
function-declaration pattern reported a clean 0/60, but was matching greedily past the helper body and anchoring on the next declaration's brace — attributing unrelated code as the helper body. A synthetic object-return-type test caught what the real file had masked. Replaced with a deterministic body-brace walk; that test now pins it.One deliberate divergence from Design v2
v2 asked to add the issue rule to
acquire's reentrancy check. I replacedisSameHolderwith the single shared predicate instead, so symmetry is structural rather than maintained by two edits kept in step. Consequence worth a look: thesessionIdbranch now sits behind the hostname check, so a cross-host caller with a matching session id is no longer reentrant. One existing assertion changed accordingly and is now stated explicitly as rule 1.Adjacent defects — filed, not fixed here
Design v2 scoped these out; verified against the code and filed with fix sketches and test plans: #908 (stale-lock steal is unlink-then-create, so two stealers can both win), #909 (locks dir is cwd-relative while the hook reads the git toplevel — acquiring from a subdirectory silently protects nothing), #910 (
new-feature.shbypasses the guard — the script the block message recommends), #911 (/mergerand/releasemutate the main checkout without participating).Fixes #906
🤖 Generated with Claude Code