Skip to content

fix(loop): three base-ref scripts trust a stale local main #162

Closed

Description

@sydevs-bot

Summary

rule-delta.mjs is the only guard against a skill rewrite silently dropping a rule, and the base
ref documented for it — --base main — is the wrong baseline. In a routine clone the local main
branch ref is stale, so the tool invents removals and can hide a real one. Six documented call
sites carry the wrong ref, one of which a routine executes, and three scripts read a base ref
and all three mishandle it.

Approach

Reproduced in this run's clone, working tree clean and identical to origin/main, after
start-run step 6 (git fetch origin main, then git remote set-head origin main):

$ git rev-parse main origin/main HEAD
83a9b8eb12897c12a081fc9a9b59390b34d4f414   # refs/heads/main — stale, 25 skill files behind
ae51afef3e3eae83317e3836b626ea76f2fdb13c   # refs/remotes/origin/main
ae51afef3e3eae83317e3836b626ea76f2fdb13c   # HEAD

$ node workflow/lib/rule-delta.mjs --base main workflow/skills
fatal: path 'workflow/skills/audit-code/SKILL.md' exists on disk, but not in 'main'
  … 24 more fatal: lines …
directives: 26 → 77
ADDED (50):                      …
REMOVED — adjudicate each (1):   - Never merge the base branch in to keep a PR fresh.
EXIT=1

$ node workflow/lib/rule-delta.mjs --base origin/main workflow/skills
directives: 77 → 77
No directive disappeared.
EXIT=0

Exit 1 on an unchanged tree: 25 fatal: lines, 50 phantom additions, and one phantom removal
handed to a human to adjudicate. Neither command in step 6 moves refs/heads/main — confirmed
here, main was still 83a9b8e after both. A run that follows start-run exactly still gets the
wrong answer.

The drift grows. The first revision of this ticket, three days ago, saw one phantom ADDED and
one phantom REMOVED. The same command on a clean tree now reports 50 and 1.

Phase 1 — one base spelling in the documented commands

File:line Documented base Note
AGENTS.md:124 main the contributor instruction
workflow/skills/improve-loop/SKILL.md:106 main a routine executes this — auditCalendar.sunday
docs/rollback/README.md:115 main
workflow/lib/rule-delta.mjs:30 main usage header
workflow/lib/comment-lint.mjs:32-33 main usage header
workflow/lib/comment-fingerprint.mjs:32-33 main usage header — the third reader, missed by the first revision
workflow/skills/finalize-pr/SKILL.md:124 origin/main already correct
docs/cleanup.md:54 origin/main already correct
workflow/skills/audit-code/comment-sweep.md:112 <branch-point> already correct

Change the six wrong ones to origin/main.

Also reword AGENTS.md:129, which reads "Both are development tools, never run steps." Both are
run steps: improve-loop/SKILL.md:103-106 has the Sunday run execute rule-delta.mjs, and
audit-code/comment-sweep.md:68 has audit-code run ste-lint.py --json on three weekdays.
Keep what the sentence was reaching for — neither is part of the automated gate, which is
leanGate.command alone — and name the two runs that do execute them.

improve-loop/SKILL.md is a skill edit, so raise version in
workflow/.claude-plugin/plugin.json to 3.0.1 in the same commit — it is the install cache
key, main is at 3.0.0, and cut-release/SKILL.md:31-32 makes a fix a patch bump.

Phase 2 — the scripts derive their own baseline

origin/main is right for a stale local ref and still wrong when the base advances after the
branch point, which is this same defect mirrored: a rule the base gained reads as REMOVED, a rule
it dropped reads as ADDED.

