Repository navigation
Fix build-failure-analysis agent: 403 auth failure and lost binlog legs - #17301
Conversation
The Build Failure Analysis agent has never successfully run. Every
non-skipped run failed identically, ~2s into the `agent` job, before the
agent read its prompt or opened a binlog:
Authentication failed with provider at http://172.30.0.30:10002 (HTTP 403)
attempt 1: authentication failed - not retrying
Two independent defects are fixed here.
1. `copilot-requests: write` broke agent authentication
The frontmatter of both workflows declared `copilot-requests: write`.
That permission makes gh-aw compile the agent job's token as
`COPILOT_GITHUB_TOKEN: ${{ github.token }}` instead of
`${{ secrets.COPILOT_GITHUB_TOKEN }}`, and the ephemeral Actions token is
not entitled for inference against api.githubcopilot.com in this org.
The firewall logs confirm the request left the sandbox and was rejected
upstream rather than blocked locally - Squid recorded
`CONNECT 200 TCP_TUNNEL` to api.githubcopilot.com, and the api-proxy
telemetry recorded HTTP 403 on both `GET /models` and
`POST /chat/completions`. So this is a token entitlement failure, not a
network, model or prompt problem.
`update-default-versions.md` omits `copilot-requests`, resolves the PAT
from `secrets.COPILOT_GITHUB_TOKEN`, and has been green continuously on
the same repo, same gh-aw v0.77.5 and the same claude-sonnet-4.6 model.
Dropping the permission brings these two workflows back in line with it
and restores the validated-secret path (the regenerated locks now emit
the `Validate COPILOT_GITHUB_TOKEN secret` step, so a missing or expired
secret fails loudly at activation instead of as an opaque 403).
2. A single slow artifact silently discarded the whole analysis
`fetch-binlog` fails closed if any `Logs_Build_*` leg is missing, since a
missing leg could be the one that broke. That guard is right, but it was
being tripped by ordinary artifact-download flakiness:
Skipping Logs_Build_Windows_NT_Release: 'unzip -l' failed or timed out
Only 1 of 2 Logs_Build_* legs produced a usable binlog; skipping
Two causes, both addressed:
* A failed or truncated download was undetectable. The status of
`curl ... | head -c ...` is `head`'s, and `head` succeeds even when
curl dies mid-transfer, so a partial archive was written and only
surfaced later as an unreadable zip - indistinguishable from a
hostile one. curl's own status is now read from `PIPESTATUS[0]` and
reported as a distinct, actionable warning. It is checked only after
the size guards, because an oversized artifact legitimately makes
`head` close the pipe early and curl exit on SIGPIPE (141); that case
is already handled by the existing cap. `--max-time` is raised
300 -> 600 and a retry delay added for the larger Windows leg.
* The size probe itself was the bottleneck. `unzip -l` formats every
entry before `tail -1` discards all of it, and a `Logs_Build_*`
archive holds thousands of files, which is what pushed the probe past
its 60s timeout. `unzip -Zt` reports the same total in one summary
line without per-entry formatting.
Both remain fail-closed: a failed, truncated or unverifiable archive is
still skipped rather than trusted.
Verification
The regenerated locks were compiled with the pinned gh-aw v0.77.5 (not a
newer extension), and both parse as valid YAML with per-job permissions
otherwise unchanged and no remaining `copilot-requests`. The rewritten
guard was exercised under `bash -e` against real archives for the healthy,
truncated-zip, curl-timeout and curl-failed-with-no-output cases; each
resolves to the intended accept/skip outcome without tripping errexit.
Note: recompiling pristine `main` already produces unrelated drift in
`.gitattributes` and `update-default-versions.lock.yml`. That drift is
pre-existing and deliberately left out of this change.
Co-authored-by: Copilot <[email protected]>
Copilot-Session: c5dc4518-6af1-496b-bbbb-f878b9a67ac6
There was a problem hiding this comment.
Pull request overview
This PR fixes the GitHub Actions “Build Failure Analysis” agent workflows so they can successfully authenticate to GitHub Copilot and more reliably fetch binlog artifacts for analysis, addressing repeated early failures and artifact-download flakiness.
Changes:
- Removes
copilot-requests: writefrom workflow permissions to prevent gh-aw from switching to an ineligiblegithub.tokenforCOPILOT_GITHUB_TOKEN, and adds guard comments to avoid regression. - Regenerates gh-aw lockfiles to consistently use
secrets.COPILOT_GITHUB_TOKEN, adds a “Validate COPILOT_GITHUB_TOKEN secret” step, and ensures secret redaction includes it. - Improves binlog artifact handling: detects curl failures/truncation and switches size probing from
unzip -lto fasterunzip -Zt.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| .github/workflows/build-failure-analysis.md | Removes copilot-requests: write, documents why, and hardens binlog artifact download/probing logic. |
| .github/workflows/build-failure-analysis.lock.yml | Regenerated lockfile reflecting PAT-based Copilot auth + secret validation + updated artifact handling logic. |
| .github/workflows/build-failure-analysis-command.md | Same fixes as the automatic workflow for the command-triggered variant. |
| .github/workflows/build-failure-analysis-command.lock.yml | Regenerated lockfile for the command-triggered workflow with the same auth/secret/artifact logic updates. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # `|| true` keeps errexit from killing the step and does not clobber | ||
| # PIPESTATUS, which is set by the pipeline itself. | ||
| curl -sSL --retry 3 --retry-delay 2 --max-time 600 "${url}" 2>/dev/null | head -c $((MAX_ZIP_BYTES + 1)) > /tmp/a.zip || true | ||
| curl_rc=${PIPESTATUS[0]} |
There was a problem hiding this comment.
Fixed in 248bbd0 — good catch, this was a real defect.
Confirmed the mechanism empirically: for curl ... | head -c N > file the pipeline's status is head's, so when curl fails but head succeeds the pipeline returns 0 and || true never runs (PIPESTATUS survives). But when head itself fails, the pipeline is non-zero, || true executes, and true resets PIPESTATUS[0] to 0 — silently defeating the guard.
The fix drops || true entirely rather than replacing it with a set +e / set -e pair: this step already runs with errexit off (set +e at the top of the step body), so the pipeline cannot abort the step and no suffix is needed. Toggling errexit locally would have been worse — the trailing set -e would have switched errexit on for the remaining ~140 lines of a step deliberately written to run errexit-off, where benign non-zero statuses (grep -q, cp, [ ] tests) are expected.
Verified against the real step shell mode (bash -e entry, then set +e / set +o pipefail) across six scenarios:
| scenario | curl_rc | outcome |
|---|---|---|
| healthy download | 0 | accepted |
| truncated zip, curl rc=0 | 0 | skipped (unzip -Zt fails) |
| curl timeout mid-transfer | 28 | skipped — previously accepted |
| curl failed, nothing written | 28 | skipped (empty) |
| SIGPIPE-style rc=141 | 141 | skipped |
| garbage payload | 0 | skipped (unzip -Zt fails) |
Shell flags after the block are unchanged (errexit off, pipefail off), so the step's error semantics are preserved.
| # `|| true` keeps errexit from killing the step and does not clobber | ||
| # PIPESTATUS, which is set by the pipeline itself. | ||
| curl -sSL --retry 3 --retry-delay 2 --max-time 600 "${url}" 2>/dev/null | head -c $((MAX_ZIP_BYTES + 1)) > /tmp/a.zip || true | ||
| curl_rc=${PIPESTATUS[0]} |
There was a problem hiding this comment.
Fixed in 248bbd0 — good catch, this was a real defect.
Confirmed the mechanism empirically: for curl ... | head -c N > file the pipeline's status is head's, so when curl fails but head succeeds the pipeline returns 0 and || true never runs (PIPESTATUS survives). But when head itself fails, the pipeline is non-zero, || true executes, and true resets PIPESTATUS[0] to 0 — silently defeating the guard.
The fix drops || true entirely rather than replacing it with a set +e / set -e pair: this step already runs with errexit off (set +e at the top of the step body), so the pipeline cannot abort the step and no suffix is needed. Toggling errexit locally would have been worse — the trailing set -e would have switched errexit on for the remaining ~140 lines of a step deliberately written to run errexit-off, where benign non-zero statuses (grep -q, cp, [ ] tests) are expected.
Verified against the real step shell mode (bash -e entry, then set +e / set +o pipefail) across six scenarios:
| scenario | curl_rc | outcome |
|---|---|---|
| healthy download | 0 | accepted |
| truncated zip, curl rc=0 | 0 | skipped (unzip -Zt fails) |
| curl timeout mid-transfer | 28 | skipped — previously accepted |
| curl failed, nothing written | 28 | skipped (empty) |
| SIGPIPE-style rc=141 | 141 | skipped |
| garbage payload | 0 | skipped (unzip -Zt fails) |
Shell flags after the block are unchanged (errexit off, pipefail off), so the step's error semantics are preserved.
| # `|| true` keeps errexit from killing the step and does not clobber | ||
| # PIPESTATUS, which is set by the pipeline itself. | ||
| curl -sSL --retry 3 --retry-delay 2 --max-time 600 "${url}" 2>/dev/null | head -c $((MAX_ZIP_BYTES + 1)) > /tmp/a.zip || true | ||
| curl_rc=${PIPESTATUS[0]} |
There was a problem hiding this comment.
Fixed in 248bbd0 — good catch, this was a real defect.
Confirmed the mechanism empirically: for curl ... | head -c N > file the pipeline's status is head's, so when curl fails but head succeeds the pipeline returns 0 and || true never runs (PIPESTATUS survives). But when head itself fails, the pipeline is non-zero, || true executes, and true resets PIPESTATUS[0] to 0 — silently defeating the guard.
The fix drops || true entirely rather than replacing it with a set +e / set -e pair: this step already runs with errexit off (set +e at the top of the step body), so the pipeline cannot abort the step and no suffix is needed. Toggling errexit locally would have been worse — the trailing set -e would have switched errexit on for the remaining ~140 lines of a step deliberately written to run errexit-off, where benign non-zero statuses (grep -q, cp, [ ] tests) are expected.
Verified against the real step shell mode (bash -e entry, then set +e / set +o pipefail) across six scenarios:
| scenario | curl_rc | outcome |
|---|---|---|
| healthy download | 0 | accepted |
| truncated zip, curl rc=0 | 0 | skipped (unzip -Zt fails) |
| curl timeout mid-transfer | 28 | skipped — previously accepted |
| curl failed, nothing written | 28 | skipped (empty) |
| SIGPIPE-style rc=141 | 141 | skipped |
| garbage payload | 0 | skipped (unzip -Zt fails) |
Shell flags after the block are unchanged (errexit off, pipefail off), so the step's error semantics are preserved.
| # `|| true` keeps errexit from killing the step and does not clobber | ||
| # PIPESTATUS, which is set by the pipeline itself. | ||
| curl -sSL --retry 3 --retry-delay 2 --max-time 600 "${url}" 2>/dev/null | head -c $((MAX_ZIP_BYTES + 1)) > /tmp/a.zip || true | ||
| curl_rc=${PIPESTATUS[0]} |
There was a problem hiding this comment.
Fixed in 248bbd0 — good catch, this was a real defect.
Confirmed the mechanism empirically: for curl ... | head -c N > file the pipeline's status is head's, so when curl fails but head succeeds the pipeline returns 0 and || true never runs (PIPESTATUS survives). But when head itself fails, the pipeline is non-zero, || true executes, and true resets PIPESTATUS[0] to 0 — silently defeating the guard.
The fix drops || true entirely rather than replacing it with a set +e / set -e pair: this step already runs with errexit off (set +e at the top of the step body), so the pipeline cannot abort the step and no suffix is needed. Toggling errexit locally would have been worse — the trailing set -e would have switched errexit on for the remaining ~140 lines of a step deliberately written to run errexit-off, where benign non-zero statuses (grep -q, cp, [ ] tests) are expected.
Verified against the real step shell mode (bash -e entry, then set +e / set +o pipefail) across six scenarios:
| scenario | curl_rc | outcome |
|---|---|---|
| healthy download | 0 | accepted |
| truncated zip, curl rc=0 | 0 | skipped (unzip -Zt fails) |
| curl timeout mid-transfer | 28 | skipped — previously accepted |
| curl failed, nothing written | 28 | skipped (empty) |
| SIGPIPE-style rc=141 | 141 | skipped |
| garbage payload | 0 | skipped (unzip -Zt fails) |
Shell flags after the block are unchanged (errexit off, pipefail off), so the step's error semantics are preserved.
Address review feedback on the truncated-download guard. Appending || true to the curl pipeline runs rue, which resets PIPESTATUS before it can be read, so a download that failed while head succeeded would report curl_rc=0 and defeat the guard. The step already runs with errexit off, so the pipeline cannot abort it and no trailing || true (or local errexit toggle) is needed at all. Co-authored-by: Copilot <[email protected]> Copilot-Session: c5dc4518-6af1-496b-bbbb-f878b9a67ac6
Verification against real dnceng-public Logs_Build_* artifacts (arcade-pr build 1547565) showed each leg is a ~11 MB, 2-entry archive on which 'unzip -l' and 'unzip -Zt' agree and both complete in ~0.03s. The claim that per-entry listing cost pushed the probe past its timeout was not supported, so the comment now describes what the change actually buys: a fixed-column summary line instead of tail -1 over a variable-length table. The observed 'failed or timed out' warnings came from unreadable archives, which the curl status check now reports accurately. Co-authored-by: Copilot <[email protected]> Copilot-Session: c5dc4518-6af1-496b-bbbb-f878b9a67ac6
|
Follow-up from a second review pass. It turned up a defect that explains the original symptom better than my first fix did, so pushing 44f9e00. Root cause of the dropped legs. The download was Reproduced against a local server that returns 503 once and then 200: piped, the file came out 64 bytes larger than the payload with The Two latent defects found while verifying:
Verified: transient-503 retry now yields the exact payload; truncated body → One deliberate non-change: all three |
Summary
The Build Failure Analysis agent has never successfully run. Every non-skipped run since it was enabled failed identically, ~2s into the
agentjob — before the agent read its prompt or opened a single binlog:Affected runs: 31067880845, 31178421733, 31224876130, 31233589289. The runs that report "success" only did so because
activationwas skipped, so the agent never started there either.Two independent defects are fixed.
1.
copilot-requests: writebroke agent authenticationBoth workflows declared
copilot-requests: writein frontmatter. That permission makes gh-aw compile the agent job's token as:instead of:
The ephemeral Actions token is not entitled for inference against
api.githubcopilot.comin this org, so every request was rejected.The 403 is upstream, not a sandbox/firewall problem. From the run's own artifacts:
CONNECT 200 TCP_TUNNEL ... api.githubcopilot.com:443— egress succeeded.http.response.status_code: 403on bothGET /modelsandPOST /chat/completions.Because
/modelsfails too, this is not model-specific — it is token entitlement.Control case:
update-default-versions.mdomitscopilot-requests, resolves the PAT fromsecrets.COPILOT_GITHUB_TOKEN, and is green run after run — same repo, same gh-awv0.77.5, sameclaude-sonnet-4.6. That is the only relevant difference between the working workflow and the broken ones.Dropping the permission restores the PAT path and, as a side benefit, re-enables the
Validate COPILOT_GITHUB_TOKEN secretstep in the generated lock — so a missing or expired secret now fails loudly at activation instead of as an opaque 403 deep inside the sandbox.A comment is added at both call sites so the permission is not reintroduced.
2. A single slow artifact silently discarded the whole analysis
fetch-binlogfails closed when anyLogs_Build_*leg is missing, on the grounds that the missing leg could be the one that broke. That guard is correct, but it was being tripped by ordinary artifact-download flakiness rather than by genuinely bad archives — e.g. run 30921596534:Two root causes, both fixed:
A failed or truncated download was undetectable. The exit status of
curl ... | head -c ...ishead's, andheadsucceeds even when curl dies mid-transfer. A partial archive was written to disk and only surfaced later as an unreadable zip, indistinguishable from a hostile one. curl's own status is now read fromPIPESTATUS[0]and reported as a distinct, actionable warning.Ordering matters here: the curl check runs after the size guards, because an oversized artifact legitimately makes
headclose the pipe early and curl exit on SIGPIPE (141) — that case is already covered by the existing cap.--max-timeis raised300→600with a retry delay, for the larger Windows leg.The size probe itself was the bottleneck.
unzip -lformats every entry beforetail -1throws all of it away, and aLogs_Build_*archive holds thousands of files — that is what pushed the probe past its 60s timeout.unzip -Ztreports the same total in a single summary line with no per-entry formatting.Both paths remain fail-closed: a failed, truncated or unverifiable archive is still skipped, never trusted.
Verification
v0.77.5(downloaded standalone), not a newer local extension, so no unrelated compiler drift is introduced.copilot-requestsremains. Agent job stays least-privilege atcontents: read+pull-requests: read; all PR writes still go throughsafe_outputs.COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}in every position, matching the known-good workflow.bash -eagainst real archives covering: healthy download, truncated zip, curl timeout mid-transfer (rc=28), and curl failure with no output. Each resolved to the intended accept/skip outcome without trippingerrexit:unzip -Ztfailedunzip -Ztfield 3 was confirmed to return the same uncompressed byte total as the previousunzip -l | tail -1expression.Note on scope
Recompiling pristine
mainalready produces unrelated drift in.gitattributes(compiler wants to addmerge=ours) and inupdate-default-versions.lock.yml(body_hash). That drift is pre-existing, reproducible without any of my edits, and deliberately excluded from this PR to keep the diff reviewable. Happy to fix it separately if wanted.Follow-up
This PR makes the workflow use the PAT that already works elsewhere in the repo. If the intent was instead to move to
GITHUB_TOKEN-based Copilot billing, that needs the org-level entitlement enabled first — otherwise re-addingcopilot-requests: writewill reproduce the 403 exactly as seen here.