Skip to content

Add the pi agent composite action for Bedrock - #199566

Closed
drisspg wants to merge 19 commits into
gh/drisspg/435/basefrom
gh/drisspg/435/head
Closed

drisspg wants to merge 19 commits into
gh/drisspg/435/basefrom
gh/drisspg/435/head

Conversation

@drisspg

@drisspg drisspg commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Human Note

Agent note

AI-assisted implementation and summary.

This adds the pi runner that the next two PRs use. The point is to make the model runtime
independent of the triage policy, so changing a Bedrock model does not mean rewriting the workflow.
This PR does not switch any workflow over yet. The same action is already running in ciforge.

The caller picks the model, tools, skill, and optional result schema. The action installs pi from
an integrity-pinned lockfile without install scripts, loads only explicitly supplied configuration,
and enforces the tool allowlist. File tools stay inside the working directory. With a result schema,
the model must call submit_result with valid JSON; finishing without a result is a failure.
Provider errors also fail the action, even when pi itself exits zero.

This is not a sandbox by itself. The caller still owns AWS credentials, GitHub permissions, and
network restrictions. The next PR uses a read-only model job with blocked egress and a separate
write job. Logs retain the Claude execution-file format so the existing inspector and usage
uploader can read them.

For review, start with action.yml and run.sh, then the tool guard and result extension. The
large lockfile is dependency pinning, not the main logic.

Test Plan

The action was exercised locally with a scripted provider: valid result, missing result,
provider error, unknown model, and six path/tool escape attempts. The escape attempts were blocked.
It also ran through the real Bedrock issue-triage flow in ciforge. ShellCheck passed on run.sh.

The latest two-issue replay using this action and the shared workflow completed successfully:
https://github.com/pytorch/ciforge/actions/runs/37075392603

cc @albanD

[ghstack-poisoned]
@drisspg
drisspg requested a review from a team as a code owner October 2, 2026 21:19
@pytorch-bot

pytorch-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

🟡 AUTOMATED REVIEW - OUTDATED (earlier commit) - Changes requested:

This PR adds `.github/actions/pi-agent`, a composite action that runs one pi
session on Bedrock with a tool allowlist and path guard, a schema-checked
`submit_result` tool, pinned `rg`/`fd`, a converter to Claude's execution-file
format, and offline tests. Recommendation: Request Changes. The `.git/config`
token exposure and the `text_or_file` path read are security defaults in the
action itself, and the guard/result-schema behaviour has no test against the
real pinned pi.

Findings (7):

