From 27934ac68d78d5c5491e3174d250d95d4c5d9ed0 Mon Sep 17 00:00:00 2001 From: William Easton Date: Tue, 10 Mar 2026 15:14:14 -0700 Subject: [PATCH 1/2] Fix #660: write Buildkite event context to file instead of env vars The "Resolve event context" step runs in the agent job, but the prompt is built in the activation job. Env vars don't cross job boundaries, so all BK_* values were empty in the prompt. Write a plain text file to /tmp/gh-aw/buildkite-event.txt instead and tell the agent to read it. The file is available in the agent's filesystem at runtime. Made-with: Cursor --- .../gh-aw-estc-pr-buildkite-detective.md | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/gh-aw-estc-pr-buildkite-detective.md b/.github/workflows/gh-aw-estc-pr-buildkite-detective.md index 4e71c113..f5b7f97c 100644 --- a/.github/workflows/gh-aw-estc-pr-buildkite-detective.md +++ b/.github/workflows/gh-aw-estc-pr-buildkite-detective.md @@ -96,22 +96,27 @@ steps: - name: Resolve event context run: | set -euo pipefail - echo "BK_EVENT_NAME=$GITHUB_EVENT_NAME" >> "$GITHUB_ENV" - if [ "$GITHUB_EVENT_NAME" = "status" ]; then - echo "BK_EVENT_ID=$(jq -r '.id' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_FAILURE_STATE=$(jq -r '.state' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_COMMIT_SHA=$(jq -r '.commit.sha' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_TARGET_URL=$(jq -r '.target_url // empty' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_BRANCHES=$(jq -c '[(.branches // [])[].name]' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_PR_NUMBERS=" >> "$GITHUB_ENV" - else - echo "BK_EVENT_ID=$(jq -r '.check_run.id' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_FAILURE_STATE=$(jq -r '.check_run.conclusion' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_COMMIT_SHA=$(jq -r '.check_run.head_sha' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_TARGET_URL=$(jq -r '.check_run.details_url // empty' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_BRANCHES=" >> "$GITHUB_ENV" - echo "BK_PR_NUMBERS=$(jq -rc '[(.check_run.pull_requests // [])[].number] | if length == 0 then "" else . end' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - fi + mkdir -p /tmp/gh-aw + { + echo "event_name: $GITHUB_EVENT_NAME" + if [ "$GITHUB_EVENT_NAME" = "status" ]; then + echo "event_id: $(jq -r '.id' "$GITHUB_EVENT_PATH")" + echo "failure_state: $(jq -r '.state' "$GITHUB_EVENT_PATH")" + echo "commit_sha: $(jq -r '.commit.sha' "$GITHUB_EVENT_PATH")" + echo "target_url: $(jq -r '.target_url // empty' "$GITHUB_EVENT_PATH")" + echo "branches: $(jq -r '[(.branches // [])[].name] | join(", ")' "$GITHUB_EVENT_PATH")" + echo "pr_numbers:" + else + echo "event_id: $(jq -r '.check_run.id' "$GITHUB_EVENT_PATH")" + echo "failure_state: $(jq -r '.check_run.conclusion' "$GITHUB_EVENT_PATH")" + echo "commit_sha: $(jq -r '.check_run.head_sha' "$GITHUB_EVENT_PATH")" + echo "target_url: $(jq -r '.check_run.details_url // empty' "$GITHUB_EVENT_PATH")" + echo "branches:" + echo "pr_numbers: $(jq -r '[(.check_run.pull_requests // [])[].number | tostring] | join(", ")' "$GITHUB_EVENT_PATH")" + fi + } > /tmp/gh-aw/buildkite-event.txt + echo "Buildkite event context:" + cat /tmp/gh-aw/buildkite-event.txt - name: Repo-specific setup if: ${{ inputs.setup-commands != '' }} env: @@ -128,15 +133,10 @@ Analyze failed Buildkite CI builds for pull requests in ${{ github.repository }} ## Context - **Repository**: ${{ github.repository }} -- **Event Name**: ${{ env.BK_EVENT_NAME }} -- **Event ID**: ${{ env.BK_EVENT_ID }} -- **Failure State**: ${{ env.BK_FAILURE_STATE }} -- **Commit SHA**: ${{ env.BK_COMMIT_SHA }} -- **Target URL**: ${{ env.BK_TARGET_URL }} -- **PR Numbers**: ${{ env.BK_PR_NUMBERS }} -- **Branches**: ${{ env.BK_BRANCHES }} - **Buildkite Organization**: ${{ inputs.buildkite-org }} +**Read `/tmp/gh-aw/buildkite-event.txt` first.** It contains the event context (commit SHA, target URL, PR numbers, branches, failure state) extracted from the GitHub event payload. + ## Constraints - **CAN**: Read files, search code, run tests and commands, query Buildkite via MCP, comment on PRs @@ -165,10 +165,10 @@ Classify each failure to guide your investigation: ### Step 1: Gather Context -1. Use the commit SHA provided in the Context section above. If it is empty, discover it from the PR's commit statuses or check runs. +1. Read `/tmp/gh-aw/buildkite-event.txt` to get the event context. Use the `commit_sha` value. If it is empty, discover it from the PR's commit statuses or check runs. 2. Find the associated pull request(s): - - If **PR Numbers** in the Context section above is non-empty (e.g., from `check_run` events), use those PR numbers directly with `pull_request_read` method `get`. - - Otherwise, use `bash` + `gh api repos/${{ github.repository }}/commits/{commit_sha}/pulls` to find PRs containing the commit SHA. Filter the results to keep only PRs whose `state` is `"open"` and, when **Branches** is available, whose `head.ref` matches one of the listed branches. If no candidates remain, also try searching open PRs whose head branch matches one of the **Branches** listed in the Context section. + - If `pr_numbers` is non-empty (from `check_run` events), use those PR numbers directly with `pull_request_read` method `get`. + - Otherwise, use `bash` + `gh api repos/${{ github.repository }}/commits/{commit_sha}/pulls` to find PRs containing the commit SHA. Filter the results to keep only PRs whose `state` is `"open"` and, when `branches` is non-empty, whose `head.ref` matches one of the listed branches. If no candidates remain, also try searching open PRs whose head branch matches one of the branches. - If no PR is found after all attempts, call `noop` with message "No pull request associated with failed commit status; nothing to do" and stop. 3. For each matching PR, call `pull_request_read` with method `get` to capture the author, branches, and fork status for downstream analysis. From 6ab92353b54a2ad6902262bbeda4805e0e72dd90 Mon Sep 17 00:00:00 2001 From: William Easton Date: Tue, 10 Mar 2026 15:18:14 -0700 Subject: [PATCH 2/2] compile workflow --- ...gh-aw-estc-pr-buildkite-detective.lock.yml | 64 ++----------------- 1 file changed, 7 insertions(+), 57 deletions(-) diff --git a/.github/workflows/gh-aw-estc-pr-buildkite-detective.lock.yml b/.github/workflows/gh-aw-estc-pr-buildkite-detective.lock.yml index 20eb7ef7..a572738f 100644 --- a/.github/workflows/gh-aw-estc-pr-buildkite-detective.lock.yml +++ b/.github/workflows/gh-aw-estc-pr-buildkite-detective.lock.yml @@ -36,7 +36,7 @@ # # inlined-imports: true # -# gh-aw-metadata: {"schema_version":"v2","frontmatter_hash":"df8ca7d584d83760b992c10ddce0dd529cb00c17400cf20aff40103ae7002b6e"} +# gh-aw-metadata: {"schema_version":"v2","frontmatter_hash":"3882c6673727a6d21ba110797bf529eb51a5dd30d5804598ae6495a118485d5f"} name: "PR Buildkite Detective" "on": @@ -171,13 +171,6 @@ jobs: env: GH_AW_PROMPT: /tmp/gh-aw/aw-prompts/prompt.txt GH_AW_SAFE_OUTPUTS: ${{ env.GH_AW_SAFE_OUTPUTS }} - GH_AW_ENV_BK_BRANCHES: ${{ env.BK_BRANCHES }} - GH_AW_ENV_BK_COMMIT_SHA: ${{ env.BK_COMMIT_SHA }} - GH_AW_ENV_BK_EVENT_ID: ${{ env.BK_EVENT_ID }} - GH_AW_ENV_BK_EVENT_NAME: ${{ env.BK_EVENT_NAME }} - GH_AW_ENV_BK_FAILURE_STATE: ${{ env.BK_FAILURE_STATE }} - GH_AW_ENV_BK_PR_NUMBERS: ${{ env.BK_PR_NUMBERS }} - GH_AW_ENV_BK_TARGET_URL: ${{ env.BK_TARGET_URL }} GH_AW_EXPR_0EAAB79A: ${{ inputs.buildkite-pipeline }} GH_AW_EXPR_49B959F1: ${{ inputs.additional-instructions }} GH_AW_EXPR_6908A9DD: ${{ inputs.buildkite-org }} @@ -329,15 +322,10 @@ jobs: ## Context - **Repository**: __GH_AW_GITHUB_REPOSITORY__ - - **Event Name**: __GH_AW_ENV_BK_EVENT_NAME__ - - **Event ID**: __GH_AW_ENV_BK_EVENT_ID__ - - **Failure State**: __GH_AW_ENV_BK_FAILURE_STATE__ - - **Commit SHA**: __GH_AW_ENV_BK_COMMIT_SHA__ - - **Target URL**: __GH_AW_ENV_BK_TARGET_URL__ - - **PR Numbers**: __GH_AW_ENV_BK_PR_NUMBERS__ - - **Branches**: __GH_AW_ENV_BK_BRANCHES__ - **Buildkite Organization**: __GH_AW_EXPR_6908A9DD__ + **Read `/tmp/gh-aw/buildkite-event.txt` first.** It contains the event context (commit SHA, target URL, PR numbers, branches, failure state) extracted from the GitHub event payload. + ## Constraints - **CAN**: Read files, search code, run tests and commands, query Buildkite via MCP, comment on PRs @@ -366,10 +354,10 @@ jobs: ### Step 1: Gather Context - 1. Use the commit SHA provided in the Context section above. If it is empty, discover it from the PR's commit statuses or check runs. + 1. Read `/tmp/gh-aw/buildkite-event.txt` to get the event context. Use the `commit_sha` value. If it is empty, discover it from the PR's commit statuses or check runs. 2. Find the associated pull request(s): - - If **PR Numbers** in the Context section above is non-empty (e.g., from `check_run` events), use those PR numbers directly with `pull_request_read` method `get`. - - Otherwise, use `bash` + `gh api repos/__GH_AW_GITHUB_REPOSITORY__/commits/{commit_sha}/pulls` to find PRs containing the commit SHA. Filter the results to keep only PRs whose `state` is `"open"` and, when **Branches** is available, whose `head.ref` matches one of the listed branches. If no candidates remain, also try searching open PRs whose head branch matches one of the **Branches** listed in the Context section. + - If `pr_numbers` is non-empty (from `check_run` events), use those PR numbers directly with `pull_request_read` method `get`. + - Otherwise, use `bash` + `gh api repos/__GH_AW_GITHUB_REPOSITORY__/commits/{commit_sha}/pulls` to find PRs containing the commit SHA. Filter the results to keep only PRs whose `state` is `"open"` and, when `branches` is non-empty, whose `head.ref` matches one of the listed branches. If no candidates remain, also try searching open PRs whose head branch matches one of the branches. - If no PR is found after all attempts, call `noop` with message "No pull request associated with failed commit status; nothing to do" and stop. 3. For each matching PR, call `pull_request_read` with method `get` to capture the author, branches, and fork status for downstream analysis. @@ -440,13 +428,6 @@ jobs: uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 env: GH_AW_PROMPT: /tmp/gh-aw/aw-prompts/prompt.txt - GH_AW_ENV_BK_BRANCHES: ${{ env.BK_BRANCHES }} - GH_AW_ENV_BK_COMMIT_SHA: ${{ env.BK_COMMIT_SHA }} - GH_AW_ENV_BK_EVENT_ID: ${{ env.BK_EVENT_ID }} - GH_AW_ENV_BK_EVENT_NAME: ${{ env.BK_EVENT_NAME }} - GH_AW_ENV_BK_FAILURE_STATE: ${{ env.BK_FAILURE_STATE }} - GH_AW_ENV_BK_PR_NUMBERS: ${{ env.BK_PR_NUMBERS }} - GH_AW_ENV_BK_TARGET_URL: ${{ env.BK_TARGET_URL }} GH_AW_GITHUB_REPOSITORY: ${{ github.repository }} GH_AW_EXPR_49B959F1: ${{ inputs.additional-instructions }} GH_AW_EXPR_6908A9DD: ${{ inputs.buildkite-org }} @@ -461,13 +442,6 @@ jobs: uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 env: GH_AW_PROMPT: /tmp/gh-aw/aw-prompts/prompt.txt - GH_AW_ENV_BK_BRANCHES: ${{ env.BK_BRANCHES }} - GH_AW_ENV_BK_COMMIT_SHA: ${{ env.BK_COMMIT_SHA }} - GH_AW_ENV_BK_EVENT_ID: ${{ env.BK_EVENT_ID }} - GH_AW_ENV_BK_EVENT_NAME: ${{ env.BK_EVENT_NAME }} - GH_AW_ENV_BK_FAILURE_STATE: ${{ env.BK_FAILURE_STATE }} - GH_AW_ENV_BK_PR_NUMBERS: ${{ env.BK_PR_NUMBERS }} - GH_AW_ENV_BK_TARGET_URL: ${{ env.BK_TARGET_URL }} GH_AW_EXPR_0EAAB79A: ${{ inputs.buildkite-pipeline }} GH_AW_EXPR_49B959F1: ${{ inputs.additional-instructions }} GH_AW_EXPR_6908A9DD: ${{ inputs.buildkite-org }} @@ -491,13 +465,6 @@ jobs: return await substitutePlaceholders({ file: process.env.GH_AW_PROMPT, substitutions: { - GH_AW_ENV_BK_BRANCHES: process.env.GH_AW_ENV_BK_BRANCHES, - GH_AW_ENV_BK_COMMIT_SHA: process.env.GH_AW_ENV_BK_COMMIT_SHA, - GH_AW_ENV_BK_EVENT_ID: process.env.GH_AW_ENV_BK_EVENT_ID, - GH_AW_ENV_BK_EVENT_NAME: process.env.GH_AW_ENV_BK_EVENT_NAME, - GH_AW_ENV_BK_FAILURE_STATE: process.env.GH_AW_ENV_BK_FAILURE_STATE, - GH_AW_ENV_BK_PR_NUMBERS: process.env.GH_AW_ENV_BK_PR_NUMBERS, - GH_AW_ENV_BK_TARGET_URL: process.env.GH_AW_ENV_BK_TARGET_URL, GH_AW_EXPR_0EAAB79A: process.env.GH_AW_EXPR_0EAAB79A, GH_AW_EXPR_49B959F1: process.env.GH_AW_EXPR_49B959F1, GH_AW_EXPR_6908A9DD: process.env.GH_AW_EXPR_6908A9DD, @@ -623,24 +590,7 @@ jobs: run: "set -euo pipefail\nif [ -f \"AGENTS.md\" ]; then\n cp AGENTS.md /tmp/agents.md\n echo \"Repository conventions copied from AGENTS.md to /tmp/agents.md\"\nelse\n OWNER=\"${GITHUB_REPOSITORY%/*}\"\n REPO=\"${GITHUB_REPOSITORY#*/}\"\n summary=$(curl -sf --max-time 15 -X POST https://agents-md-generator.fastmcp.app/mcp \\\n -H \"Content-Type: application/json\" \\\n -H \"Accept: application/json, text/event-stream\" \\\n -d \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"id\\\":1,\\\"method\\\":\\\"tools/call\\\",\\\"params\\\":{\\\"name\\\":\\\"generate_agents_md\\\",\\\"arguments\\\":{\\\"owner\\\":\\\"${OWNER}\\\",\\\"repo\\\":\\\"${REPO}\\\"}}}\" \\\n | sed 's/^data: //' \\\n | jq -r '.result.structuredContent.summary // empty' 2>/dev/null) || true\n if [ -n \"$summary\" ]; then\n echo \"$summary\" > /tmp/agents.md\n echo \"Repository conventions written to /tmp/agents.md\"\n else\n echo \"::warning::Could not fetch repository conventions; continuing without them\"\n fi\nfi" shell: bash - name: Resolve event context - run: | - set -euo pipefail - echo "BK_EVENT_NAME=$GITHUB_EVENT_NAME" >> "$GITHUB_ENV" - if [ "$GITHUB_EVENT_NAME" = "status" ]; then - echo "BK_EVENT_ID=$(jq -r '.id' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_FAILURE_STATE=$(jq -r '.state' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_COMMIT_SHA=$(jq -r '.commit.sha' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_TARGET_URL=$(jq -r '.target_url // empty' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_BRANCHES=$(jq -c '[(.branches // [])[].name]' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_PR_NUMBERS=" >> "$GITHUB_ENV" - else - echo "BK_EVENT_ID=$(jq -r '.check_run.id' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_FAILURE_STATE=$(jq -r '.check_run.conclusion' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_COMMIT_SHA=$(jq -r '.check_run.head_sha' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_TARGET_URL=$(jq -r '.check_run.details_url // empty' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - echo "BK_BRANCHES=" >> "$GITHUB_ENV" - echo "BK_PR_NUMBERS=$(jq -rc '[(.check_run.pull_requests // [])[].number] | if length == 0 then "" else . end' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV" - fi + run: "set -euo pipefail\nmkdir -p /tmp/gh-aw\n{\n echo \"event_name: $GITHUB_EVENT_NAME\"\n if [ \"$GITHUB_EVENT_NAME\" = \"status\" ]; then\n echo \"event_id: $(jq -r '.id' \"$GITHUB_EVENT_PATH\")\"\n echo \"failure_state: $(jq -r '.state' \"$GITHUB_EVENT_PATH\")\"\n echo \"commit_sha: $(jq -r '.commit.sha' \"$GITHUB_EVENT_PATH\")\"\n echo \"target_url: $(jq -r '.target_url // empty' \"$GITHUB_EVENT_PATH\")\"\n echo \"branches: $(jq -r '[(.branches // [])[].name] | join(\", \")' \"$GITHUB_EVENT_PATH\")\"\n echo \"pr_numbers:\"\n else\n echo \"event_id: $(jq -r '.check_run.id' \"$GITHUB_EVENT_PATH\")\"\n echo \"failure_state: $(jq -r '.check_run.conclusion' \"$GITHUB_EVENT_PATH\")\"\n echo \"commit_sha: $(jq -r '.check_run.head_sha' \"$GITHUB_EVENT_PATH\")\"\n echo \"target_url: $(jq -r '.check_run.details_url // empty' \"$GITHUB_EVENT_PATH\")\"\n echo \"branches:\"\n echo \"pr_numbers: $(jq -r '[(.check_run.pull_requests // [])[].number | tostring] | join(\", \")' \"$GITHUB_EVENT_PATH\")\"\n fi\n} > /tmp/gh-aw/buildkite-event.txt\necho \"Buildkite event context:\"\ncat /tmp/gh-aw/buildkite-event.txt\n" - env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}