Skip to content

fix(agents): scope the drift check to the generated blocks, not whole files - #271

Merged
athvin merged 1 commit into
mainfrom
fix/skills-drift-block-scoped
Oct 22, 2026
Merged

athvin merged 1 commit into
mainfrom
fix/skills-drift-block-scoped

Conversation

@athvin

@athvin athvin commented Oct 22, 2026

Copy link
Copy Markdown
Owner

A false positive I introduced in #255, found by a parallel session hitting it.

The defect

git diff --quiet HEAD -- "${generated_files[@]}" was correct while every target was a generated-only reference. #255 added CLAUDE.md and docs/agent-skills.md to that array so the inventory tables could stop being hand-maintained — but both files are mostly prose, so any in-progress edit to either failed the gate with "generated skill references are stale" while every GENERATED block was byte-identical to HEAD.

It is the false-positive mirror of the false-green rule this repo already keeps, and it degrades badly: the failure names the right file with the wrong reason, so the obvious response is to re-run the generator, which changes nothing, and the response after that is to stop believing the gate.

The fix

Extract the BEGIN/END blocks from HEAD and from the worktree; compare only those.

  • Still HEAD-relative, so a git add cannot launder a stale file.
  • A deleted block is still caught, because the markers are inside the extraction.
  • Failure output is now a labelled unified diff of the block (HEAD/… vs regenerated/…) rather than a 126 ++--- stat line.

One subtlety, now written into the standard

check runs regen before it diffs, so hand-editing a block proves nothing — the edit is overwritten and the gate passes. What it detects is a source change that makes committed output wrong. Testing it the other way shows a passing gate and proves nothing, which is how I nearly convinced myself this fix had broken the gate.

Verified both directions

Case Expected Result
clean tree pass pass
prose edit to CLAUDE.md / docs/agent-skills.md pass (was failing) pass
new resource "aws_sns_topic" in a .tf fail fail — + 1 aws_sns_topic
remove the campaigns screen from the axe gate fail fail — moves swept → unswept
delete a whole GENERATED block fail fail

🤖 Generated with Claude Code

… files

`git diff --quiet HEAD -- "${generated_files[@]}"` was right while every target
was a generated-only reference. It stopped being right in #255, when CLAUDE.md
and docs/agent-skills.md joined that array: both are mostly hand-written prose,
so ANY in-progress edit to either — a sentence in the authoring rules, a line in
the gate table — failed with "generated skill references are stale" while every
GENERATED block was byte-identical to HEAD.

That is the false-positive mirror of the rule this repo already keeps about
false greens, and it is worse than it sounds: the failure names the right file
with the wrong reason, so the obvious response is to re-run the generator, which
changes nothing, and the next response is to stop believing the gate.

The check now extracts the BEGIN/END blocks from HEAD and from the worktree and
compares only those. Still HEAD-relative, so a `git add` cannot launder a stale
file. A deleted block is still caught, because the markers are included in the
extraction. The failure output is now a real unified diff of the block, labelled
HEAD/ vs regenerated/, instead of a `126 ++---` stat line.

One subtlety worth writing down, because testing it wrong is easy: `check` runs
regen BEFORE it diffs, so hand-editing a block proves nothing — the edit is
overwritten and the gate passes. What it detects is a SOURCE change that makes
committed output wrong. Verified against both: a new `resource "aws_sns_topic"`
surfaced as `+ 1 aws_sns_topic` in footprint.md, and removing the campaigns
screen from the axe gate's SCREENS moved it from swept to unswept in
screens.md. Prose edits to CLAUDE.md and docs/agent-skills.md now pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 1e4c3d7 into main Oct 22, 2026
17 checks passed
athvin added a commit that referenced this pull request Oct 22, 2026
…top it passing silently (#279)

Two defects, the second of my own making an hour ago.

## The drift check did not run on the PRs that change skills

`detect` skips every compile job for a PR touching nothing but `.claude/**`,
and the drift check rode the cargo `lint` job — so it did not run on exactly
those PRs. That was sound while every generator derived from code OUTSIDE
`.claude/`, because a code change always ran the full gate.

`gen_skill_inventory` broke it. It derives from SKILL.md descriptions, so a
one-line description edit makes the inventory tables in docs/agent-skills.md
and CLAUDE.md stale. Demonstrated: changing landing-page's first clause to
"the PROBE route group" leaves both tables stale, and a PR carrying only that
change reports three green checks, none of which looks at staleness. It merges
green and turns main red on the push-to-main run.

The `skills` job now runs `all` rather than `lint`. It still needs no
toolchain — verified by running the whole script in a bare ubuntu container
with no cargo, node, pnpm, docker, terraform or aws. The check stays in the
cargo job as well, because `skills` is not a required status check and so
cannot block a merge on its own; promoting it would make the pair redundant,
and both halves have now been observed failing.

The job is renamed to `agent skills (lint + drift)`, which is safe because it
is not among the eight required contexts.

## The drift check passed silently when git was unavailable

Introduced in #271. The per-file comparison skips anything it cannot read out
of HEAD (`git cat-file -e … || continue`), which is right for a newly added
file — but outside a git repository EVERY file is skipped, the stale list comes
back empty, and the check reports "generated references are current" and exits
0 having compared nothing.

That is the failure this repo keeps a rule about: success and never-ran are
indistinguishable from outside. Two guards now, mirroring `lint`'s zero-skills
exit and check-bff-authz.mjs's zero-routes exit — HEAD must resolve, and the
comparison must have examined at least one file. Verified: outside a repo the
check now exits 1 with a named reason.

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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