Skip to content

Share the guarded worker CLI scaffolding through guarded_mutation.py #15607

Description

@kyle-sexton

Agent Brief

Type: Task
Summary: Move the state-lock wrapper and the shared arguments of the three guarded babysit worker CLIs into guarded_mutation.py (part of restructuring pass #14823).

Current behavior:
plugins/source-control/skills/babysit-prs/scripts/guarded_mutation.py:1-6 is the shared opening of manage_feedback_ledger.py, refresh_pr_branch.py and request_review.py, and all three import it (manage_feedback_ledger.py:27, refresh_pr_branch.py:37, request_review.py:37). Each still repeats:

  • run, 5 lines that resolve --state-dir, take state_lock and call the module's run_locked: manage_feedback_ledger.py:196-200, refresh_pr_branch.py:151-155, request_review.py:270-274. Only the return annotation differs.
  • the --pr and --expected-head-sha arguments, 9 identical lines: manage_feedback_ledger.py:242-250, refresh_pr_branch.py:351-359, request_review.py:505-513.
  • the --state-dir, --lease-token and --apply arguments, 12 lines where only the --apply help text differs: manage_feedback_ledger.py:277-288, refresh_pr_branch.py:360-371, request_review.py:514-525.

Desired behavior:

  • guarded_mutation.py gains run_under_state_lock(args, run_locked), add_head_pin_arguments(parser) and add_worker_arguments(parser, apply_help). It already imports argparse and state_lock (:37, :43-48) and gains resolve_state_dir, state_path_for and MIN_HEAD_SHA_PREFIX_LENGTH.
  • Each CLI's main calls the two argument helpers where its blocks sit now, so every script keeps its argument order. The ledger's order is action, the head-pin pair, its own four flags, the worker trio, then --fix-round-cap (manage_feedback_ledger.py:233-297).
  • Each CLI's run is replaced by run_under_state_lock(args, run_locked), and imports left unused are dropped.
  • Each CLI keeps run_locked and main under their names: tests/test_babysit_merge.py:2066,2389 call refresh_pr_branch.run_locked, tests/test_request_review_policy.py:90,120 call request_review.run_locked and request_review.main(), and tests/guard_contract.py:726 locates refusals at manage_feedback_ledger.py::main.
  • None of the four files is a hold path. None is in FLOOR_CLASSES (babysit_risk.py:320-360) or is a floor-paths row of docs/conventions/pr-pipeline.yaml, and no floored module imports them, so the floor's import closure that tests/test_merge_holds_sync.py:498-521 checks does not change.

Files:

  • plugins/source-control/skills/babysit-prs/scripts/guarded_mutation.py
  • plugins/source-control/skills/babysit-prs/scripts/manage_feedback_ledger.py
  • plugins/source-control/skills/babysit-prs/scripts/refresh_pr_branch.py
  • plugins/source-control/skills/babysit-prs/scripts/request_review.py
  • a new patch fragment in .changes/source-control/: ### Changed, "Internal restructuring, no behavior change."

Key interfaces:

  • Each CLI's --help output, arguments, JSON output, exit codes and error text: unchanged.
  • No test calls run on these modules or patches state_lock, resolve_state_dir, state_path_for or MIN_HEAD_SHA_PREFIX_LENGTH on them.

Acceptance criteria:

  • run_under_state_lock, add_head_pin_arguments and add_worker_arguments exist in guarded_mutation.py, and the three CLIs use them in place of their copies.
  • python3 <script> --help prints the same bytes before and after the change, for each of the three CLIs.
  • Behavior is unchanged: the same outputs, exit codes and printed results for the same inputs.
  • No file is added to or removed from FLOOR_CLASSES in babysit_risk.py.
  • plugins/source-control/skills/babysit-prs/scripts/tests/test_floor_paths.py and test_merge_holds_sync.py pass unchanged.
  • The diff edits only the listed files and the lines of a test that assert on them when the change breaks that assertion.
  • The pull request stays within 400 changed lines and 15 hand-edited files.
  • scripts/run-ruff.sh check passes on the changed files.
  • The pytest suites test_guarded_mutation.py, test_manage_feedback_ledger.py, test_request_review_policy.py, test_review_trigger_race.py, test_babysit_merge.py and test_guards.py in babysit-prs/scripts/tests/ pass.
  • ci-status is green.

Out of scope:

  • The main tails (the ledger's FlakeCapReached branch, manage_feedback_ledger.py:322-324), the --state-dir arguments of manage_babysit_lease.py and pr_queue_snapshot.py, other duplication, eval cases, fixtures, and skill and agent text.

Activity

  1. added
    status: ready
    on Nov 12, 2026
  2. added theissue type on Nov 12, 2026
  3. removed
    status: ready
    on Nov 12, 2026
  4. melodic-automation-lanes commented on Nov 12, 2026

    @melodic-automation-lanes
    Contributor

    {"v":1,"actor_id":337595936,"title_sha256":"b3d6381677e256df2c416c72edbe7925d54077bbec7f9aa022b6314ee466a6f7","body_sha256":"5d0d7499b43ea1e6af45d88d0093ad68b8b268d09b40bf7f09359f96fc2690dc"}

  5. github-actions commented on Nov 12, 2026

    @github-actions
    Contributor
    No description provided.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Work status

    needs-triage

    Priority

    low

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions