Skip to content

feat(source-control): add the unattended merge policy readers - #7324

Merged
kyle-sexton merged 9 commits into
mainfrom
feat/babysit-policy-readers
Oct 12, 2026
Merged

kyle-sexton merged 9 commits into
mainfrom
feat/babysit-policy-readers

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #6202

Summary

Phase 8 of the auto-merge-safe-prs plan. babysit_merge_policy.py gains the readers that decide whether an unattended merge could run, and resolve() now uses them. Every result is still inert (enabled=false): no merge path is connected until a later phase.

Fix

  • read_config_at (contents API at a SHA, strict parse, unreadable -> refuse), effective_rung (min of four inputs, unknown -> off), read_kill_switch, read_rung_cap (read only), is_human, read_demotion, resolve_identity, eligibility (incl. the claim rule), in_flight.
  • Every reader fails closed on doubt, missing data or an API error. assess() names the first refusing reader in the inert reason.
  • Plain --merge refuses (exit 10) when the acting login is the configured merge.agent-identity or the policy config cannot be read; tested end to end from a real config fixture.
  • Python resolves bash by lib/exec-bash.mjs's Windows rules (never System32, Sysnative or WindowsApps).
  • parse-concern-value.sh and yaml-subset.awk registered as shared copies.
  • Existing main() test harnesses gain one inert resolve patcher in setUp (no assertion changed); engine.test.sh keeps its unreadable-policy check network-free with a failing gh on PATH.

Verification

  • uvx --from pytest==9.1.1 pytest -q plugins/source-control/skills/babysit-prs/scripts/tests: 1061 passed (also with gh off PATH); engine.test.sh: 12 PASS; bash scripts/sync-shared-copies.sh --check: 461 match.
  • Fresh-context security verification: all 7 criteria PASS; its four findings (demotion edit-history exclusion, null author, lease author, merged-PR window) are fixed with red-first tests.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 6 commits October 12, 2026 12:46
…ugin

Register lib/parse-concern-value.sh and lib/yaml-subset.awk as copies under
plugins/source-control/lib/ so the babysit merge policy can parse
docs/conventions/pr-pipeline.yaml with the repository's one YAML reader.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fill babysit_merge_policy.py with the readers the unattended merge path
needs, each failing closed: read_config_at (contents API at the base SHA,
shared YAML reader with --strict, exit 3 is off), effective_rung,
read_kill_switch, read_rung_cap, is_human, read_demotion, resolve_identity,
eligibility (with the lane-claim rule) and in_flight. The Python caller
resolves bash by lib/exec-bash.mjs's Windows rules.

assess() composes them and always returns an inert policy naming the
first refusing reader. resolve() stays the inert stub: the existing test
pins it to no network, so wiring it waits on that test changing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drive babysit_merge.py --merge end to end with the token acting as the
configured merge.agent-identity, read from a real pipeline file through
read_config_at and the shared YAML reader over a faked gh transport: it
exits 10 before evaluating or writing. resolve is pointed at assess, so
the test holds before and after the two are wired.

Also state the self_logins contract: callers pass only lane or bot self
identities, each treated as non-human per the Design.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
resolve() now returns assess(repo): the pipeline config at the default
branch head, then the identity, kill switch, rung, demotion and in-flight
readers. Every outcome is still inert, and the reason names the first
refusing reader. A plain --merge now refuses the agent identity's token
from the configured merge.agent-identity.

The inert-stub test becomes a fake-backed one (no merge block gives
authority-unconfigured, with no real gh call). The main() harnesses in
the merge, async and rate-limit suites patch resolve to an inert policy,
and engine.test.sh runs its --unattended --merge check with a failing gh
first on PATH, so it stays network-free.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Demotion: only the earliest revision stamped at createdAt, with a named
  author and editor of the same login, is the original body; any other
  revision, including a second one at createdAt or one with a null
  author or editor, is judged as an edit.
- Claim: a lease comment counts only when the identity's App posted it
  (comment user is a Bot with the identity's login).
- In flight: read merged pull requests page by page until one predates
  the merged-since floor or the history ends; a history longer than the
  read bound is not clear.
- Tests: the role-label test now asserts no query reads labels; fixtures
  name the REST timeline actor shape and the createdBy [bot] spelling.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…times

- in_flight with no merged_since floor is not clear (merged-since-unset)
  and reads nothing; assess passes no floor yet, so it reports that.
- Only a boolean hasNextPage of false ends a paginated read, in both the
  merged-PR and the demotion-record listings; anything else is unreadable.
- A timestamp without an offset raises PolicyReadError, so the demotion,
  eligibility and in-flight readers return their hold reasons instead of
  crashing on a naive-versus-aware comparison.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kyle-sexton and others added 2 commits October 12, 2026 14:27
…aders

A truncated demotion edit history now holds the rung off instead of hiding
the record; a non-count max-changed-lines and any value carrying a control
or line-separator character read as off; the permission reader is built
once per call; and the docs no longer claim resolve() makes no network read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 12, 2026 18:35
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T18:41:13.239445Z 803a1d4 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.

@claude

claude Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 6m 0s —— View job


Claude's review

  • Gather context (PR diff, CLAUDE.md/AGENTS.md, REVIEW.md)
  • Review babysit_merge_policy.py readers
  • Review shared-copy scripts (parse-concern-value.sh, yaml-subset.awk)
  • Review test changes
  • Post findings

This repo runs a dedicated security lane (pr-review-security-hosted.yml), so security-scoped findings (trust boundaries, auth, injection) are intentionally out of scope here and left to that lane.

Scope reviewed: babysit_merge_policy.py's new readers (read_config_at, effective_rung, read_kill_switch, read_rung_cap, is_human, read_demotion, resolve_identity, eligibility, in_flight, assess), resolve_bash (ported from lib/exec-bash.mjs), the new shared parse-concern-value.sh/yaml-subset.awk copies, babysit_merge.py's small comment-only diff, engine.test.sh, and the test suite additions.

This is a careful, well-tested implementation — the fail-closed discipline is consistent throughout, and several subtle GraphQL quirks (bot login spelling in createdBy filters, userContentEdits ordering, null-author handling in _record_hold) are empirically probed and documented in code/test comments rather than assumed. resolve_bash is a faithful line-for-line port of lib/exec-bash.mjs's Windows resolution rules, including the System32/Sysnative/WindowsApps refusals. The shared-copy registration (scripts/shared-copies.txt) and generated copies match their canonical sources byte-for-byte apart from the expected generator header.

Finding posted inline (plugins/source-control/skills/babysit_merge_policy.py:669-693): _candidate_issues (used by read_demotion, which runs on every --merge/--unattended check) paginates with no page cap, unlike the MERGED_PAGE_LIMIT-bounded _merged_since reader a few hundred lines below for the same class of concern. Over the repository's lifetime this read-only walk only grows, with no bound and no short-circuit once a demotion-marker hit is found.

No security, authorization, or secrets-handling findings — those are scoped to the security lane.

claude-lane-summary: lane=claude-review sha=803a1d4921e173f4c1f98dd1bafec9cf63dfaa3e run=38291957487

@claude

claude Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 5m 53s —— View job


Security review complete

Reviewed the full diff against origin/main (13 files, +2974/-25), focused on babysit_merge_policy.py's new readers plus the shared parse-concern-value.sh / yaml-subset.awk copies. Checked for: command/path injection in the new bash/awk shell-out (_concern_values), config-smuggling via the PR's own branch (config is read at the default-branch SHA, not the PR head — good), spoofing of GitHub Actor/Bot identity (login/type come from the API, not attacker text), and fail-closed behavior across every reader (is_human, read_demotion, in_flight, read_kill_switch, eligibility). All of those held up; the design is deliberately fail-closed and the subprocess seam is an argv-list allowlist with no shell interpolation of untrusted content.

One finding posted inline:

  • IMPORTANT — assess() never bounds eligibility()'s work_class (C1-C5) by the effective rung (C2/C3/off). A repo configured for merge.rung: C2 would still mark a PR linked to a validly-labeled work-class: untrusted-provenance (C5) issue as eligible=True, with nothing in the refusal list catching the mismatch — contradicting this repo's own documented invariant that the rung is "a work-class ceiling, not a route around an owner invariant" (plugins/source-control/skills/babysit-loop/SKILL.md:487). Not exploitable today since enabled is unconditionally False in this PR, but worth closing before a later phase wires enabled straight into a merge call. See inline comment on babysit_merge_policy.py#L1273-L1281.

claude-lane-summary: lane=claude-security-review sha=803a1d4921e173f4c1f98dd1bafec9cf63dfaa3e run=38291957593

@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: 803a1d4921

ℹ️ 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".

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

claude-review has reviewed this pull request through f043803; a later push is reviewed from there.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review has reviewed this pull request through f043803; a later push is reviewed from there.

… default branch

assess() now refuses a pull request whose work class is above the
effective rung (C4 and C5 never pass), hands in_flight() the repository's
default branch instead of "main", and the demotion candidate walk stops at
ten pages, holding the rung off past it. The Windows PATH fixture uses the
<user> placeholder the machine-path check asks for, and the separator
pattern keeps its escapes.

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

claude Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 4s —— View job


Security review complete

Scope: incremental — only the diff since 803a1d4 (this lane's last review) in babysit_merge_policy.py and test_babysit_merge_policy.py, per .claude-lane/incremental.diff. Every other file is unchanged since 803a1d4 and was reviewed then.

This diff closes the two findings raised against 803a1d4, both correctly:

  • Work-class ceiling (previously flagged IMPORTANT by this lane): assess() now adds a fifth refusal, class-above-rung, comparing eligible.work_class through the new CLASS_RANK table (C1-C3) against RUNG_RANK[rung.rung] (babysit_merge_policy.py#L1288-L1294). C4/C5 fall through CLASS_RANK.get(..., 99) to a sentinel that always exceeds any real rung, so they're refused unconditionally — matching the "C4 and C5 never merge unattended" invariant. The eligible is not None and eligible.eligible and ... short-circuit avoids any AttributeError when eligible is None (no pr_number) or ineligible, and rung-off is still checked earlier in the refusal tuple so an off rung refuses on its own reason first. Covered by test_a_work_class_above_the_rung_refuses and test_a_work_class_within_the_rung_reaches_merge_unconnected, against the rung: C2 fixture.
  • Real default branch for in-flight (Codex P2): _default_branch_head now returns (branch, sha) instead of discarding the branch name, and assess() passes branch=branch into in_flight(...) (babysit_merge_policy.py#L1259-L1261) instead of defaulting to the "main" literal. Covered by test_in_flight_reads_the_default_branch_not_main.
  • Unbounded demotion-issue pagination (this lane's non-security finding against 803a1d4): _candidate_issues now bounds its walk with ISSUES_PAGE_LIMIT = 10 (mirroring MERGED_PAGE_LIMIT) and fails closed — raising PolicyReadError, which read_demotion turns into an active demotion (rung held off) — once exceeded, rather than looping unbounded.

No new security issue in this diff: the new ceiling check reads only code-defined constants and a value eligibility() already validates for human-applied provenance; the branch name flows only into parameterized GraphQL variables and a urllib.parse.quote-escaped REST path, both pre-existing seams; the page-limit fix fails closed on its own new error path. No inline findings to post.

claude-lane-summary: lane=claude-security-review sha=f04380397d765215a6cc2771de325f6a5cb8a6fe run=38293335675

@claude

claude Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 15s —— View job


Reviewing PR #7324 (incremental)

  • Gather context (PR diff, CLAUDE.md/AGENTS.md, custom instructions)
  • Read .claude-lane/incremental.diff
  • Review babysit_merge_policy.py / test_babysit_merge_policy.py changes since 803a1d4
  • Post findings

Scope reviewed: the incremental diff since this lane's last review (803a1d4), limited to babysit_merge_policy.py and test_babysit_merge_policy.py per the lane's instructions.

This diff closes all three findings raised in this PR's previous review round, cleanly and with tests:

  • Codex's default-branch finding: _default_branch_head now returns (branch, sha), and assess() passes the discovered branch into in_flight(..., branch=branch) instead of relying on in_flight's "main" default (babysit_merge_policy.py#L1224, #L1256). Covered by test_in_flight_reads_the_default_branch_not_main.
  • The work-class-ceiling security finding (rung as a ceiling, not a bypass): assess() adds a CLASS_RANK-vs-RUNG_RANK refusal (class-above-rung) comparing eligible.work_class to the effective rung (#L1289-L1295). The .get(..., 99) default correctly forces any C4/C5 work class to always exceed a C2 or C3 rung, matching the "C4 and C5 never merge unattended" invariant. Covered by test_a_work_class_above_the_rung_refuses and test_a_work_class_within_the_rung_reaches_merge_unconnected.
  • The unbounded-pagination finding on _candidate_issues: now bounded by ISSUES_PAGE_LIMIT (10, matching MERGED_PAGE_LIMIT's pattern), raising PolicyReadError past the limit, which read_demotion's existing try/except turns into a fail-closed Demotion(active=True, ...) (#L677-L699). Covered by test_issues_past_the_page_limit_are_off.

Also noted: a drive-by fix to _SEPARATOR (#L96) now explicitly matches U+2028/U+2029 instead of embedding literal Unicode characters in the regex source, with the corresponding test updated to use 
 instead of an ambiguous literal space character.

No new findings. The fail-closed discipline is consistent with the rest of the module, and each fix has a direct regression test.

claude-lane-summary: lane=claude-review sha=f04380397d765215a6cc2771de325f6a5cb8a6fe run=38293335529

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 12, 2026
Merged via the queue into main with commit 692243c Oct 12, 2026
29 checks passed
@kyle-sexton
kyle-sexton deleted the feat/babysit-policy-readers branch October 12, 2026 18:57
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