Skip to content

guardrails: skill-reference-verify's partial-Edit anchor still breaks diff-scope (stale-path-verify is fixed) #1453

Closed

Description

@kyle-sexton

skill-reference-verify locates partial-Edit context by word token, and its header comment claims that anchor holds the diff-scope contract. It does not. The same claim was made by stale-path-verify until 65b4f67c on #1432 replaced token-anchoring with line-anchoring and proved the gap with a regression case. This issue is what is left after that fix: the sibling guards that still carry the loose anchor.

The gap

An Edit can replace a bare substring inside an existing citation — swapping setup for ghost inside /alpha:setup leaves /alpha:ghost on disk — and the hunk then carries no complete citation for the direct scan. Reconstruction recovers bounded on-disk context:

mapfile -t toks < <(printf '%s' "$residue" | grep -oE '[a-z][a-z0-9-]{3,}' | sort -u)
for tok in "${toks[@]}"; do
  lines=$(grep -F -- "$tok" "$FILE" 2>/dev/null)
  ...

A 4-character token is short enough to occur on lines the edit never touched. A hunk of unrelated prose containing such a token greps back every line carrying it, and a pre-existing broken reference among them passes the later substring filter and fires — from an edit that did not touch it. The guard's own stated contract, violated by the mechanism meant to preserve it.

The fix that already exists

stale-path-verify now anchors on the hunk's own lines: every line of new_string is on disk verbatim by PostToolUse time, so grepping the hunk's lines always retains the line the edit landed in and selects a strict subset of what token-anchoring returned. The token filter survives as a second gate on the reported candidate rather than as the locator. Porting that shape is the work here, adjusted to each guard's reference syntax.

Per-guard scope

  • skill-reference-verify — the real target. Identical mechanism, identical 4-char word-token floor, identical overstated claim in its header comment ("a pre-existing unrelated reference sharing one of those lines never fires").
  • cli-flag-verify — lesser, and already honest. It anchors on flag tokens (--force-with-lease), which are far more specific than a bare word, and its comment already states the residual accurately: "a hunk flag that also occurs on an untouched line is scanned there too; only a DIFFERENT pre-existing flag is excluded." Worth converting for uniformity once skill-reference-verify lands, not worth its own risk budget first.

Acceptance

  • skill-reference-verify locates context by the hunk's lines, with the token filter demoted to a candidate gate.
  • A behavioral test in the false-positive direction: an Edit to unrelated prose whose word token also occurs in an untouched broken reference elsewhere in the file must not fire — verified to fail against the pre-fix guard, as feat(guardrails): rescope the withdrawn path guard onto a provenance gate #1432's cases were.
  • Existing partial-replacement true-positive cases keep passing.
  • The header comment states what the anchor guarantees rather than overstating it.

Related

