Repository navigation
fix(loop): three base-ref scripts trust a stale local main - #175
Conversation
A routine clone never checks out `main`, so `refs/heads/main` is whatever the clone was seeded with. Here it sat 25 skill files behind `origin/main` on a clean tree, and `rule-delta.mjs --base main` answered with 25 `fatal:` lines, 50 phantom additions and one phantom REMOVED line handed to a human to adjudicate. Neither command in `start-run` step 6 moves the local ref, so a run that follows the skill exactly still got the wrong answer. That one phantom removal is the whole value of the tool inverted: the one place a reviewer is told to trust it. Six documented call sites named `main`. All now name `origin/main`, which also makes `comment-sweep.md` drop its `<branch-point>` placeholder — phase 2 has the script derive the branch point itself, so one spelling serves all three readers. `AGENTS.md` also called both `rule-delta.mjs` and `ste-lint.py` "development tools, never run steps" while two routines execute them. What the sentence was reaching for is that neither is part of the automated gate; it now says that, and names the two runs. `improve-loop/SKILL.md` is a skill edit, so `version` bumps. The ticket planned `3.0.1` against `main` at `3.0.0`; `main` has since moved to `3.1.2`, and `cut-release` makes a fix a patch bump, so this is `3.1.3`. Refs #162 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R7rHeMsmNeH6pQwUvxDkUz
A correct spelling in the docs only fixes the call sites we control. The three scripts still took whatever ref they were handed, raw, and got it wrong in both directions. Stale ref: a routine clone never checks out the default branch, so `refs/heads/main` is whatever the clone was seeded with. `git merge-base` alone does not rescue it — a stale ref is an ancestor of HEAD, so merge-base returns the stale commit. The remote counterpart has to win first. Base moved on: comparing against the tip of `origin/main` reads every commit the base gained since the branch point as this branch's work, inverted — a rule the base added shows as REMOVED, one it dropped as ADDED. The branch point is the only honest baseline. Unresolvable ref: all three diverged, and two were worse than useless. `rule-delta.mjs` swallowed every `git show` failure and printed `No directive disappeared.` at exit 0 — a tripwire that reports all-clear is worse than no tripwire. The other two threw 20 and 39 lines of uncaught stack. All three now print one message and exit 2. One `base-ref.mjs` rather than three copies, for the reason `merge-gate.mjs` exists: a baseline derived three ways is three chances to derive it differently. `base-ref.test.mjs` covers the three changes against real git repos built commit by commit, because `git merge-base main HEAD` returning the stale commit is the property the fix turns on, and a mock would let it be assumed instead of shown. Refs #162 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R7rHeMsmNeH6pQwUvxDkUz
The table enumerates `workflow/lib/*.mjs` by file, so a new shared module that is absent from it is a module nobody finds. Refs #162 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R7rHeMsmNeH6pQwUvxDkUz
Two holes the review found in the baseline this PR had just centralised. Both are the same failure as the original defect — a wrong answer that reads clean. `--base HEAD` has no slash, so it took the bare-name path and resolved to `refs/remotes/origin/HEAD`, which `start-run` step 6 creates in every routine clone. The baseline silently became the default branch's branch point, and the divergence warning could not fire because `refs/heads/HEAD` never exists. Git's pseudorefs and an object name are now taken as given. `git show <rev>:<path>` resolves against the worktree root while `mdFiles` walks from the cwd. Run `rule-delta.mjs` from a subdirectory and every read failed, the swallowing `catch` ate all 25 of them, and the tool printed `No directive disappeared.` at exit 0 — the silent all-clear this PR exists to end, reached by a second route. Verified: from `workflow/` it reported `directives: 0 → 2`; it now reports `82 → 82`. `repoRoot()` gives all three readers one answer to "which git root", and `rule-delta.mjs` was the one passing none. `baseline` also fell back to the tip, unannounced, when `merge-base` found nothing. Tip semantics are what this module calls backwards, so it now says so. The simplify pass rides in the same hunks: the shebang goes (this is a pure module, and the convention here is exact), `git` and `tryGit` collapse into one fallible helper, the 256MB `maxBuffer` goes from a call returning 41 bytes, and two provably redundant `rev-parse` spawns go — `resolved` reuses the sha the remote lookup already held, and the `HEAD` guard duplicated a check the catch already performs. `--base main` now forks git three times, not five. Tests go 10 → 13: the pseudoref case, the subdirectory case, and rule-delta's unresolvable base asserted where it can actually fail. Two shared fixtures replace three inline copies of the stale-clone shape, and `maintenance.auto` off drops 15 `git maintenance` forks from repos deleted a second later. Refs #162 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R7rHeMsmNeH6pQwUvxDkUz
The reword in the first commit overshot. `audit-code` does not run `ste-lint.py` "on its three weekdays": it is reached only from `comment-sweep.md`, which is the code-comments angle — one of six in `auditAngles.saturday` — so roughly one Saturday in six. `rule-delta.mjs` is conditional too, on the Sunday PR editing a skill. Both claims now match the calendar. `docs/why.md#a-routine-clone-is-not-a-developers-checkout` gains the dependency in the other direction. Step 6's fetch is now load-bearing for three scripts, and step 6 is exactly what the Sunday run trims for tokens. The story goes in why.md rather than in the run-loaded skill, which pays for every paragraph on every dispatch. Refs #162 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R7rHeMsmNeH6pQwUvxDkUz
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
Holistic assessment. The diff is the right shape and no bigger than the ticket. Three readers that each got ref resolution wrong now share one module, which AGENTS.md:155-159 prescribes. Every verification claim in the body reproduces here. Both declared departures from the ticket are correct: main reads 3.1.2, so 3.1.3 is the patch bump, and comment-sweep.md:112 held a hand-filled placeholder that is now the script's job.
One thing is unfinished rather than wrong. The PR builds the shared owner and leaves two siblings outside it — comment-lint.mjs:164 and comment-fingerprint.mjs:500 still hand-roll git rev-parse --show-toplevel beside their new import of the module that exports repoRoot(). And the bare-name rule stops at the first slash, so it skips claude/*, which is every branch in this repo.
Findings
- should-fix — the diff creates the shared owner and two siblings stay outside it →
workflow/lib/comment-lint.mjs:170 - consider — the bare-name rule excludes
claude/*, this repo's only branch shape →workflow/lib/base-ref.mjs:95 - consider — the
AGENTS.mdreword spends four lines on a one-line criterion →AGENTS.md:135
What was checked. Ticket #162 and all seven acceptance criteria. Read whole: base-ref.mjs, base-ref.test.mjs, and each reader's CLI block. Ran at a9e11bc: the 13 new tests pass; workflow/lib/*.test.mjs is 50 of 52, both failures payload.test.mjs's and filed as #176; claude plugin validate ./workflow --strict passes; all three readers exit 2 with one message on --base no-such-ref; --base main warns and compares against origin/main; rule-delta.mjs from workflow/ reads 82 directives; the --base grep shows one spelling per script. origin/main has gained nothing since the branch point. No contract surface is touched.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
… import Both CLI blocks shelled out `git rev-parse --show-toplevel` by hand, three lines above their import of the module that exports `repoRoot()` for exactly that. The two forms are not equivalent: the inline `execFileSync` throws an uncaught stack trace outside a git worktree, which is the failure mode this branch removes everywhere else. `repoRoot()` falls back to the cwd, the base ref then fails to resolve, and the reader prints the one message and exits 2. `base-ref.mjs`'s own `git()` now ignores git's stderr, so that really is one message. `--show-toplevel` alone printed two `fatal:` lines before it, and every failure in this module has a caller-written message waiting for it. `comment-fingerprint.mjs` imports the helper as `worktreeRoot`, matching `hooks/lib/workflow-config.mjs`, because `repoRoot` is its own CLI block's variable name. Three tests, one per reader, run from outside any worktree. All three fail without this commit. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Db6u57BAYTuSHEekHUGHhm
The bare-name rule tested `!name.includes('/')`, so it excluded the only
branch shape it ever meets: AGENTS.md makes every branch in all five repos
`claude/*`. `--base claude/other` exited 2 in a routine clone with
`refs/remotes/origin/claude/other` sitting right there, which is the exact
case this module was added to fix. git's DWIM does not rescue it either —
`rev-parse claude/other` tries `refs/remotes/claude/other`, never
`refs/remotes/origin/claude/other`.
The slash was standing in for "already says where it lives". Say that
instead: a `refs/…` ref or an `origin/…` ref is taken as given, and
everything else that is not a pseudoref or a sha is a branch name. The
divergence warning now reaches slashed branches too.
Not routed through `rev-parse --symbolic-full-name`, as the thread offers. It
answers for a ref git can already resolve, and the case here is the one git
cannot: a branch with no local ref returns empty from it, indistinguishable
from a sha. The explicit sets stay.
`--base origin/main`, the documented call, forks git no more often than
before.
Two tests, both failing without this commit.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Db6u57BAYTuSHEekHUGHhm
Acceptance criterion 3 asks only that this line name the two runs. The reword spent five lines on it, in the file every session loads — the cost AGENTS.md itself charges for two sections up. The conditions stay, since they are the correction a9e11bc made: a skill edit for one, the comments angle for the other. The calendar colour goes, and the why.md anchor already carries it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Db6u57BAYTuSHEekHUGHhm
|
Three critic threads, all adopted, all resolved. Pushed
Gate ✓. 57 of 57 across Body refreshed: commit list, test counts, flow diagram, dismissed findings. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Resolves the one conflict: `version` in `workflow/.claude-plugin/plugin.json`. Both sides advance the plugin cache key for the same reason, so neither side could be taken wholesale. The merge base read `3.1.2`. This branch bumped it to `3.1.3` for its `workflow/lib/**` fix; `main` took it to `3.2.0` for #179's new `settle-roadmap` skill. Taking `3.1.3` would reinstate a stale cache key against the new base, and taking `3.2.0` would ship this branch's lib change with no bump at all — the exact failure `cut-release/SKILL.md:30-32` exists to prevent. `3.2.1` keeps both: `main`'s minor bump for the new skill, plus a patch for the fix that rides on top of it. Everything else merged clean, `docs/why.md` included — #179 touched no `--base` call site, so this branch's `origin/main` invariant still holds across the tree. Gate: `claude plugin validate ./workflow --strict` passes. `node --test dispatcher/test/*.test.mjs` 214/214. `node --test workflow/lib/*.test.mjs` 55/57 — the two failures are `payload.test.mjs`'s worktree-path tests, which pass from the main checkout and fail inside `.claude/worktrees/<slug>` on `main` too. Pre-existing, tracked as #176. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BeswvK5JHWgfd6hLdnb9Zu
|
🧶 Merged Both sides bump the plugin cache key, so neither could be taken whole. The base read This supersedes the body's Everything else merged clean, Gate: 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
rule-delta.mjs --base maininvented 50 rule additions and one removal on a clean tree, because a routine clone'srefs/heads/mainis never checked out. Six documented call sites named that ref; all now nameorigin/main.--basereaders now derive the branch point themselves and fail loudly on a ref that does not resolve, so a wrong answer can no longer read as a clean one.Change outline
Flow — what
--base <ref>now resolves toThe three readers stopped interpreting the ref. One module answers, and the two cases that used to give a wrong answer silently now either correct themselves or say something.
Behaviour — the two ways a clean report used to be wrong
Both produced
No directive disappeared.at exit 0 on a tree that had not been read at all.Files
Test results
claude plugin validate ./workflow --strictnode --test workflow/lib/base-ref.test.mjs— 18 passednode --test workflow/lib/*.test.mjs— 57 of 57 passed from the main checkout. Inside.claude/worktrees/<slug>twopayload.test.mjstests still fail, for a reason unrelated to this branch — see Notes and fix(loop): the lib test suite runs in no gate, and two of its tests fail in a worktree #176.Manual verification
The headline reproduction, on a clean tree where
git rev-parse main≠git rev-parse origin/main:node workflow/lib/rule-delta.mjs --base origin/main workflow/skills→directives: 82 → 82,No directive disappeared., exit 0.node workflow/lib/rule-delta.mjs --base main workflow/skills→ the same clean delta, plus one stderr line naming both refs. Before: 25fatal:lines, 50 phantom ADDED, 1 phantom REMOVED, exit 1.cd workflow && node lib/rule-delta.mjs --base origin/main skills→directives: 82 → 82. Before:directives: 0 → 2and exit 0, having read nothing.node workflow/lib/{rule-delta,comment-lint,comment-fingerprint}.mjs --base no-such-ref→ one identical message, exit 2, from all three.grep -rn '\-\-base ' AGENTS.md docs workflow --include=*.md --include=*.mjs→ one spelling per script.fatal:line and no stack. Before: a 20- and a 39-line uncaught stack from the two comment readers.--base claude/otherin a clone holding onlyrefs/remotes/origin/claude/other→ resolves, wheregit rev-parse claude/otherexits 1. Before: exit 2.Notes for reviewer
Two judgement calls that depart from the ticket, both because
mainmoved under it.versionis3.1.3, not the3.0.1the ticket asked for. The ticket was grounded whenmainread3.0.0; it now reads3.1.2, so3.0.1would be a downgrade of a cache key.cut-release/SKILL.md:31-32makes a fix a patch bump, which is what the ticket was reasoning from.comment-sweep.md:112changed too, though the ticket marked it already correct. It said--base <branch-point>— a placeholder the agent filled by hand. Phase 2 makes that the script's job, so it now namesorigin/mainlike the other five, which is what acceptance criterion 2 asks for.One commit per behaviour, in build order:
3e7f8d7— six documented call sites, theAGENTS.mdreword, the version bump.ac4e095— the three readers derive their own baseline.e94b610— docs sync:base-ref.mjsin the layout table.0d61047— review round: the two holes below, plus the simplify pass.a9e11bc— theAGENTS.mdreword in 1 overstated how often the tools run; corrected against the calendar.4777a40— the two comment readers takerepoRoot()from the module they already import.8e453f2— a branch name keeps preferringoriginpast the first slash.154ccfa— theAGENTS.mdline in 5 spends two lines, not five.The first review round found two real holes in commit 2, both the original defect in a new costume — a wrong baseline that reads clean.
--base HEADresolved torefs/remotes/origin/HEAD, whichstart-runstep 6 creates in every routine clone, with no warning possible becauserefs/heads/HEADnever exists. Andrule-delta.mjsrun from any subdirectory read nothing at all and called it clean, becausegit show <rev>:<path>is root-relative whilemdFilesis cwd-relative. Both now have a test that fails without the fix.The second round found a third, and the same shape again — a resolver that cannot reach the case it exists for. The bare-name rule stopped at the first slash, so it excluded
claude/*, whichAGENTS.mdmakes every branch in all five repos. git's own DWIM does not rescue it:rev-parse claude/othertriesrefs/remotes/claude/other, neverrefs/remotes/origin/claude/other. The slash was standing in for "already says where it lives", andbase-ref.mjsnow says that instead (6,7). It also left two siblings outside the owner it had just built: both comment readers hand-rolledgit rev-parse --show-toplevelthree lines above importing the module that exportsrepoRoot(), and the inline form threw an uncaught stack outside a worktree — the one failure mode this branch removes everywhere else.base-ref.mjs'sgit()ignores git's stderr now, so "one message, exit 2" holds there too. Each of the three has a test that fails without its commit.Dismissed findings, with reasons:
--basethroughgit rev-parse --symbolic-full-nameinstead of the explicit pseudoref and sha sets — rejected, though the finding it came with was adopted. It answers for a ref git can already resolve, and the case here is the one it cannot: a branch with no local ref returns empty from it, indistinguishable from a sha.git rev-parse --show-toplevelintobase-ref.mjs— adopted in4777a40for the two inworkflow/lib/. The third isworkflow/hooks/block-wrong-bash.mjs:43, and it stays:gitTopLevel(dir)answers for an arbitrary captured path and returns null outside a repo, which is a different question fromworktreeRoot()'s. Folding the four copies of thegitshell-out helper is still a second behaviour, and still worth a follow-up.--basethroughconfig.mjs's existingflag()— same reason. Three call sites, none of them this ticket's.named,resolvedandbranchPointare what let the tests assert the mechanism rather than just the answer, which is the difference between the merge-base case being shown and being assumed.basetocomment-fingerprint --json— a real diagnosability gap, sincecomment-sweep.md:120has a human read that pasted verdict. Out of scope for a one-behaviour PR; named here so it is not lost.Two findings filed rather than fixed, per the incidental-finding rule — neither is this ticket's:
payload.test.mjsfails inside a worktree, which is whereimplement-ticketworks by default. It cost this run a diagnostic detour and will cost every future one the same. Filed as fix(loop): the lib test suite runs in no gate, and two of its tests fail in a worktree #176.workflow/lib/*.test.mjsruns in no gate at all, and.claude/workflow.json'sleanGate.contentsstill reads "There is no test suite" with 57 tests in the directory. That file is a protected path, so an unattended run cannot fix it.Detail
Why a shared module rather than three fixes.
AGENTS.md:155-159prescribes it, citingmerge-gate.mjs: a computation re-derived three ways is three chances to derive it differently. The three readers had already diverged on exactly this —rule-delta.mjsprintedNo directive disappeared.at exit 0 on an unresolvable ref, while the other two threw 20 and 39 lines of uncaught stack.Why
start-runstep 6 does not instead refresh the local ref. Step 6 is read on every dispatch, 25 to 40 times a day, andAGENTS.md:117-122charges for every paragraph there. Addinggit fetch origin main:mainwould spend tokens on each one to keep fresh a ref that nothing should read. Removing the dependency is the cheaper fix. The reverse dependency is now recorded atdocs/why.md#a-routine-clone-is-not-a-developers-checkout, so a future token-trimming edit to step 6 can see what rests on its fetch.Why
origin/mainalone would not have been enough. It is right for a stale local ref and still wrong once the base advances past the branch point: a rule the base gained reads as REMOVED, one it dropped as ADDED.git merge-base main HEADdoes not rescue the stale case either — the stale ref is an ancestor of HEAD, so merge-base returns it unchanged. That property is asserted directly inbase-ref.test.mjs, because a mock would let it be assumed.Fixture pre-mortem.
base-ref.test.mjsbuilds throwaway repos commit by commit and assumes nothing about any sydevs repo. The one real-world fact it leans on is that the remote is namedorigin, whichstart-runstep 6'sgit remote set-head origin …settles too. Checked against.claude/workflow.json(worktreeSetup: [],packageManager: "none") — the fixture needs no install, and the suite uses onlynode:*.Security review: ran, because
securityReview.triggerPatternmatches the twoSKILL.md-directory files touched. No findings. The only new executable isbase-ref.mjs, which shells out withexecFileSync('git', [...])— an argv array, no shell — and the only data crossing a boundary is a ref name from--base, which a leading--rejects and which git itself rejects otherwise. Neither skill edit changesallowed-toolsor adds an instruction. The second review round touches no file the pattern matches, so it needed no second review.rule-delta.mjsgains an exit code it never had (2, for an unresolvable base; it previously had only 0 and 1).improve-loop/SKILL.md:109still says "It exits non-zero on a directive that vanished with no close match", which is now incomplete — but the two cases print different things, and adding a clause to a run-loaded skill costs on every dispatch. Left as is, deliberately.Dropped from
base-ref.mjsin the simplify pass: the#!/usr/bin/env nodeshebang (a pure module with no CLI block — the convention in this directory is exact),maxBuffer: 1 << 28on a call returning 41 bytes, agit/tryGitsplit where only the fallible form was ever used, and two redundantrev-parsespawns.--base mainforks git three times now rather than five, and--base origin/main, the documented call, no more often after8e453f2than before it.Closes #162
🤖 Generated with Claude Code
https://claude.ai/code/session_01R7rHeMsmNeH6pQwUvxDkUz
Generated by Claude Code