rule-delta.mjs:116-124 (collectRef), comment-lint.mjs:180,186-190 and
comment-fingerprint.mjs:343,376-380 all take the named ref raw. Three changes, in each of the
three scripts:

  1. Resolve a bare branch name to refs/remotes/origin/<name> when that ref exists, and warn
    once on stderr when the local ref differs from it. git merge-base alone does not fix this —
    git merge-base main HEAD returned 83a9b8e here, because the stale ref is an ancestor.
    Resolve to the remote ref first.

  2. Then take git merge-base <resolved> HEAD as the baseline, so commits the base gained
    after the branch point stay out of the delta. comment-fingerprint.mjs already documents its
    base as <branch-point> (audit-code/comment-sweep.md:112) — same vocabulary.

  3. Fail loudly on a ref that does not resolve, with one message, in all three. Today they
    diverge, and only one of the three is silent:

    Script --base no-such-ref today Wanted
    rule-delta.mjs No directive disappeared. — exit 0 one message, exit non-zero
    comment-lint.mjs 20-line uncaught stack trace, exit 1 one message, exit non-zero
    comment-fingerprint.mjs 39-line uncaught stack trace, exit 1 one message, exit non-zero

    collectRef swallows every git show error (rule-delta.mjs:120), so an unresolvable base
    yields an empty before-set and a clean report. The other two throw from their git diff
    (comment-lint.mjs:180, comment-fingerprint.mjs:343) before the baseSrc = '' fallback is
    ever reached, so that fallback is not the defect there — the missing catch is.

Cover all three changes in a new workflow/lib/rule-delta.test.mjs, following
workflow/lib/budget.test.mjs. node --test workflow/lib/*.test.mjs passes 37 tests today.

One commit per phase, each named in the PR body. No ceiling change rides along.

Acceptance criteria

  • Every documented rule-delta.mjs, comment-lint.mjs and comment-fingerprint.mjs
    invocation names a base that is correct in a fresh routine clone, with no step beyond
    start-run step 6.
  • All three scripts are documented with the same kind of base ref.
  • AGENTS.md:129 no longer says neither tool is a run step, and names the two runs that
    execute them.
  • version in workflow/.claude-plugin/plugin.json is 3.0.1, because
    improve-loop/SKILL.md changes.
  • A base ref that does not resolve makes all three scripts exit non-zero with one message:
    rule-delta.mjs instead of reporting a clean delta, the other two instead of a stack trace.
  • A bare branch name resolves to its remote counterpart, and warns when the local ref differs.
  • Commits the base gained after the branch point no longer appear in the delta.

Verification checklist

  • In a clone where git rev-parse main differs from git rev-parse origin/main, the command
    as written in AGENTS.md, run on a clean tree, prints No directive disappeared. and
    exits 0.
  • grep -rn '\-\-base ' AGENTS.md docs workflow --include=*.md --include=*.mjs shows one base
    spelling per script.
  • node workflow/lib/rule-delta.mjs --base no-such-ref workflow/skills exits non-zero and
    prints one message, not a clean delta.
  • node workflow/lib/comment-lint.mjs --base no-such-ref and
    node workflow/lib/comment-fingerprint.mjs --base no-such-ref each print one message, not a
    stack trace.
  • node --test workflow/lib/*.test.mjs passes.
  • claude plugin validate ./workflow --strict passes.
  • node workflow/lib/rule-delta.mjs --base origin/main workflow/skills accounts for every
    directive this PR removes.

Decisions

  • AGENTS.md:127-129 calls rule-delta.mjs and ste-lint.py "development tools, never run
    steps", while a routine executes both. Which line is true?
    → Neither tool is a development
    tool only. AGENTS.md:129 is the wrong line, and Phase 1 rewords it; the two skill
    instructions stand. This was a fact, not a decision — settled from
    improve-loop/SKILL.md:103-106, audit-code/comment-sweep.md:68 and auditCalendar
    (settled from source, 2026-10-09)
  • Phase 2: resolve a bare name silently, or warn when the named ref is behind
    origin/<name>?
    → Warn, once, on stderr, only when a remote counterpart exists and differs.
    Silent resolution reads identically to today's bug: a run seeing No directive disappeared.
    cannot tell which ref it compared against, and that ambiguity is what produced the phantom
    REMOVED line above. The warning also leaves the only trace a routine's journal can carry.
    --base <sha> and --base <other-branch> stay unsurprising, because the warning fires only on
    a divergent remote counterpart (bot recommendation, 2026-10-09)

Notes

Filed as an incidental finding by the adversarial review of #161. It is not
that PR's defect — that PR's own rule-delta line is correct, confirmed against origin/main —
and a critic never touches the branch, so it is a ticket rather than a fix there.

Nothing is broken at runtime. The cost is a wrong line in the PR body a human reads to adjudicate
rule removals, which is the one place rule-delta is supposed to be trustworthy.

Re-grounded against the code at ae51afe. Three skills were renamed since the first revision, so
every path in the previous body was stale: reflect → improve-loop, handler-preflight →
start-run, surveyCalendar → auditCalendar. The planned version 2.8.0 is also stale —
main is at 3.0.0.

workflow/skills/improve-loop/SKILL.md matches securityReview.triggerPattern, so the PR carries
a security review.

🤖 Written by the sydevs autonomous loop — see what this is

Activity

  1. added theissue type on Oct 6, 2026
  2. added
    proposal
    bot:working
    and removed on Oct 6, 2026
  3. sydevs-bot commented on Oct 6, 2026

    @sydevs-bot
    ContributorAuthor

    🤖 no session running

    recent dispatches
    • 21:05Z implement · attempt 2 · session · done
    • 21:05Z implement · attempt 2 · session
    • 17:55Z implement · attempt 1 · session · timed out
    • 17:55Z implement · attempt 1 · session
    • 18:40Z revise · attempt 1 · session · done

    Written by the sydevs dispatcher. Sessions never edit this comment.

  4. changed the title [-]fix(docs): rule-delta's documented `--base main` misreports in a routine clone[/-] [+]fix(loop): rule-delta's documented base is wrong in a routine clone[/+] on Oct 6, 2026
  5. sydevs-bot commented on Oct 6, 2026

    @sydevs-bot
    ContributorAuthor

    Revised from the code. The defect reproduces here: --base main exits 1 on a clean tree identical to origin/main.

    • The ticket named one wrong call site. There are five. workflow/skills/reflect/SKILL.md:105 is one a routine runs on Sunday — exactly the stale-clone case.
    • Confirmed handler-preflight step 6 does not move refs/heads/main.
    • Found a second failure mode. An unresolvable base exits 0 saying No directive disappeared., verified with --base no-such-ref.
    • origin/main is still wrong once the base advances past the branch point. git merge-base main HEAD does not rescue a stale ref. Resolve to the remote ref first.
    • Both fixes stay in one ticket, ordered as phases in ## Approach.

    Retitled the scope docs → loop, since the work now touches workflow/lib. Type stays Bug. Effort Easy → Moderate.

    @sydevs-bot implement starts the work.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  6. added and removed
    bot:working
    on Oct 6, 2026
  7. Ardnived commented on Oct 9, 2026

    @Ardnived
    Contributor

    @sydevs-bot implement

  8. removed
    proposal
    on Oct 9, 2026
  9. 3 remaining items

  10. added
    bot:working
    and removed on Oct 9, 2026
  11. changed the title [-]fix(loop): rule-delta's documented base is wrong in a routine clone[/-] [+]fix(loop): three base-ref scripts trust a stale local main[/+] on Oct 9, 2026
  12. sydevs-bot commented on Oct 9, 2026

    @sydevs-bot
    ContributorAuthor

    Both open questions were facts, not decisions. Settled from source, now in ## Decisions.

    1. "Development tools, never run steps" — AGENTS.md:129 is the wrong line. The Sunday run executes rule-delta.mjs (improve-loop/SKILL.md:103-106), and audit-code runs ste-lint.py (comment-sweep.md:68). Phase 1 rewords AGENTS.md.

    2. Silent resolution, or a warning — warn once, on stderr, only when a remote counterpart differs. Silence reads like the bug: a clean report never says which ref it compared.

    Re-grounded at ae51afe:

    • Stale paths throughout. reflect → improve-loop, handler-preflight → start-run, surveyCalendar → auditCalendar.
    • A sixth wrong call site, comment-fingerprint.mjs:32-33. Three scripts read a base ref, not two.
    • Only rule-delta exits 0 on an unresolvable ref. The other two throw an uncaught stack.
    • Version 2.8.0 → 3.0.1. main already reads 3.0.0.

    Retitled for scope.

    No open questions remain. @sydevs-bot implement starts the work. Either call is one revise away.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  13. added and removed
    bot:working
    on Oct 9, 2026
  14. Ardnived commented on Oct 10, 2026

    @Ardnived
    Contributor

    @sydevs-bot implement

  15. added
    bot:working
    and removed
    bot:working
    on Oct 10, 2026
  16. removed
    bot:working
    on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    Medium

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions