Skip to content

Feat(publish): Gate workflow edits behind a switch - #188

Merged
ModeSevenIndustrialSolutions merged 2 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-143
Nov 13, 2026
Merged

ModeSevenIndustrialSolutions merged 2 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-143

Conversation

@lf-releng-code-monkey-bot

@lf-releng-code-monkey-bot lf-releng-code-monkey-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #143

Authored by an AI agent; human review required
Command Exit
uv run python -B -m unittest tests.test_workflow_gate (new tests on the old code: 2 failures, both findings reproduced) 1
uv run python -B -m unittest discover -s tests (head) 0
uv run python -B -m unittest discover -s tests (test commit) 0
prek run --files scripts/workflow_gate.py tests/test_workflow_gate.py docs/DESIGN.md 0
uvx zizmor --persona auditor .github/workflows/ 0
git log --raw --format=%h d5881c29034245057f5c480b75ca36b905790df8..HEAD (no 100755/120000/160000, no mode change) 0

The github-code-monkey-bot workflow opened this pull request.
Nobody has merged it; a maintainer must review it first.
Review findings on this pull request are answered by a later revision round of this workflow, up to ten rounds per antagonistic review round; after that a maintainer, or the next antagonistic review, takes on any finding that remains, and a maintainer reviews every round before merge.

Round 4 of revision, on its base.


Closes #143.

What this pull request does

  • New proposals: a new reusable-workflow input, allow_workflow_edits, is off by default and recorded in selection.json. While it is off, the publisher rejects a new proposal that adds, edits or deletes a file under .github/workflows/. The rejection reason names the file, and the author prompt tells the agent to abstain in that case. The cron and testing callers forward the input.
  • Revision rounds: whatever the switch says, a round may change only the workflow files its pull request already changes. The publisher decides this from the diff between the pull request's recorded base and its published head (scripts/workflow_gate.py), never from agent output or review text. Upstream workflow changes that a rebase brings in do not count against the round.
  • Carried commits: a round that keeps the pull request's own edit and revert of another workflow file still passes. Each change the chain makes to that file must match a published change, in order and at most once. The publisher replays the published changes onto the chain's base before it compares.
  • Contract tests, gate tests, docs/DESIGN.md (§8, §9, §10.1, §14, §17, §18, §20.3), both prompts and the README are updated.

This round (Copilot review round 4)

  • Hunkless fingerprints: with hunk positions dropped, a published edit and revert of contents: read in one job matched the same pair in another job. The gate now compares the exact mode and blob of each path before and after each commit. The published changes are replayed onto the chain's base with git merge-file --object-id --diff-algorithm=histogram, so a change has to sit where the published one did. A rebase over an upstream edit elsewhere in the file still matches.
  • Glob pathspecs: the per-path patch passed the path as a pathspec, so a name like ci*.yaml also picked up ci-other.yaml. Transitions now come from each commit's diff-tree --raw output with no pathspec at all.
  • Regression tests: the same edit in another job is rejected, the published job's own pair passes, and a wildcard name is isolated from its sibling. The round-3 carriage-return test is now behavioural. All of them were reproduced on the old code first. The tests are amended into the test commit as expected failures, and the fix plus the DESIGN.md §20.3 text into the feature commit.

Checks run

  • uv run python -B -m unittest discover -s tests: 1494 tests, OK at the head; OK with 33 expected failures at the test commit.
  • prek run --files on the changed files, including the aislop gate, basedpyright and mypy: passed.
  • uvx zizmor --persona auditor .github/workflows/: no findings.

For the reviewer

  • The gate needs git 2.44 or later on the publish runner, for merge-file --object-id and --diff-algorithm. If the merge fails for any reason, replay stops, which only rejects more.
  • No rebase: the branch stays on d5881c2.

Copilot AI 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.

🟡 Changes recommended

The gate can incorrectly reject README-only revisions due to inherited reverted workflow changes and redundantly repeats network fetches and diffs for every workflow path.

2 open issues
What changed in this PR

Adds an off-by-default operator switch for workflow edits in new bot proposals, addressing #143. The trusted publisher also limits revision rounds to workflow files already changed by their pull request.

Changes:

  • Passes allow_workflow_edits through workflow callers into trusted selection evidence.
  • Adds publisher checks for new proposals and revision workflow paths.
  • Updates agent prompts, documentation, and tests for the new rules.
File Description
tests/​test_workflow.py Pins switch defaults, forwarding, and prompt context.
tests/​test_workflow_gate.py Tests proposal permissions and revision workflow restrictions.
tests/​test_select_issues.py Checks selection records the switch.
tests/​test_proposal_check.py Updates fixtures and existing workflow-edit tests.
scripts/​workflow_gate.py Implements workflow-path authorization checks.
scripts/​selection_inputs.py Adds the selection command-line flag.
scripts/​selection_document.py Records the switch in selection evidence.
scripts/​proposal_model.py Tracks the PR’s original base and permission context.
scripts/​proposal_check.py Applies the gate using the trusted selection value.
README.md Summarizes workflow-edit restrictions.
prompt/​revise.md Defines revision workflow-file limits.
prompt/​author.md Requires abstention when workflow edits are disabled.
docs/​DESIGN.md Documents the switch and publisher enforcement.
.github/​workflows/​testing.yaml Forwards the manual switch and disables it for plumbing.
.github/​workflows/​code-monkey.yaml Declares the input and passes it to selection and prompt context.
.github/​workflows/​code-monkey-cron.yaml Exposes and forwards the switch, defaulting off.

Review effort: Balanced

Comment thread scripts/workflow_gate.py Resolved
Comment thread scripts/workflow_gate.py Resolved

Copilot AI 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.

🟡 Changes recommended

The workflow gate permits additional out-of-scope edit/revert pairs and can incorrectly reject README-only rebases after upstream changes to the same workflow.

2 open issues

Review effort: Balanced

Comment thread scripts/workflow_gate.py Resolved
Comment thread scripts/workflow_gate.py Resolved

Copilot AI 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.

🟡 Changes recommended

Lossy UTF-8 decoding makes distinct patch bytes produce identical fingerprints, allowing a rewritten edit/revert pair on a disallowed workflow path to bypass the gate.

1 open issue

Review effort: Balanced

Comment thread scripts/workflow_gate.py Resolved

Copilot AI 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.

🟡 Changes recommended

The gate can authorize unpublished workflow changes by matching edits at different locations, while nonliteral pathspecs can also include unrelated files in fingerprints.

2 open issues

Review effort: Balanced

Comment thread scripts/workflow_gate.py Resolved
Comment thread scripts/workflow_gate.py Resolved
lf-releng-code-monkey-bot Bot and others added 2 commits November 13, 2026 00:05
Add expected-fail tests for issue lfreleng-actions#143. A new proposal that adds,
edits or deletes a file under .github/workflows/ is rejected, naming
the file, unless the trusted selection sets allow_workflow_edits to
true; a selection without the field keeps it off. A revision round
may change only the workflow files its pull request already changes,
whatever the switch says, and upstream workflow changes a rebase
brings in do not count against it. A round carrying over the pull
request's own workflow commits, such as an edit and its revert,
passes when it leaves those files as its base had them and writes
nothing to them the published commits did not; the check reads the
pull request's diff once however many workflow paths a round names.

Carried-over changes must match the published ones in order and no
more often, so a round repeating an edit and its revert is rejected;
a rebase over an upstream edit elsewhere in the same workflow file
still passes, since the carried edit makes the same line change.

Changes are compared as raw bytes, split at LF alone: a rewritten
edit whose bytes are not UTF-8, or hold another line separator, must
not read the same as the published one (Copilot review round 3).

A carried change must also sit where the published one did: the same
edit and revert of a line repeated in another job is rejected, while
the published job's own pair passes. A workflow name holding a glob
character covers that file alone, so changing a sibling workflow the
glob would match in the same commit leaves the carried change intact
(Copilot review round 4).

The contract tests expect the reusable workflow's input, off by
default, its record in selection.json, a runtime context line for
the agent, the prompt rules, and both dispatch callers forwarding
it. The existing tests that propose a workflow change now turn the
switch on.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
A new proposal could change any file under .github/workflows/, the
change with the widest reach the bot makes. Put it behind an
operator switch, allow_workflow_edits, off by default.

The reusable workflow takes the input and the select step records it
in selection.json, which the publisher trusts. The offline check
(workflow_gate.py) rejects a new proposal that adds, edits or deletes
a workflow file unless the switch is on, naming the file; a
selection without the field counts as off. A revision round may
change the workflow files its pull request already changes and no
other, whatever the switch says: the check fetches the pull
request's recorded base and published head from the bot fork and
compares the round's workflow paths with that diff, computed once
for all of them. A chain that touches no workflow file fetches
nothing.

A round keeps the pull request's commits, so it can carry a workflow
edit and its revert that the net diff no longer shows. Such a path
passes when the chain leaves it as its base had it and the published
commits, read along the first-parent line for at most 64 commits,
already made each change the chain makes to it, in the same order
and no more often. A change is the file's mode and blob before and
after a commit, read from its raw diff with no pathspec. The
published changes are replayed onto the chain's base, each merged
three ways as a rebase would, so a rebase over an upstream edit
elsewhere in the file still matches; a new, moved, rewritten or
repeated change is rejected.

Review round 1 (Copilot): the check rejected a readme-only round
that preserved an inherited workflow edit and revert; it now
recognises carried-over writes, with regression tests. The allowed
path set was fetched and diffed once per workflow path inside a
comprehension; it is now computed once.

Review round 2 (Copilot): the carried writes were compared as an
unordered set of blobs, which let a round replay a published edit
and revert a second time, and rejected a rebased edit and revert
whose blobs an upstream edit to the same file had changed. Compare
each path's line changes in order instead, with regression tests
for both.

Review round 3 (Copilot): the carried changes were read through
UTF-8 replacement decoding and split at every Unicode line break, so
a rewritten edit with other non-UTF-8 bytes, or a carriage return
in place of a line feed, read the same as the published one. Read
the patches as bytes and split them at LF alone, with regression
tests for both.

Review round 4 (Copilot): with hunk positions dropped, a published
edit and revert of a line in one job matched a rewritten pair making
the same edit in another job. The per-path patch also took the path
as a pathspec, so a workflow name holding a glob character pulled in
a sibling file's changes. Compare exact mode and blob transitions
from each commit's raw diff, with the published ones replayed onto
the chain's base by git merge-file, with regression tests for both.
This also covers round 3's byte-level concerns.

The author prompt's runtime context states the switch for an issue
session, and both prompts carry the rule. The cron and testing
callers offer the input on their dispatch forms, off by default, and
forward it; the plumbing job passes false. Update DESIGN.md sections
8, 9, 10.1, 14, 17, 18 and 20.3 and the README.

Fixes lfreleng-actions#143

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>

Copilot AI 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.

🔵 Needs a closer look

Publication authorization now relies on shallow-history reconstruction and three-way replay of workflow edits, requiring maintainer review of the security semantics and Git compatibility validation on the publish runner.

No open issues 🎉

Review effort: Balanced

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Antagonistic review by agent: no line-level findings; the summary below is the verdict.

The change appears sound: the default-off switch reaches the publisher through trusted selection data, and revision permissions derive from the published pull request rather than agent output. No actionable defects found in the diff and surrounding code.

Antagonistic round 1 of 3.


Automated antagonistic review by lf-releng-antagonistic-review-bot[bot] using model gpt-6-astra; see the run. This is not a human review and never an approval: a maintainer must still review and approve this pull request.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit 7768188 into lfreleng-actions:main Nov 13, 2026
32 checks passed
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the code-monkey/issue-143 branch November 13, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gate workflow edits behind an operator switch

2 participants