88 workflow_run :
99 workflows : ["Merge Conditions"]
1010 types : [completed]
11+ # PR trigger for testing (remove after validation)
12+ pull_request :
13+ branches : [main]
14+ paths :
15+ - " scripts/autocurrency/agent-fix.py"
16+ - " .github/workflows/agent-currency-fix.yml"
17+ - " docker/vllm/Dockerfile"
1118
1219permissions :
1320 contents : read
2330jobs :
2431 fix-agent :
2532 if : >-
26- github.event.workflow_run.conclusion == 'failure' &&
27- startsWith(github.event.workflow_run.head_branch, 'auto-update/')
33+ github.event_name == 'workflow_dispatch' ||
34+ github.event_name == 'pull_request' || (
35+ github.event.workflow_run.conclusion == 'failure' &&
36+ startsWith(github.event.workflow_run.head_branch, 'auto-update/')
37+ )
2838 runs-on :
2939 - codebuild-runner-${{ github.run_id }}-${{ github.run_attempt }}
3040 fleet:default-runner
3141 buildspec-override:true
3242 env :
33- HEAD_BRANCH : ${{ github.event.workflow_run.head_branch }}
34- RUN_ID : ${{ github.event.workflow_run.id }}
35- RUN_URL : ${{ github.event.workflow_run.html_url }}
43+ HEAD_BRANCH : ${{ github.event.workflow_run.head_branch || github.head_ref }}
44+ RUN_ID : ${{ github.event.workflow_run.id || '' }}
45+ RUN_URL : ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
3646 steps :
3747 - name : Validate branch name
3848 run : |
49+ # Skip validation for pull_request testing
50+ if [ "${{ github.event_name }}" = "pull_request" ]; then
51+ echo "Skipping branch validation for PR testing"
52+ exit 0
53+ fi
3954 if [[ ! "$HEAD_BRANCH" =~ ^auto-update/[a-z]+-[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
4055 echo "::error::Branch '${HEAD_BRANCH}' does not match expected pattern."
4156 exit 1
@@ -51,13 +66,40 @@ jobs:
5166 fi
5267 gh --version
5368
69+ # For pull_request testing: poll until a tracked workflow fails (or timeout)
70+ - name : Wait for CI failure
71+ if : github.event_name == 'pull_request'
72+ env :
73+ GH_TOKEN : ${{ github.token }}
74+ run : |
75+ TRACKED="PR - vLLM EC2|PR - vLLM SageMaker|PR - SGLang EC2|PR - SGLang SageMaker"
76+ SHA="${{ github.event.pull_request.head.sha }}"
77+ echo "Polling for tracked workflow failures on SHA: $SHA"
78+ for i in $(seq 1 40); do
79+ FOUND=$(gh api "/repos/${{ github.repository }}/actions/runs?head_sha=${SHA}&status=completed&per_page=50" \
80+ --jq "[.workflow_runs[] | select(.conclusion == \"failure\" and (.name | test(\"${TRACKED}\")))] | length")
81+ if [ "$FOUND" -gt 0 ]; then
82+ echo "Found $FOUND failed tracked workflow(s) after $i minutes"
83+ break
84+ fi
85+ echo "No failures yet, waiting 60s... ($i/40)"
86+ sleep 60
87+ done
88+
5489 - name : Find failed tracked workflows
5590 id : failures
5691 env :
5792 GH_TOKEN : ${{ github.token }}
5893 run : |
5994 TRACKED="PR - vLLM EC2|PR - vLLM SageMaker|PR - SGLang EC2|PR - SGLang SageMaker"
60- SHA=$(gh api "/repos/${{ github.repository }}/actions/runs/${RUN_ID}" --jq '.head_sha')
95+
96+ # Get HEAD SHA depending on event type
97+ if [ -n "$RUN_ID" ]; then
98+ SHA=$(gh api "/repos/${{ github.repository }}/actions/runs/${RUN_ID}" --jq '.head_sha')
99+ else
100+ SHA="${{ github.event.pull_request.head.sha || github.sha }}"
101+ fi
102+ echo "SHA: $SHA"
61103
62104 FAILED_RUN_IDS=$(gh api "/repos/${{ github.repository }}/actions/runs?head_sha=${SHA}&status=completed&per_page=50" \
63105 --jq "[.workflow_runs[] | select(.conclusion == \"failure\" and (.name | test(\"${TRACKED}\")))] | .[].id" \
@@ -93,16 +135,19 @@ jobs:
93135 if : steps.failures.outputs.has_failures == 'true'
94136 uses : actions/checkout@v5
95137 with :
96- ref : main
138+ ref : ${{ github.event_name == 'pull_request' && github.head_ref || ' main' }}
97139 fetch-depth : 0
98140 token : ${{ steps.app-token.outputs.token }}
99141
100142 - name : Prepare workspace
101143 if : steps.failures.outputs.has_failures == 'true'
102144 run : |
103145 cp scripts/autocurrency/agent-fix.py /tmp/agent-fix.py
104- git fetch origin "$HEAD_BRANCH"
105- git checkout "origin/$HEAD_BRANCH" -B pr-branch
146+ # For pull_request testing, we're already on the right branch
147+ if [ "${{ github.event_name }}" != "pull_request" ]; then
148+ git fetch origin "$HEAD_BRANCH"
149+ git checkout "origin/$HEAD_BRANCH" -B pr-branch
150+ fi
106151
107152 - name : Count previous attempts
108153 if : steps.failures.outputs.has_failures == 'true'
@@ -139,35 +184,43 @@ jobs:
139184 Agent run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
140185 fi
141186
142- - name : Download failed run logs
143- if : steps.failures.outputs.has_failures == 'true' && steps.retry.outputs.max_reached != 'true'
144- env :
145- GH_TOKEN : ${{ steps.app-token.outputs.token }}
146- FAILED_RUNS : ${{ steps.failures.outputs.failed_runs }}
147- run : |
148- mkdir -p /tmp/ci-logs
149- for RUN in $FAILED_RUNS; do
150- gh api "/repos/${{ github.repository }}/actions/runs/${RUN}/logs" > "/tmp/ci-logs-${RUN}.zip" || true
151- [ -s "/tmp/ci-logs-${RUN}.zip" ] && unzip -o "/tmp/ci-logs-${RUN}.zip" -d "/tmp/ci-logs/run-${RUN}/" || true
152- done
153-
154187 - name : Determine framework
155188 if : steps.failures.outputs.has_failures == 'true' && steps.retry.outputs.max_reached != 'true'
189+ env :
190+ GH_TOKEN : ${{ github.token }}
156191 run : |
157- FRAMEWORK=$(echo "$HEAD_BRANCH" | sed 's|auto-update/||' | sed 's|-[0-9].*||')
192+ # Derive framework from which tracked workflow failed
193+ SHA="${{ github.event.pull_request.head.sha || github.sha }}"
194+ if [ -n "$RUN_ID" ]; then
195+ SHA=$(gh api "/repos/${{ github.repository }}/actions/runs/${RUN_ID}" --jq '.head_sha' 2>/dev/null || echo "$SHA")
196+ fi
197+ FAILED_NAME=$(gh api "/repos/${{ github.repository }}/actions/runs?head_sha=${SHA}&status=completed&per_page=50" \
198+ --jq '[.workflow_runs[] | select(.conclusion == "failure" and (.name | test("PR - vLLM|PR - SGLang")))][0].name' 2>/dev/null || echo "")
199+ if echo "$FAILED_NAME" | grep -qi "vllm"; then
200+ FRAMEWORK="vllm"
201+ elif echo "$FAILED_NAME" | grep -qi "sglang"; then
202+ FRAMEWORK="sglang"
203+ else
204+ # Fallback to branch name parsing
205+ FRAMEWORK=$(echo "$HEAD_BRANCH" | sed 's|auto-update/||' | sed 's|-[0-9].*||')
206+ fi
207+ echo "Framework: $FRAMEWORK (from: $FAILED_NAME)"
158208 echo "FRAMEWORK=$FRAMEWORK" >> $GITHUB_ENV
159209
160210 - name : Run fix agent
161211 if : steps.failures.outputs.has_failures == 'true' && steps.retry.outputs.max_reached != 'true'
162212 id : fix
163213 env :
164214 AWS_REGION : us-west-2
215+ GH_TOKEN : ${{ steps.app-token.outputs.token }}
165216 run : |
166217 python3 -m pip install boto3 -q
167218 python3 /tmp/agent-fix.py \
168- --logs-dir /tmp/ci-logs/ \
169219 --framework "$FRAMEWORK" \
170- --branch "$HEAD_BRANCH"
220+ --branch "$HEAD_BRANCH" \
221+ --run-ids "${{ steps.failures.outputs.failed_runs }}" \
222+ --token "$GH_TOKEN" \
223+ --repo "${{ github.repository }}"
171224
172225 - name : Commit and push
173226 if : steps.failures.outputs.has_failures == 'true' && steps.retry.outputs.max_reached != 'true' && steps.fix.outcome == 'success'
0 commit comments