Activity

  1. added
    needs-triage
    on Jul 26, 2026
  2. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    Scope correction — #1432 moved under this issue while it was being written.

    Commit 65b4f67c on that PR fixed the anchor in stale-path-verify: reconstruction now locates lines by the hunk's own lines (every line of new_string is on disk verbatim by PostToolUse time, so line-anchoring selects a strict subset of what token-anchoring did and always retains the edited line), with the token filter demoted to a second gate on the reported candidate. A regression case covers the exact shape described above — a prose hunk sharing only a path segment with an untouched stale citation elsewhere in the file.

    So this issue is now about the two siblings that still carry the loose token anchor: skill-reference-verify and cli-flag-verify. The "candidate directions" section is superseded by a better answer than either option it lists — port stale-path-verify's line-anchoring, adjusted to each guard's own reference shape. The reuse-or-replace argument now runs the other way: stale-path-verify is the divergent one until the siblings follow.

  3. changed the title [-]guardrails: partial-Edit reconstruction narrows diff-scope but does not close it, in all three guards[/-] [+]guardrails: skill-reference-verify's partial-Edit anchor still breaks diff-scope (stale-path-verify is fixed)[/+] on Jul 26, 2026
  4. added
    agent-ready
    and removed
    needs-triage
    on Jul 26, 2026
  5. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Verification: Confirmed against skill-reference-verify as currently shipped on main: the token floor is exactly grep -oE '[a-z][a-z0-9-]{3,}' (4-char minimum), and the header comment reads "the anchor is the token, not the line" / "a pre-existing unrelated reference sharing one of those lines never fires" — the overstated guarantee this issue describes. Also confirmed cli-flag-verify's comment already states its narrower, honest residual ("only a DIFFERENT pre-existing flag is excluded"), matching this issue's framing of it as "lesser, and already honest" and explicitly out of scope here. Confirmed via this issue's own follow-up comment that its scope is corrected to the two siblings that still carry the loose token anchor — this is not a duplicate of stale-path-verify's own (already-fixed, still-unmerged-to-main) issue.

    Not a duplicate of #1455. #1455 is a false negative in stale-path-verify (reconstruction refuses to run below a 4-char token). This issue is a false positive in a different, already-shipped guard (skill-reference-verify's token-anchor pulls in untouched lines). Different guards, different failure directions, different fixes — correctly tracked as separate items.

    Classification: Bug. priority: medium.

    Routing: delegable -> autonomous-eligible. Unlike its three siblings, this issue has a proven reference pattern to port (line-anchoring, already shipped for an equivalent problem in a sibling guard in this plugin) and a single, concretely scoped target (skill-reference-verify only — cli-flag-verify is explicitly out of scope per the issue body). The pattern itself is fully specified in this issue's body, so implementing it does not require the sibling guard's own PR to merge first. No open design fork remains.

    Agent Brief

    Type: Bug
    Summary: skill-reference-verify's partial-Edit reconstruction anchors on a word-token substring search across the whole file, which can select lines the triggering edit never touched — violating the guard's own stated diff-scope contract.

    Current behavior:
    When an Edit replaces a bare substring inside an existing skill-reference citation, the direct scan on the hunk's own text finds no complete citation, so the guard falls back to reconstruction: it extracts word tokens of at least 4 characters from the edited region, greps the whole file for any line containing one of those tokens, and adjudicates every returned line as if the edit had touched it. A 4-character token is short enough to occur on unrelated lines, so an edit to ordinary prose can pull in a pre-existing, already-broken reference elsewhere in the file and report it as a finding for an edit that never touched that line. The guard's header comment currently overstates what this anchor guarantees ("a pre-existing unrelated reference sharing one of those lines never fires").

    Desired behavior:
    Reconstruction locates on-disk context using the lines of the edit's own replacement text (every such line is present verbatim in the file by the time this guard runs), not by token search across the whole file. Line-based anchoring is a strict subset of what token search returns: it always retains the line the edit actually landed on, and it never pulls in an untouched line just because that line happens to share a token. The existing word-token check survives as a secondary filter applied to a candidate the line-anchor already found, not as the primary locator. This pattern — anchor on the hunk's own lines first, treat the token as a second gate rather than the locator — is already proven and shipped for an equivalent partial-Edit reconstruction problem in stale-path-verify, a sibling guard in this same plugin; port its shape, adjusted to this guard's own reference syntax (e.g. /plugin:skill-style citations rather than filesystem paths).

    Key interfaces:

    • The partial-Edit reconstruction path inside skill-reference-verify's hook script — its locator changes from "grep the whole file by token" to "grep the hunk's own lines, then apply the token as a secondary filter on what that returns."
    • The header comment documenting the anchor's guarantee — must be corrected to state what the line-based mechanism actually guarantees, replacing the current overstated token-based claim.

    Acceptance criteria:

    • A behavioral test in the false-positive direction: an Edit to unrelated prose whose word token also occurs in an untouched, already-broken reference elsewhere in the same file produces NO finding. Confirm this case fails against the current (pre-fix) guard before landing the fix, mirroring how the equivalent regression case was proven for stale-path-verify.
    • All existing true-positive partial-replacement test cases for skill-reference-verify continue to pass unchanged.
    • The header comment is corrected to describe the new line-based guarantee rather than the token-based claim it currently overstates.

    Out of scope:

    • cli-flag-verify — has a related but narrower anchor already, explicitly deferred by this issue to a follow-up once this fix lands; do not touch it here.
    • The direct (non-reconstruction) scan path, or what counts as a valid skill-reference citation shape.
    • Corpus re-measurement — this ports an already-measured, already-shipped anchoring pattern rather than widening what the guard fires on.
  6. added theissue type on Jul 26, 2026
  7. self-assigned this
    on Jul 26, 2026
  8. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor
    No description provided.
  9. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during work-loop execution.

    Claimed and executed autonomously (work-loop, admission gate already passed). Fix implemented in PR #1466: skill-reference-verify's partial-Edit reconstruction now anchors on the hunk's own lines (mirroring stale-path-verify's #1432/65b4f67c fix), with the token filter demoted to a second gate on the candidate. A regression test proves the false-positive direction, verified to fail against the pre-fix guard. Scope stayed bounded to skill-reference-verify only — the human-gated siblings (#1446/#1452/#1455) were not touched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-ready

Type

Fields

No fields configured for Bug.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions