Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 111 additions & 44 deletions .github/workflows/persona-runner-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
# Prompt-only marker enforcement is how .github-private#860 happened (1,481 acks
# in 4.5h).
#
# Job layout (each job gets its own runner; tests/persona_runner.bats pins this):
# gate — pinned tooling only, no model. Resolves the persona, runs the event
# pre-gate, resolves the posting identity, and preflights its PAT.
# run — the model. Holds the engine credential and the read-only github.token,
# and never references a posting PAT.
# post — pinned tooling only, no model. A fresh checkout at the workflow SHA;
# the one posting PAT the manifest names; the advisory arrives as one
# artifact file that is parsed as data. Target repo and item come from
# this workflow's inputs, never from `run`.
#
# Posting identity (per persona, from the manifest — NOT a repo-wide default):
# Which account a persona's advisory posts as is read from that persona's
# personas/<id>/persona.yml runtime.identity (account + credential), the
Expand Down Expand Up @@ -108,7 +118,7 @@
# restoring the ADR-0005 position; reverses #1650, fixes #1734). Chosen per
# persona from runtime.identity.credential, never a repo-wide default.
required: false
# GH_PAT_WORKFLOWS removed (#1650): the broadly-scoped workflows PAT is no

Check warning on line 121 in .github/workflows/persona-runner-reusable.yml

View workflow job for this annotation

GitHub Actions / Lint

121:7 [comments-indentation] comment not indented like content
# longer a posting fallback here — least privilege, and posting under it
# attributed advisories to a human owner account.

Expand All @@ -122,16 +132,21 @@
cancel-in-progress: false

jobs:
run:
gate:
# AGENTS_PAUSED (#1525, #2249): with the fleet paused this job is skipped
# (neutral, not red) and `fleet-paused` below reports why.
# (neutral, not red), `run` and `post` are skipped with it, and `fleet-paused`
# below reports why.
if: vars.AGENTS_PAUSED != 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 10
outputs:
proceed: ${{ steps.resolve.outputs.skip == 'false' && steps.pregate.outputs.run == 'true' }}
prompt_path: ${{ steps.resolve.outputs.prompt_path }}
marker: ${{ steps.resolve.outputs.marker }}
account: ${{ steps.identity.outputs.account }}
credential: ${{ steps.identity.outputs.credential }}
permissions:
# checkout THIS repo's tooling + prompts. The agent reads the public source
# repo with github.token; the comment is posted with the persona's manifest
# PAT.
# checkout THIS repo's tooling.
contents: read
# the event pre-gate (#1905) reads the PR's changed files, labels, and
# reviews via github.token — with only contents:read those reads 403 on a
Expand All @@ -142,9 +157,10 @@
# already-advised marker / automation budget.
issues: read
steps:
- name: Checkout persona tooling + prompts
- name: Checkout persona tooling
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.workflow_sha }}
fetch-depth: 1
persist-credentials: false

Expand Down Expand Up @@ -277,21 +293,15 @@
id: authz_preflight
if: steps.resolve.outputs.skip == 'false' && steps.pregate.outputs.run == 'true'
env:
# Same manifest-driven PAT selection as the post step — the token that
# WILL post is the token we probe. The agent step never sees these.
BOT_PAT: ${{ secrets.DON_PETRY_BOT_GH_PAT }}
OWNER_PAT: ${{ secrets.GH_PAT_DON_PETRY }}
# Same manifest-driven PAT selection as the post job — the token that
# WILL post is the token we probe. An unset secret stays empty rather
# than falling through to the other PAT.
GH_TOKEN: ${{ steps.identity.outputs.credential == 'DON_PETRY_BOT_GH_PAT' && secrets.DON_PETRY_BOT_GH_PAT || (steps.identity.outputs.credential == 'GH_PAT_DON_PETRY' && secrets.GH_PAT_DON_PETRY || '') }}
POSTING_ACCOUNT: ${{ steps.identity.outputs.account }}
POSTING_CREDENTIAL: ${{ steps.identity.outputs.credential }}
SOURCE_REPO: ${{ inputs.source_repo }}
run: |
set -euo pipefail
if [ "$POSTING_CREDENTIAL" = "DON_PETRY_BOT_GH_PAT" ]; then
GH_TOKEN="${BOT_PAT}"
else
GH_TOKEN="${OWNER_PAT}"
fi
export GH_TOKEN

# Verify the token authenticates as the manifest identity BEFORE probing
# write access — otherwise a writable token for the WRONG account passes
Expand All @@ -314,8 +324,35 @@

bash scripts/persona-authz-preflight.sh

