Repository navigation
v1.91.228.0 fix(gstack-lease): take the lease lock with mkdir, not ln -s, so Git Bash on Windows stops waiting out 300 tries (#3330) - #3424
Conversation
…Bash on Windows stops waiting out 300 tries (#3330) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
|
😎 This pull request was merged. |
|
Windows negative control: this PR's tests with the old |
E2E Evals: ✅ PASS125 executed, 0 reused rule/judge records | 0 manual accepted (unscored; no score-cache credit) | $32.02 rule/judge cost | reconcile exit: 0 Profile: pr / mode Derived dependents (scripts/pr-dependencies.ts):
Rule and judge shards
Fail-closed reconciliationSliced lane: planner → duration-packed executors → fail-closed report. Behavior cases run a pre-registered 3-trial panel (PASS at 2/3 with no contract violation); a PASS 2/3 is shown with its failed trial, never as a clean pass. Reused results retain their original provenance and expiry. Dispatched narrow screen (gstack-ship-queue ready --screen) of merge commit |
…lock() break_lock ignored drop()'s failure and returned 0, so lock() continued past the tries limit forever when a dead holder's .lock could not be renamed aside (a Windows file in use). It now removes the lock in place under .lock.break, and returns 1 when that also fails so the try is counted. touch no longer calls a dead holder 'live' in its exit-3 message. Adds the /ship coverage-audit tests for the lock's failure paths. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
- drop() reports a lock released once it is renamed aside, so a failed delete of the renamed copy never makes unlock or break_lock rm -rf a new taker's lock at .lock. - An ownerless lock is broken only once it is 2 s old, so a live taker whose claim landed after a breaker read the claims keeps the lock it is about to publish. An empty owner, an invalid pid or a stray file counts as ownerless. - touch's prune stays out of the lock (top-level lease files only) and clears leftover renamed-aside locks; a failed claim write leaves no claim. - Docs and CHANGELOG state the mixed-version and dead-break-lock limits instead of claiming exclusion that does not hold. Tests pin each fix (each fails against the previous bin), make the exclusion case wait on a release file, prove the parallel case is mutually exclusive, and check the Git Bash holder keeps its lock. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
- orphaned() reads the clock before the lock's mtime and requires the mtime unchanged at the end, so a lock made meanwhile is never removed; an mtime a minute or more ahead (clock skew) counts as old. - Claims older than 2 minutes are abandoned and pruned by touch. - A waiter skips the claim and mkdir while the lock is visibly held; the wait is bounded at 300 tries or 30 s; a non-numeric tries value falls back to 300; ten quick retries (not three) before a lock nobody holds is reported as untakeable; pid 1 is a valid holder again. - Tests: deterministic young-lock clock, skew and non-numeric owner shapes, abandoned claims, the deadline, explicit 30 s timeouts. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
- A claim is honored while its claimant lives; only a claim with no start identity expires after 2 minutes, so a stalled live taker keeps its lock on hosts that record identities (the remaining case is a documented limit). - A late taker never overwrites an owner already in its directory, and does not remove a directory that has one. - A lock whose owner file exists but cannot be read is never ownerless. - Zero-padded owner pids count as dead; --help prints the whole usage; touch prunes only claims whose claimant is gone or recorded no identity. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…rain slot 2) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
What changed
Before: under Git Bash's default
ln -s, the old lock is never taken, sogstack-lease touchwaits out its 300 tries (31.5 s here, 499 s in the #3330 report), blames a "live process" with an empty pid, and writes no lease. After: themkdirlock is taken on the first try and the lease is written.Before/after as text: gstack-lease touch under Git Bash ln -s semantics: before, 31.5 s and no lease, blaming a live process with an empty pid; after, the mkdir lock is taken at once and the lease is written (#3330)
Why
Every gstack skill starts with
gstack-skill-start, which runsgstack-lease touchbefore it prints anything. In Git for Windows' default mode (MSYSunset),ln -scan't link to a target that doesn't exist, and the old lock's target was the holder token, which never exists as a file. So on Windows every skill start stalled for the whole retry loop (one user measured 499 s in #3330) and still wrote no lease.Approvals
Source: gstack-approvals record for gsta-94-lease-mkdir-lock (display only; not an approval citation).
Summary
The lock is a directory.
bin/gstack-leasetakes.lock/withmkdirinstead ofln -s. A taker writes a claim (.lock.claim.<pid>) before itsmkdirand renames it in as.lock/owner(<pid> <start identity>) after. A lock that names a holder is broken only when that holder is dead or its pid now belongs to another process, never by age. An ownerless lock is broken only once no live claimant exists and it is at least 2 s old. Breakers serialize on.lock.breakand reread before removing; a directory lock is renamed aside before removal so nobody sees it half-removed. Unlock removes only the caller's own lock.Mixed versions stay exclusive. A symlink
.lockleft by an older gstack is still read and broken under the same rules, and it blocks the new lock at the same path, so an old and a new gstack never both hold it.Failures are fast and named. If the lock can't be taken while nobody holds it,
touchfails after three quick retries withgstack-lease: cannot take the lease directory lock <path>instead of waiting out every try and blaming an empty pid. A dead lock that can't be renamed aside no longer spinslock()(7bef38f).gstack-skill-startstays fail-open./ship review hardening (a94c167, 3f6ebca, 681e92f). Three review passes fixed, among others: the break path removing the wrong generation, claim and
.goneleftovers, malformed and identity-less owner files, zero-padded pids, a future owner mtime, an exclusion race between a breaker and a new taker, and an unreadable owner treated as dead. Each fix has a test.Docs.
docs/capy-install.mddescribes the directory lock; the "never by age" sentence is scoped to locks that name a holder (75d5aac).Test Coverage
All new code paths have test coverage. The coverage audit found one real defect (a dead lock that can't be renamed aside made
lock()spin), fixed in 7bef38f with a test that fails against the previous bin.test/gstack-lease-git-bash.test.ts(new, in the curated windows-free-tests lane) launches the bin throughlib/script-invocation.ts, which is Git Bash onwindows-latest:touchwith the default 300 tries takes the lock without a single sleep; a host whoseln -sfails like Git Bash's still takes it (with a control proving the shim really fails); a live Git Bash holder's lock is kept and named; a dead holder's lock is broken.test/gstack-lease.test.ts: dead-holder, live-holder and dead-breaker cases run against both the directory lock and the legacy symlink lock. New cases cover a running gstack-lease excluding a second taker, 16 parallel touches all landing with nothing left behind, ownerless locks with and without a live claimant, an un-renamable dead lock, and each review fix above.ln -sbin. The Windows negative control (this PR's tests with the old bin, branchgsta-94-negctl-windows) is linked in the comments.Tests ran: tests 30298 (17/17 shards PASS, from the runner's per-shard summary; the evidence ledger recorded
tests_ran: 0because its bun parser looks for per-testN passlines that the quiet shard runner does not print, a gstack parser defect reported separately)Pre-Landing Review
Four /ship review passes (specialists, Claude adversarial, Red Team, Codex adversarial and Codex structured on each). Passes 1–3 auto-fixed 5 critical and 26 informational findings (commits a94c167, 3f6ebca, 681e92f). Pass 4 converged with 0 critical and 12 informational findings, all skipped as known limits or wording: an identity-less owner or an unreadable claim can wedge until it ages out; a delayed claim publisher;
GSTACK_LEASE_LOCK_TRIESoverflow; ownerless-lock age truncation to whole seconds; a claim with a future mtime; network-filesystem clock skew; and two comment/test-placement nits.gstack-skill-startstill prints "stayed locked by a live process" for every exit 3, including the new "cannot take the lock" case; that file belongs to PR #3432, so it is left for there.Gate edits: none detected (10 listed, 7 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)
Three existing race tests moved their fault injection from
lntomkdirbecause the lock no longer callsln; their assertions are unchanged. No threshold, budget, timeout, trial count, case kind or assertion was weakened.Outside review: Codex adversarial ran on every pass. Codex structured review on pass 4 returned
unverified(exit 4) and is recorded as unavailable, so it counts as missing coverage for that pass, not a pass.Exploratory QA
CLI smoke on
bin/gstack-lease(functional surface, Linux), run at a94c167 and again at 681e92f, 4 of 12 budgeted probes:touchwrites the lease and leaves no lock; a dead holder's directory lock is broken and the lease renewed; a live holder keeps the lock andtouchexits 3 naming it without writing;listreports the renewed lease alive. All pass (gstack-qa-evidenceverdict pass). Git Bash behaviour is proven by the windows-free-tests lane, not by these probes; full exploration was not run.Design Review
No frontend files changed — design review skipped.
Eval Results
No prompt-related files changed — evals skipped.
Greptile Review
No Greptile comments.
Issues
Fixes #3330
Verification Results
Build (
bun run build) exit 0 at 75d5aac. Full free suite on Ubicloud: 17/17 shards PASS at 3f6ebca, 681e92f and 75d5aac. Remote free-tier pregate at tree c4b8c354: 9213 tests, 0 failed, $0.04. CI at 681e92f all green, including windows-free-tests; CI at 75d5aac: Free Tests green, windows-free-tests green and cleared into the pregate receipt. Not verified: Windows-lane duration packing inscripts/free-test-durations-windows.json.TODOS
No TODO items completed in this PR.
Documentation
Status: updated. One factual precision fix in
docs/capy-install.md; no blockers.Scope. Base
c23d7d48f, head681e92f72(branchgsta-94-lease-mkdir-lock), mode edit. Selected release content:CHANGELOG.md,bin/gstack-lease,docs/capy-install.mdand the two lease test files (committed only; no staged, unstaged or new files). Discovery inventoried 736 doc-role files (git ls-files --cached --others --exclude-standard) and searched all of them for lease and lock contract claims. Onlydocs/capy-install.mdanddocs/troubleshooting.md(the UPGRADE_BUSY section) describe the lease; README, AGENTS.md, CLAUDE.md, CONTRIBUTING.md anddocs/PROJECT_STRUCTURE.mdcarry no lease claims. Banned-terms check: none (no list on main). The doc claims were checked against thebin/gstack-leasediff by static read; no tests were run.Edit.
docs/capy-install.md: "The lock is broken only when its holder is dead or its pid was reused, never by age" now begins "A lock that names a holder is broken only when ...". The paragraph just before it says an ownerless lock is broken once it is at least 2 s old and an identity-less claim is abandoned after 2 minutes, so the unqualified sentence contradicted it.Documentation health:
docs/capy-install.md Updated (lock-breaking sentence now scoped to locks that name a holder; directory-lock, claim, 300 tries or 30 s bound, exit 3 and the three known limits match bin/gstack-lease)
docs/troubleshooting.md Current (UPGRADE_BUSY section does not describe the lock mechanism; 120-minute prune and
gstack-lease listclaims still hold)README.md, AGENTS.md, CLAUDE.md, CONTRIBUTING.md, docs/PROJECT_STRUCTURE.md Current (no lease or lock claims; searched, not read in full)
CHANGELOG.md Current (not edited per ship-owned rules; the [Unreleased] entry matches the diff)
TODOS.md Not edited (outside ship-owned scope)
Documentation coverage debt.
touchfailuregstack-lease: cannot take the lease directory lock <path>(exit 3 with nobody holding the lock): reference indocs/capy-install.md; nodocs/troubleshooting.mdentry, no how-to. Common gap.GSTACK_LEASE_LOCK_TRIES(default 300, non-numeric falls back to 300) and the 30 s wait bound: bin header and CHANGELOG only; the capy-install paragraph states the bound but not the variable. Common gap.Diagram drift. None. The changed docs hold no ASCII or Mermaid diagrams naming lease entities.
Not verified.
bin/gstack-skill-startprints "stayed locked by a live process" on any exit 3, including the new "cannot take the lock" case, which can mislead; it is outside the selected diff, so it is reported as a decision, not edited. Windows-lane membership oftest/gstack-lease-git-bash.test.tsandscripts/free-test-durations-windows.jsonwere not verified.Test plan
env -u GSTACK_CAPY -u GSTACK_INSTALL_VERDICT -u GSTACK_SESSION_KIND -u GSTACK_STATE_ROOT -u GSTACK_EPHEMERAL bun run test:ubicloud: 17/17 shards PASS, 30298 tests, exit 0 at 75d5aacbun test test/gstack-lease.test.ts test/gstack-lease-git-bash.test.ts: 42 pass, 0 failgstack-pregate --stage tests --remote: 9213 tests, 0 failed at tree c4b8c354bun run build: exit 0🤖 Generated with Claude Code