Skip to content

fix(pr-kit): make the force-push guard actually run, and cap the CI loop - #54

Merged
jbabin91 merged 1 commit into
mainfrom
fix/pr-kit-safety
Sep 17, 2026
Merged

jbabin91 merged 1 commit into
mainfrom
fix/pr-kit-safety

Conversation

@jbabin91

Copy link
Copy Markdown
Contributor

First audit of pr-kit found four defects. Three are safety-relevant; all four are fixed. Every claim below was measured in scratch git repos — commands and outputs are in the commit body and the changesets.

The P0: a force-push guard that could not run

make-pr-easy-to-review rewrites history and force-pushes. Its only guard captured the pre-rewrite tree into a shell variable, read back many tool calls later. Shell state does not survive between tool calls, so the byte-identical check compared two empty strings and the "do not push" rule never fired.

Replacing the mechanism exposed a quieter version of the same bug, caught in review before it shipped. Comparing two command substitutions —

test "$(git rev-parse A)" = "$(git rev-parse B)"

— passes when both are empty, and command substitution discards git's exit code. A git that is absent, shimmed, broken, or run outside a repository gives "" = "", exit 0, no output: byte-identical to a genuine pass, in a harness that resets the working directory between calls. That is the same class as cpl-ol6, reintroduced into the fix for it.

The check now requires a token a dead git cannot fabricate:

o=$(git rev-parse --verify refs/pr-kit/original-tree^{tree}) &&
h=$(git rev-parse --verify HEAD^{tree}) &&
[ -n "$o" ] && [ "$o" = "$h" ] && echo "TREES MATCH $o"
Case Old New
Genuine match exit 0, silent exit 0, TREES MATCH <sha>
Dead git (exit 0, no output) exit 0 — passes exit 1
No git on PATH exit 0 — passes exit 127
Outside a git repo exit 0 — passes exit 128

The lease: a fix that was briefly worse than the bug

The bare --force-with-lease reads a remote-tracking ref a freshly added fork remote does not have, so it is rejected as stale info when nothing is wrong. An earlier version of this fix told the model to fetch and retry on that rejection — which refreshes the lease to include a collaborator's commit and then overwrites it. Measured: their file gone, exit 0, output reading forced update. That is --force by another route, written into the section whose purpose is refusing it.

The push now states its lease explicitly against the recorded head. Measured: succeeds with no tracking ref, and still refuses after a contributor push with their commit intact. stale info now means stop, with the reason stated so the shortcut is not reinvented.

Also in that skill

  • The fork capture never checked out the commit it captured. git fetch <url> <ref> writes FETCH_HEAD and moves nothing else, so the section written for fork PRs could not be executed on one — the model would rewrite the base branch and the guard would refuse with no explanation.
  • The fork URL was built from headRepositoryOwner, which is an object — the URL was malformed. Now headRepository.nameWithOwner.
  • The fork remote is named per PR and its URL confirmed: git remote add exits 3 on a name clash, and the push then goes to whatever repository the leftover name refers to.
  • Capture steps chain with && and use --verify, so a failed fetch cannot record a stale baseline.

fix-ci

  • Stopped instructing /review-cycle:accept, which is disable-model-invocation: true and exists for a human who reviewed the change themselves. Instructing it dead-ended the step, and routing around it would let the skill self-certify a fix it then pushed. This repo's own AGENTS.md forbids it verbatim.
  • Hard cap of three rounds, or two on the same check. The previous same-check heuristic could never fire when a fix for check A broke check B whose fix re-broke A — an oscillation that writes unbounded commits to a live PR.
  • The merge-the-base guardrail names its commands and uses baseRefName instead of assuming main.
  • The README no longer claims fix-ci stages and hands off. It commits and pushes each round by design, and now says so.

Verification

Check Result
bin/run-bats 568 ok, 0 not ok
claude plugin validate ./plugins/pr-kit --strict ✔ passed
oakum check --strict exit 0
markdownlint 0 issues

Reviewed by three legs plus Codex. Nine findings fixed inline, four of which were defects introduced while fixing defects — the empty-comparison guard, the fetch-and-retry lease, and two changelog claims stronger than what was measured. Both changelog overstatements are corrected, which matters because under squash-merge the changelog is the surviving history.

Known limitation

pr-kit has no tests/ directory, so nothing mechanically prevents any of these from returning — every fix is prose a future edit can silently undo. Tracked as cpl-k3s with candidate invariants drawn from the defects actually found, two of which are mechanical and would have caught findings from this audit outright.

Closes cpl-9uz
Closes cpl-1yu
Closes cpl-blp

A first audit of this plugin found four defects. Three are safety-relevant and
all four are fixed here.

make-pr-easy-to-review rewrites git history and force-pushes. Its only guard
captured the pre-rewrite tree into a shell variable read back many tool calls
later — and shell state does not survive between tool calls, so the
byte-identical check compared two empty strings and the "do not push" rule
never fired. The tree now lives in a git ref.

Replacing that mechanism exposed a quieter version of the same bug, which
review caught before it shipped: comparing two command substitutions passes
when BOTH are empty, and command substitution discards git's exit code. A git
that is absent, shimmed, broken, or run outside a repository produced exit 0
with no output — byte-identical to a genuine pass, in a harness that resets the
working directory between calls. The check now uses --verify, chains with &&,
and prints TREES MATCH <sha>; the instruction is to push only on seeing that
token. Measured: dead git exits 1, absent git 127, outside a repository 128.

