Skip to content

Fix Buildkite detective empty event context (#660)#661

Merged
strawgate merged 2 commits intomainfrom
fix/660-buildkite-detective-context
Mar 10, 2026
Merged

Fix Buildkite detective empty event context (#660)#661
strawgate merged 2 commits intomainfrom
fix/660-buildkite-detective-context

Conversation

@strawgate
Copy link
Collaborator

@strawgate strawgate commented Mar 10, 2026

Summary

Fixes #660

Resolve event context was writing BK_* values to $GITHUB_ENV, but those values were later consumed during prompt rendering in a different job. Because environment variables do not cross job boundaries, the detective prompt could receive empty event context (including commit SHA, PR numbers, branches, and target URL).

This PR switches event context handoff to a runtime file at /tmp/gh-aw/buildkite-event.txt, then updates the detective prompt to read that file directly.

What changed

  • The Resolve event context step now writes normalized fields (event_name, event_id, failure_state, commit_sha, target_url, branches, pr_numbers) to /tmp/gh-aw/buildkite-event.txt for both status and check_run payloads.
  • Prompt rendering no longer relies on GH_AW_ENV_BK_* substitutions for Buildkite context.
  • The detective instructions now explicitly read /tmp/gh-aw/buildkite-event.txt first and use commit_sha (plus pr_numbers/branches) from that file when resolving the target PR.

Test plan

  • Trigger the Buildkite detective workflow via a status event and verify /tmp/gh-aw/buildkite-event.txt contains the expected values.
  • Trigger via a check_run event and verify the same.
  • Confirm the agent reads the file and uses the event commit_sha (not the workflow run commit).

The body of this PR is automatically managed by the Trigger Update PR Body workflow.

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
@strawgate strawgate enabled auto-merge (squash) March 10, 2026 22:15
@strawgate strawgate disabled auto-merge March 10, 2026 22:15
@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d06a780a-3885-4c81-86bf-f1d80ae0cbe1

📥 Commits

Reviewing files that changed from the base of the PR and between 27934ac and 6ab9235.

📒 Files selected for processing (1)
  • .github/workflows/gh-aw-estc-pr-buildkite-detective.lock.yml

📝 Walkthrough

Walkthrough

This PR centralizes Buildkite event context extraction by writing a structured file at /tmp/gh-aw/buildkite-event.txt (event_name, event_id, failure_state, commit_sha, target_url, branches, pr_numbers) instead of exporting individual BK_* environment variables. Workflow steps, prompt/template rendering, and README guidance are updated to read and use fields from that file for PR discovery and prompt generation; downstream logic now prefers pr_numbers from the file and uses branches for filtering when present.

Possibly related PRs

Suggested labels

medium_boom

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/660-buildkite-detective-context
  • 🛠️ Update Documentation: Commit on current branch
  • 🛠️ Update Documentation: Create PR

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
.github/workflows/gh-aw-estc-pr-buildkite-detective.md (1)

108-108: Format inconsistency: empty field representation

Lines 108 and 114 output pr_numbers: and branches: (no space after colon) when explicitly empty, but lines 107 and 115 with jq will output branches: and pr_numbers: (space after colon) when the jq expression returns an empty string. While the agent can likely handle both, standardizing the format improves consistency.

♻️ Standardize empty field format

Option 1: Add explicit empty string to match jq output:

-          echo "pr_numbers:"
+          echo "pr_numbers: "
-          echo "branches:"
+          echo "branches: "

Option 2: Use a structured format like JSON for more robust parsing:

       mkdir -p /tmp/gh-aw
+      if [ "$GITHUB_EVENT_NAME" = "status" ]; then
+        jq -n \
+          --arg event_name "$GITHUB_EVENT_NAME" \
+          --arg event_id "$(jq -r '.id' "$GITHUB_EVENT_PATH")" \
+          --arg failure_state "$(jq -r '.state' "$GITHUB_EVENT_PATH")" \
+          --arg commit_sha "$(jq -r '.commit.sha' "$GITHUB_EVENT_PATH")" \
+          --arg target_url "$(jq -r '.target_url // ""' "$GITHUB_EVENT_PATH")" \
+          --argjson branches "$(jq '[(.branches // [])[].name]' "$GITHUB_EVENT_PATH")" \
+          '{event_name: $event_name, event_id: $event_id, failure_state: $failure_state, commit_sha: $commit_sha, target_url: $target_url, branches: $branches, pr_numbers: []}' \
+          > /tmp/gh-aw/buildkite-event.txt
+      else
+        jq -n \
+          --arg event_name "$GITHUB_EVENT_NAME" \
+          --arg event_id "$(jq -r '.check_run.id' "$GITHUB_EVENT_PATH")" \
+          --arg failure_state "$(jq -r '.check_run.conclusion' "$GITHUB_EVENT_PATH")" \
+          --arg commit_sha "$(jq -r '.check_run.head_sha' "$GITHUB_EVENT_PATH")" \
+          --arg target_url "$(jq -r '.check_run.details_url // ""' "$GITHUB_EVENT_PATH")" \
+          --argjson pr_numbers "$(jq '[(.check_run.pull_requests // [])[].number]' "$GITHUB_EVENT_PATH")" \
+          '{event_name: $event_name, event_id: $event_id, failure_state: $failure_state, commit_sha: $commit_sha, target_url: $target_url, branches: [], pr_numbers: $pr_numbers}' \
+          > /tmp/gh-aw/buildkite-event.txt
+      fi
-      {
-        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

Also applies to: 114-114

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/gh-aw-estc-pr-buildkite-detective.md at line 108, The
workflow outputs for empty fields are inconsistent; update the echo statements
to use a standard empty-field format by adding a trailing space (or an explicit
empty string) so they match jq's output. Locate the two echo lines identified as
echo "pr_numbers:" and echo "branches:" and change them to emit a space after
the colon (e.g., echo "pr_numbers: " and echo "branches: ") or otherwise append
an explicit empty string to ensure consistent formatting across the file.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/gh-aw-estc-pr-buildkite-detective.md:
- Line 108: The workflow outputs for empty fields are inconsistent; update the
echo statements to use a standard empty-field format by adding a trailing space
(or an explicit empty string) so they match jq's output. Locate the two echo
lines identified as echo "pr_numbers:" and echo "branches:" and change them to
emit a space after the colon (e.g., echo "pr_numbers: " and echo "branches: ")
or otherwise append an explicit empty string to ensure consistent formatting
across the file.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1a5b21ef-fde7-47c6-b142-b292a22f0b25

📥 Commits

Reviewing files that changed from the base of the PR and between 92e9c27 and 27934ac.

📒 Files selected for processing (1)
  • .github/workflows/gh-aw-estc-pr-buildkite-detective.md

@github-actions github-actions bot added the medium_boom Medium PR blast radius; likely benefits from human review label Mar 10, 2026
@strawgate strawgate merged commit ed4b908 into main Mar 10, 2026
23 checks passed
@strawgate strawgate deleted the fix/660-buildkite-detective-context branch March 10, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

medium_boom Medium PR blast radius; likely benefits from human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh-aw-estc-pr-buildkite-detective.md is not using the right details

1 participant