diff --git a/.github/scripts/check-fix-eligibility-test.sh b/.github/scripts/check-fix-eligibility-test.sh index 3e93fff0d3..bdebd086f5 100755 --- a/.github/scripts/check-fix-eligibility-test.sh +++ b/.github/scripts/check-fix-eligibility-test.sh @@ -90,6 +90,8 @@ run_test() { local mock_bin mock_bin=$(build_mock "${is_bot}" "${login}" "${labels}") + : > "${TMPDIR}/eligibility-output" + local actual_exit=0 output output=$(PATH="${mock_bin}:${PATH}" \ TRIGGER_SOURCE="${trigger}" \ @@ -97,6 +99,7 @@ run_test() { SOURCE_REPO="org/repo" \ GH_TOKEN="fake" \ FULLSEND_APP_SET="${app_set}" \ + GITHUB_OUTPUT="${TMPDIR}/eligibility-output" \ bash "${SCRIPT}" 2>&1) || actual_exit=$? if [[ "${actual_exit}" -ne "${expected_exit}" ]]; then @@ -111,6 +114,17 @@ run_test() { return fi + local expected_policy=false actual_policy + if [[ "${expected_exit}" -eq 1 ]]; then + expected_policy=true + fi + actual_policy="$(grep '^policy_skip=' "${TMPDIR}/eligibility-output" | tail -n 1 || true)" + if [[ "${actual_policy}" != "policy_skip=${expected_policy}" ]]; then + echo "FAIL: ${name} — expected final policy_skip=${expected_policy} output" + FAILURES=$((FAILURES + 1)) + return + fi + echo "PASS: ${name}" } @@ -187,6 +201,7 @@ MOCKEOF PR_NUM="999" \ SOURCE_REPO="org/repo" \ GH_TOKEN="fake" \ + GITHUB_OUTPUT="${TMPDIR}/eligibility-output" \ bash "${SCRIPT}" 2>&1) || actual_exit=$? if [[ "${actual_exit}" -ne 1 ]]; then @@ -201,6 +216,14 @@ MOCKEOF return fi + local actual_policy + actual_policy="$(grep '^policy_skip=' "${TMPDIR}/eligibility-output" | tail -n 1 || true)" + if [[ "${actual_policy}" != "policy_skip=false" ]]; then + echo "FAIL: gh pr view failure — expected final policy_skip=false output" + FAILURES=$((FAILURES + 1)) + return + fi + echo "PASS: gh pr view failure" } run_test_gh_failure diff --git a/.github/scripts/check-fix-eligibility.sh b/.github/scripts/check-fix-eligibility.sh index 507535b5ea..3d16a7c572 100755 --- a/.github/scripts/check-fix-eligibility.sh +++ b/.github/scripts/check-fix-eligibility.sh @@ -10,9 +10,21 @@ # # Exits 0 if fix should proceed, 1 if it should be skipped. # Emits GitHub Actions annotations (::warning::) for skip reasons. +# Emits policy_skip=true only for intentional policy skips; operational errors +# leave policy_skip=false so the caller can report the startup failure. set -euo pipefail +if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + echo "policy_skip=false" >> "${GITHUB_OUTPUT}" +fi + +mark_policy_skip() { + if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + echo "policy_skip=true" >> "${GITHUB_OUTPUT}" + fi +} + # Only gate bot-triggered runs; human /fs-fix always proceeds. if [[ ! "${TRIGGER_SOURCE}" =~ \[bot\]$ ]]; then exit 0 @@ -25,6 +37,7 @@ PR_INFO=$(gh pr view "${PR_NUM}" --repo "${SOURCE_REPO}" \ HAS_NO_FIX=$(echo "${PR_INFO}" | jq -r '.labels | any(. == "fullsend-no-fix")') if [[ "${HAS_NO_FIX}" == "true" ]]; then echo "::warning::PR #${PR_NUM} has 'fullsend-no-fix' label — skipping bot-triggered fix" + mark_policy_skip exit 1 fi @@ -70,6 +83,7 @@ if [[ "${KNOWN_CODER}" != "true" ]]; then HAS_FIX_LABEL=$(echo "${PR_INFO}" | jq -r '.labels | any(. == "fullsend-fix")') if [[ "${HAS_FIX_LABEL}" != "true" ]]; then echo "::warning::PR #${PR_NUM} (author: ${PR_LOGIN_SAFE}, is_bot: ${PR_IS_BOT_SAFE}) is not the coder bot and lacks 'fullsend-fix' label — skipping bot-triggered fix" + mark_policy_skip exit 1 fi fi diff --git a/.github/scripts/pre-fetch-review-body-test.sh b/.github/scripts/pre-fetch-review-body-test.sh index f430df6423..cc9997a0d0 100755 --- a/.github/scripts/pre-fetch-review-body-test.sh +++ b/.github/scripts/pre-fetch-review-body-test.sh @@ -94,9 +94,10 @@ chmod +x "${MOCK_BIN}/gh" # $4 — expected review body (exact; ignored when expected exit is non-zero) # $5 — expected output substring (optional) # $6 — FULLSEND_APP_SET override (optional; default custom-prefix) +# $7 — expected policy_skip output (optional) run_test() { local name="$1" expected_exit="$2" trigger="$3" expected_body="$4" - local expected_output="${5:-}" app_set="${6-custom-prefix}" + local expected_output="${5:-}" app_set="${6-custom-prefix}" expected_policy="${7:-false}" local workspace="${TMPDIR}/workspace" rm -rf "${workspace}" mkdir -p "${workspace}" @@ -128,6 +129,12 @@ run_test() { return fi + if [[ "$(grep '^policy_skip=' "${TMPDIR}/github-output" | tail -n 1)" != "policy_skip=${expected_policy}" ]]; then + echo "FAIL: ${name} — expected policy_skip=${expected_policy} output" + FAILURES=$((FAILURES + 1)) + return + fi + if [[ "${expected_exit}" -eq 0 ]]; then local actual_body actual_body="$(cat "${workspace}/review-body.txt")" @@ -213,7 +220,7 @@ reset_pages filler 30 1 | write_page 1 filler 15 31 | write_page 2 run_test "no match fails bot-triggered run" 1 "${ORG_BOT}" "" \ - "Bot-triggered run but review body is empty" + "Bot-triggered run but review body is empty" "custom-prefix" "true" run_test "no match proceeds for human trigger" 0 "human-user" "" \ "Pre-fetched review body: 1 bytes" @@ -226,7 +233,7 @@ reset_pages review 1 "${ORG_BOT}" "CHANGES_REQUESTED" "unreachable" | write_page 1 touch "${TMPDIR}/fail" run_test "API failure warns and fails bot-triggered run" 1 "${ORG_BOT}" "" \ - "::warning::Failed to fetch reviews for PR #123: HTTP 502: Bad Gateway" + "::warning::Failed to fetch reviews for PR #123: HTTP 502: Bad Gateway" "custom-prefix" "false" run_test "API failure warns and proceeds for human trigger" 0 "human-user" "" \ "::warning::Failed to fetch reviews for PR #123" rm -f "${TMPDIR}/fail" diff --git a/.github/scripts/pre-fetch-review-body.sh b/.github/scripts/pre-fetch-review-body.sh index c0e837e308..a35f587db9 100755 --- a/.github/scripts/pre-fetch-review-body.sh +++ b/.github/scripts/pre-fetch-review-body.sh @@ -14,7 +14,8 @@ # # Writes the body of the latest CHANGES_REQUESTED review submitted by a # recognized review bot to ${GITHUB_WORKSPACE}/review-body.txt and emits -# review_file= to GITHUB_OUTPUT. +# review_file= to GITHUB_OUTPUT. Emits policy_skip=true only when a +# bot-triggered run has no review body to act on. # # Reviews are fetched across every API page. The reviews endpoint returns # 30 reviews per page by default (100 at most), so on a PR with many @@ -25,6 +26,10 @@ set -euo pipefail +if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + echo "policy_skip=false" >> "${GITHUB_OUTPUT}" +fi + REVIEW_FILE="${GITHUB_WORKSPACE:-.}/review-body.txt" REVIEW_BOT="${ORG_NAME}-review[bot]" SHARED_REVIEW_BOT="fullsend-ai-review[bot]" @@ -35,6 +40,7 @@ fi ERR_FILE="$(mktemp)" trap 'rm -f "${ERR_FILE}"' EXIT +REVIEW_FETCH_FAILED=false # Collect every page before selecting: `last` must run over the combined # review list, not per page (see docs/contributing/shell-scripting.md). @@ -52,6 +58,7 @@ if ! gh api --paginate "repos/${SOURCE_REPO}/pulls/${PR_NUM}/reviews?per_page=10 ERR_MSG="$(head -c 500 "${ERR_FILE}" | tr '\r\n' ' ')" echo "::warning::Failed to fetch reviews for PR #${PR_NUM}: ${ERR_MSG//::/__}" echo "" > "${REVIEW_FILE}" + REVIEW_FETCH_FAILED=true fi BYTE_COUNT="$(wc -c < "${REVIEW_FILE}")" @@ -63,6 +70,9 @@ if [[ "${BYTE_COUNT}" -gt "${MAX_REVIEW_BYTES}" ]]; then fi if [[ "${TRIGGER_SOURCE}" =~ \[bot\]$ && "${BYTE_COUNT}" -le 1 ]]; then echo "::error::Bot-triggered run but review body is empty — nothing to fix" + if [[ "${REVIEW_FETCH_FAILED}" != "true" && -n "${GITHUB_OUTPUT:-}" ]]; then + echo "policy_skip=true" >> "${GITHUB_OUTPUT}" + fi exit 1 fi echo "review_file=${REVIEW_FILE}" >> "${GITHUB_OUTPUT:-/dev/null}" diff --git a/.github/scripts/report-agent-startup-failure-test.sh b/.github/scripts/report-agent-startup-failure-test.sh new file mode 100755 index 0000000000..e80c5ee076 --- /dev/null +++ b/.github/scripts/report-agent-startup-failure-test.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env bash +# report-agent-startup-failure-test.sh — Tests for report-agent-startup-failure.sh +# +# Run from the repo root: +# bash .github/scripts/report-agent-startup-failure-test.sh + +set -euo pipefail +FAILURES=0 + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SCRIPT="${SCRIPT_DIR}/report-agent-startup-failure.sh" +TMPDIR="$(mktemp -d)" +trap 'rm -rf "${TMPDIR}"' EXIT + +MOCK_BIN="${TMPDIR}/bin" +mkdir -p "${MOCK_BIN}" +cat > "${MOCK_BIN}/gh" <<'MOCKEOF' +#!/usr/bin/env bash +set -euo pipefail + +MOCK_DIR="$(cd "$(dirname "$0")/.." && pwd)" +if [[ "$1" != "api" ]]; then + echo "unexpected gh call: $*" >&2 + exit 1 +fi + +if [[ "$*" == *"graphql"* ]]; then + if [[ "${MOCK_GRAPHQL_FAIL:-}" == "true" ]]; then + exit 1 + fi + printf '%s\n' "${MOCK_VIEWER_LOGIN}" +elif [[ "$*" == *"--method PATCH"* ]]; then + if [[ "${MOCK_PATCH_FAIL:-}" == "true" ]]; then + exit 1 + fi + printf 'patch\n' >> "${MOCK_DIR}/calls" +elif [[ "$*" == *"--method POST"* ]]; then + printf 'post\n' >> "${MOCK_DIR}/calls" +else + if [[ "${MOCK_COMMENTS_FAIL:-}" == "true" ]]; then + exit 1 + fi + printf '%s\n' "${MOCK_COMMENTS_JSON}" +fi +MOCKEOF +chmod +x "${MOCK_BIN}/gh" + +run_case() { + local name="$1" viewer="$2" comment_login="$3" trusted_bots="${4:-}" role="${5:-review}" body_prefix="${6:-marker}" expected="${7:-patch}" graphql_fail="${8:-false}" stable_marker="${9:-false}" agent="${10:-review}" patch_fail="${11:-false}" comments_fail="${12:-false}" + local marker="' + local body="${marker}\n\nold comment\n\n[View the workflow run](https://github.com/org/repo/actions/runs/123)" + if [[ "${body_prefix}" == "embedded" ]]; then + body="old comment\n\n${marker}" + elif [[ "${body_prefix}" == "old-run" ]]; then + body="${marker}\n\nold comment\n\n[View the workflow run](https://github.com/org/repo/actions/runs/99)" + elif [[ "${body_prefix}" == "prefix-run" ]]; then + body="${marker}\n\nold comment\n\n[View the workflow run](https://github.com/org/repo/actions/runs/1234)" + fi + export MOCK_VIEWER_LOGIN="${viewer}" + export MOCK_GRAPHQL_FAIL="${graphql_fail}" + export MOCK_PATCH_FAIL="${patch_fail}" + export MOCK_COMMENTS_FAIL="${comments_fail}" + export MOCK_COMMENTS_JSON="[[{\"id\":42,\"user\":{\"type\":\"Bot\",\"login\":\"${comment_login}\"},\"body\":\"${body}\"}]]" + : > "${TMPDIR}/calls" + + PATH="${MOCK_BIN}:${PATH}" \ + GH_TOKEN=test \ + RUNNER_TEMP="${TMPDIR}" \ + FULLSEND_FAILURE_REPOSITORY=org/repo \ + FULLSEND_FAILURE_NUMBER=123 \ + FULLSEND_FAILURE_AGENT="${agent}" \ + FULLSEND_FAILURE_ROLE="${role}" \ + FULLSEND_FAILURE_STABLE_MARKER="${stable_marker}" \ + FULLSEND_FAILURE_TRUSTED_BOTS="${trusted_bots}" \ + FULLSEND_FAILURE_RUN_URL=https://github.com/org/repo/actions/runs/123 \ + FULLSEND_FAILURE_CATEGORY="workflow setup" \ + bash "${SCRIPT}" >/dev/null + + local actual + actual="$(cat "${TMPDIR}/calls")" + if [[ "${actual}" == "${expected}" ]]; then + printf 'PASS: %s\n' "${name}" + else + printf 'FAIL: %s — expected %s, got %s\n' "${name}" "${expected:-no call}" "${actual:-no call}" >&2 + FAILURES=$((FAILURES + 1)) + fi +} + +run_case "job token finds app-bot comment" "github-actions" "fullsend-ai-review[bot]" +run_case "app token finds job-bot comment" "fullsend-ai-review" "github-actions[bot]" +run_case "custom app set finds job-bot comment" "acme-review" "github-actions[bot]" "acme" +run_case "job token finds custom app-set comment" "github-actions" "acme-review[bot]" "acme" +run_case "non-listed role is trusted" "github-actions" "acme-scribe[bot]" "acme" "scribe" +run_case "custom app-set whitespace is trimmed" "github-actions" "acme-scribe[bot]" " acme " "scribe" +run_case "lookalike app is not trusted" "github-actions" "acme-reviewer[bot]" "acme" "review" "marker" "post" +run_case "marker must start the comment" "github-actions" "fullsend-ai-review[bot]" "" "review" "embedded" "post" +run_case "different run posts a new historical comment" "github-actions" "fullsend-ai-review[bot]" "" "review" "old-run" "post" +run_case "prefix-matching run posts a new historical comment" "github-actions" "fullsend-ai-review[bot]" "" "review" "prefix-run" "post" +run_case "GraphQL viewer failure does not prevent reporting" "github-actions" "fullsend-ai-review[bot]" "" "review" "marker" "patch" "true" +run_case "stable harness marker updates a prior run" "github-actions" "fullsend-ai-harness[bot]" "" "harness" "old-run" "patch" "false" "true" "harness" +run_case "failed cross-identity patch falls back to post" "github-actions" "fullsend-ai-review[bot]" "" "review" "marker" "post" "false" "false" "review" "true" +run_case "comments lookup failure falls back to post" "github-actions" "fullsend-ai-review[bot]" "" "review" "marker" "post" "false" "false" "review" "false" "true" + +if [[ "${FAILURES}" -gt 0 ]]; then + printf '%d test(s) FAILED\n' "${FAILURES}" + exit 1 +fi +printf 'All tests passed\n' diff --git a/.github/scripts/report-agent-startup-failure.sh b/.github/scripts/report-agent-startup-failure.sh new file mode 100755 index 0000000000..a829b1fbb4 --- /dev/null +++ b/.github/scripts/report-agent-startup-failure.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash +# Post or update the single user-facing comment for an agent launch that +# failed before the agent process started. This intentionally uses gh directly +# because the fullsend CLI may be the dependency that failed to install. +set -euo pipefail + +if [[ -z "${GH_TOKEN:-}" ]]; then + echo "::warning::Skipping startup failure comment: GH_TOKEN is required" >&2 + exit 1 +fi +FULLSEND_FAILURE_REPOSITORY="${FULLSEND_FAILURE_REPOSITORY:-}" +FULLSEND_FAILURE_NUMBER="${FULLSEND_FAILURE_NUMBER:-}" +FULLSEND_FAILURE_AGENT="${FULLSEND_FAILURE_AGENT:-}" +FULLSEND_FAILURE_ROLE="${FULLSEND_FAILURE_ROLE:-${FULLSEND_FAILURE_AGENT}}" +FULLSEND_FAILURE_RUN_URL="${FULLSEND_FAILURE_RUN_URL:-}" +FULLSEND_FAILURE_CATEGORY="${FULLSEND_FAILURE_CATEGORY:-}" +FULLSEND_FAILURE_SUMMARY="${FULLSEND_FAILURE_SUMMARY:-}" +FULLSEND_FAILURE_STABLE_MARKER="${FULLSEND_FAILURE_STABLE_MARKER:-false}" + +if [[ ! "${FULLSEND_FAILURE_REPOSITORY}" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ ]]; then + echo "::warning::Skipping startup failure comment: invalid repository" >&2 + exit 1 +fi +if [[ ! "${FULLSEND_FAILURE_NUMBER}" =~ ^[1-9][0-9]*$ ]]; then + echo "::warning::Skipping startup failure comment: invalid issue number" >&2 + exit 1 +fi +if [[ ! "${FULLSEND_FAILURE_AGENT}" =~ ^[A-Za-z0-9_-]+$ ]]; then + echo "::warning::Skipping startup failure comment: invalid agent" >&2 + exit 1 +fi +if [[ ! "${FULLSEND_FAILURE_ROLE}" =~ ^[A-Za-z0-9_-]+$ ]]; then + echo "::warning::Skipping startup failure comment: invalid role" >&2 + exit 1 +fi +case "${FULLSEND_FAILURE_CATEGORY}" in + "workflow setup"|"runtime setup"|"CLI setup"|"token mint") ;; + *) + echo "::warning::Skipping startup failure comment: invalid category" >&2 + exit 1 + ;; +esac +if [[ "${FULLSEND_FAILURE_STABLE_MARKER}" != "true" && "${FULLSEND_FAILURE_STABLE_MARKER}" != "false" ]]; then + echo "::warning::Skipping startup failure comment: invalid stable-marker flag" >&2 + exit 1 +fi +if [[ ! "${FULLSEND_FAILURE_RUN_URL}" =~ ^https://[A-Za-z0-9.-]+/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+/actions/runs/[1-9][0-9]*$ ]]; then + echo "::warning::Skipping startup failure comment: invalid workflow URL" >&2 + exit 1 +fi + +MARKER="" +BODY_FILE="${RUNNER_TEMP:-/tmp}/fullsend-agent-startup-failure.md" +{ + printf '%s\n\n' "${MARKER}" + if [[ -n "${FULLSEND_FAILURE_SUMMARY}" ]]; then + printf '⚠️ **%s**\n\n' "${FULLSEND_FAILURE_SUMMARY}" + else + printf '⚠️ **Fullsend %s agent did not run**\n\n' "${FULLSEND_FAILURE_AGENT}" + fi + printf 'The agent could not start because of a **%s** failure.\n\n' "${FULLSEND_FAILURE_CATEGORY}" + printf '[View the workflow run](%s)\n\n' "${FULLSEND_FAILURE_RUN_URL}" +} > "${BODY_FILE}" + +BOT_LOGIN="$(gh api graphql -f query='{ viewer { login } }' --jq '.data.viewer.login' 2>/dev/null || true)" +if ! COMMENTS_JSON="$(gh api --paginate --slurp \ + "repos/${FULLSEND_FAILURE_REPOSITORY}/issues/${FULLSEND_FAILURE_NUMBER}/comments")"; then + echo "::warning::Could not read existing startup failure comments; posting a new comment" >&2 + COMMENTS_JSON='[[]]' +fi +TRUSTED_BOT_LOGINS="github-actions,fullsend-ai-${FULLSEND_FAILURE_ROLE}" +# FULLSEND_FAILURE_TRUSTED_BOTS contains app-set prefixes (for example, +# "fullsend-ai" or "acme"), not arbitrary login prefixes. Expand each set to +# the known agent identities so a lookalike app cannot update this comment. +TRUSTED_BOTS_JSON="$(jq -Rn \ + --arg current "${BOT_LOGIN}" \ + --arg logins "${TRUSTED_BOT_LOGINS}" \ + --arg app_sets "${FULLSEND_FAILURE_TRUSTED_BOTS:-}" \ + --arg role "${FULLSEND_FAILURE_ROLE}" \ + '[ $current ] + + ($logins | split(",") | map(select(length > 0))) + + ($app_sets | split(",") | map(gsub("^\\s+|\\s+$"; "") | select(length > 0) + | . as $set + | [$set + "-" + $role]) | add) + | map(sub("\\[bot\\]$"; "")) + | unique')" +COMMENT_ID="$(printf '%s' "${COMMENTS_JSON}" | jq -r \ + --arg marker "${MARKER}" \ + --arg run_link "[View the workflow run](${FULLSEND_FAILURE_RUN_URL})" \ + --arg stable "${FULLSEND_FAILURE_STABLE_MARKER}" \ + --argjson trusted "${TRUSTED_BOTS_JSON}" \ + 'add | map(select((.user.type == "Bot") + and ((.user.login | sub("\\[bot\\]$"; "")) as $login + | (($trusted | index($login)) != null)) + and (.body | startswith($marker) + and ($stable == "true" or contains($run_link))))) | last | .id // empty')" + +if [[ -n "${COMMENT_ID}" ]]; then + if gh api --method PATCH "repos/${FULLSEND_FAILURE_REPOSITORY}/issues/comments/${COMMENT_ID}" \ + -f body="$(<"${BODY_FILE}")" >/dev/null; then + echo "Updated startup failure comment ${COMMENT_ID}" + exit 0 + fi + echo "::warning::Could not update existing startup failure comment ${COMMENT_ID}; posting a new comment" >&2 +fi + +gh api --method POST "repos/${FULLSEND_FAILURE_REPOSITORY}/issues/${FULLSEND_FAILURE_NUMBER}/comments" \ + -f body="$(<"${BODY_FILE}")" >/dev/null +echo "Posted startup failure comment" diff --git a/.github/workflows/reusable-dispatch.yml b/.github/workflows/reusable-dispatch.yml index c63945eaa7..1522b887a0 100644 --- a/.github/workflows/reusable-dispatch.yml +++ b/.github/workflows/reusable-dispatch.yml @@ -1512,6 +1512,7 @@ jobs: run: bash .github/scripts/setup-agent-env.sh - name: Run triage agent + id: run-agent uses: ./.defaults/ env: GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} @@ -1551,10 +1552,43 @@ jobs: run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} + source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} status-comment-id: ${{ fromJSON(needs.route.outputs.event_payload).comment.id }} + failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} mint-url: ${{ inputs.mint_url }} pr-head-sha: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} + - name: Report triage launch failure + if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github' }} + env: + GH_TOKEN: ${{ github.token }} + MINT_OUTCOME: ${{ steps.app-token.outcome }} + FULLSEND_FAILURE_TRUSTED_BOTS: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + REPOSITORY: ${{ github.repository }} + NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + set -euo pipefail + script=".defaults/.github/scripts/report-agent-startup-failure.sh" + [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" + if [[ ! -f "${script}" ]]; then + script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + printf '%s' "${encoded}" | base64 --decode > "${script}" + chmod +x "${script}" + else + echo "::warning::Startup failure reporter is unavailable" + exit 0 + fi + fi + export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" + export FULLSEND_FAILURE_NUMBER="${NUMBER}" + export FULLSEND_FAILURE_AGENT="triage" + export FULLSEND_FAILURE_RUN_URL="${RUN_URL}" + FULLSEND_FAILURE_CATEGORY="$([[ "${MINT_OUTCOME}" == "failure" ]] && echo 'token mint' || echo 'workflow setup')" + export FULLSEND_FAILURE_CATEGORY + bash "${script}" + code: name: Code needs: route @@ -1644,6 +1678,7 @@ jobs: run: bash .github/scripts/setup-agent-env.sh - name: Run code agent + id: run-agent uses: ./.defaults/ env: GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} @@ -1675,6 +1710,7 @@ jobs: FULLSEND_INFERENCE_GATEWAY_API_KEY: ${{ secrets.FULLSEND_INFERENCE_GATEWAY_API_KEY }} with: agent: code + role: coder gcp_wif_provider: ${{ secrets.FULLSEND_GCP_WIF_PROVIDER }} gcp_project_id: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} jira-token: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_TOKEN || '' }} @@ -1687,10 +1723,44 @@ jobs: run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} + source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} status-comment-id: ${{ fromJSON(needs.route.outputs.event_payload).comment.id }} + failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} mint-url: ${{ inputs.mint_url }} pr-head-sha: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} + - name: Report code launch failure + if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github' }} + env: + GH_TOKEN: ${{ github.token }} + MINT_OUTCOME: ${{ steps.app-token.outcome }} + FULLSEND_FAILURE_TRUSTED_BOTS: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + REPOSITORY: ${{ github.repository }} + NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + set -euo pipefail + script=".defaults/.github/scripts/report-agent-startup-failure.sh" + [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" + if [[ ! -f "${script}" ]]; then + script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + printf '%s' "${encoded}" | base64 --decode > "${script}" + chmod +x "${script}" + else + echo "::warning::Startup failure reporter is unavailable" + exit 0 + fi + fi + export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" + export FULLSEND_FAILURE_NUMBER="${NUMBER}" + export FULLSEND_FAILURE_AGENT="code" + export FULLSEND_FAILURE_ROLE="coder" + export FULLSEND_FAILURE_RUN_URL="${RUN_URL}" + FULLSEND_FAILURE_CATEGORY="$([[ "${MINT_OUTCOME}" == "failure" ]] && echo 'token mint' || echo 'workflow setup')" + export FULLSEND_FAILURE_CATEGORY + bash "${script}" + review: name: Review needs: route @@ -1820,6 +1890,7 @@ jobs: run: bash .github/scripts/setup-agent-env.sh - name: Run review agent + id: run-agent uses: ./.defaults/ env: GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} @@ -1864,10 +1935,43 @@ jobs: run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number || fromJSON(needs.route.outputs.event_payload).issue.number }} + source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} status-comment-id: ${{ fromJSON(needs.route.outputs.event_payload).comment.id }} + failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} mint-url: ${{ inputs.mint_url }} pr-head-sha: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} + - name: Report review launch failure + if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github' }} + env: + GH_TOKEN: ${{ github.token }} + MINT_OUTCOME: ${{ steps.app-token.outcome }} + FULLSEND_FAILURE_TRUSTED_BOTS: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + REPOSITORY: ${{ github.repository }} + NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number || fromJSON(needs.route.outputs.event_payload).issue.number }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + set -euo pipefail + script=".defaults/.github/scripts/report-agent-startup-failure.sh" + [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" + if [[ ! -f "${script}" ]]; then + script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + printf '%s' "${encoded}" | base64 --decode > "${script}" + chmod +x "${script}" + else + echo "::warning::Startup failure reporter is unavailable" + exit 0 + fi + fi + export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" + export FULLSEND_FAILURE_NUMBER="${NUMBER}" + export FULLSEND_FAILURE_AGENT="review" + export FULLSEND_FAILURE_RUN_URL="${RUN_URL}" + FULLSEND_FAILURE_CATEGORY="$([[ "${MINT_OUTCOME}" == "failure" ]] && echo 'token mint' || echo 'workflow setup')" + export FULLSEND_FAILURE_CATEGORY + bash "${script}" + fix: name: Fix needs: route @@ -1936,16 +2040,19 @@ jobs: git config --global user.name "${BOT_LOGIN}" - name: Block fork PRs + id: fork_guard env: GH_TOKEN: ${{ steps.app-token.outputs.token }} EVENT_PAYLOAD: ${{ needs.route.outputs.event_payload }} SOURCE_REPO: ${{ github.repository }} PR_NUM_INPUT: '' run: | + echo "policy_skip=false" >> "${GITHUB_OUTPUT}" HEAD_REPO="$(echo "${EVENT_PAYLOAD}" | jq -r '.pull_request.head.repo.full_name // empty')" BASE_REPO="$(echo "${EVENT_PAYLOAD}" | jq -r '.pull_request.base.repo.full_name // empty')" if [[ -n "${HEAD_REPO}" && -n "${BASE_REPO}" && "${HEAD_REPO}" != "${BASE_REPO}" ]]; then echo "::error::Fork PRs are not allowed to trigger the fix agent" + echo "policy_skip=true" >> "${GITHUB_OUTPUT}" exit 1 fi if [[ -z "${HEAD_REPO}" && -z "${BASE_REPO}" ]]; then @@ -1960,6 +2067,7 @@ jobs: fi if [[ "${IS_FORK}" == "true" ]]; then echo "::error::Fork PRs are not allowed to trigger the fix agent" + echo "policy_skip=true" >> "${GITHUB_OUTPUT}" exit 1 fi fi @@ -2035,6 +2143,7 @@ jobs: echo "iteration=${ITERATION}" >> "${GITHUB_OUTPUT}" - name: Check fix eligibility + id: eligibility env: GH_TOKEN: ${{ steps.app-token.outputs.token }} TRIGGER_SOURCE: ${{ needs.route.outputs.trigger_source }} @@ -2089,6 +2198,7 @@ jobs: run: bash .github/scripts/setup-agent-env.sh - name: Run fix agent + id: run-agent uses: ./.defaults/ env: PR_NUMBER: ${{ steps.context.outputs.pr_number }} @@ -2120,6 +2230,7 @@ jobs: FULLSEND_INFERENCE_GATEWAY_API_KEY: ${{ secrets.FULLSEND_INFERENCE_GATEWAY_API_KEY }} with: agent: fix + role: coder gcp_wif_provider: ${{ secrets.FULLSEND_GCP_WIF_PROVIDER }} gcp_project_id: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} jira-token: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_TOKEN || '' }} @@ -2132,10 +2243,44 @@ jobs: run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ steps.context.outputs.pr_number }} + source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} status-comment-id: ${{ fromJSON(needs.route.outputs.event_payload).comment.id }} + failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} mint-url: ${{ inputs.mint_url }} pr-head-sha: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} + - name: Report fix launch failure + if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && steps.fork_guard.outputs.policy_skip != 'true' && steps.eligibility.outputs.policy_skip != 'true' && steps.review-body.outputs.policy_skip != 'true' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github' }} + env: + GH_TOKEN: ${{ github.token }} + MINT_OUTCOME: ${{ steps.app-token.outcome }} + FULLSEND_FAILURE_TRUSTED_BOTS: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + REPOSITORY: ${{ github.repository }} + NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number || fromJSON(needs.route.outputs.event_payload).issue.number }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + set -euo pipefail + script=".defaults/.github/scripts/report-agent-startup-failure.sh" + [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" + if [[ ! -f "${script}" ]]; then + script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + printf '%s' "${encoded}" | base64 --decode > "${script}" + chmod +x "${script}" + else + echo "::warning::Startup failure reporter is unavailable" + exit 0 + fi + fi + export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" + export FULLSEND_FAILURE_NUMBER="${NUMBER}" + export FULLSEND_FAILURE_AGENT="fix" + export FULLSEND_FAILURE_ROLE="coder" + export FULLSEND_FAILURE_RUN_URL="${RUN_URL}" + FULLSEND_FAILURE_CATEGORY="$([[ "${MINT_OUTCOME}" == "failure" ]] && echo 'token mint' || echo 'workflow setup')" + export FULLSEND_FAILURE_CATEGORY + bash "${script}" + retro: name: Retro needs: route @@ -2207,6 +2352,7 @@ jobs: run: bash .github/scripts/setup-agent-env.sh - name: Run retro agent + id: run-agent uses: ./.defaults/ env: ORIGINATING_URL: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.html_url || fromJSON(needs.route.outputs.event_payload).issue.html_url }} @@ -2246,10 +2392,43 @@ jobs: run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number || fromJSON(needs.route.outputs.event_payload).issue.number }} + source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} status-comment-id: ${{ fromJSON(needs.route.outputs.event_payload).comment.id }} + failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} mint-url: ${{ inputs.mint_url }} pr-head-sha: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} + - name: Report retro launch failure + if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github' }} + env: + GH_TOKEN: ${{ github.token }} + MINT_OUTCOME: ${{ steps.app-token.outcome }} + FULLSEND_FAILURE_TRUSTED_BOTS: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + REPOSITORY: ${{ github.repository }} + NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number || fromJSON(needs.route.outputs.event_payload).issue.number }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + set -euo pipefail + script=".defaults/.github/scripts/report-agent-startup-failure.sh" + [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" + if [[ ! -f "${script}" ]]; then + script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + printf '%s' "${encoded}" | base64 --decode > "${script}" + chmod +x "${script}" + else + echo "::warning::Startup failure reporter is unavailable" + exit 0 + fi + fi + export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" + export FULLSEND_FAILURE_NUMBER="${NUMBER}" + export FULLSEND_FAILURE_AGENT="retro" + export FULLSEND_FAILURE_RUN_URL="${RUN_URL}" + FULLSEND_FAILURE_CATEGORY="$([[ "${MINT_OUTCOME}" == "failure" ]] && echo 'token mint' || echo 'workflow setup')" + export FULLSEND_FAILURE_CATEGORY + bash "${script}" + prioritize: name: Prioritize needs: route @@ -2308,6 +2487,7 @@ jobs: run: mkdir -p target-repo - name: Run prioritize agent + id: run-agent uses: ./.defaults/ env: GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} @@ -2346,8 +2526,39 @@ jobs: run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} + source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} + failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} mint-url: ${{ inputs.mint_url }} + - name: Report prioritize launch failure + if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github' }} + env: + GH_TOKEN: ${{ github.token }} + FULLSEND_FAILURE_TRUSTED_BOTS: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + REPOSITORY: ${{ github.repository }} + NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).issue.number || fromJSON(needs.route.outputs.event_payload).pull_request.number }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + set -euo pipefail + script=".defaults/.github/scripts/report-agent-startup-failure.sh" + [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" + if [[ ! -f "${script}" ]]; then + script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + printf '%s' "${encoded}" | base64 --decode > "${script}" + chmod +x "${script}" + else + echo "::warning::Startup failure reporter is unavailable" + exit 0 + fi + fi + export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" + export FULLSEND_FAILURE_NUMBER="${NUMBER}" + export FULLSEND_FAILURE_AGENT="prioritize" + export FULLSEND_FAILURE_RUN_URL="${RUN_URL}" + export FULLSEND_FAILURE_CATEGORY="workflow setup" + bash "${script}" + harness-dispatch: name: Harness dispatch if: ${{ inputs.matrix == '' }} @@ -2356,6 +2567,9 @@ jobs: actions: write contents: read id-token: write + # Callers must grant issues: write for startup-failure comments and + # pull-requests: read for harness event inspection. + issues: write pull-requests: read outputs: matrix: ${{ steps.dispatch.outputs.matrix }} @@ -2378,7 +2592,9 @@ jobs: /OWNERS_ALIASES .defaults/action.yml .defaults/.github/actions/install-fullsend-cli/ + .defaults/.github/scripts/report-agent-startup-failure.sh .fullsend/.defaults/action.yml + .fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh sparse-checkout-cone-mode: false - name: Detect registered harness triggers @@ -2511,6 +2727,38 @@ jobs: echo "${DELIM}" } >> "${GITHUB_OUTPUT}" + - name: Report harness dispatch failure + if: ${{ failure() && !cancelled() && steps.dispatch.outcome != 'success' && (github.event.issue.number != '' || github.event.pull_request.number != '') }} + env: + GH_TOKEN: ${{ github.token }} + FULLSEND_FAILURE_TRUSTED_BOTS: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + REPOSITORY: ${{ github.repository }} + NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + set -euo pipefail + script=".defaults/.github/scripts/report-agent-startup-failure.sh" + [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" + if [[ ! -f "${script}" ]]; then + script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + printf '%s' "${encoded}" | base64 --decode > "${script}" + chmod +x "${script}" + else + echo "::warning::Startup failure reporter is unavailable" + exit 0 + fi + fi + export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" + export FULLSEND_FAILURE_NUMBER="${NUMBER}" + export FULLSEND_FAILURE_AGENT="harness" + export FULLSEND_FAILURE_ROLE="harness" + export FULLSEND_FAILURE_RUN_URL="${RUN_URL}" + export FULLSEND_FAILURE_CATEGORY="workflow setup" + export FULLSEND_FAILURE_SUMMARY="Harness dispatch failed; agents may not have run" + export FULLSEND_FAILURE_STABLE_MARKER="true" + bash "${script}" + harness-run: name: Harness run (${{ matrix.agent }}) needs: [harness-dispatch] @@ -2689,6 +2937,7 @@ jobs: } >> "${GITHUB_OUTPUT}" - name: Run harness agent + id: run-agent uses: ./.defaults/ env: GITHUB_ISSUE_URL: ${{ steps.dispatch-env.outputs.issue_url }} @@ -2729,10 +2978,51 @@ jobs: runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} version: ${{ inputs.fullsend_version || job.workflow_sha }} fullsend-dir: .fullsend + github_token: ${{ github.token }} + failure-token: ${{ steps.app-token.outputs.token || github.token }} run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ matrix.status_repo }} status-number: ${{ matrix.status_number }} + source-system: ${{ matrix.event_payload._normalized_event.source.system || 'github' }} status-comment-id: ${{ matrix.event_payload.comment.id }} + failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} mint-url: ${{ inputs.mint_url }} pr-head-sha: ${{ matrix.event_payload.pull_request.head.sha || '' }} artifact-name: ${{ steps.dispatch-env.outputs.artifact_name }} + - name: Report harness launch failure + if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && matrix.status_number != '' && (matrix.event_payload._normalized_event.source.system || 'github') == 'github' && (matrix.status_repo == github.repository || steps.app-token.outcome == 'success') }} + env: + GH_TOKEN: ${{ steps.app-token.outputs.token || github.token }} + MINT_OUTCOME: ${{ steps.app-token.outcome }} + FULLSEND_FAILURE_TRUSTED_BOTS: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + REPOSITORY: ${{ matrix.status_repo }} + NUMBER: ${{ matrix.status_number }} + AGENT: ${{ matrix.agent }} + ROLE: ${{ matrix.role }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + set -euo pipefail + script=".defaults/.github/scripts/report-agent-startup-failure.sh" + [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" + if [[ ! -f "${script}" ]]; then + script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + printf '%s' "${encoded}" | base64 --decode > "${script}" + chmod +x "${script}" + else + echo "::warning::Startup failure reporter is unavailable" + exit 0 + fi + fi + export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" + export FULLSEND_FAILURE_NUMBER="${NUMBER}" + export FULLSEND_FAILURE_AGENT="${AGENT}" + export FULLSEND_FAILURE_ROLE="${ROLE}" + export FULLSEND_FAILURE_RUN_URL="${RUN_URL}" + FULLSEND_FAILURE_CATEGORY="$([[ "${MINT_OUTCOME}" == "failure" ]] && echo 'token mint' || echo 'workflow setup')" + export FULLSEND_FAILURE_CATEGORY + bash "${script}" + + - name: Warn when cross-repository harness failure cannot be reported + if: ${{ always() && steps.run-agent.outcome == 'skipped' && matrix.status_number != '' && (matrix.event_payload._normalized_event.source.system || 'github') == 'github' && matrix.status_repo != github.repository && steps.app-token.outcome != 'success' }} + run: echo "::warning::Harness startup failure could not be reported because no token authorized for the target repository was available" diff --git a/.github/workflows/reusable-prioritize.yml b/.github/workflows/reusable-prioritize.yml index 28e4dccbad..619a438c9d 100644 --- a/.github/workflows/reusable-prioritize.yml +++ b/.github/workflows/reusable-prioritize.yml @@ -147,6 +147,16 @@ jobs: with: source_repo: ${{ inputs.source_repo }} + - name: Mint prioritize status token + id: app-token + continue-on-error: true + if: ${{ (fromJSON(inputs.event_payload)._normalized_event.source.system || 'github') == 'github' && inputs.source_repo != github.repository }} + uses: ./.defaults/.github/actions/mint-token + with: + role: prioritize + repos: ${{ steps.repo-parts.outputs.name }} + mint_url: ${{ inputs.mint_url }} + - name: Prepare GCP credentials for an explicit CLI override if: env.FULLSEND_LEGACY_GCP_SETUP == 'true' uses: ./.defaults/.github/actions/setup-gcp @@ -171,6 +181,7 @@ jobs: run: mkdir -p target-repo - name: Run prioritize agent + id: run-agent uses: ./.defaults/ env: GITHUB_ISSUE_URL: ${{ fromJSON(inputs.event_payload).issue.html_url }} @@ -203,6 +214,52 @@ jobs: runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} version: ${{ inputs.fullsend_version || job.workflow_sha }} fullsend-dir: .fullsend + github_token: ${{ github.token }} + failure-token: ${{ steps.app-token.outputs.token || github.token }} mint-url: ${{ inputs.mint_url }} + run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + failure-repo: ${{ inputs.source_repo }} + failure-number: ${{ fromJSON(inputs.event_payload).issue.number || fromJSON(inputs.event_payload).pull_request.number }} + source-system: ${{ fromJSON(inputs.event_payload)._normalized_event.source.system || 'github' }} + failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} gcp_wif_provider: ${{ secrets.FULLSEND_GCP_WIF_PROVIDER }} gcp_project_id: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} + + - name: Report prioritize launch failure + if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && (fromJSON(inputs.event_payload)._normalized_event.source.system || 'github') == 'github' && (inputs.source_repo == github.repository || steps.app-token.outcome == 'success') }} + env: + GH_TOKEN: ${{ steps.app-token.outputs.token || github.token }} + MINT_OUTCOME: ${{ steps.app-token.outcome }} + FULLSEND_FAILURE_TRUSTED_BOTS: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + REPOSITORY: ${{ inputs.source_repo }} + NUMBER: ${{ fromJSON(inputs.event_payload).issue.number || fromJSON(inputs.event_payload).pull_request.number }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + set -euo pipefail + script=".defaults/.github/scripts/report-agent-startup-failure.sh" + [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" + if [[ ! -f "${script}" ]]; then + script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + printf '%s' "${encoded}" | base64 --decode > "${script}" + chmod +x "${script}" + else + echo "::warning::Startup failure reporter is unavailable" + exit 0 + fi + fi + export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" + export FULLSEND_FAILURE_NUMBER="${NUMBER}" + export FULLSEND_FAILURE_AGENT="prioritize" + export FULLSEND_FAILURE_RUN_URL="${RUN_URL}" + if [[ "${MINT_OUTCOME}" == "failure" && "${REPOSITORY}" != "${GITHUB_REPOSITORY}" ]]; then + FULLSEND_FAILURE_CATEGORY="token mint" + else + FULLSEND_FAILURE_CATEGORY="workflow setup" + fi + export FULLSEND_FAILURE_CATEGORY + bash "${script}" + + - name: Warn when cross-repository failure cannot be reported + if: ${{ always() && steps.run-agent.outcome == 'skipped' && (fromJSON(inputs.event_payload)._normalized_event.source.system || 'github') == 'github' && inputs.source_repo != github.repository && steps.app-token.outcome != 'success' }} + run: echo "::warning::Prioritize startup failure could not be reported because no token authorized for the target repository was available" diff --git a/Makefile b/Makefile index a53613904b..e4e9e0f2e1 100644 --- a/Makefile +++ b/Makefile @@ -197,6 +197,7 @@ script-test: $(call run-timed,bash .github/scripts/count-fix-commits-test.sh) $(call run-timed,bash .github/scripts/pre-fetch-review-body-test.sh) $(call run-timed,bash .github/scripts/review-diff-hash-test.sh) + $(call run-timed,bash .github/scripts/report-agent-startup-failure-test.sh) $(call run-timed,bash .github/scripts/retry-with-backoff-test.sh) $(call run-timed,bash scripts/check-agents-gate-pin-test.sh) $(call run-timed,bash scripts/semgrep-scan-test.sh) diff --git a/action.yml b/action.yml index 83cc1fcaa3..20e2ec4ec2 100644 --- a/action.yml +++ b/action.yml @@ -41,6 +41,26 @@ inputs: status-number: description: Issue/PR number for status comments (optional). default: "" + failure-repo: + description: Repository (owner/repo) for startup-failure comments (optional). + default: "" + failure-number: + description: Issue/PR number for startup-failure comments (optional). + default: "" + failure-trusted-bots: + description: Comma-separated custom app-set prefixes used to derive trusted startup-failure bot identities (optional). + default: "" + failure-token: + description: >- + Optional token used only for startup-failure reporting. Keep github_token + as the workflow token so installation, cloning, provider credentials, and + fullsend run do not receive a reporting-only App token. + default: "" + source-system: + description: >- + Originating tracker for the event (github, gitlab, or jira). GitHub + startup-failure comments are not posted for non-GitHub-originated events. + default: github status-comment-id: description: >- ID of the comment that triggered this run via a slash command @@ -276,6 +296,7 @@ runs: fi - name: Install vendored binary + id: install-vendored if: steps.detect.outputs.install-method == 'vendored' shell: bash env: @@ -348,6 +369,7 @@ runs: echo "${RUNNER_TEMP}/fullsend" >> "${GITHUB_PATH}" - name: Clone fullsend at ref for source build + id: clone-source if: steps.detect.outputs.install-method == 'source' || steps.download-release.outcome == 'failure' shell: bash env: @@ -418,6 +440,7 @@ runs: cache-dependency-path: ${{ runner.temp }}/fullsend-src/go.sum - name: Build fullsend from source + id: build-source if: steps.detect.outputs.install-method == 'source' || steps.download-release.outcome == 'failure' shell: bash run: | @@ -429,6 +452,7 @@ runs: echo "${RUNNER_TEMP}/fullsend" >> "${GITHUB_PATH}" - name: Print fullsend version + id: print-version shell: bash run: fullsend --version @@ -458,11 +482,13 @@ runs: - name: Install Podman if: steps.sandbox-host.outputs.local == 'true' + id: install-podman shell: bash run: "$GITHUB_ACTION_PATH/.github/scripts/install-podman.sh" - name: Configure rootless Podman if: steps.sandbox-host.outputs.local == 'true' + id: configure-podman shell: bash run: | test -f /sys/fs/cgroup/cgroup.controllers || { echo "::error::cgroups v2 required"; exit 1; } @@ -497,6 +523,7 @@ runs: # a remote-gateway runner that already has the CLI skips it. - name: Install OpenShell CLI if: steps.sandbox-host.outputs.install-openshell == 'true' + id: install-openshell shell: bash run: "$GITHUB_ACTION_PATH/.github/scripts/install-openshell.sh" @@ -729,6 +756,61 @@ runs: name: ${{ inputs.artifact-name || format('fullsend-{0}', inputs.agent) }} path: ${{ steps.prepare-artifacts.outputs.dir }} + - name: Report pre-agent startup failure + if: >- + failure() && !cancelled() && steps.run.outcome == 'skipped' && + inputs.agent != '__install_only__' && inputs.source-system == 'github' && + ((inputs.failure-repo != '' && inputs.failure-number != '') || + (inputs.status-repo != '' && inputs.status-number != '')) + shell: bash + env: + GH_TOKEN: ${{ inputs.failure-token || inputs.github_token }} + AGENT: ${{ inputs.agent }} + ROLE: ${{ inputs.role || inputs.agent }} + FAILURE_REPO: ${{ inputs.failure-repo != '' && inputs.failure-number != '' && inputs.failure-repo || inputs.status-repo }} + FAILURE_NUMBER: ${{ inputs.failure-repo != '' && inputs.failure-number != '' && inputs.failure-number || inputs.status-number }} + FULLSEND_FAILURE_TRUSTED_BOTS: ${{ inputs.failure-trusted-bots }} + RUN_URL: ${{ inputs.run-url }} + INSTALL_CLI_OUTCOME: ${{ steps.detect.outcome }} + VENDORED_OUTCOME: ${{ steps.install-vendored.outcome }} + DOWNLOAD_RELEASE_OUTCOME: ${{ steps.download-release.outcome }} + CLONE_SOURCE_OUTCOME: ${{ steps.clone-source.outcome }} + BUILD_SOURCE_OUTCOME: ${{ steps.build-source.outcome }} + PRINT_VERSION_OUTCOME: ${{ steps.print-version.outcome }} + PODMAN_OUTCOME: ${{ steps.install-podman.outcome }} + CONFIGURE_PODMAN_OUTCOME: ${{ steps.configure-podman.outcome }} + OPENSHELL_OUTCOME: ${{ steps.install-openshell.outcome }} + run: | + set -euo pipefail + FAILURE_CATEGORY="workflow setup" + if [[ "${PODMAN_OUTCOME}" == "failure" \ + || "${CONFIGURE_PODMAN_OUTCOME}" == "failure" \ + || "${OPENSHELL_OUTCOME}" == "failure" ]]; then + FAILURE_CATEGORY="runtime setup" + elif [[ "${INSTALL_CLI_OUTCOME}" == "failure" \ + || "${VENDORED_OUTCOME}" == "failure" \ + || ("${DOWNLOAD_RELEASE_OUTCOME}" == "failure" && "${BUILD_SOURCE_OUTCOME}" != "success") \ + || "${CLONE_SOURCE_OUTCOME}" == "failure" \ + || "${BUILD_SOURCE_OUTCOME}" == "failure" \ + || "${PRINT_VERSION_OUTCOME}" == "failure" ]]; then + FAILURE_CATEGORY="CLI setup" + fi + + FULLSEND_FAILURE_REPOSITORY="${FAILURE_REPO}" + FULLSEND_FAILURE_NUMBER="${FAILURE_NUMBER}" + FULLSEND_FAILURE_AGENT="${AGENT}" + FULLSEND_FAILURE_ROLE="${ROLE}" + FULLSEND_FAILURE_RUN_URL="${RUN_URL:-${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}}" + FULLSEND_FAILURE_CATEGORY="${FAILURE_CATEGORY}" + export FULLSEND_FAILURE_REPOSITORY FULLSEND_FAILURE_NUMBER \ + FULLSEND_FAILURE_AGENT FULLSEND_FAILURE_ROLE FULLSEND_FAILURE_RUN_URL \ + FULLSEND_FAILURE_CATEGORY + if "$GITHUB_ACTION_PATH/.github/scripts/report-agent-startup-failure.sh"; then + echo "FULLSEND_STARTUP_FAILURE_REPORTED=true" >> "${GITHUB_ENV}" + else + echo "::warning::Could not post pre-agent failure comment" + fi + - name: Finalize orphaned status comment # Runs last (after all other always() steps) so job.status reflects # the job's true final outcome, not just the fullsend run outcome. @@ -772,6 +854,11 @@ runs: # remains in "Started" state. This step runs unconditionally (if: # always()) to detect and finalize orphaned comments. See #2149. + if [[ "${FULLSEND_STARTUP_FAILURE_REPORTED:-}" == "true" ]]; then + echo "Startup failure was reported; skipping orphaned status reconciliation" + exit 0 + fi + # Resolve the correct commit SHA. Priority order: # 1. Explicit pr-head-sha input (per-repo workflow_call callers) # 2. Native pull_request.head.sha diff --git a/docs/contributing/forge-abstraction.md b/docs/contributing/forge-abstraction.md index 308540e7a1..2598a6e992 100644 --- a/docs/contributing/forge-abstraction.md +++ b/docs/contributing/forge-abstraction.md @@ -26,7 +26,7 @@ polls because an absent job may become visible later. **When reviewing PRs:** Flag any direct `exec.Command("gh", ...)`, raw GitHub API calls, or other forge-specific operations outside `internal/forge/github/` as a medium-severity or higher finding. This is an architectural violation, not a style preference. -**Composite action (`action.yml`):** The forge abstraction extends to `action.yml` bash scripts. New GitHub API operations in action steps should be implemented as `fullsend` CLI subcommands (under `internal/cli/`) that use `forge.Client`, not as inline `gh api` calls. Existing `gh api` calls in `action.yml` that predate this rule are grandfathered but should be migrated when touched. +**Composite action (`action.yml`):** The forge abstraction extends to `action.yml` bash scripts. New GitHub API operations in action steps should be implemented as `fullsend` CLI subcommands (under `internal/cli/`) that use `forge.Client`, not as inline `gh api` calls. Existing `gh api` calls in `action.yml` that predate this rule are grandfathered but should be migrated when touched. The startup-failure reporter is an explicit exception: it runs when installing the Fullsend CLI may itself have failed, so a CLI subcommand cannot be relied on to report that failure. It is limited to GitHub-originated events, validates its inputs, and uses the workflow token—or a separately supplied role token for an authorized cross-repository target—only for the target issue or pull request. The role token is passed through the dedicated reporting input and is not used for installation, cloning, provider credentials, or `fullsend run`. ## Security considerations for destructive operations diff --git a/docs/guides/getting-started/operations.md b/docs/guides/getting-started/operations.md index cda7b83539..34231cf608 100644 --- a/docs/guides/getting-started/operations.md +++ b/docs/guides/getting-started/operations.md @@ -313,6 +313,18 @@ gcloud services enable \ See [`status_notifications`](../../reference/config-reference.md#status_notifications) for configuring start/completion comments and reactions. +If an agent cannot start because workflow setup fails, the GitHub fallback posts or +updates a separate startup-failure comment with the failure category and workflow +run link. Retries of the same workflow run update that comment, while a later +workflow run posts a new historical comment. Harness-dispatch failures are the +exception: repeated pre-dispatch failures update one stable comment per issue +or PR to avoid comment spam. A later successful run does not remove the +historical failure comment. This fallback applies only to GitHub-originated events; pre-agent +failures from Jira- and GitLab-originated events are currently not reported by +this path. It is independent of `status_notifications`; after it posts +successfully, orphaned status reconciliation is skipped to avoid a duplicate +notification. + The composite action accepts optional inputs for status notifications and review reconciliation: @@ -321,6 +333,11 @@ review reconciliation: | `run-url` | URL of the CI/CD run shown in the status comment | | `status-repo` | Repository (`owner/repo`) to post status comments on | | `status-number` | Issue or PR number for status comments | +| `failure-repo` | Repository (`owner/repo`) for startup-failure comments; falls back to `status-repo` when unset | +| `failure-number` | Issue or PR number for startup-failure comments; falls back to `status-number` when unset | +| `failure-trusted-bots` | Comma-separated GitHub App set names (as in `FULLSEND_APP_SET`); each is expanded to the `-` bot identity for startup-failure comment deduplication (optional) | +| `failure-token` | Optional token used only for startup-failure reporting; the normal `github_token` remains the workflow token | +| `source-system` | Originating tracker (`github`, `gitlab`, or `jira`); startup-failure comments are GitHub-only (default: `github`) | | `status-comment-id` | ID of the comment that triggered a slash-command run; when set, reactions target that comment instead of the issue/PR | | `mint-url` | URL of the token mint service used to obtain fresh tokens for posting comments | | `role` | Mint role selected by dispatch, used to reconcile an interrupted run before the agent reports its resolved role (default: empty) | diff --git a/docs/reference/config-reference.md b/docs/reference/config-reference.md index 523332cd84..f96201ba95 100644 --- a/docs/reference/config-reference.md +++ b/docs/reference/config-reference.md @@ -681,6 +681,43 @@ In `enabled` mode, a hard crash or cancellation that happens before the agent could post anything at all is also surfaced after the fact: a post-job cleanup step synthesizes an "Interrupted" comment so the run doesn't silently vanish. +If workflow setup fails before the agent process starts, the dispatch workflow +posts a separate "Fullsend agent did not run" comment with the failure category +and workflow-run link. This startup-failure comment is emitted only for +GitHub-originated events. Pre-agent failures from Jira- and GitLab-originated +events are currently not reported by this fallback; tracker-specific +startup-failure reporting is tracked in [#9256](https://github.com/fullsend-ai/fullsend/issues/9256). +Retries of the same workflow run update the existing startup-failure comment +instead of creating duplicates. A later workflow run normally posts a new +comment so the historical failure and its workflow-run link are preserved; a +later successful run does not remove that historical comment. Harness-dispatch +failures are the exception: because they can recur on every forwarded event +before any agent is selected, they update one stable comment per issue or PR +with neutral wording that agents may not have run. + +The standalone prioritize workflow also supplies the status target and, for +GitHub-originated calls targeting a different repository, mints a +prioritize-scoped GitHub token only for the startup-failure reporter. +Same-repository calls use the workflow token and non-GitHub calls do not mint this +reporting token. The normal `github_token` input remains the workflow token for +installation, cloning, provider credentials, and `fullsend run`. This enables +the same startup-failure reporting for cross-repository prioritize calls; if +minting fails and the target is a different repository, the workflow emits an +explicit warning because the caller's `GITHUB_TOKEN` cannot write to that +repository. + +Because this fallback runs specifically when the Fullsend CLI may not have been +installed, it uses the workflow's GitHub comment API directly and does not read +`status_notifications`. Therefore, a startup-failure comment can still be +posted when status comments are disabled; this is intentional because the +comment reports that the requested agent did not run at all. + +When the startup-failure fallback has successfully posted, the action skips +orphaned-status reconciliation. No Fullsend run was started in that case, so +there is no start comment to reconcile; skipping it also prevents a second, +misleading "Interrupted" comment. Other status side effects are consequently +not run for that pre-agent failure. + **Reactions.** Emoji reactions don't generate a GitHub notification, so they are a lower-noise way to show that an agent is working and how the run turned out. Unlike comments, they default to `disabled`. When `reaction.start` is diff --git a/internal/scaffold/vendorcontent.go b/internal/scaffold/vendorcontent.go index d86f1c385f..946d789d39 100644 --- a/internal/scaffold/vendorcontent.go +++ b/internal/scaffold/vendorcontent.go @@ -174,14 +174,15 @@ func isVendoredReusableWorkflow(path string) bool { // and scripts/renovate/update-openshell-sha.sh) must stay at their // current path regardless of whether they are listed. var vendoredDefaultsScripts = map[string]bool{ - ".github/scripts/check-fix-eligibility.sh": true, - ".github/scripts/count-fix-commits.jq": true, - ".github/scripts/install-openshell.sh": true, - ".github/scripts/install-podman.sh": true, - ".github/scripts/openshell-version.sh": true, - ".github/scripts/pre-fetch-review-body.sh": true, - ".github/scripts/review-diff-hash.sh": true, - ".github/scripts/retry-with-backoff.sh": true, + ".github/scripts/check-fix-eligibility.sh": true, + ".github/scripts/count-fix-commits.jq": true, + ".github/scripts/install-openshell.sh": true, + ".github/scripts/install-podman.sh": true, + ".github/scripts/openshell-version.sh": true, + ".github/scripts/pre-fetch-review-body.sh": true, + ".github/scripts/review-diff-hash.sh": true, + ".github/scripts/retry-with-backoff.sh": true, + ".github/scripts/report-agent-startup-failure.sh": true, } // vendoredDefaultsActions is the explicit allowlist of .github/actions/ diff --git a/internal/scaffold/vendorcontent_test.go b/internal/scaffold/vendorcontent_test.go index af568a73bd..9b3a9d24bc 100644 --- a/internal/scaffold/vendorcontent_test.go +++ b/internal/scaffold/vendorcontent_test.go @@ -118,6 +118,7 @@ func TestIsVendoredDefaultsInfra(t *testing.T) { assert.True(t, isVendoredDefaultsInfra(".github/scripts/install-openshell.sh")) assert.True(t, isVendoredDefaultsInfra(".github/scripts/retry-with-backoff.sh")) assert.False(t, isVendoredDefaultsInfra(".github/scripts/retry-with-backoff-test.sh")) + assert.True(t, isVendoredDefaultsInfra(".github/scripts/report-agent-startup-failure.sh")) assert.False(t, isVendoredDefaultsInfra(".github/scripts/run.sh")) assert.False(t, isVendoredDefaultsInfra(".github/scripts/check-fix-eligibility-test.sh")) assert.False(t, isVendoredDefaultsInfra(".github/scripts/count-fix-commits-test.sh")) diff --git a/internal/scaffold/vendormanifest.go b/internal/scaffold/vendormanifest.go index d3ba9b32eb..3c72cccf79 100644 --- a/internal/scaffold/vendormanifest.go +++ b/internal/scaffold/vendormanifest.go @@ -165,6 +165,7 @@ var vendoredDefaultsInfraPaths = []string{ ".github/scripts/pre-fetch-review-body.sh", ".github/scripts/review-diff-hash.sh", ".github/scripts/retry-with-backoff.sh", + ".github/scripts/report-agent-startup-failure.sh", } // enumerateVendoredPaths returns embed-derived paths for a current --vendor install layout. diff --git a/internal/scaffold/workflow_call_alignment_test.go b/internal/scaffold/workflow_call_alignment_test.go index 714f631741..116ddc8028 100644 --- a/internal/scaffold/workflow_call_alignment_test.go +++ b/internal/scaffold/workflow_call_alignment_test.go @@ -45,6 +45,75 @@ func TestReviewWorkflowKeepsThreadFetchAgentOwned(t *testing.T) { assert.NotContains(t, section, "HUMAN_RESOLVED_FETCH_SCRIPT:") } +// TestStartupFailureReportingGuards verifies the workflow conditions that keep +// policy skips and cancellations from being reported as setup failures. +func TestStartupFailureReportingGuards(t *testing.T) { + dispatch, err := os.ReadFile(filepath.Join("..", "..", ".github", "workflows", "reusable-dispatch.yml")) + require.NoError(t, err) + dispatchText := string(dispatch) + + for _, agent := range []string{"triage", "code", "review", "fix", "retro", "prioritize", "harness"} { + assert.Contains(t, dispatchText, "Report "+agent+" launch failure") + } + assert.Contains(t, dispatchText, "Report harness dispatch failure") + assert.Contains(t, dispatchText, "steps.dispatch.outcome != 'success'") + for _, line := range strings.Split(dispatchText, "\n") { + if strings.Contains(line, "if: ${{ failure()") && strings.Contains(line, "steps.run-agent.outcome") { + assert.Contains(t, line, "!cancelled()", "startup failure reporters must not run after cancellation") + } + } + assert.Contains(t, dispatchText, "id: fork_guard") + assert.Contains(t, dispatchText, "id: eligibility") + assert.Contains(t, dispatchText, "steps.fork_guard.outputs.policy_skip != 'true'") + assert.Contains(t, dispatchText, "steps.eligibility.outputs.policy_skip != 'true'") + assert.Contains(t, dispatchText, "steps.review-body.outputs.policy_skip != 'true'") + assert.NotContains(t, dispatchText, "fromJSON(matrix.event_payload)", + "matrix.event_payload is already a structured object") + assert.Contains(t, dispatchText, "source-system: ${{ matrix.event_payload._normalized_event.source.system || 'github' }}") + assert.Contains(t, dispatchText, "status-comment-id: ${{ matrix.event_payload.comment.id }}") + harnessDispatchStart := strings.Index(dispatchText, "\n harness-dispatch:\n") + harnessRunStart := strings.Index(dispatchText, "\n harness-run:\n") + require.NotEqual(t, -1, harnessDispatchStart, "harness-dispatch job must be present") + require.NotEqual(t, -1, harnessRunStart, "harness-run job must be present") + harnessDispatchText := dispatchText[harnessDispatchStart:harnessRunStart] + harnessCheckoutSection := extractStepSection(t, harnessDispatchText, "Checkout caller repository") + assert.Contains(t, harnessCheckoutSection, + ".defaults/.github/scripts/report-agent-startup-failure.sh", + "harness-dispatch sparse checkout must include the vendored reporter") + assert.Contains(t, harnessCheckoutSection, + ".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh", + "harness-dispatch sparse checkout must include the .fullsend vendored reporter") + harnessFailureSection := extractStepSection(t, dispatchText, "Report harness dispatch failure") + assert.Contains(t, harnessFailureSection, `FULLSEND_FAILURE_SUMMARY="Harness dispatch failed; agents may not have run"`) + assert.Contains(t, harnessFailureSection, `FULLSEND_FAILURE_STABLE_MARKER="true"`) + prioritizeFailureSection := extractStepSection(t, dispatchText, "Report prioritize launch failure") + assert.NotContains(t, prioritizeFailureSection, "FULLSEND_FAILURE_SUMMARY=") + assert.NotContains(t, prioritizeFailureSection, "FULLSEND_FAILURE_STABLE_MARKER=") + assert.GreaterOrEqual(t, strings.Count(dispatchText, `export FULLSEND_FAILURE_ROLE="coder"`), 2, + "code and fix reporters must use the shared coder bot role") + + prioritize, err := os.ReadFile(filepath.Join("..", "..", ".github", "workflows", "reusable-prioritize.yml")) + require.NoError(t, err) + prioritizeText := string(prioritize) + assert.Contains(t, prioritizeText, "failure-repo: ${{ inputs.source_repo }}") + assert.NotContains(t, prioritizeText, "status-repo: ${{ inputs.source_repo }}") + section := extractStepSection(t, prioritizeText, "Run prioritize agent") + assert.Contains(t, section, "failure-repo:") + assert.Contains(t, section, "failure-number:") + assert.Contains(t, section, "source-system:") + assert.Contains(t, section, "github_token: ${{ github.token }}") + assert.Contains(t, section, "failure-token: ${{ steps.app-token.outputs.token || github.token }}") + + for _, agent := range []string{"code", "fix"} { + t.Run(agent+" uses coder role for startup reporting", func(t *testing.T) { + section := extractStepSection(t, dispatchText, "Run "+agent+" agent") + assert.Contains(t, section, "agent: "+agent) + assert.Contains(t, section, "role: coder", + "the %s composite path must use the coder identity for startup-failure deduplication", agent) + }) + } +} + type workflowInput struct { Required bool `yaml:"required"` Type string `yaml:"type"` @@ -1717,8 +1786,16 @@ func TestActionReconcileStatusUsesSuppliedRoleFallback(t *testing.T) { "action.yml must declare the optional role supplied by matrix dispatch") assert.Contains(t, s, "SUPPLIED_ROLE: ${{ inputs.role }}", "reconcile step must receive the supplied role") + assert.Contains(t, s, "ROLE: ${{ inputs.role || inputs.agent }}", + "startup failure reporter must receive a role even when the run step is skipped") + assert.Contains(t, s, "FAILURE_REPO: ${{ inputs.failure-repo != '' && inputs.failure-number != '' && inputs.failure-repo || inputs.status-repo }}", + "startup failure reporter must select the failure repository and number as a pair") + assert.Contains(t, s, "FAILURE_NUMBER: ${{ inputs.failure-repo != '' && inputs.failure-number != '' && inputs.failure-number || inputs.status-number }}", + "startup failure reporter must select the failure repository and number as a pair") assert.Contains(t, s, "RESOLVED_ROLE=\"${HARNESS_ROLE:-${SUPPLIED_ROLE:-${AGENT}}}\"", "reconciliation must use the supplied role when an early failure prevents the harness from reporting one") + assert.NotContains(t, s, " GH_TOKEN: ${{ inputs.github_token }}\n MINT_URL:", + "status reconciliation mints its own token and must not receive the workflow token") } func TestActionReconcileStatusSupportsOlderCLIs(t *testing.T) { @@ -1904,6 +1981,8 @@ func TestReusableDispatchStatusCommentPassthrough(t *testing.T) { "%s agent step must pass status-repo to action.yml", stage) assert.Contains(t, section, "status-number:", "%s agent step must pass status-number to action.yml", stage) + assert.Contains(t, section, "source-system:", + "%s agent step must pass source-system to action.yml", stage) }) } @@ -1916,7 +1995,14 @@ func TestReusableDispatchStatusCommentPassthrough(t *testing.T) { "harness-run agent step must pass status-repo to action.yml") assert.Contains(t, section, "status-number:", "harness-run agent step must pass status-number to action.yml") + assert.Contains(t, section, "source-system:", + "harness-run agent step must pass source-system to action.yml") + assert.Contains(t, section, "github_token: ${{ github.token }}", + "harness-run must keep the workflow token as github_token") + assert.Contains(t, section, "failure-token: ${{ steps.app-token.outputs.token || github.token }}", + "harness-run must pass the minted token only to failure reporting") }) + } // TestShimPerRepoProjectNumberPassthrough validates that the per-repo shim