[major] .github/actions/pi-agent/extensions/tool-guard.ts:31
The path guard lets the model read the job's GitHub token in `.git/config`. The
guard treats the whole working directory as safe and claims this protects
"runner secrets". With `actions/checkout`'s default `persist-credentials: true`,
the job token sits inside that directory as `http.(link removed) in
`.git/config` (`hardened-pr-review-run.yml:568-569` already flags this as "a
file the model's Read tool is allowed to open"). A prompt-injected issue body
can get the model to `read .git/config`. The token then lands in `events.jsonl`
and `transcript.html` in the always-uploaded public artifact, and can reach
`structured_output`. The README usage example sets `persist-credentials: false`,
but the Lockdown section doesn't list it as a requirement and nothing enforces
it. Fix: have the guard block `.git/config`, or fail `run.sh` when `git config
--get-regexp 'http..*.extraheader'` matches. Also add `persist-credentials:
false` to the Lockdown list.

[major] .github/actions/pi-agent/run.sh:30
`prompt` and `result-schema` read any path that passes `[[ -f ]]` (advertised at
`action.yml:14` and `README.md:43`). `action.yml` never states the
"trusted-caller contract", and the input description invites literal text.
Failure: a later caller writes `prompt: ${{ github.event.issue.body }}`. A body
of exactly `/proc/self/environ` passes `-f`, so the step's environment,
including the AWS session credentials from `configure-aws-credentials`, is
copied into `prompt.md`. From there it reaches the model and the public
artifact, bypassing `tool-guard.ts` entirely. Once the next PRs in the stack
adopt this input shape, changing it becomes a breaking change, so it is cheapest
to fix now. Fix: split into `prompt`/`prompt-file` and
`result-schema`/`result-schema-file`, and never infer a file read from `-f`.

[major] .github/actions/pi-agent/run.sh:111
No test loads `tool-guard.ts` or `submit-result.ts` into the real pinned pi. The
extension tests use mock `ExtensionAPI` objects, `test_run.py` uses a fake `pi`
with a hand-written event stream, and `real-tools.mjs` calls the tool factories
directly, bypassing the guard. So CI never checks that pi 0.99.1 accepts `-e
tool-guard.ts`, honours `{block: true}` from `tool_call`, enforces a plain JSON
Schema passed as `parameters`, or emits the `message_end`/`role:
"system"`/`toolsAdded` shape the allowlist audit depends on. If that shape
differs, `declared` is empty and the audit at `run.sh:115` passes without
checking anything. `run.sh` also never re-validates `result.json` against the
schema. Fix: add CI steps in `pi-agent-tests.yml` against the lockfile install
that run `pi --no-extensions -e /tool-guard.ts -e /submit-result.ts
--list-models`, drive one guarded tool call and one schema-violating
`submit_result` through real pi (a faux/scripted provider is enough), and record
a real event stream to replace the hand-written one in `test_run.py`.

[minor] .github/actions/pi-agent/run.sh:68
Low confidence: some `pi` calls skip the isolation flags. `pi update --models`
(line 68), `pi --version` (lines 73, 134) and `pi --export` (line 86) run in the
checkout directory without `"${isolation[@​]}"`. The review couldn't check
offline whether pi 0.99.1 loads project `.pi/` settings or extensions on these
code paths. If it does, a checkout runs code in a step holding AWS credentials.
Passing the flags, or running these calls from `$out`, costs nothing.

(3 more not shown, see the review run)

Reviewed commit: c407f21 (NOT the current head 790f75b)

Review run

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/199566

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 790f75b with merge base 421855c (image):
💚 Looks good so far! There are no failures yet. 💚
🟡 GreenLight: changes are too big to review

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Oct 2, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T21:22:51.911394Z 2ea30e6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ea30e6c56

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/actions/pi-agent/run.sh Resolved
Comment thread .github/actions/pi-agent/action.yml Resolved
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@drisspg
drisspg requested review from albanD and malfet as code owners October 2, 2026 23:14
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@drisspg
drisspg requested a review from izaitsevfb October 5, 2026 23:33
[ghstack-poisoned]
@pytorchbot pytorchbot added the in progress PR is being worked on by the author, until the automated review accepts it label Oct 16, 2026
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

@drisspg

drisspg commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot

pytorch-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

This PR has pending changes requested. Please address the comments and update the PR before merging.

@drisspg

drisspg commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot review

I want to keep this scoped to the trusted-checkout triage callers in this stack. I am accepting the remaining generic-action hardening as follow-up work rather than expanding this PR further.

Agent details (AI-generated)

  • The triage caller supplies a workflow-authored prompt and a fixed schema path. It does not forward an issue body as the action's prompt or result-schema input; issue content is fetched through read-only tools. The path-or-text input is a trusted-caller contract, not a safe passthrough interface for arbitrary untrusted text.
  • Full traces are intentional for these public-issue triage runs. Their tool allowlist excludes bash/write/edit; the model job has no GitHub write scope. This does not claim that full trace uploads are appropriate for every possible caller.
  • pi is pinned to 0.99.1. The guard tests cover its current path forms, and real pinned pi read/ls/grep/find were exercised offline on Ubuntu in https://github.com/pytorch/ciforge/actions/runs/40768542069. New tool fields in a future version need review when that pin changes; they are not an observed bypass of the current tool schemas.

Ivan's requested grep/find check is implemented and tested. The current head has no failing CI checks.

@pytorch-bot pytorch-bot Bot added in progress PR is being worked on by the author, until the automated review accepts it and removed in progress PR is being worked on by the author, until the automated review accepts it labels Oct 29, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review of c407f21: changes requested before human review.

This PR adds .github/actions/pi-agent, a composite action that runs one pi session on Bedrock with a tool allowlist and path guard, a schema-checked submit_result tool, pinned rg/fd, a converter to Claude's execution-file format, and offline tests. Recommendation: Request Changes. The .git/config token exposure and the text_or_file path read are security defaults in the action itself, and the guard/result-schema behaviour has no test against the real pinned pi.

🔴 3 blocking findings are attached to the code below.

⚪ 4 non-blocking findings

PI_OFFLINE=0 pi update --models || true

Low confidence: some pi calls skip the isolation flags. pi update --models (line 68), pi --version (lines 73, 134) and pi --export (line 86) run in the checkout directory without "${isolation\[@\]}". The review couldn't check offline whether pi 0.99.1 loads project .pi/ settings or extensions on these code paths. If it does, a checkout runs code in a step holding AWS credentials. Passing the flags, or running these calls from $out, costs nothing.


The execution-file output doesn't match the README's "same shape" claim. The output is named execution-file, but every claude-code-action consumer reads outputs.execution_file (claude-autorevert-advisor.yml:253,259, hardened-pr-review-run.yml:843-845,1017,1052, auto-pr-triage/action.yml:151,194). It is also inconsistent with this action's own structured_output. In claude-execution.jq:73-74, modelUsage is always {($model): {}}, so the summing at hardened-pr-review-run.yml:1036-1042 yields nothing, and permission_denials is hard-coded to \[\] even though run.sh:113-114 counts blocked calls. Fix: rename the output to execution_file, fill modelUsage\[$model\] from the computed totals, and emit the blocked tool_execution_end entries as permission_denials. Otherwise drop "same shape" from the README.


printf '%s\n' "$bin_dir" >> "${GITHUB_PATH:?}"

This line changes PATH for every later step in the job: appending pi-tools/bin to GITHUB_PATH makes the pinned rg/fd shadow the system binaries for all later steps. Prepend it locally in run.sh instead, as run.sh:11 already does for pi-install/node_modules/.bin, and drop the GITHUB_PATH write. That also removes the GITHUB_PATH assertion from test_install_tools.py.


PI_OUTPUT_DIR: ${{ runner.temp }}/pi-run

A second invocation in the same job breaks the first one's output. The output directory is hard-coded to $RUNNER_TEMP/pi-run, and rm -rf "$out" (run.sh:9) clears it on every run, while the comment at run.sh:7-8 expects a second invocation. When that happens, the first step's execution-file output points at the second session's file, so an end-of-job usage uploader counts the second run twice. hardened-pr-review-run.yml:839-846 has to work around the same problem for claude-code-action. Fix: use a per-invocation output directory (keyed on artifact-name) or add an output-dir input.

Please address the findings and push; a new commit normally gets a fresh automated review.

This review is AI-generated and advisory. Each new automated review replaces the previous one.

if (allowed.size === 0) {
throw new Error("tool-guard: PI_ALLOWED_TOOLS must list the session's tools");
}
const root = realpathSync(process.cwd());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 The path guard lets the model read the job's GitHub token in .git/config. The guard treats the whole working directory as safe and claims this protects "runner secrets". With actions/checkout's default persist-credentials: true, the job token sits inside that directory as http.(link removed) in .git/config (hardened-pr-review-run.yml:568-569already flags this as "a file the model's Read tool is allowed to open"). A prompt-injected issue body can get the model toread .git/config. The token then lands in events.jsonlandtranscript.htmlin the always-uploaded public artifact, and can reachstructured_output. The README usage example sets persist-credentials: false, but the Lockdown section doesn't list it as a requirement and nothing enforces it. Fix: have the guard block .git/config, or fail run.shwhengit config --get-regexp 'http..*.extraheader'matches. Also addpersist-credentials: false` to the Lockdown list.

