Skip to content

Fix build-failure-analysis agent: 403 auth failure and lost binlog legs - #17301

Merged
YuliiaKovalova merged 3 commits into
dotnet:mainfrom
YuliiaKovalova:fix-copilot-requests-auth
Aug 11, 2026
Merged

YuliiaKovalova merged 3 commits into
dotnet:mainfrom
YuliiaKovalova:fix-copilot-requests-auth

Conversation

@YuliiaKovalova

Copy link
Copy Markdown
Member

Summary

The Build Failure Analysis agent has never successfully run. Every non-skipped run since it was enabled failed identically, ~2s into the agent job — before the agent read its prompt or opened a single binlog:

Authentication failed with provider at http://172.30.0.30:10002 (HTTP 403).
attempt 1 failed: ... isAuthenticationFailedError=true
attempt 1: authentication failed — not retrying (first-attempt auth failure is non-retryable)

Affected runs: 31067880845, 31178421733, 31224876130, 31233589289. The runs that report "success" only did so because activation was skipped, so the agent never started there either.

Two independent defects are fixed.


1. copilot-requests: write broke agent authentication

Both workflows declared copilot-requests: write in frontmatter. That permission makes gh-aw compile the agent job's token as:

COPILOT_GITHUB_TOKEN: ${{ github.token }}      # ephemeral Actions token

instead of:

COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}

The ephemeral Actions token is not entitled for inference against api.githubcopilot.com in this org, so every request was rejected.

The 403 is upstream, not a sandbox/firewall problem. From the run's own artifacts:

  • Squid logged CONNECT 200 TCP_TUNNEL ... api.githubcopilot.com:443 — egress succeeded.
  • api-proxy telemetry recorded http.response.status_code: 403 on both GET /models and POST /chat/completions.

Because /models fails too, this is not model-specific — it is token entitlement.

Control case: update-default-versions.md omits copilot-requests, resolves the PAT from secrets.COPILOT_GITHUB_TOKEN, and is green run after run — same repo, same gh-aw v0.77.5, same claude-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 secret step 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-binlog fails closed when any Logs_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:

::warning::Skipping Logs_Build_Windows_NT_Release: 'unzip -l' failed or timed out
::warning::Only 1 of 2 Logs_Build_* legs produced a usable binlog; skipping

Two root causes, both fixed:

A failed or truncated download was undetectable. The exit status of curl ... | head -c ... is head's, and head succeeds 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 from PIPESTATUS[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 head close the pipe early and curl exit on SIGPIPE (141) — that case is already covered by the existing cap. --max-time is raised 300 → 600 with a retry delay, for the larger Windows leg.

The size probe itself was the bottleneck. unzip -l formats every entry before tail -1 throws all of it away, and a Logs_Build_* archive holds thousands of files — that is what pushed the probe past its 60s timeout. unzip -Zt reports 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

  • Locks regenerated with the pinned gh-aw v0.77.5 (downloaded standalone), not a newer local extension, so no unrelated compiler drift is introduced.
  • Both locks parse as valid YAML; per-job permissions are otherwise unchanged and no copilot-requests remains. Agent job stays least-privilege at contents: read + pull-requests: read; all PR writes still go through safe_outputs.
  • Locks now emit COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }} in every position, matching the known-good workflow.
  • The rewritten guard was executed under bash -e against 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 tripping errexit:
Case Outcome
healthy download accepted
truncated zip, curl succeeded skip — unzip -Zt failed
curl timeout mid-transfer skip — download failed or truncated (curl exit 28)
curl failed, nothing written skip — empty or failed download
  • unzip -Zt field 3 was confirmed to return the same uncompressed byte total as the previous unzip -l | tail -1 expression.

Note on scope

Recompiling pristine main already produces unrelated drift in .gitattributes (compiler wants to add merge=ours) and in update-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-adding copilot-requests: write will reproduce the 403 exactly as seen here.

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
Copilot AI lite review requested due to automatic review settings August 10, 2026 15:55

Copilot AI 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.

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: write from workflow permissions to prevent gh-aw from switching to an ineligible github.token for COPILOT_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 -l to faster unzip -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.

Comment on lines +336 to +339
# `|| 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]}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment on lines +392 to +395
# `|| 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]}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment on lines +1613 to +1616
# `|| 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]}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment on lines +1704 to +1707
# `|| 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]}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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
Copilot AI review requested due to automatic review settings August 10, 2026 16:12

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

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
Copilot AI review requested due to automatic review settings August 11, 2026 09:29

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@YuliiaKovalova
YuliiaKovalova merged commit da8da4b into dotnet:main Aug 11, 2026
2 of 6 checks passed
@YuliiaKovalova

Copy link
Copy Markdown
Member Author

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 curl --retry 3 ... | head -c CAP > file. Stdout is not seekable, so curl cannot rewind when it retries. If the server answers a transient 5xx, curl writes the error body, then retries and appends the real archive. The result is <error page><zip> on disk — and curl exits 0, so no exit-status check can catch it. unzip then reports extra bytes at beginning, the leg is skipped, and the all-legs guard aborts the analysis. That is exactly the Skipping Logs_Build_... / Only 1 of 2 legs pair seen in run 30921596534.

Reproduced against a local server that returns 503 once and then 200: piped, the file came out 64 bytes larger than the payload with curl_rc=0 and unzip -Zt rc=1; with -o it is byte-identical to the payload. --fail also keeps error bodies off disk in the first place.

The head -c cap is preserved as ulimit -f (1 KiB units), which the kernel enforces even when the response declares no Content-Length. SIGXFSZ is ignored so hitting the cap becomes an ordinary write error (curl 23) rather than a signal death that would print File size limit exceeded (core dumped) into the log. The size guard is -ge because the truncation lands exactly on the cap.

Two latent defects found while verifying:

  • awk '{print $3}' ran over every line of unzip -Zt, and Info-ZIP writes recoverable-archive warnings to stdout. UNCOMP could therefore be multi-line, and grep -q matches if any line matches — so a corrupt archive could pass the numeric check. Now awk 'END{print $3}'.
  • The shell: bash I added is not a no-op: GitHub's default is bash -e {0}, but an explicit shell: bash is bash --noprofile --norc -eo pipefail {0}. In the fetch step pipefail is cleared explicitly, but in "Export agent context" it left printf | head -1 able to abort the step on SIGPIPE. Replaced with ${LIST%%$'\n'*}.

Verified: transient-503 retry now yields the exact payload; truncated body → curl_rc=18, skipped; length-less oversized response → capped at exactly the limit, no scary log line; 404 → 0 bytes, skipped. End to end against live dnceng-public builds 1547565 and 1547234, both stage 2/2 legs through traversal scan, extraction and staging. Both lock files recompiled with the pinned gh-aw v0.77.5; the diff is only these four files.

One deliberate non-change: all three unzip invocations still fail closed on rc≠0, so an archive that is merely warning-producing but extractable still drops its leg. That is the existing posture for untrusted PR archives and I did not want to loosen it, especially now that the thing which was generating such archives is gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants