Skip to content

feat(guardrails,source-control): one merge-readiness script for the merge guard and the pull-request skill - #18835

Merged
kyle-sexton merged 7 commits into
mainfrom
feat/merge-guard-shared
Nov 24, 2026
Merged

kyle-sexton merged 7 commits into
mainfrom
feat/merge-guard-shared

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Closes #18822

Summary

The guardrails merge hook and the source-control pull-request skill's merge preflight each judged merge readiness, with different rules (hold-label case, which failures block, how many review threads are read, changes-requested reviews, and the pr-verify no-verdict wait). The owner decided on one shared script, option (a): owner-decisions row docs/owner-decisions.md#L411 (melodic-software/architecture#237). Owner, verbatim: "Yes, go with recommendations."

Fix

  • lib/merge-readiness.sh owns every mechanical condition: hold labels (one list, lib/merge-hold-labels.json, any case), unresolved review threads (every page over GraphQL, else the Claude Code cloud route), changes-requested reviews, failed and pending checks with the workflow-file exemption and merge_guard_ignored_checks, and the pr-verify verdict with one 30-minute no-verdict rule. scripts/sync-shared-copies.sh copies it (and the label list) into guardrails hooks/ and source-control skills/pull-request/scripts/, so either plugin alone enforces it.
  • One merge_guard_ignored_checks value for both: the hook gets the operator's guardrails setting from Claude Code as CLAUDE_PLUGIN_OPTION_MERGE_GUARD_IGNORED_CHECKS; the skill runs the script outside that hook environment, so in command mode the script reads the same guardrails@<marketplace> pluginConfigs entry from the operator's managed and user settings through lib/merge-guard-option.mjs and the shared channel-F reader lib/plugin-options.mjs (both synced into skills/pull-request/scripts/), ignores any inherited env value (a repository settings env block reaches that shell), applies the option's default when guardrails has no value, and is UNCHECKED when a settings file cannot be read or node is missing. Before this, a custom guardrails value never reached the skill.
  • The hook is renamed hooks/merge-guard.sh, switched by merge_guard_enabled beside merge_guard_ignored_checks. It keeps command parsing and target resolution, sources the library, and turns its verdict into a refusal that points at /source-control:pull-request merge. Guardrails releases as a major: the removed block_unresolved_pr_merge_enabled key turns a saved false back on.
  • The skill's merge §4.1 step 3 runs the script at the pinned head (--head), merges only on READY, re-runs on BLOCKED no-verify-pass, and holds on any other BLOCKED or UNCHECKED. Gate 2 no longer allows an agent-judged informational failure. The provider's hand-written pr-verify read is gone.
  • Unreadable state: the hook still fails open with a notice (it sees every merge on every machine; rulesets are the backstop), the skill holds (it merges on this evidence alone). Documented in both headers.
  • Ownership line in the hook header, the library header and readiness.md: the script owns the mechanical conditions; the skill owns judgment and process; rulesets are the backstop.
  • Not generated: babysit's MERGE_HOLD_LABELS tuple stays hand-written, tied to lib/merge-hold-labels.json by a drift test (test_merge_holds_sync.py) rather than generated from it; .github/scripts/lib/lane-vocabulary.mjs ARM_HOLDS is unchanged and shares its constants with merge-holds.mjs, which the existing hold-label test ties to babysit. babysit cannot read the JSON at run time in CI: pr-require-checks.yml (line 5494) sparse-checks-out only plugins/source-control/skills/babysit-prs/scripts/*.py from the base. A drift is a failing test, not a silent disagreement.

Loosened checks

Each is authorized by the owner-decisions row docs/owner-decisions.md#L411, owner verbatim: "Yes, go with recommendations."

  • Hook, pr-verify: a judged PR with no verdict 30 minutes after its head's last check finished, with no check run or commit status still pending, now merges with a notice (was: blocked with no limit). While any check runs, --auto and merge-queue requests stay blocked.
  • Skill, workflow-file exemption: a failed check the base branch does not require, on a PR that changes a workflow or action file and whose run loaded the base copy, passes mechanically (was: an agent classification).
  • Skill, review threads: a session where GraphQL is refused reads threads through the cloud route instead of holding as unproven.
  • Toggle: merge_guard_enabled replaces block_unresolved_pr_merge_enabled; a saved old-key false is dropped, so the guard comes back on (tightening).

Tightened: the hook reads threads past 100 (was: unchecked); the skill holds on hold labels in any case, on changes-requested reviews, on timed_out, cancelled, action_required, startup_failure and stale checks, and on any failure the setting does not name.

Verification

  • plugins/guardrails/hooks/merge-guard.test.sh 727 passed, including "a saved old-key false leaves the guard on", which fails against origin/main's hook (exit 0, expected 2).
  • merge-guard-c.test.sh 15 passed. Its thread-pagination and pr-verify cases derive from captured GitHub answers in hooks/fixtures/ (two reviewThreads pages and one CI Status check-runs page).
  • lib/merge-readiness.test.sh 48 passed. The new case (no verdict, a check still in progress, --auto gives BLOCKED no-verify-pass) fails without the fix (READY).
  • Every plugins/guardrails/hooks/*.test.sh, plugins/guardrails/git-hooks/*.test.sh, plugins/source-control/skills/pull-request/scripts/*.test.sh and scripts/check-killswitch-hoist.test.sh passed: 83 suites.
  • scripts/sync-shared-copies.sh --check, scripts/validate-plugins.sh, python3 scripts/sync-plugin-options-docs.py --check, scripts/check-changelog-fragments.sh --check, scripts/check-killswitch-hoist.sh, shellcheck and the comment lint pass.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 3 commits November 24, 2026 11:48
…erge guard and the pull-request skill

The guardrails merge hook and the pull-request skill's merge preflight each
judged readiness with different rules. Both now run lib/merge-readiness.sh,
copied into each plugin by scripts/sync-shared-copies.sh, so either plugin
alone still enforces it.

- Rename the hook to merge-guard.sh and its switch to merge_guard_enabled.
- Read every page of review threads; past 100 the hook no longer fails open.
- End the pr-verify no-verdict wait 30 minutes after the head's last check
  finished, in the hook as in the skill.
- The skill now holds on hold labels in any case, changes-requested reviews
  and every failed conclusion; no failure is judged informational.

Closes #18822

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…etting in the merge preflight

The skill runs merge-readiness.sh as a command, outside the guardrails hook
environment that carries CLAUDE_PLUGIN_OPTION_MERGE_GUARD_IGNORED_CHECKS, so it
always applied the built-in default and could disagree with the merge guard
for an operator with a custom value.

Run as a command, the script now reads the operator's guardrails@<marketplace>
pluginConfigs entry through lib/merge-guard-option.mjs and the shared
channel-F reader lib/plugin-options.mjs, ignores an inherited env value, and is
UNCHECKED when a settings file cannot be read or node is missing. The test sets
a custom value in a fake install's user settings and proves the hook and the
skill copy both honor it, and pins the built-in default to plugin.json's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 24, 2026 16:57
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T17:00:43.761824Z f4d5d56 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f4d5d56296

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…option budget

The description ran 693 characters, over the 300-character budget in
docs/contracts/plugin-option-naming/README.md, so the plugin contract validator
warned and Check Catalog failed. The detail moves to the README's Option
details, and the generated options table is regenerated, which Check Plugins
reported stale.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 2e179c22e341c3c618504a8722f2a627e28ffdf4: read 38 of 38 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #18835 at 2e179c2

I found no security issues. This lane already reviewed an earlier head, so this pass reports blocking findings only. I read every hunk of all 37 files in .claude-lane/to-read.txt. plugins/source-control/skills/pull-request/scripts/merge-hold-labels.json was skipped because it is a copy of lib/merge-hold-labels.json, and it does nothing different at its path: merge-readiness.sh reads it as data from its own directory.

What I checked

  • Shared readiness script. The script is lib/merge-readiness.sh, and its two generated copies are identical to it (same blob 0f7fd219 plus the GENERATED header).

    • The merge guard hook now sources the script and overrides its callbacks after the source line (merge-guard.sh:1925-1957). In hook mode, a closed PR still exits 0 and an unreadable PR still fails open with a notice, as before. The CLI block runs only when the file is executed directly, never when it is sourced.
    • The time budget and the 30-minute wait are still fixed values with no environment knob (lib/merge-readiness.sh:190-194).
  • merge_guard_ignored_checks in command mode. The script drops any value it inherits from the environment (lib/merge-readiness.sh:714), so a repository's settings env block cannot clear a failed check for the skill.

    • The value is then read through merge-guard-option.mjs and the channel-F reader plugin-options.mjs. That reader only uses fixed-path managed settings and the user settings.json it finds from its own real install path. It never reads the environment or the checkout's .claude/settings.json.
    • A malformed entry, or no node, gives UNCHECKED, and the skill holds on that.
    • Hook mode still reads the value from the environment. That predates this PR and the diff doesn't change it.
  • Loosened checks (each authorized by the owner decision the PR cites):

    • pr-verify no-verdict wait in the hook. The wait starts only once no check run or commit status is pending (lib/merge-readiness.sh:492-499). The pr-verify-failed label is still a hold and still outranks the wait. The merge queue's CI Status still requires a pass for a lanes App PR.
    • Workflow-file exemption in the skill. It only covers checks the base branch's rules do not require, and only GitHub Actions runs that loaded the base copy. Required checks stay enforced on the server by the rulesets.
    • Cloud-route thread read. This only changes where the threads are read from. It lets nothing through that the GraphQL read would block.

    None of these lets in a new actor, grows a token's scope, or brings untrusted text to a lane that holds credentials.

  • Tightened checks:

    • Hold labels now match in any case.
    • Changes-requested reviews and the timed_out, cancelled, action_required, startup_failure and stale conclusions now hold in the skill.
    • Every page of review threads is read, up to 2,000 threads; past that the read counts as failed.
    • The skill can no longer judge a failure "informational".
    • The guard comes back on for anyone who had saved the old key as false.
  • Instruction surface. I checked this against docs/contracts/instruction-exception-register/README.md (irreversible-action is the relevant class).

    • The hand-written pr-verify read in the provider's merge.md was replaced by a deterministic script. The register allows that.
    • The user-approval step (§4.1 step 5) is unchanged.
    • The removed "classify as informational" text in SKILL.md, readiness.md and monitor.md is a tightening.
  • Embedded text. The review-thread fixtures quote earlier review comments. They are test data and reach no lane that holds credentials. The guard's thread listing keeps its untrusted-content framing.

  • Trust controls. None changed. The diff touches nothing under .github/actions/, no pr-merge/ hold script, no pr-pipeline.yaml and no trusted-actor list.

Spend: none. The changes are local scripts, docs and tests; the only extra use is a few more GitHub API reads per merge check.

Manifest lines (3)
  • manifest userConfig.block_unresolved_pr_merge_enabled: pass, removed and replaced by merge_guard_enabled. The guard's off switch (merge-guard.sh:174) reads only the new key, so a saved false turns the guard back on. Nobody gets a weaker check.
  • manifest userConfig.merge_guard_enabled: pass, an added guard with "default": true (the protective value).
  • manifest userConfig.merge_guard_ignored_checks: pass, only title and description changed (inert set); default is unchanged.

critical-findings: 0

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude-review: 3 inline finding(s) on 35ac98585fd054cfbd94ebbe0ea2e05f0269f309; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread lib/merge-readiness.sh Resolved
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 2e179c22e341c3c618504a8722f2a627e28ffdf4: read 38 of 38 changed file(s); 0 finding(s), 0 as inline comments.

Code review: shared merge-readiness script (#18835), blocking only

This lane already reviewed two earlier heads, so this pass looked only for blocking findings and manifest flags. Advisory findings were dropped.

Nothing blocking at 2e179c2. I read all 37 listed files in full. The newest commit merges main into the branch. After that merge:

  • The three copies still match. The two generated merge-readiness.sh copies are the same as lib/merge-readiness.sh apart from their two-line GENERATED header.
  • The earlier fixes are still in place:
    • _mg_running is saved before the --auto clear (lib/merge-readiness.sh#L652).
    • The 30-minute wait starts only when no check is still running (L493-L495).
    • The guardrails changelog fragment is bump: major.
    • The test "a saved old-key false leaves the guard on" is still there.
  • Nothing still calls the old name. At head, block-unresolved-pr-merge, block_unresolved_pr_merge_enabled and the removed #read-the-pr-verify-verdict anchor appear only in the CHANGELOGs, the new fragment, and the hook's and README's notes that the old key is no longer read.
  • The hook's callbacks map the script's verdicts as before:
    • closed still allows the merge (exit 0).
    • not-ready, hold-label and no-verify-pass keep their old telemetry forms.
    • A failed read still fails open through _bupm_unchecked.

Closing issue #18822, acceptance criteria:

  1. Hook and skill call the same shared script; sync-shared-copies.sh --check passes. Met: scripts/shared-copies.txt lists both copies. That the check passes is the author's claim.
  2. A test fails on the old behavior for each difference. Tests cover each difference:
    • hold labels in any case;
    • changes-requested reviews;
    • the timed_out, cancelled, action_required, startup_failure and stale conclusions;
    • an unnamed failure blocks;
    • thread pages past 100;
    • the cloud-route fallback;
    • the pr-verify wait, including a check still running;
    • the saved old key.
  3. Existing hook tests pass under the renamed paths. Author-claimed.
  4. merge_guard_enabled: false turns the hook off. Covered by the "switched off" test.
  5. Each plugin works alone. The skill-copy test runs from a source-control-only cache layout, and the hook sources its own copy.

I ran no tests; every pass count above is the author's claim.

Loosened checks would be marked: fail (default; the prompt has no loosened_check_verdict: line); patterns: 0 (no loosened_check_patterns: line). The prompt has no loosened_check_decision_record: line, so the citation requirement was not checked. Each loosening in the diff (the pr-verify no-verdict wait, the skill's workflow-file exemption, the skill's cloud-route thread read, the toggle rename) is named in the closing issue and in the PR body's ## Loosened checks section.

Advisory and manifest lines (4)
  • manifest userConfig block_unresolved_pr_merge_enabled (removed): pass. The PR and Consolidate the merge gate into one shared merge-readiness script #18822 give the owner decision as the reason, and the fragment's ### Removed entry says what to set instead.
  • manifest userConfig merge_guard_enabled (new, default true): pass. hooks/merge-guard.sh reads it as CLAUDE_PLUGIN_OPTION_MERGE_GUARD_ENABLED.
  • manifest version: pass. The guardrails fragment is bump: major for the removed key.
  • manifest description: pass. No manifest or marketplace text names the old hook or key.

Verifier dropped 0 of 0 candidates.

@github-actions

Copy link
Copy Markdown
Contributor

The pr-verify verifier failed head 35ac98585fd054cfbd94ebbe0ea2e05f0269f309. What it wrote, as data:

What it wrote (31 lines)
Summary: Issue #18822 asks for one shared merge-readiness script used by the guardrails merge guard
  and the source-control pull-request skill. The diff delivers that design: lib/merge-readiness.sh
  is synced into both plugins through scripts/shared-copies.txt, the hook is renamed merge-guard.sh
  and sources the script, and the skill's preflight in merge.md §4.1 step 3 runs its own copy pinned
  to the head commit. Hold labels come from one list and match in any case, no failed check is
  treated as informational, the 30-minute no-verdict rule lives only in the script, the toggle is
  renamed merge_guard_enabled, and a drift test ties babysit's label list to the shared one. Every
  Test Bash, Test Node and Test Python job concluded success on the judged head (e.g.
  https://github.com/melodic-software/claude-code-plugins/actions/runs/45446399598/job/138644349698),
  so the existing hook tests (renamed) and the new lib/merge-readiness.test.sh and
  merge-guard-c.test.sh passed. It fails on two grounds. First, the diff loosens checks: the hook
  used to block a merge with no pr-verify verdict for as long as it took and now allows it 30
  minutes after the head's last check finished, and the skill's preflight is loosened for
  workflow-file failures and for reading threads through the cloud route. Issue #18822 quotes the
  owner verbatim but links only architecture PR #237, not a line link to docs/owner-decisions.md, so
  the spec does not authorize the loosening. Second, an acceptance criterion is not met: no test
  shows that a saved block_unresolved_pr_merge_enabled false no longer turns the guard off. No
  binary files are in the diff, and nothing in the PR text tries to steer the reviewer.
- lib/merge-readiness.sh:374: the no-verdict fallback lets the merge guard allow a judged PR with no
  pr-verify PASS 30 minutes after its checks finished (it used to block with no limit). Issue #18822
  also loosens the skill (the workflow-file exemption replaces an agent's classification, and
  threads are read through the cloud route where GraphQL is refused). The issue links only
  melodic-software/architecture PR #237, not a line link of the form
  https://github.com/melodic-software/architecture/blob/<commit or
  main>/docs/owner-decisions.md#L<line>, so it does not authorize a loosened check. Add that line
  link to the issue body next to the owner's verbatim words, or keep the guard blocking a judged
  head with no verdict, with no time limit.
- plugins/guardrails/hooks/merge-guard.test.sh: add a case that runs 'gh pr merge 42' on an
  unresolved-thread scenario with CLAUDE_PLUGIN_OPTION_BLOCK_UNRESOLVED_PR_MERGE_ENABLED=false and
  expects exit 2, so a test covers the issue's 'Tightened (both)' change (a saved old-key false no
  longer turns the guard off), as its acceptance criterion requires.

This pull request leaves the merge queue, and ci-status holds it out while it carries pr-verify-failed. A pr-verify pass removes the label, at a new commit or at this same head: once a trusted person edits the body, and only trusted people have edited it since the fail, this head is judged again, so a fail on the body or the issues it links needs only the body fixed, no new commit.

@github-actions github-actions Bot added the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Lane run report

Field Value
Run 45450183994

pr-unblock/apply-feedback-patch, attempt 1

Field Value
Model rung 0
Leg base
Run job failure
Activity step skipped
Commits pushed none recorded

Failed GitHub API calls

No failed call recorded by the run job's scripts.

pr-unblock/publish-feedback, attempt 1

Field Value
Model rung 0
Leg base
Run job failure
Activity step skipped
Commits pushed none recorded

Failed GitHub API calls

No failed call recorded by the run job's scripts.

pr-unblock/report-escalation, attempt 1

Field Value
Model rung 0
Leg base
Run job failure
Activity step skipped
Commits pushed none recorded

Failed GitHub API calls

No failed call recorded by the run job's scripts.

kyle-sexton and others added 2 commits November 24, 2026 13:18
… runs

The 30-minute no-verdict wait measured from the newest completed check
run, and an --auto or merge-queue request cleared the pending list
before it, so the wait could end while a long check was still running.
The wait now starts only once no check run or commit status on the
head is pending.

- Guardrails releases as a major: removing block_unresolved_pr_merge_enabled
  turns a saved false back on.
- A test proves a saved old-key false no longer switches the guard off.
- The reviewThreads pagination and pr-verify tests derive their cases
  from captured GitHub answers in hooks/fixtures/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
editorconfig-checker in Lint Repo requires a final newline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lane-Activity: pr-unblock/resolve-conflicts
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 24, 2026
@github-actions github-actions Bot removed the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Nov 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 24, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit cca676e Nov 24, 2026
99 of 100 checks passed
@kyle-sexton
kyle-sexton deleted the feat/merge-guard-shared branch November 24, 2026 20:55
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidate the merge gate into one shared merge-readiness script

1 participant