The push states its lease explicitly against the recorded head. The bare
--force-with-lease reads a remote-tracking ref a freshly added fork remote does
not have, and is rejected as `stale info` even when nothing is wrong. An
earlier version of this fix told the model to fetch and retry on that
rejection — which refreshes the lease to include a collaborator's commit and
then overwrites it. Measured on a fixture: their file gone, exit 0, output
reading `forced update`. `stale info` now means stop.

Also in that skill: the fork capture never checked out the commit it captured,
so the section written for fork PRs could not be executed on one; the fork URL
was built from headRepositoryOwner, an object; the fork remote is now named per
PR with its URL confirmed, because `git remote add` exits 3 on a name clash and
the push then goes to whatever repository the leftover name refers to; and the
capture chains with && so a failed fetch cannot record a stale baseline.

fix-ci stopped pointing at /review-cycle:accept, which is
disable-model-invocation: true and exists for a human who reviewed the change
themselves — instructing it both dead-ended the step and, if routed around, let
the skill self-certify a fix it then pushed. This repo's own AGENTS.md forbids
that verbatim. The loop gains a cap of three rounds, or two on the same check:
the previous same-check heuristic could never fire when a fix for check A broke
check B whose fix re-broke A. The merge-the-base guardrail names its commands
and uses baseRefName instead of assuming main.

The README no longer claims fix-ci stages and hands off; it commits and pushes
each round by design, and now says so.

Closes cpl-9uz
Closes cpl-1yu
Closes cpl-blp
@oakoss

oakoss Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

These packages will release:

  • pr-kit 0.1.0 → 0.1.1 (patch)

@jbabin91
jbabin91 merged commit 9c61f80 into main Sep 17, 2026
12 checks passed
@jbabin91
jbabin91 deleted the fix/pr-kit-safety branch September 17, 2026 01:22
jbabin91 added a commit that referenced this pull request Sep 25, 2026
…onflict markers, and pin skill contracts (#94)

Fixes two pr-kit skill defects from the 2026-09-17 audit and adds
pr-kit's first tests. Every command claim below was measured in scratch
repos or against live PRs.

## Changes

- **`get-pr-comments` keeps open threads (cpl-0ye).** It skipped every
outdated thread, but outdated means only that a later push changed the
code the comment was left on. Outdated but unresolved threads now appear
under **Possibly stale — verify**, located by `originalLine` (`line` is
null on them — measured on vitejs/vite#15000, #11228, #2432 and
cli/cli#14475).
- **`get-pr-comments` pages for real (cpl-0ye).** The thread query
declares `$endCursor`, which `gh api --paginate` requires; `--slurp`
returns every page. A `node(id)` follow-up re-reads a thread with more
than 50 comments. Measured with `first:2`: 5 pages, 9 threads;
`--paginate` follows the thread cursor even when a nested comments page
has more.
- **`fix-merge-conflicts` checks the whole tree (cpl-r73).** `git diff
--cached --check` missed a conflicted file left unstaged and failed on
trailing whitespace. It is replaced by `git diff --name-only
--diff-filter=U` plus two `git grep` marker searches with `-- ':/'`: one
over the working tree, one over the index (`--cached`). The pattern
covers diff3 `|||||||` and markers longer than 7; exit 128 is a failed
search.
- **`fix-merge-conflicts` states that a rebase swaps sides (cpl-r73).**
A table and sentence: during `git rebase`, `ours` is the upstream and
`theirs` is your commit; check `git status` for `rebase in progress`
first.
- **`fix-merge-conflicts` handles conflicts that leave no markers.**
Binaries, symlinks, and paths one side deleted or both sides renamed
pass every marker check once staged, with `git add` silently keeping the
working-tree copy (the upstream, during a rebase). The skill now has the
agent keep a side or `git rm` the path explicitly and report it.
Submodule conflicts are out of scope: `git checkout --ours/--theirs`
exits 0 on them and changes nothing.
- **pr-kit prose-anchor tests (cpl-k3s).**
`plugins/pr-kit/tests/skill-contracts.spec.ts`, 16 vitest tests, pinning
the fixes above plus the earlier audit's contracts: the
`make-pr-easy-to-review` tree guard, the `fix-ci` round cap, no skill
invoking a model-disabled skill, every gh field a skill fills in being
fetched, and the README's `gh` requirement matching the skills that call
`gh`. Each of 42 literal mutations fails its own test.
- **Release note:** `.changeset/pr-kit-audit-findings.md` (pr-kit
patch).

cpl-121 (README `gh` claim) was already fixed on main by #54 and is
closed with no code change.

## Review

`/review-cycle:review` converged in 5 iterations (Codex, code-reviewer,
pr-test-analyzer, silent-failure-hunter; then spec conformance and a
maintainability audit). Spec conformance found no missing or wrong
requirements.

## Follow-ups

- cpl-yxo — deferred anchor and marker-check gaps (CRLF `=======`,
slashless skill references, `True` in frontmatter, a submodule cue, nine
test-tightening suggestions).
- cpl-crj — share anchor helpers across plugins and run the
model-disabled-reference check repo-wide (3 unchecked references in
review-cycle today).

## Test plan

- `pnpm test` — 727 passed
- `pnpm lint`, `pnpm format:check`, markdownlint — clean
- `claude plugin validate ./plugins/pr-kit --strict` — passed
- `pnpm exec oakum check --strict` — exit 0
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.

1 participant