Skip to content

Gate pre-commit config edits behind an operator switch #227

Closed

Description

Context

scripts/proposal_policy.py lists the root .pre-commit-config.yaml
in PROTECTED_PATHS, so walk_diff in scripts/proposal_check.py
rejects any proposal that changes it (… is protected and cannot change), and prompt/author.md tells the agent to abstain when a fix
needs it.

That is the right default: the file decides which gates run, and an
agent that could edit it could switch off a check its own change fails.
But it leaves a class of legitimate work no run can do. On 2026-11-22
run https://github.com/lfreleng-actions/github-code-monkey-bot/actions/runs/45085142472
was dispatched against eight issues that remove the pytest hook
from .pre-commit-config.yaml (tests now run in CI alone, and the
organisation is moving pre-commit execution off pre-commit.ci). Seven
abstained and one was rejected, all for this reason alone:

More of the same is coming as repositories migrate off pre-commit.ci.

Decision

Gate .pre-commit-config.yaml edits behind an operator switch, exactly
as #143 gated workflow edits, and bound what a revision round may widen.

1. New proposals: an allow_precommit_config_edits input

  • Add a boolean reusable-workflow input allow_precommit_config_edits,
    default false, to .github/workflows/code-monkey.yaml. Record it in
    the trusted selection (scripts/selection_document.py, beside
    allow_workflow_edits), and have the publisher read it from there
    alone: only a JSON true turns it on, as for
    allow_workflow_edits in scripts/proposal_check.py.
  • Forward it from the callers: code-monkey-cron.yaml (a
    workflow_dispatch input; a schedule passes no inputs, so it keeps
    the default false) and testing.yaml. The cron form has 20 inputs
    today and GitHub caps a workflow_dispatch form at 25, so this one
    fits; say so in a comment beside it.
  • The switch unlocks one path: .pre-commit-config.yaml at the
    repository root, compared as PROTECTED_PATHS compares it today.
    Every other protected file stays protected whatever the switch says,
    in particular every agent instruction file (AGENTS.md and the
    rest): the switch must never let the agent rewrite its own
    instructions. Do not add a general "unprotect" mechanism.
  • With the switch false, behaviour is unchanged: the publisher
    rejects the proposal with today's reason, extended to name the
    switch (as the workflow gate's reason names allow_workflow_edits),
    and the reason reaches the issue comment.
  • With the switch true, the publisher accepts the change and records
    it: add changes_precommit_config to the check (proposal_model.py
    Check, the step summary, and check.json), and add a line to the
    pull request's provenance block (provenance_block in
    proposal_policy.py) stating that the pull request changes
    .pre-commit-config.yaml, the repository's lint gate, so the human
    reviewer cannot miss it.
  • Pass the switch into the author session's runtime context, as the
    workflow switch is (- pre-commit config edits: allowed / not allowed, beside - workflow edits: … in code-monkey.yaml).
  • prompt/author.md: take .pre-commit-config.yaml out of the
    unconditional protected list and give it the same runtime-context
    rule as .github/workflows/: allowed, edit it; not allowed, abstain
    and name it. When allowed, the agent changes only what the issue asks
    of the file, and never removes, disables, skips or weakens a hook the
    issue does not name.

2. Revision rounds: only if the pull request already changes it

Independent of the switch, so revise-only schedules and review-bot
hand-backs work without it, mirroring rule 2 of #143:

  • A revision round may change .pre-commit-config.yaml only if its
    pull request already changes it, relative to the base the round is
    rebased onto. A round touching it otherwise is rejected, with a
    reason naming the file that reaches the issue comment.
  • The trusted publisher decides this from the diff, never from agent
    output or review text. scripts/workflow_gate.py already solves this
    for workflow paths, including commits a round carries over and
    rebases that bring in upstream changes; generalise it to a set of
    gated paths (workflow files plus this one) rather than duplicating
    the logic.
  • prompt/revise.md: the agent may change .pre-commit-config.yaml
    only when its pull request already changes it; otherwise it says so
    in its reply and leaves the file alone.

3. Out of scope

  • No change to any other protected path, to CODEOWNERS, .gitlint,
    REUSE.toml, the zizmor configurations, .aislop/ or licences.
  • The continue job and the review bot's hand-back do not forward the
    switch, for the reasons Gate workflow edits behind an operator switch #143 gives; revision rounds are covered by
    rule 2.
  • No new label; nothing here is a permission an issue can grant.

Files

.github/workflows/code-monkey.yaml, .github/workflows/code-monkey-cron.yaml,
.github/workflows/testing.yaml, scripts/selection_document.py,
scripts/proposal_policy.py, scripts/proposal_check.py,
scripts/proposal_model.py, scripts/workflow_gate.py,
prompt/author.md, prompt/revise.md, README.md (beside the
allow_workflow_edits paragraph), tests/test_workflow.py
(InputContracts), the tests for the new checks, and docs/DESIGN.md:
the protected-file list in §8, §9.1, §9.2, §18.1, §18.3 and §20.3, and a
row in the §17 decisions table beside "Workflow edits". Edit existing
descriptions in place.

Acceptance

  • With the switch false (the default), a new proposal changing
    the root .pre-commit-config.yaml is rejected with a reason
    naming the switch, the reason reaches the issue comment, and the
    agent abstains.
  • With the switch true, such a proposal is accepted, the check
    records changes_precommit_config, and the pull request's
    provenance block says it changes the lint gate.
  • With the switch true, a proposal changing any other protected
    file (AGENTS.md at any depth, .gitlint, SECURITY.md) is
    still rejected.
  • A revision round changing .pre-commit-config.yaml is accepted
    only when its pull request already changes it, whatever the
    switch says.
  • Contract tests pin that the input exists, is boolean, defaults to
    false, and is forwarded by code-monkey-cron.yaml and
    testing.yaml, and that the continue job does not forward it.
  • Existing tests, prek (including the aislop gate) and
    zizmor --persona auditor pass.

Activity

  1. lf-releng-code-monkey-bot commented on Nov 23, 2026

    @lf-releng-code-monkey-bot
    Contributor

    🐒 An AI agent has proposed a change for this issue: pull request #229 (head 8117897). The Copilot review of it is clean. An antagonistic review was requested from the review bot.

  2. lf-releng-code-monkey-bot commented on Nov 23, 2026

    @lf-releng-code-monkey-bot
    Contributor

    🐒 Round 1: an AI agent revised pull request #229 (head c4becac). Round 1 on #229. There was one maintainer thread, and I fixed it. - Fixed: added test_continue_job_forwards_neither_switch to tests/test_workflow.py. It asserts that the cron continue job names neither allow_precommit_config_edits nor allow_workflow_edits. I confirmed it fails when a switch is added to the dispatch. The test is amended into the tip feature commit, so the chain stays at three commits. - Not rebased: the branch stays on base_sha. No maintainer asked for a rebase and the PR is mergeable. - Checks: none were failing on the head. The unit suite, prek on the changed file and zizmor --persona auditor all pass. - Remains: Copilot's overview flags for a human that hook preservation is enforced by the prompt, not by the publisher. That is the design tradeoff #227 accepted; I made no code change for it.. The Copilot review of it is clean. An antagonistic review was requested from the review bot.

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

    CIfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions