Skip to content

feat(bot-review): add the pr-bot-review reusable workflow - #26

Merged
ken-b4m merged 7 commits into
mainfrom
feat/pr-bot-review-reusable
Sep 30, 2026
Merged

ken-b4m merged 7 commits into
mainfrom
feat/pr-bot-review-reusable

Conversation

@ken-b4m

@ken-b4m ken-b4m commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

What

Adds pr-bot-review.yml as a workflow_call reusable, generalized from the copy that runs in Bike4Mind/bike4mind today. Nothing calls it yet, so merging it runs nothing.

  • .github/workflows/pr-bot-review.yml. The review job and its fold-mode commit, push and reporter steps.
    • Repo-specific values are now inputs: 19 of them, with skill_ref required and no default, so every caller pins the skill to a commit.
    • Permissions and concurrency stay in each caller's stub.
    • The fold label is bot-review-fold throughout.
  • .github/scripts/redact-review-transcript.py and its self-test. The reusable fetches the redactor from its own commit (job.workflow_repository / job.workflow_sha), not from the caller. If that fetch fails, the transcript upload is skipped and the review is not failed.
  • .github/scripts/checkBotFoldWritePath.test.mjs. The fold write-path guard test, ported to node --test with no dependencies. scripts-ci.yml gets a job that runs it.
  • Fold-mode verdict fix. Fold mode used to request changes whenever any finding was left unfolded, so one unfolded P3 blocked the PR. It now requests changes only for an unfolded P0/P1, matching review mode.

Verification

  • node --test .github/scripts/checkBotFoldWritePath.test.mjs: 31/31 pass locally.
  • The workflow YAML parses.
  • The existing scripts-ci.yml step parses every workflow and runs bash -n on every run: block. It covers this file with no changes.

Not in this PR

The caller stub and the canary run are the next step, on the calling repo.

Copied verbatim from bike4mind's .github/scripts/ - not moved, so bike4mind's
own pr-bot-review-guard.yml keeps passing until the reusable workflow this
redactor supports lands and bike4mind cuts over to it.