run:
# The model's job. Its only credentials are the engine credential and the
# read-only github.token; a posting PAT must never be referenced here.
needs: gate
# AGENTS_PAUSED (#1525, #2249): the fleet-pause contract requires the model
# job's condition to mirror `fleet-paused`, so the gate's verdict is checked
# on each step below rather than here. A skipped or failed `gate` skips this.
if: vars.AGENTS_PAUSED != 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
skip_post: ${{ steps.advise.outputs.skip_post }}
permissions:
# checkout THIS repo's prompts. The agent reads the public source repo with
# github.token; the comment is posted by the post job.
contents: read
pull-requests: read
issues: read
steps:
- name: Checkout persona tooling + prompts
if: needs.gate.outputs.proceed == 'true'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.workflow_sha }}
fetch-depth: 1
persist-credentials: false

- name: Install Claude Code
if: steps.resolve.outputs.skip == 'false' && steps.pregate.outputs.run == 'true'
if: needs.gate.outputs.proceed == 'true'
env:
CLAUDE_CODE_VERSION: ${{ vars.CLAUDE_CODE_VERSION || 'latest' }}
run: |
Expand All @@ -326,7 +363,7 @@
npm install -g "@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}"

- name: Produce the advisory (agent — read only, no post)
if: steps.resolve.outputs.skip == 'false' && steps.pregate.outputs.run == 'true'
if: needs.gate.outputs.proceed == 'true'
id: advise
env:
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
Expand All @@ -341,8 +378,8 @@
ITEM_NUMBER: ${{ inputs.item_number }}
COMMENT_URL: ${{ inputs.comment_url }}
REQUESTED_BY: ${{ inputs.requested_by }}
AGENT_MARKER: ${{ steps.resolve.outputs.marker }}
PROMPT_PATH: ${{ steps.resolve.outputs.prompt_path }}
AGENT_MARKER: ${{ needs.gate.outputs.marker }}
PROMPT_PATH: ${{ needs.gate.outputs.prompt_path }}
run: |
set -euo pipefail
export PATH="$HOME/.npm-global/bin:$PATH"
Expand All @@ -353,6 +390,8 @@
# bad AI_MODELS_* entry is named, not silently ignored.
# shellcheck source=scripts/lib/engine-models.sh
source scripts/lib/engine-models.sh
# shellcheck source=scripts/lib/persona-runner.sh
source scripts/lib/persona-runner.sh
while IFS= read -r _models_line; do
[ -n "$_models_line" ] && echo "::warning::$_models_line"
done <<< "$(ai_models_problems)"
Expand Down Expand Up @@ -396,27 +435,61 @@
exit "$_rc"
fi

# Stash raw agent output for the post step to parse (multi-line, so a
# file, not a step output).
cp "$_out" "$RUNNER_TEMP/agent-out.txt"
# Hand only the advisory to the post job, redacted: run artifacts of this
# public repository are readable by anyone, so the raw output stays here.
pr_write_handoff "$_out" "$RUNNER_TEMP/persona-handoff/${PR_HANDOFF_FILE}"
echo "skip_post=false" >> "$GITHUB_OUTPUT"

- name: Upload the advisory for the post job
if: steps.advise.outputs.skip_post == 'false'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: persona-agent-handoff
path: ${{ runner.temp }}/persona-handoff/advisory.txt
if-no-files-found: error
overwrite: true
retention-days: 1

post:
# The only writer. Runs pinned tooling on its own runner; `run` reaches it
# through the handoff file and the skip_post flag and nothing else.
needs: [gate, run]
# Also paused: a fleet pause stops the writes as well as the model calls.
if: vars.AGENTS_PAUSED != 'true' && needs.run.outputs.skip_post == 'false'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
# checkout THIS repo's tooling. The comment is posted with the manifest PAT.
contents: read
steps:
- name: Checkout persona tooling
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.workflow_sha }}
fetch-depth: 1
persist-credentials: false

- name: Download the advisory from the agent job
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: persona-agent-handoff
# Outside the workspace: this directory is read as data, never run.
path: ${{ runner.temp }}/persona-handoff

