Skip to content

Commit 492c1ba

Browse files
authored
[CI] Preserve Claude execution logs for review inspection (#8381)
## Summary Expose two opt-in controls on the reusable Claude workflow: - `show_full_output` streams the complete Claude SDK event sequence into the GitHub Actions log. - `upload_execution_log` uploads the action's existing `claude-execution-output.json` after completion without modifying or forking `anthropics/claude-code-action`. Execution logs are keyed both by the triggering comment and by workflow run: ```text review-logs/claude-code/<owner>/<repo>/<issue-or-pr>/<comment-id>.json review-logs/claude-code/<owner>/<repo>/<issue-or-pr>/runs/<run-id>_<attempt>.json ``` The comment-keyed object lets a viewer start from a PR, enumerate its `@claude` mentions through the GitHub API, and load each review independently without maintaining a separate S3 manifest. Both options default to `false`, so existing callers are unchanged. ## Validation CIForge temporarily enabled both options for one probe and was then restored to `test-infra@main`. - Run: https://github.com/pytorch/ciforge/actions/runs/30318082793 - Job: https://github.com/pytorch/ciforge/actions/runs/30318082793/job/90147956380 - Claude step succeeded with full assistant and tool events visible in the job log. - Upload step succeeded. - Both S3 keys returned the same 10-event execution stream with a successful four-turn result. The CIForge prototype viewer enumerated all eight `@claude` mentions on issue #527 and rendered the newly persisted trace selected by comment ID. ## Security model This is opt-in and follows the existing distributed-triage model: full output may contain assistant text, tool arguments, and tool results. Callers should enable it only where that exposure is acceptable.
1 parent 592772d commit 492c1ba

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

.github/workflows/_claude-code.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ on:
2828
description: 'Claude settings JSON'
2929
type: string
3030
default: '{"alwaysThinkingEnabled": true}'
31+
show_full_output:
32+
description: 'PUBLIC: Show complete Claude messages and tool output in the job log'
33+
type: boolean
34+
default: false
35+
upload_execution_log:
36+
description: 'PUBLIC: Upload the execution log after Claude exits; hard timeouts may leave no file'
37+
type: boolean
38+
default: false
39+
execution_log_s3_prefix:
40+
description: 'Prefix for Claude execution logs in the public S3 bucket'
41+
type: string
42+
default: 'review-logs/claude-code'
3143
setup_script:
3244
description: 'Shell commands to run before Claude (e.g. install lintrunner)'
3345
type: string
@@ -185,6 +197,7 @@ jobs:
185197
use_bedrock: "true"
186198
claude_args: "--model ${{ inputs.model }} ${{ inputs.additional_claude_args }} ${{ steps.ghstack-check.outputs.extra_claude_args }}"
187199
settings: ${{ inputs.settings }}
200+
show_full_output: ${{ inputs.show_full_output }}
188201
env:
189202
APPEND_SYSTEM_PROMPT: |
190203
${{ steps.ghstack-check.outputs.ghstack_notice }}
@@ -193,3 +206,33 @@ jobs:
193206
- name: Upload usage metrics
194207
if: always()
195208
uses: pytorch/test-infra/.github/actions/upload-claude-usage@main
209+
210+
- name: Upload Claude execution log
211+
if: always() && inputs.upload_execution_log
212+
continue-on-error: true
213+
timeout-minutes: 2
214+
shell: bash
215+
env:
216+
EXECUTION_FILE: ${{ runner.temp }}/claude-execution-output.json
217+
ENTITY_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number || 0 }}
218+
TRIGGER_ID: ${{ github.event.comment.id || github.event.issue.id || github.run_id }}
219+
S3_PREFIX: ${{ inputs.execution_log_s3_prefix }}
220+
run: |
221+
if [ ! -f "$EXECUTION_FILE" ]; then
222+
echo "Claude execution log not found: $EXECUTION_FILE"
223+
exit 0
224+
fi
225+
if [ "$ENTITY_NUMBER" = "0" ]; then
226+
echo "No issue or pull request number available; skipping execution log upload"
227+
exit 0
228+
fi
229+
230+
BASE_KEY="${S3_PREFIX}/${GITHUB_REPOSITORY}/${ENTITY_NUMBER}"
231+
MENTION_KEY="${BASE_KEY}/${TRIGGER_ID}.json"
232+
RUN_KEY="${BASE_KEY}/runs/${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}.json"
233+
234+
aws s3 cp "$EXECUTION_FILE" "s3://ossci-raw-job-status/${MENTION_KEY}"
235+
aws s3 cp "$EXECUTION_FILE" "s3://ossci-raw-job-status/${RUN_KEY}"
236+
237+
echo "Uploaded mention log: s3://ossci-raw-job-status/${MENTION_KEY}"
238+
echo "Uploaded run log: s3://ossci-raw-job-status/${RUN_KEY}"

0 commit comments

Comments
 (0)