Skip to content

fix: a glob that matches nothing, and a worktree guard that would have deleted live work - #716

Merged
athvin merged 2 commits into
mainfrom
fix/entity-glob-and-worktree-guard
Nov 6, 2026
Merged

athvin merged 2 commits into
mainfrom
fix/entity-glob-and-worktree-guard

Conversation

@athvin

@athvin athvin commented Nov 6, 2026

Copy link
Copy Markdown
Owner

The two items I'd left as "worth a decision, not a drive-by". Both turned out to
be worse than the summary implied, and the second one inverts the premise.

1. entities/*.yaml matches zero files (1247499c)

Nine tracked files told the reader that er-entity gen / verify work from
entities/*.yaml. The layout is entities/<name>/entity.yaml, 49 of them, so
that glob expands to nothing and does it silently: CLAUDE.md, CONTRIBUTING.md
(×2), the Makefile comment, rust.yml's entities job comment, the design
doc's layer diagram and CLI block, the eslint ignore comment, and the generated
crate's manifest header.

It survived because it was shorthand everywhere rather than a typo somewhere —
no single site looked wrong, and nothing executes a comment. Rewritten with each
file's match count asserted before and after (9 replaced, 0 remaining) rather
than a blind pass.

This is the commit that costs the full gates, which is the thing worth
deciding and the reason it was not a drive-by. Verified locally across all four
comment syntaxes first: make -n entities-check still prints its recipe,
rust.yml still loads as YAML with 16 jobs, the manifest still parses as TOML,
eslint.config.mjs passes node --check, the mermaid fences stay balanced, and
skills-check all is green (CLAUDE.md is a splice target, so the edit had to
stay outside its generated block).

One instance is deliberately left alone: rust-conventions/evals.md is fixed on
#703 and touching it here would conflict.

2. The worktree guard would have deleted work in progress (0c00f67c)

I reported the prune as blocked by my own caution. It was worse than that — the
documented guard is wrong, and following it literally destroys unpushed work.

lsof -a -p <pid> -d cwd does not find a live session. It is proof of
attachment when it hits and proves nothing when it misses, because the dominant
pattern here is a session whose cwd is the primary checkout driving its
worktree via git -C. No descriptor in that directory, nothing to see.
Measured with 19 worktrees open: 15 had a commit land in the previous 22
minutes; only 7 were any process's cwd.
One committed 12 seconds before the
audit evaluated it as unattached; another moved HEAD between two commands of the
same run.

And the stated justification for pruning was false. "Each worktree carries
its own rust/target, at tens of gigabytes" is only true after a worktree
compiles; a skills session that never runs make check stays near a gigabyte.
Measured: 83GB across all 19, concentrated in one 24GB outlier, most with no
target at all — while the primary checkout's own target is 132GB, larger
than every worktree combined.
The worktree count is a poor proxy for the disk
problem, and the prune ritual targets the smaller half.

scripts/worktree-audit.sh makes the four real guards one read-only command. It
prints KEEP with reasons or REMOVABLE with the removal line, and never removes
anything — a wrong removal costs another session's unpushed work, which is not a
cost a script should pay alone.

Three bugs found while building it, each now a comment at the site:

  • A plain git status refreshes the index, so the dirty check overwrote the
    mtime the activity check then read, stamping every worktree "active 0m ago".
    The audit was perturbing exactly what it measured.
    git --no-optional-locks status fixes it.
  • The age of the commit HEAD points at is not liveness. A worktree cut from
    a week-old commit is brand new; one cut from a commit that landed a minute ago
    may be abandoned.
  • /usr/bin/env bash here is 3.2.57, where mapfile, EPOCHSECONDS and
    declare -A are runtime failures bash -n does not catch. I had used all
    three; no other script here does.

Verified by discrimination rather than by it merely running: a synthetic
worktree at the merged #692 squash commit — clean, activity backdated — reports
REMOVABLE with its removal command, while all 19 live worktrees report KEEP with
specific reasons. Deriving the primary checkout from --git-common-dir was
needed for that: run from inside a worktree, the first version excluded itself
and offered the primary checkout up for removal.

Outcome on the original ask

Nothing was pruned, and that is the correct result — the audit says so with
a reason per worktree, rather than me declining. The actionable disk finding is
the primary checkout's 132GB target, which I did not touch: 13 sessions have
that directory as cwd and cleaning it makes every one of their next builds cold.
That is your call, not a drive-by either.

🤖 Generated with Claude Code

bmoore813 and others added 2 commits November 6, 2026 01:12
…ty.yaml

Nine tracked files told the reader that `er-entity gen` and `er-entity verify`
work from `entities/*.yaml`. That glob expands to zero files: every declaration
is `entities/<name>/entity.yaml`, 49 of them. Anyone who trusted the literal got
an empty expansion and no error, in CLAUDE.md, CONTRIBUTING.md, the Makefile
comment, rust.yml's `entities` job comment, the design doc's layer diagram and
its CLI block, the eslint ignore comment, and the generated crate's manifest
header.

It was shorthand everywhere rather than a typo in one place, which is why it
survived: no single site looked wrong, and nothing executes a comment. The
decision to rewrite all nine rather than leave them is deliberate — a path in
prose that resolves to nothing is the same defect as a stale count, and this repo
does not keep those.

Each file was rewritten with its match count asserted before and after (9
replaced, 0 remaining) rather than by a blind pass over the tree.

Verified beyond the grep, because this touches four languages' worth of comment
syntax: `make -n entities-check` still prints its recipe, rust.yml still loads as
YAML with 16 jobs, `er-entities/Cargo.toml` still parses as TOML,
`frontend/eslint.config.mjs` passes `node --check`, the mermaid fences are still
balanced with the label intact, and `skills-check all` is green (CLAUDE.md is a
splice target, so an edit outside its generated block has to stay outside it).

One instance is deliberately left: `rust-conventions/evals.md` is fixed on the
branch for #703 and touching it here would conflict.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…k claim was wrong

Two claims in the worktree procedure did not survive being measured against a
clone with 19 worktrees open.

**`lsof -a -p <pid> -d cwd` does not find a live session.** It is proof of
attachment when it hits and proves nothing when it misses, because the dominant
pattern here is a session whose cwd is the PRIMARY checkout driving its worktree
with `git -C <path>` — no descriptor in that directory, nothing for `lsof` to
see. Measured: 15 of 19 worktrees had a commit land in the previous 22 minutes
while only 7 were any process's cwd. One committed 12 seconds before the audit
evaluated it as unattached, and another moved its HEAD between two commands of
the same run. A session following the old procedure literally would have deleted
work in progress.

What catches those is local git activity — the per-worktree `index` and
`logs/HEAD` mtime — plus HEAD resampled at the end of the audit.

**"Each worktree carries its own rust/target, at tens of gigabytes" is false**
as a general claim, and it was the stated reason the prune is non-negotiable. A
worktree only grows a target once something in it compiles; a skills or docs
session that never runs `make check` stays near a gigabyte. Measured: 83GB
across all 19, concentrated in a single 24GB outlier, most carrying no target at
all — while the primary checkout's own target was 132GB, larger than every
worktree combined. The worktree count is a poor proxy for the disk problem.

`scripts/worktree-audit.sh` turns the four guards into one read-only command. It
prints KEEP with reasons or REMOVABLE with the removal line, and never removes
anything: a wrong removal costs another session's unpushed work, which is not a
cost a script should be allowed to pay alone.

Three things learned building it, each now a comment at the site:

- A plain `git status` REFRESHES THE INDEX, so the dirty check overwrote the
  mtime the activity check then read, stamping every worktree "active 0m ago".
  `git --no-optional-locks status` is the fix. The audit was perturbing exactly
  what it measured.
- The age of the commit HEAD points at is not liveness. A worktree cut from a
  week-old commit is brand new; one cut from a commit that landed a minute ago
  may be abandoned.
- `/usr/bin/env bash` on this machine is 3.2.57, where `mapfile`,
  `EPOCHSECONDS` and `declare -A` are runtime failures that `bash -n` does not
  catch. No other script here uses them either.

Verified by discrimination, not just by it running: a synthetic worktree at the
merged #692 squash commit — clean, backdated activity — is reported REMOVABLE
with its removal command, while all 19 live worktrees report KEEP with specific
reasons. Deriving the primary checkout from `--git-common-dir` rather than the
script's own location was needed for that: run from inside a worktree, the
earlier version excluded itself and offered the primary checkout for removal.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 39d5faf into main Nov 6, 2026
42 checks passed
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.

2 participants