- name: Enforce marker and post the comment (workflow — the only writer)
id: post
if: steps.resolve.outputs.skip == 'false' && steps.pregate.outputs.run == 'true' && steps.advise.outputs.skip_post == 'false'
env:
# The PAT lives ONLY here. The agent step above never had it. WHICH
# PAT is used is driven by the persona manifest
# (runtime.identity.credential), resolved in the "identity" step —
# never a repo-wide default. The resolve step already constrained
# credential to this known set.
BOT_PAT: ${{ secrets.DON_PETRY_BOT_GH_PAT }}
OWNER_PAT: ${{ secrets.GH_PAT_DON_PETRY }}
# The one PAT the persona manifest names (runtime.identity.credential,
# resolved in the gate job, which constrained it to this known set) —
# never a repo-wide default. An unset secret stays empty and fails
# closed in pr_run_post rather than falling through to the other PAT.
GH_TOKEN: ${{ needs.gate.outputs.credential == 'DON_PETRY_BOT_GH_PAT' && secrets.DON_PETRY_BOT_GH_PAT || (needs.gate.outputs.credential == 'GH_PAT_DON_PETRY' && secrets.GH_PAT_DON_PETRY || '') }}
PERSONA: ${{ inputs.persona }}
POSTING_ACCOUNT: ${{ steps.identity.outputs.account }}
POSTING_CREDENTIAL: ${{ steps.identity.outputs.credential }}
POSTING_ACCOUNT: ${{ needs.gate.outputs.account }}
POSTING_CREDENTIAL: ${{ needs.gate.outputs.credential }}
SOURCE_REPO: ${{ inputs.source_repo }}
ITEM_NUMBER: ${{ inputs.item_number }}
HANDOFF_DIR: ${{ runner.temp }}/persona-handoff
run: |
set -euo pipefail
# shellcheck source=scripts/lib/persona-runner.sh
Expand All @@ -434,13 +507,7 @@
echo "body_file=${body_file}"
} >> "$GITHUB_OUTPUT"

# Select the appropriate PAT based on the persona's manifest identity
if [ "$POSTING_CREDENTIAL" = "DON_PETRY_BOT_GH_PAT" ]; then
GH_TOKEN="${BOT_PAT}"
else
GH_TOKEN="${OWNER_PAT}"
fi
export GH_TOKEN
pr_validate_handoff "$HANDOFF_DIR"

# Extract the advisory, guarantee the recursion marker, and write the
# redacted body to $body_file FIRST — so the upload step below has it
Expand All @@ -454,7 +521,7 @@
pr_run_post \
"$PERSONA" "$SOURCE_REPO" "$ITEM_NUMBER" \
"$POSTING_ACCOUNT" "$POSTING_CREDENTIAL" \
"$RUNNER_TEMP/agent-out.txt" "$body_file" "$GITHUB_STEP_SUMMARY"
"$HANDOFF_DIR/$PR_HANDOFF_FILE" "$body_file" "$GITHUB_STEP_SUMMARY"

- name: Preserve the advisory as a run artifact (post failed)
# Failure-only, byte-for-byte re-postable copy of record. Named
Expand All @@ -471,8 +538,8 @@
if-no-files-found: ignore
retention-days: 30

# Fleet pause notice (#2249). With AGENTS_PAUSED=true the `run` job above is
# skipped by its `if:`, and a skipped job cannot log. This job runs instead, on
# Fleet pause notice (#2249). With AGENTS_PAUSED=true the jobs above are
# skipped by their `if:`, and a skipped job cannot log. This job runs instead, on
# the same events, and says why in one line. Inventory and rules: AGENTS.md
# "Pausing the agent fleet" and scripts/lib/fleet-pause-registry.tsv.
fleet-paused:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/persona-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ jobs:
# Absent surface -> 'mention' so existing dispatches are unchanged (#1905).
surface: ${{ github.event.client_payload.surface || 'mention' }}
event_action: ${{ github.event.client_payload.event_action || '' }}
secrets: inherit
# Named, not inherited: the reusable gets the three secrets it declares and no
# other org secret.
secrets:
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
DON_PETRY_BOT_GH_PAT: ${{ secrets.DON_PETRY_BOT_GH_PAT }}
GH_PAT_DON_PETRY: ${{ secrets.GH_PAT_DON_PETRY }}
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ gated (with the one upstream exception above), and a test keeps it that way.
|---|---|---|---|
| `dev-lead-reusable.yml` | Job condition, no notice | `dispatch,ci-relay,resume` | The original gate (#1525). No notice job: a contract test requires every job of this reusable to carry the condition, and a notice job would start a runner for every event in every consumer repository during a pause. |
| `pr-review.yml` | Job condition, no notice | `review` | Reusable. A job condition, because the AGENTS_PAUSED branch of validate-engines.sh is not enough: with Claude as the primary engine, review-batch.sh carries on. No notice job: the canary promotion gate counts a green run as a health sample, so a paused run must end skipped. |
| `persona-runner-reusable.yml` | Job condition | `run` | Runs every persona advisory (qa-lead, the architects and the rest). |
| `persona-runner-reusable.yml` | Job condition | `run` | Runs every persona advisory (qa-lead, the architects and the rest). The gate job makes no model call and carries the same condition; the post job needs run, so it is skipped with it. |
| `ci-failure-analyst-reusable.yml` | Job condition, no notice | `analyze` | Reusable. No notice job, for the same reason as pr-review.yml: the canary promotion gate samples its runs. |
| `gh-aw-cross-org.yml` | Job condition | `dispatch` | |
| `issue-triage-runner.yml` | Job condition | `triage` | The apply job needs triage, so it is skipped with it. |
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/fleet-pause-registry.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
# ── Agents and model-calling workflows, gated here ───────────────────────────
dev-lead-reusable.yml job-gate-silent dispatch,ci-relay,resume The original gate (#1525). No notice job: a contract test requires every job of this reusable to carry the condition, and a notice job would start a runner for every event in every consumer repository during a pause.
pr-review.yml job-gate-silent review Reusable. A job condition, because the AGENTS_PAUSED branch of validate-engines.sh is not enough: with Claude as the primary engine, review-batch.sh carries on. No notice job: the canary promotion gate counts a green run as a health sample, so a paused run must end skipped.
persona-runner-reusable.yml job-gate run Runs every persona advisory (qa-lead, the architects and the rest).
persona-runner-reusable.yml job-gate run Runs every persona advisory (qa-lead, the architects and the rest). The gate job makes no model call and carries the same condition; the post job needs run, so it is skipped with it.
ci-failure-analyst-reusable.yml job-gate-silent analyze Reusable. No notice job, for the same reason as pr-review.yml: the canary promotion gate samples its runs.
gh-aw-cross-org.yml job-gate dispatch -
issue-triage-runner.yml job-gate triage The apply job needs triage, so it is skipped with it.
Expand Down
55 changes: 55 additions & 0 deletions scripts/lib/persona-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,61 @@ pr_ensure_marker() {
fi
}

# ----------------------------------------------------------------------------
# Handoff from the agent job to the post job
# ----------------------------------------------------------------------------
# The two jobs run on separate runners and share one artifact holding one file.
# The post job reads that file as data only: it never sources or runs anything
# from the artifact, and takes the target repo and item from the workflow inputs.

# The file's name. Mirrored by the upload step's `path:` in the reusable.
PR_HANDOFF_FILE='advisory.txt'
# GitHub caps a comment at 65,536 characters, at most 4 bytes each.
PR_HANDOFF_MAX_BYTES=262144

# pr_write_handoff <agent_out_file> <handoff_file> — write only the advisory
# between the sentinels, redacted, with the sentinels pr_extract_advisory expects.
# Everything else the agent printed stays out of the artifact, which is readable
# by anyone on a public repository. No advisory writes an empty block, which
# pr_run_post reports as nothing to post.
pr_write_handoff() {
local agent_out="$1" handoff="$2" body
body="$(pr_extract_advisory "$(cat "$agent_out")")"
mkdir -p "$(dirname "$handoff")"
{
printf '%s\n' "$PR_ADVISORY_BEGIN"
if [ -n "$body" ]; then
printf '%s\n' "$body" | redact_secrets
fi
printf '%s\n' "$PR_ADVISORY_END"
} > "$handoff"
}

# pr_validate_handoff <handoff_dir> — 0 only if the directory holds exactly one
# entry: a regular file named $PR_HANDOFF_FILE, no larger than
# $PR_HANDOFF_MAX_BYTES. Fails closed, and never prints the artifact's content.
pr_validate_handoff() {
local dir="$1" file="$1/$PR_HANDOFF_FILE" count size
if [ -L "$dir" ] || [ ! -d "$dir" ]; then
echo "::error::advisory handoff: '${dir}' is not a directory — nothing posted" >&2
return 1
fi
count="$(find "$dir" -mindepth 1 | wc -l)"
if [ "$count" -ne 1 ]; then
echo "::error::advisory handoff: expected one file, found ${count// /} entries — nothing posted" >&2
return 1
fi
if [ -L "$file" ] || [ ! -f "$file" ]; then
echo "::error::advisory handoff: ${PR_HANDOFF_FILE} is not a regular file — nothing posted" >&2
return 1
fi
size="$(wc -c < "$file")"
if [ "$size" -gt "$PR_HANDOFF_MAX_BYTES" ]; then
echo "::error::advisory handoff: ${size// /} bytes is over the ${PR_HANDOFF_MAX_BYTES}-byte cap — nothing posted" >&2
return 1
fi
}

# ----------------------------------------------------------------------------
# Post-failure preservation (#1775)
# ----------------------------------------------------------------------------
Expand Down
Loading
Loading