scripts-ci.yml gains its own job for the self-test, matching the file's
existing one-job-per-component shape, and .github/scripts/** joins its
path trigger.
Generalized from bike4mind's local copy: fork/draft/protected-ref guards,
timeout and job env move inside; permissions, concurrency and the label
test stay in the caller stub, which reusable job permissions can only
narrow and which a workflow_call body cannot reliably cancel for.

The transcript redactor is now fetched from this workflow's own commit
(job.workflow_repository / job.workflow_sha) rather than read out of the
PR head via `git show HEAD:...`, since the head is untrusted and, on a
fold run, partially agent-writable.
Ports packages/scripts/src/checkBotFoldWritePath.test.ts from the
bike4mind monorepo to guard this repo's own pr-bot-review.yml reusable,
converting the vitest surface to node:test/node:assert and updating
every assertion for the reusable's own shape: parameterised inputs
(runner_label, max_turns, skill_repo/skill_ref, size-guard thresholds),
the 5-conjunct job if:, no permissions/concurrency block in this file,
the renamed skill-fetch steps, the bot-review-fold label spelling, the
EXTRA_WRITE_DENY_GLOBS push-step env key, and the new redactor_fetch
step that reads the transcript redactor from this workflow's own
trusted commit instead of the untrusted PR checkout.

Wires it into scripts-ci.yml as test-bot-fold-write-path, alongside the
other self-tests.
…MMENT

Fold mode requested changes whenever any finding was left unfolded, so a single P3 the bot chose not to fold blocked the PR. Request changes only for an unfolded P0/P1, matching review mode.

@ken-b4m ken-b4m left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PR Review: feat(bot-review): add the pr-bot-review reusable workflow

Assessment: REQUEST CHANGES (posted as a comment, because GitHub does not accept a change request on your own PR). This is a self-review: the reviewing account authored the PR.

Reviewed at c47c79e. CI: all 5 checks passed at this SHA. Mergeable: yes, 0 commits behind main.

Fix before the first caller stub lands:

  1. P1 .github/workflows/pr-bot-review.yml:191. The checkout post step runs git submodule foreach after the agent, with no GIT_CONFIG_GLOBAL nulling. On a fold run the agent can Write ~/.gitconfig, so a planted core.fsmonitor executes with GITHUB_TOKEN and the runner's ACTIONS_* tokens. Add a last if: always() main step that deletes ~/.gitconfig and ~/.config/git. Add Edit(//home/runner/.gitconfig) and Edit(//home/runner/.config/git/**) to the fold fence as the belt. This is inherited from bike4mind, which has the same gap live today.
  2. P2 pr-bot-review.yml:853 and :952. A malformed extra_write_deny_globs value makes the guard's grep -E exit 2, and || true swallows that. BLOCKED comes back empty and the whole deny list is off, .github/ included. Validate each name against ^[A-Za-z0-9_-][A-Za-z0-9._-]*$, escape ., and fail the step on a grep exit above 1.
  3. P2 pr-bot-review.yml:334. skill_ref: main is accepted. required: true stops an empty value, not a branch name. Reject anything that is not ^[0-9a-f]{40}$ in the fetch step, and assert that check in the test at checkBotFoldWritePath.test.mjs:3717.

Four P3s are in the fold below. Each is a one-line fix.

Findings in full
P1 - .github/workflows/pr-bot-review.yml:191 - checkout's post step runs agent-plantable git config

The bound at :602-603 says global git config is nulled "on every step that runs git after the agent". Only Push fold commit does it. actions/checkout@v6 also has a post step, and post steps run after every main step, so it runs after the agent.

In checkout v6, cleanup() calls removeAuth(), then removeToken(), then removeSubmoduleGitConfig(), which runs git submodule foreach. configureTempGlobalConfig() copies $HOME/.gitconfig into the temp HOME it uses. The git child inherits the full process.env (git-command-manager.ts:628-631).

Reproduced on git 2.50.1: with core.fsmonitor = echo PWNED >&2; false # in $HOME/.gitconfig, git submodule foreach --recursive true in a repo with no submodules printed PWNED.

Reachability: fold mode grants Write with no $HOME fence (:667). The comment at :783-792 records that a $HOME write was already reproduced for the filter.*.clean route. The agent reads issue comments, and anyone can comment on a public caller. So an injected comment on a fold-labelled PR is enough.

Disposition: Fix now. Checkout's post step takes no env:, so the neutralizing has to happen in a main step. A final if: always() main step runs before every post step. Unverified: whether claude-code-action@v1's own post steps run git. If they do, the same final step covers them too.

P2 - .github/workflows/pr-bot-review.yml:853 - one bad deny entry disables every deny pattern

:853 splices the raw input into the directory alternation at :946. Every deny pattern sits in the one grep -z -E call, and it ends in || true at :952. GNU grep 3.11 with vendor[ or docs( prints Unmatched [ and exits 2, and BLOCKED is empty for .github/workflows/ci.yml. The input is also named "globs", but it is read as ERE, so gen* silently fails to deny generated/.

The source had no caller-supplied entry, so this is new in the port. The only test sets it to '' (checkBotFoldWritePath.test.mjs:1647). Two lenses found this independently.

Disposition: Fix now. Also consider renaming the input to extra_write_deny_dirs, since it takes directory names.

P2 - .github/workflows/pr-bot-review.yml:334 - the skill pin accepts a moving ref

The source test asserted SKILL_REF matches /^[0-9a-f]{40}$/. The port replaced that with required: true and no default:. Nothing in the workflow checks the value's shape. :342 passes it straight to ?ref=. The test title "fetches the skill at a pinned commit, never a moving ref" still passes for skill_ref: main. So every merge to the skill repo would go live on the next review, and the test would read as proof it cannot.

Disposition: Fix now. Add [[ "$SKILL_REF" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::skill_ref must be a full commit SHA"; exit 1; } to the fetch step, and assert it in the test.

P3 - .github/workflows/pr-bot-review.yml:176 - an empty prefix skips every PR

startsWith(x, '') is true. A caller that sets skip_head_ref_prefix: '' to turn the guard off skips the whole job for every PR, with no comment, and the label is never removed. Disposition: Fix now. Use (inputs.skip_head_ref_prefix == '' || !startsWith(...)). The protected_*_refs inputs are safe when empty.

P3 - .github/workflows/pr-bot-review.yml:489 - fold verdict contradicts the pinned skill

The prompt says REQUEST_CHANGES for an unfolded P0/P1. The skill at e280101 section 9 says "Post as COMMENT, never APPROVE, whenever you pushed." A fold with a pushed fixup and an unfolded P1 gets both instructions, so whether the PR blocks depends on which one the model follows. The pre-c47c79e text had the same conflict, so this commit narrows it rather than introducing it. Disposition: Fold in. Add one sentence stating that this rule overrides section 9, or align the skill.

P3 - .github/workflows/pr-bot-review.yml:316 - skill read token is not narrowed

The mint scopes repositories: but sets no permission-contents: read, so the token carries every permission the App has on the skill repo. That includes contents write, since :769 requests it for the push token. The comment at :312-315 promises "the narrowest token possible". This is inherited from the source and is defence in depth: the token lives only in the fetch step's env. Disposition: Fix now, one line.

P3 - .github/workflows/pr-bot-review.yml:8 - the caller contract is undocumented

The header says "See this repo's README for the stub template". This repo has no root README. Three things a caller needs appear nowhere:

  • vars.PREMIUM_OVERLAY_CLIENT_ID, read from the caller at :321 and :758.
  • The two secrets secrets: inherit must carry.
  • The fact that runner_label now defaults to ubuntu-latest (:158) where the source used ubuntu-latest-m.

Disposition: Fold in, when you write the stub. Put the template, required secrets and vars, and the stub's permissions: in the README the header points to.

Verified and clean
  • Expression injection. Every ${{ }} of event data (head.ref, label name, step outputs) goes through env:. The only ${{ }} outside env: is in the action's with:, and it carries caller inputs and runner.temp.
  • job.workflow_repository / job.workflow_sha are documented job-context properties. They name the reusable's own repo and commit, and this repo is public, so the redactor fetch reads the right file with GITHUB_TOKEN. If the fetch fails, the upload is skipped and the job stays green.
  • Redactor fail-closed. A skill-sha mismatch, empty SKILL_SHA, a redactor exception or bad JSON each skip the upload. The self-test has positive controls: a copy-through redactor fails it. Lines under 30 characters are not fingerprinted, which the docstring already states.
  • Input wiring. All 19 declared inputs are referenced and none undeclared. With changeset_guard off, every downstream gate uses != 'true', so the review still runs.
  • The port's step() helper asserts exactly one match, so a renamed step fails the test rather than passing vacuously.
Notes, no action expected
  • The c47c79e verdict change is untested. The verdict is chosen by the model, so only a prompt-text assertion is possible.
  • The dropped concurrency test is documented at checkBotFoldWritePath.test.mjs:3710-3714. The caller stub's CI has to carry it now.
Method

Four lenses: correctness, security, devops-sre, test-quality. Architecture, performance and memory were skipped: this is a generalization of an existing workflow, with no runtime data path. Each lens diffed against Bike4Mind/bike4mind origin/main. I re-derived every citation above against c47c79e, reproduced the fsmonitor execution locally, and read checkout v6's cleanup() path myself. No cohort: no other open PR touches these files.

- Deny agent writes to every $HOME dotfile and dot-directory on both
  arms, alongside the existing runner-path fences.
- Validate extra_write_deny_globs entries as plain paths, escape their
  dots, and fail the path guard if its grep errors instead of passing.
- Require skill_ref to be a full commit SHA.
- Treat an empty skip_head_ref_prefix as no skip.
- Narrow the skill-repo token to contents: read.
- Report a failed skill-token mint on the PR, not only as a red check.
- Fix a stale runs-on comment.

@ken-b4m ken-b4m left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PR Review (round 2): feat(bot-review): add the pr-bot-review reusable workflow

Assessment: APPROVE (posted as a comment, because GitHub does not accept an approval on your own PR). This is a self-review. I also wrote round 1 at c47c79e, so agreement with it carries no extra weight here.

Reviewed at 76ce00b. Delta since round 1: one commit, 2 files, +140/-18. CI: all 5 checks passed at this SHA, including test-bot-fold-write-path. Mergeable: yes, 0 commits behind main. No review threads.

All three gating round-1 findings are closed. Two P3s remain open and are fold-ins for the caller-stub PR, not for a push here:

  1. P3 .github/workflows/pr-bot-review.yml:8. The header still points at a README this repo does not have. Write it with the stub: template, the two secrets, vars.PREMIUM_OVERLAY_CLIENT_ID, and the runner_label default.
  2. P3 fold-mode verdict text versus the pinned skill's section 9. Unchanged from round 1. Add one sentence stating which rule wins, or align the skill.
Findings in full
P1 closed - .github/workflows/pr-bot-review.yml:681 - agent-plantable git config read by checkout's post step

The fix took the fence route rather than a final cleanup step. Edit(//home/runner/.*) and Edit(//home/runner/.*/**) are now in the always-on deny list on both arms. That covers ~/.gitconfig and ~/.config/git/*, which are the two files checkout's git submodule foreach reads. In fold mode the agent has no Bash, so its only way to write a file is through Write or Edit. Edit-rule denials bind the file-write tools, and the existing Edit(.github/**) fence already relies on that. The checkout lives under work/, which is not a dotfile, so the fold is unaffected. The test pins both entries through ALWAYS_ON_EDIT_FENCES (checkBotFoldWritePath.test.mjs:1253), which feeds the deny-set assertions at :2031 and :2047.

The comment at :592-597 now says $HOME dotfiles are fenced, which replaces the round-1 claim that turned out to be false. Verdict: FULLY CLOSED. This depends on the permission matcher following gitignore semantics for .*. That is the same premise the other runner-path fences rest on.

P2 closed - .github/workflows/pr-bot-review.yml:869 - one bad deny entry disabled every deny pattern

Two layers, both of which run. Each entry is checked against [A-Za-z0-9_][A-Za-z0-9._-]*(/[A-Za-z0-9._-]+)* before it reaches the ERE, and its dots are escaped. A failing entry emits blocked and exits 1. Behind that, :978 replaces || true with || [ $? -eq 1 ] || exit 2. The step opens with set -euo pipefail (:833), so the pipeline status is grep's, and exit 2 inside BLOCKED=$( ) fails the step. The new test runs the shipped bytes. It covers valid entries, a dot look-alike that must not match, six bad shapes, and a copy with the validation disarmed that must still fail. Verdict: FULLY CLOSED.

P2 closed - .github/workflows/pr-bot-review.yml:346 - skill pin accepted a moving ref

The fetch refuses anything that is not ^[0-9a-f]{40}$, and that includes an empty value. The test runs the fetch body with a stub gh that would serve any ref, so only the shape check can refuse. It covers main, v1, a short SHA, an uppercase SHA and an empty value. Verdict: FULLY CLOSED.

P3 closed - .github/workflows/pr-bot-review.yml:177 and :326 - empty skip prefix, broad skill token

An empty skip_head_ref_prefix now means no skip. The skill-repo mint carries permission-contents: read, and a test pins the step's exact key set. Both verdicts: FULLY CLOSED.

Verified and clean
  • The fixes added one change that round 1 did not ask for. Report skill-fetch failure now also fires on a failed mint (:1361). A failed mint skips the fetch, and before this change a skipped fetch matched no reporter. skill_token is the mint step's real id (:318). The reporter-sweep test adds a failed-mint state for all four cancelled/fold combinations and asserts exactly one reporter fires. I found no new defect in the fix commit.
Method

Inline round on the delta (c47c79e..76ce00b). No lenses were spawned. The delta is 2 files, and each change closes a round-1 finding whose trace I re-derived at this head: the fence strings against the test's deny-set assertions, the shell options of the fold push step, and the step ids behind the new reporter gate. CI's test-bot-fold-write-path run at 76ce00b executed the new tests.

- The fold's Edit() fences are literal /home/runner paths, and runs-on
  reads a caller input. The skill fetch now refuses a fold run on any
  other runner kind or OS, and the runner_label description says so.
- skill_ref must also be exactly 40 characters, so a multi-line value
  holding one SHA line is refused.
- The fetch-failure comment names setup refusals as well as fetch
  failures.
- Test: fold refused on self-hosted, macOS and unknown runners, review
  runs unaffected; multi-line skill_ref refused.

@ken-b4m ken-b4m left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PR Review (round 3): feat(bot-review): add the pr-bot-review reusable workflow

Assessment: APPROVE (posted as a comment, because GitHub does not accept an approval on your own PR). This is a self-review. I also wrote rounds 1 and 2, so agreement with them carries no extra weight.

Reviewed at a1524e9. Delta since round 2 (76ce00b): one commit, 2 files, +49/-8. CI: all 5 checks passed at this SHA, including test-bot-fold-write-path. Mergeable: yes, 0 commits behind main. No review threads.

The new commit adds no finding. Nothing here needs a push. The two round-2 P3s are still open and belong with the caller-stub PR:

  1. P3 .github/workflows/pr-bot-review.yml:8. The header still points at a README this repo does not have.
  2. P3 .github/workflows/pr-bot-review.yml:505. The fold-mode verdict rule still does not say whether it overrides the pinned skill's section 9.
Verified and clean
  • Fold runner refusal, pr-bot-review.yml:345-350. FOLD_MODE comes from job-level env (:191), so set -u holds. runner.environment and runner.os reach the step through env:, not inline. A refusal fails skill_fetch. The agent step, Run /bot-review (:412), is gated on steps.skill_fetch.outcome == 'success', so the agent never runs. The only fold reporter that fires is Report skill-fetch failure (:1374). The others all need bot_review or fold_push to have run. So a refused fold posts one comment, and its reworded body covers that case. The review arm is unaffected: it has no Write, Edit or Bash, so the /home/runner fences do not matter there.
  • skill_ref length check, :358. Without it, grep -qx matched the SHA line of a two-line value and accepted it. The new test case main\n<sha> is 45 characters, so it runs the new branch. A copy of the step without the length check would accept it.
  • The test covers self-hosted Linux, hosted macOS and an empty context, each refused for a fold and allowed for a review. It also covers a hosted-Linux fold that must pass.
Method

Inline round on the delta (76ce00b..a1524e9). No lenses were spawned: the delta is 2 files, and no escalation clause fires beyond what rounds 1 and 2 already traced. I read the full delta and the gates of every fold-mode step after the fetch. I relied on CI's run of the test file at this SHA and did not run it locally.

@ken-b4m
ken-b4m marked this pull request as ready for review September 30, 2026 13:26
Three comments still described $HOME startup files as unfenced.
@ken-b4m
ken-b4m merged commit 7e12bb8 into main Sep 30, 2026
5 checks passed
@ken-b4m
ken-b4m deleted the feat/pr-bot-review-reusable branch September 30, 2026 13:54
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