fi

# prompt and result-schema accept literal text or a path to a file.
text_or_file() { if [[ -f "$1" ]]; then cat "$1"; else printf '%s' "$1"; fi; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 prompt and result-schema read any path that passes \[\[ -f \]\] (advertised at action.yml:14 and README.md:43). action.yml never states the "trusted-caller contract", and the input description invites literal text. Failure: a later caller writes prompt: ${{ github.event.issue.body }}. A body of exactly /proc/self/environ passes -f, so the step's environment, including the AWS session credentials from configure-aws-credentials, is copied into prompt.md. From there it reaches the model and the public artifact, bypassing tool-guard.ts entirely. Once the next PRs in the stack adopt this input shape, changing it becomes a breaking change, so it is cheapest to fix now. Fix: split into prompt/prompt-file and result-schema/result-schema-file, and never infer a file read from -f.

|| echo '{}' > "$out/usage.json"

# Every tool declared to the model or run successfully must be in the allowlist.
declared=$(jq -r 'select(.type == "message_end" and .message.role == "system") | .message.toolsAdded[]?.name' "$events" | sort -u)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 No test loads tool-guard.ts or submit-result.ts into the real pinned pi. The extension tests use mock ExtensionAPI objects, test_run.py uses a fake pi with a hand-written event stream, and real-tools.mjs calls the tool factories directly, bypassing the guard. So CI never checks that pi 0.99.1 accepts -e tool-guard.ts, honours {block: true} from tool_call, enforces a plain JSON Schema passed as parameters, or emits the message_end/role: "system"/toolsAdded shape the allowlist audit depends on. If that shape differs, declared is empty and the audit at run.sh:115 passes without checking anything. run.sh also never re-validates result.json against the schema. Fix: add CI steps in pi-agent-tests.yml against the lockfile install that run pi --no-extensions -e /tool-guard.ts -e /submit-result.ts --list-models, drive one guarded tool call and one schema-violating submit_result through real pi (a faux/scripted provider is enough), and record a real event stream to replace the hand-written one in test_run.py.

@drisspg drisspg added the no automated review Request skipping the automated PR review process label Oct 29, 2026
@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Oct 29, 2026
@drisspg
drisspg dismissed stale reviews from github-actions[bot], github-actions[bot], github-actions[bot], github-actions[bot], github-actions[bot], github-actions[bot], github-actions[bot], and github-actions[bot] October 29, 2026 03:53

Reviewed the remaining automated findings and accepted them as follow-up work.

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #199555

[ghstack-poisoned]
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #199555

pytorchmergebot pushed a commit that referenced this pull request Oct 29, 2026
## Human Note

## Agent Notes

Move issue triage from Claude Code to pi while keeping Sonnet 5 as the default, at medium
thinking. Sol remains a manual option. The main change is the trust boundary: the model reads
issues and submits a structured plan; a separate job with no model or AWS credentials applies it.
The model never holds the GitHub write token.

The apply step filters labels, supplies required comment templates, and adds completion labels
for complete classifications. Reproduction requests redact download links using a fixed policy
and the current issue body, not a model-written replacement. Transfers go to human review;
automatic closes are limited to usage questions and expected numerical behavior. Reports show
the comments that will actually be posted, including automatic templates and deduplication.

Manual replay and dry-run support batches; apply accepts exactly one issue. The reusable
read-only Bedrock workflow has blocked egress and short-lived credentials; #199588 reuses it for
distributed triage. Model execution artifacts and usage metrics retain their existing formats. Job summaries remain
readable Markdown; log copies are JSON-encoded to prevent workflow-command interpretation.

For review, start with `issue-triage-pi.yml` and `pi-triage-plan.yml`, then `apply_plan.py` and
its tests. `add_bot_triaged.py` is removed here. The two validation hooks remain for the old
distributed workflow until #199588 removes their last users. The model still makes triage
judgments; these controls limit its effects rather than making those judgments infallible.

## Validation

- [20-issue Sonnet replay](https://github.com/pytorch/ciforge/actions/runs/37063139472): oncall
  routing matched the historical Claude bot on 20/20 issues. This is agreement, not ground truth.
- Live ciforge testing exercised issue-opened triage, comments, restricted closing, and the
  distributed handoff. The handoff testing exposed a subqueue-routing gap, now covered by tests.
- Effective-template reporting was checked with deterministic tests for automatic, unknown,
  and already-posted templates; no new live model run was needed for that reporting-only change.

## Linked issue or supporting maintainer

<!-- Author has write access; fill in if an issue or maintainer applies. -->

## BC-breaking?

No.

## Summary (human written only)

## Agent details (if applicable)

Implementation and validation are described in Agent Notes above.

Pull Request resolved: #199555
Approved by: https://github.com/izaitsevfb
ghstack dependencies: #199566
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
## Human Note

## Agent note

> AI-assisted implementation and summary.
>
> This adds the pi runner that the next two PRs use. The point is to make the model runtime
> independent of the triage policy, so changing a Bedrock model does not mean rewriting the workflow.
> This PR does not switch any workflow over yet. The same action is already running in ciforge.
>
> The caller picks the model, tools, skill, and optional result schema. The action installs pi from
> an integrity-pinned lockfile without install scripts, loads only explicitly supplied configuration,
> and enforces the tool allowlist. File tools stay inside the working directory. With a result schema,
> the model must call `submit_result` with valid JSON; finishing without a result is a failure.
> Provider errors also fail the action, even when pi itself exits zero.
>
> This is not a sandbox by itself. The caller still owns AWS credentials, GitHub permissions, and
> network restrictions. The next PR uses a read-only model job with blocked egress and a separate
> write job. Logs retain the Claude execution-file format so the existing inspector and usage
> uploader can read them.
>
> For review, start with `action.yml` and `run.sh`, then the tool guard and result extension. The
> large lockfile is dependency pinning, not the main logic.

## Test Plan

> The action was exercised locally with a scripted provider: valid result, missing result,
> provider error, unknown model, and six path/tool escape attempts. The escape attempts were blocked.
> It also ran through the real Bedrock issue-triage flow in ciforge. ShellCheck passed on `run.sh`.
>
> The latest two-issue replay using this action and the shared workflow completed successfully:
> https://github.com/pytorch/ciforge/actions/runs/37075392603

Pull Request resolved: pytorch#199566
Approved by: https://github.com/izaitsevfb
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
## Human Note

## Agent Notes

Move issue triage from Claude Code to pi while keeping Sonnet 5 as the default, at medium
thinking. Sol remains a manual option. The main change is the trust boundary: the model reads
issues and submits a structured plan; a separate job with no model or AWS credentials applies it.
The model never holds the GitHub write token.

The apply step filters labels, supplies required comment templates, and adds completion labels
for complete classifications. Reproduction requests redact download links using a fixed policy
and the current issue body, not a model-written replacement. Transfers go to human review;
automatic closes are limited to usage questions and expected numerical behavior. Reports show
the comments that will actually be posted, including automatic templates and deduplication.

Manual replay and dry-run support batches; apply accepts exactly one issue. The reusable
read-only Bedrock workflow has blocked egress and short-lived credentials; pytorch#199588 reuses it for
distributed triage. Model execution artifacts and usage metrics retain their existing formats. Job summaries remain
readable Markdown; log copies are JSON-encoded to prevent workflow-command interpretation.

For review, start with `issue-triage-pi.yml` and `pi-triage-plan.yml`, then `apply_plan.py` and
its tests. `add_bot_triaged.py` is removed here. The two validation hooks remain for the old
distributed workflow until pytorch#199588 removes their last users. The model still makes triage
judgments; these controls limit its effects rather than making those judgments infallible.

## Validation

- [20-issue Sonnet replay](https://github.com/pytorch/ciforge/actions/runs/37063139472): oncall
  routing matched the historical Claude bot on 20/20 issues. This is agreement, not ground truth.
- Live ciforge testing exercised issue-opened triage, comments, restricted closing, and the
  distributed handoff. The handoff testing exposed a subqueue-routing gap, now covered by tests.
- Effective-template reporting was checked with deterministic tests for automatic, unknown,
  and already-posted templates; no new live model run was needed for that reporting-only change.

## Linked issue or supporting maintainer

<!-- Author has write access; fill in if an issue or maintainer applies. -->

## BC-breaking?

No.

## Summary (human written only)

## Agent details (if applicable)

Implementation and validation are described in Agent Notes above.

Pull Request resolved: pytorch#199555
Approved by: https://github.com/izaitsevfb
ghstack dependencies: pytorch#199566
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
## Human Note

## Agent note

> AI-assisted implementation and summary.
>
> This adds the pi runner that the next two PRs use. The point is to make the model runtime
> independent of the triage policy, so changing a Bedrock model does not mean rewriting the workflow.
> This PR does not switch any workflow over yet. The same action is already running in ciforge.
>
> The caller picks the model, tools, skill, and optional result schema. The action installs pi from
> an integrity-pinned lockfile without install scripts, loads only explicitly supplied configuration,
> and enforces the tool allowlist. File tools stay inside the working directory. With a result schema,
> the model must call `submit_result` with valid JSON; finishing without a result is a failure.
> Provider errors also fail the action, even when pi itself exits zero.
>
> This is not a sandbox by itself. The caller still owns AWS credentials, GitHub permissions, and
> network restrictions. The next PR uses a read-only model job with blocked egress and a separate
> write job. Logs retain the Claude execution-file format so the existing inspector and usage
> uploader can read them.
>
> For review, start with `action.yml` and `run.sh`, then the tool guard and result extension. The
> large lockfile is dependency pinning, not the main logic.

## Test Plan

> The action was exercised locally with a scripted provider: valid result, missing result,
> provider error, unknown model, and six path/tool escape attempts. The escape attempts were blocked.
> It also ran through the real Bedrock issue-triage flow in ciforge. ShellCheck passed on `run.sh`.
>
> The latest two-issue replay using this action and the shared workflow completed successfully:
> https://github.com/pytorch/ciforge/actions/runs/37075392603

Pull Request resolved: pytorch#199566
Approved by: https://github.com/izaitsevfb
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
## Human Note

## Agent Notes

Move issue triage from Claude Code to pi while keeping Sonnet 5 as the default, at medium
thinking. Sol remains a manual option. The main change is the trust boundary: the model reads
issues and submits a structured plan; a separate job with no model or AWS credentials applies it.
The model never holds the GitHub write token.

The apply step filters labels, supplies required comment templates, and adds completion labels
for complete classifications. Reproduction requests redact download links using a fixed policy
and the current issue body, not a model-written replacement. Transfers go to human review;
automatic closes are limited to usage questions and expected numerical behavior. Reports show
the comments that will actually be posted, including automatic templates and deduplication.

Manual replay and dry-run support batches; apply accepts exactly one issue. The reusable
read-only Bedrock workflow has blocked egress and short-lived credentials; pytorch#199588 reuses it for
distributed triage. Model execution artifacts and usage metrics retain their existing formats. Job summaries remain
readable Markdown; log copies are JSON-encoded to prevent workflow-command interpretation.

For review, start with `issue-triage-pi.yml` and `pi-triage-plan.yml`, then `apply_plan.py` and
its tests. `add_bot_triaged.py` is removed here. The two validation hooks remain for the old
distributed workflow until pytorch#199588 removes their last users. The model still makes triage
judgments; these controls limit its effects rather than making those judgments infallible.

## Validation

- [20-issue Sonnet replay](https://github.com/pytorch/ciforge/actions/runs/37063139472): oncall
  routing matched the historical Claude bot on 20/20 issues. This is agreement, not ground truth.
- Live ciforge testing exercised issue-opened triage, comments, restricted closing, and the
  distributed handoff. The handoff testing exposed a subqueue-routing gap, now covered by tests.
- Effective-template reporting was checked with deterministic tests for automatic, unknown,
  and already-posted templates; no new live model run was needed for that reporting-only change.

## Linked issue or supporting maintainer

<!-- Author has write access; fill in if an issue or maintainer applies. -->

## BC-breaking?

No.

## Summary (human written only)

## Agent details (if applicable)

Implementation and validation are described in Agent Notes above.

Pull Request resolved: pytorch#199555
Approved by: https://github.com/izaitsevfb
ghstack dependencies: pytorch#199566
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GL/superseded GreenLight review is superseded by changes Merged no automated review Request skipping the automated PR review process ready for review Automated review passed, ready for a final review by a maintainer. skip-pr-sanity-checks topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants