From 66fd7fa5ec1e0c92c07d53a69edbb5d764dd5180 Mon Sep 17 00:00:00 2001 From: Michael Yochpaz Date: Mon, 30 Nov 2026 11:14:43 +0200 Subject: [PATCH] fix(dispatch)!: run built-in stages in two stage-named matrix jobs Every event created six static stage jobs (Triage, Code, Review, Fix, Retro, Prioritize), at most one of which did any work. GitHub shows the newest check per name on a pull request, so a no-op event's skipped "Review" check replaced a review that was still running, and GitHub counts a skipped check as passing. Run the built-in stages in two stage-matrix jobs instead: agent (triage, review, retro, prioritize) and coder (code and fix, which need contents: write and packages: read per ADR 0114). Like harness-run, each job builds its matrix from one expression over route's stage output, so the routed stage becomes a one-entry matrix and the check is named after it, for example "Agent (review)". A run that routes no stage skips both jobs under their unexpanded placeholder names, which never match a running check. Each event now shows two stage checks instead of six. Stage steps are unchanged and gated on matrix.stage. Concurrency groups keep their values. The agent job keeps the permissions triage, retro and prioritize had, so the review stage's job token no longer has pull-requests: write. Review writes to pull requests with its minted App token, and failure comments are issue comments, which retro already posts without that scope. The behaviour drivers match the new job names and still accept the old ones, so tests against workflows pinned to older versions keep finding agent jobs. The GitHub driver treats a run as unresolved until the stage-matrix job for a built-in agent is listed. BREAKING CHANGE: The built-in stage checks are renamed from "dispatch / Review" (and Triage, Code, Fix, Retro, Prioritize) to "dispatch / Agent (review)" or "dispatch / Coder (fix)" style names. Update scripts that match the old names. Do not make the new per-stage checks required: no check is created for a stage that intentionally does not run, such as a rebase that leaves the reviewed diff unchanged, reviews triggered only by /fs-review, or fork pull requests. Requiring the old names never guaranteed that a review ran, because a skipped check counted as passing. A stable review status is planned separately. Signed-off-by: Michael Yochpaz --- .github/workflows/reusable-dispatch.yml | 1169 +++++++---------- docs/contributing/workflow-contracts.md | 2 +- docs/guides/dev/behaviour-drivers.md | 2 +- docs/guides/user/cel-triggers-reference.md | 13 +- docs/guides/user/customizing-agents.md | 4 +- .../scaffold/fork_pr_workflow_run_test.go | 8 +- internal/scaffold/pr_trigger_test.go | 8 +- .../scaffold/workflow_call_alignment_test.go | 156 ++- .../ci/forgejoactions/forgejoactions.go | 39 +- .../ci/forgejoactions/forgejoactions_test.go | 45 +- .../ci/githubactions/dispatch_reads_test.go | 2 +- .../drivers/ci/githubactions/githubactions.go | 161 ++- .../ci/githubactions/githubactions_test.go | 290 +++- 13 files changed, 1050 insertions(+), 849 deletions(-) diff --git a/.github/workflows/reusable-dispatch.yml b/.github/workflows/reusable-dispatch.yml index 0cec1eea30..1220f60949 100644 --- a/.github/workflows/reusable-dispatch.yml +++ b/.github/workflows/reusable-dispatch.yml @@ -14,9 +14,15 @@ # caller-provided matrix. This enables reuse without extracting separate workflows # while preserving ADR 62's inlining decision. # -# Concurrency: each stage job declares a per-role cancel-in-progress group -# (fullsend-{stage}-…). Roles operate independently — review dispatches do -# not cancel triage, code, fix, etc. +# Built-in stages: route picks at most one stage per event, and it runs in +# one of two stage-matrix jobs: agent (triage, review, retro, prioritize) or +# coder (code, fix). Each check is named after the stage that ran, for example +# "Agent (review)", so a no-op event cannot replace a running check with a +# skipped one of the same name. See the comment above the agent job. +# +# Concurrency: the stage-matrix jobs declare a per-stage cancel-in-progress +# group (fullsend-{stage}-…). Stages operate independently — review +# dispatches do not cancel triage, code, fix, etc. # # Flow: shim (per-repo) → reusable-dispatch.yml (route + inlined stage logic) # Or: custom poller → reusable-dispatch.yml (pre-computed matrix → harness-run) @@ -1708,14 +1714,41 @@ jobs: echo "${DELIM}" } >> "${GITHUB_OUTPUT}" - triage: - name: Triage + # Built-in stages run in two stage-matrix jobs instead of one static job per + # stage. route picks at most one stage per event; the job whose stages + # include it runs a one-entry matrix, so its check is named after the stage + # that ran ("Agent (review)", "Coder (fix)"). When no stage matches, the job + # is skipped and GitHub shows the unexpanded placeholder name + # ("Agent (${{ matrix.stage }})"). A no-op event therefore never produces a + # skipped check with the same name as a running one, which used to replace + # a running "Review" check on the pull request with a grey "skipped" one. + # + # Two jobs, not one, because job permissions cannot vary per matrix entry: + # code and fix need contents: write and packages: read (ADR 0114); the other + # stages keep their former read-only scopes. Stage-specific steps are gated on + # matrix.stage and are otherwise unchanged from the former per-stage jobs. + agent: + name: Agent (${{ matrix.stage }}) needs: route - if: needs.route.outputs.stage == 'triage' + if: contains(fromJSON('["triage","review","retro","prioritize"]'), needs.route.outputs.stage) + strategy: + # One expression for the whole matrix, like harness-run: a matrix whose + # values hold expressions can be expanded before route has run, while + # a whole-matrix expression is expanded once this job's needs finish. + matrix: ${{ fromJSON(format('{{"stage":[{0}]}}', toJSON(needs.route.outputs.stage))) }} runs-on: ${{ inputs.runner_image }} concurrency: - group: fullsend-triage-${{ github.repository }}-${{ github.event.issue.number || github.event.pull_request.number }} + # Same group values as the former per-stage jobs: one cancel-in-progress + # group per stage and work item (fullsend-{stage}-…), so a review + # dispatch never cancels triage, code, fix, etc. + group: fullsend-${{ matrix.stage }}-${{ github.repository }}-${{ github.event.pull_request.number || github.event.issue.number || needs.route.outputs.pr_number }} cancel-in-progress: true + # No pull-requests scope on the job token, as in the former triage, retro + # and prioritize jobs. Every stage writes to pull requests with its minted + # App token: the agent and its post-script run under it, status comments + # mint their own, and the review steps below use steps.app-token. Startup + # failure comments on a pull request are issue comments (issues: write), + # as retro has always posted them. permissions: actions: write contents: read @@ -1744,21 +1777,133 @@ jobs: internal/scaffold/fullsend-repo/ action.yml + # The review stage runs in a separate job from route, so it must install + # its own copy before using the CLI to supersede an earlier skip note. + - name: Detect review dedup CLI + if: matrix.stage == 'review' + id: review-cli-mode + continue-on-error: true + shell: bash + run: | + set -euo pipefail + if [[ -f .fullsend/bin/fullsend ]] && .fullsend/bin/fullsend review-dedup --help >/dev/null 2>&1; then + echo "mode=vendored" >> "${GITHUB_OUTPUT}" + else + echo "mode=upstream" >> "${GITHUB_OUTPUT}" + fi + + - name: Restore fullsend CLI cache for review job + id: review-job-cli-cache + if: matrix.stage == 'review' && (steps.review-cli-mode.outputs.mode == 'upstream') + continue-on-error: true + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/fullsend-cache + key: fullsend-review-dedup-cli-${{ steps.review-cli-mode.outputs.mode }}-${{ runner.arch }}-${{ hashFiles('.fullsend/bin/fullsend') }}-${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} + + - name: Validate cached fullsend CLI for review job + id: review-job-cli-cache-validation + if: matrix.stage == 'review' && (steps.review-cli-mode.outputs.mode == 'upstream' && steps.review-job-cli-cache.outputs.cache-hit == 'true') + continue-on-error: true + shell: bash + run: | + set -euo pipefail + if [[ -x "${RUNNER_TEMP}/fullsend-cache/fullsend" ]] && "${RUNNER_TEMP}/fullsend-cache/fullsend" review-dedup --help >/dev/null 2>&1; then + echo "valid=true" >> "${GITHUB_OUTPUT}" + else + echo "valid=false" >> "${GITHUB_OUTPUT}" + fi + + - name: Install review dedup CLI (vendored) + if: matrix.stage == 'review' && (steps.review-cli-mode.outputs.mode == 'vendored') + continue-on-error: true + shell: bash + run: | + set -euo pipefail + mkdir -p "${RUNNER_TEMP}/fullsend-review-dedup" + cp .fullsend/bin/fullsend "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" + chmod +x "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" + + - name: Checkout review dedup CLI installer + if: matrix.stage == 'review' && (steps.review-cli-mode.outputs.mode == 'upstream' && (steps.review-job-cli-cache.outputs.cache-hit != 'true' || steps.review-job-cli-cache-validation.outputs.valid != 'true')) + continue-on-error: true + timeout-minutes: 5 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ${{ job.workflow_repository }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} + path: .review-dedup-actions + fetch-depth: 1 + sparse-checkout: | + .github/actions/install-fullsend-cli/ + sparse-checkout-cone-mode: false + + - name: Install review dedup CLI (upstream) + if: matrix.stage == 'review' && (steps.review-cli-mode.outputs.mode == 'upstream' && (steps.review-job-cli-cache.outputs.cache-hit != 'true' || steps.review-job-cli-cache-validation.outputs.valid != 'true')) + continue-on-error: true + timeout-minutes: 5 + uses: ./.review-dedup-actions/.github/actions/install-fullsend-cli + with: + mode: upstream + install_dir: ${{ runner.temp }}/fullsend-review-dedup + add_to_path: 'false' + source_dir: ${{ runner.temp }}/fullsend-review-dedup-src + workflow_repository: ${{ job.workflow_repository }} + workflow_sha: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} + github_token: ${{ github.token }} + + - name: Expose cached fullsend CLI for review job + if: matrix.stage == 'review' && (steps.review-cli-mode.outputs.mode == 'upstream' && steps.review-job-cli-cache-validation.outputs.valid == 'true') + continue-on-error: true + shell: bash + run: | + set -euo pipefail + install_dir="${RUNNER_TEMP}/fullsend-review-dedup" + mkdir -p "${install_dir}" + cp "${RUNNER_TEMP}/fullsend-cache/fullsend" "${install_dir}/fullsend" + chmod +x "${install_dir}/fullsend" + + - name: Prepare fullsend CLI cache artifact for review job + id: review-job-cli-cache-prepare + if: matrix.stage == 'review' && (steps.review-cli-mode.outputs.mode == 'upstream' && (steps.review-job-cli-cache.outputs.cache-hit != 'true' || steps.review-job-cli-cache-validation.outputs.valid != 'true')) + continue-on-error: true + shell: bash + run: | + set -euo pipefail + if [[ ! -x "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" ]]; then + echo "ready=false" >> "${GITHUB_OUTPUT}" + exit 0 + fi + mkdir -p "${RUNNER_TEMP}/fullsend-cache" + cp "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" "${RUNNER_TEMP}/fullsend-cache/fullsend" + "${RUNNER_TEMP}/fullsend-cache/fullsend" review-dedup --help >/dev/null 2>&1 + echo "ready=true" >> "${GITHUB_OUTPUT}" + + - name: Save fullsend CLI cache for review job + if: matrix.stage == 'review' && (steps.review-cli-mode.outputs.mode == 'upstream' && (steps.review-job-cli-cache.outputs.cache-hit != 'true' || steps.review-job-cli-cache-validation.outputs.valid != 'true') && steps.review-job-cli-cache-prepare.outcome == 'success' && steps.review-job-cli-cache-prepare.outputs.ready == 'true') + continue-on-error: true + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/fullsend-cache + key: fullsend-review-dedup-cli-${{ steps.review-cli-mode.outputs.mode }}-${{ runner.arch }}-${{ hashFiles('.fullsend/bin/fullsend') }}-${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} + - name: Prepare workspace id: workspace uses: ./.defaults/.github/actions/prepare-workspace with: source_repo: ${{ github.repository }} - - name: Mint triage token + - name: Mint agent token + if: matrix.stage != 'prioritize' id: app-token uses: ./.defaults/.github/actions/mint-token with: - role: triage + role: ${{ matrix.stage }} repos: ${{ steps.workspace.outputs.repo_name }} mint_url: ${{ inputs.mint_url }} - name: Checkout target repository + if: matrix.stage != 'prioritize' uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ github.repository }} @@ -1771,7 +1916,52 @@ jobs: # default branch on pull_request (#9221). ref: ${{ github.event_name == 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) || '' }} + - name: Pre-fetch prior review context + if: matrix.stage == 'review' + id: prior-review + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + SOURCE_REPO: ${{ github.repository }} + PR_NUM: >- + ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number + || fromJSON(needs.route.outputs.event_payload).issue.number }} + ORG_NAME: ${{ github.repository_owner }} + FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + REVIEW_APP_CLIENT_ID: ${{ vars.FULLSEND_REVIEW_CLIENT_ID }} + FULLSEND_DIR: .fullsend + run: bash "${FULLSEND_DIR:+$FULLSEND_DIR/}scripts/pre-fetch-prior-review.sh" + + # A previous unchanged-diff run leaves a PR-visible status note. Once + # this full review is actually dispatched, that note must not continue + # to look like the current verdict. Keep the marker for provenance, but + # replace the stale message with an explicit superseded notice. + - name: Supersede prior review skip note + if: matrix.stage == 'review' && (steps.app-token.outcome == 'success') + continue-on-error: true + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + SOURCE_REPO: ${{ github.repository }} + PR_NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number || fromJSON(needs.route.outputs.event_payload).issue.number }} + FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + REVIEW_APP_CLIENT_ID: ${{ vars.FULLSEND_REVIEW_CLIENT_ID }} + REVIEW_HEAD_SHA: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} + shell: bash + run: | + set -euo pipefail + if [[ ! -x "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" ]]; then + echo "::warning::Review deduplication CLI unavailable; skipping supersede" + exit 0 + fi + "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" review-dedup \ + --repo "${SOURCE_REPO}" \ + --pr "${PR_NUMBER}" \ + --app-set "${FULLSEND_APP_SET}" \ + --app-client-id "${REVIEW_APP_CLIENT_ID}" \ + --head-sha "${REVIEW_HEAD_SHA}" \ + --supersede + - name: Setup agent environment + if: matrix.stage == 'triage' env: AGENT_PREFIX: TRIAGE_ TRIAGE_TARGET_REPO_DIR: target-repo @@ -1783,7 +1973,8 @@ jobs: run: bash .github/scripts/setup-agent-env.sh - name: Run triage agent - id: run-agent + if: matrix.stage == 'triage' + id: run-triage uses: ./.defaults/ env: GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} @@ -1830,7 +2021,7 @@ jobs: 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' }} + if: ${{ matrix.stage == 'triage' && (failure() && !cancelled() && steps.run-triage.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 }} @@ -1860,110 +2051,32 @@ jobs: export FULLSEND_FAILURE_CATEGORY bash "${script}" - code: - name: Code - needs: route - if: needs.route.outputs.stage == 'code' - runs-on: ${{ inputs.runner_image }} - concurrency: - group: fullsend-code-${{ github.repository }}-${{ github.event.issue.number || github.event.pull_request.number }} - cancel-in-progress: true - permissions: - actions: write - contents: write - id-token: write - issues: write - packages: read - pull-requests: write - - steps: - - name: Checkout caller repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} - persist-credentials: false - allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} - - - name: Checkout upstream defaults - if: hashFiles('.defaults/action.yml', '.fullsend/.defaults/action.yml') == '' - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - repository: ${{ job.workflow_repository }} - ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - path: .defaults - fetch-depth: 1 - sparse-checkout: | - .github/actions/ - .github/scripts/ - internal/scaffold/fullsend-repo/ - action.yml - - - name: Prepare workspace - id: workspace - uses: ./.defaults/.github/actions/prepare-workspace - with: - source_repo: ${{ github.repository }} - - - name: Mint coder token - id: app-token - uses: ./.defaults/.github/actions/mint-token - with: - role: coder - repos: ${{ steps.workspace.outputs.repo_name }} - mint_url: ${{ inputs.mint_url }} - - - name: Checkout target repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - repository: ${{ github.repository }} - token: ${{ steps.app-token.outputs.token }} - path: target-repo - fetch-depth: 0 - persist-credentials: false - # With no ref, checkout uses github.ref: the default branch on - # pull_request_target, the PR merge commit on pull_request. Keep the - # default branch on pull_request (#9221). - ref: ${{ github.event_name == 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) || '' }} - - - name: Resolve bot identity - env: - GH_TOKEN: ${{ steps.app-token.outputs.token }} - run: | - set -euo pipefail - read -r BOT_LOGIN BOT_USER_ID < <( - gh api graphql -f query='{ viewer { login databaseId } }' \ - | jq -r '.data.viewer | "\(.login) \(.databaseId)"' - ) - GIT_BOT_EMAIL="${BOT_USER_ID}+${BOT_LOGIN}@users.noreply.github.com" - echo "Resolved bot identity: ${BOT_LOGIN} (${BOT_USER_ID})" - echo "GIT_BOT_EMAIL=${GIT_BOT_EMAIL}" >> "${GITHUB_ENV}" - git config --global user.email "${GIT_BOT_EMAIL}" - git config --global user.name "${BOT_LOGIN}" - - name: Setup agent environment + if: matrix.stage == 'review' env: - AGENT_PREFIX: CODE_ - CODE_TARGET_REPO_DIR: target-repo - CODE_ANTHROPIC_VERTEX_PROJECT_ID: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} - CODE_CLOUD_ML_REGION: ${{ inputs.gcp_region }} - CODE_ISSUE_NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} + AGENT_PREFIX: REVIEW_ + REVIEW_TARGET_REPO_DIR: target-repo + REVIEW_ANTHROPIC_VERTEX_PROJECT_ID: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} + REVIEW_CLOUD_ML_REGION: ${{ inputs.gcp_region }} # Per-run runtime/model/effort overrides from repository variables - # (FULLSEND_MODEL, CODE_FULLSEND_MODEL, ...); see docs/runtimes.md. + # (FULLSEND_MODEL, REVIEW_FULLSEND_MODEL, ...); see docs/runtimes.md. FULLSEND_REPO_VARS: ${{ toJSON(vars) }} run: bash .github/scripts/setup-agent-env.sh - - name: Run code agent - id: run-agent + - name: Run review agent + if: matrix.stage == 'review' + id: run-review uses: ./.defaults/ env: GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} - FULLSEND_WORK_ITEM_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} - FULLSEND_WORK_ITEM_KEY: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} - ISSUE_NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} - COMMENT_BODY: ${{ fromJSON(needs.route.outputs.event_payload).comment.body }} + FULLSEND_WORK_ITEM_URL: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.html_url || fromJSON(needs.route.outputs.event_payload).issue.html_url }} + GITHUB_PR_URL: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.html_url || fromJSON(needs.route.outputs.event_payload).issue.html_url }} REPO_FULL_NAME: ${{ github.repository }} - CODE_ALLOWED_TARGET_BRANCHES: '' - TARGET_BRANCH: main + PR_NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number || fromJSON(needs.route.outputs.event_payload).issue.number }} + PRIOR_REVIEW_SHA: ${{ steps.prior-review.outputs.prior_sha }} + PRIOR_REVIEW_FILE: ${{ steps.prior-review.outputs.prior_review_file }} + PRIOR_REVIEW_PROVENANCE: ${{ steps.prior-review.outputs.prior_review_provenance }} + FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} OTEL_EXPORTER_OTLP_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_ENDPOINT }} OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT }} OTEL_EXPORTER_OTLP_TRACES_HEADERS: ${{ secrets.OTEL_EXPORTER_OTLP_TRACES_HEADERS }} @@ -1984,8 +2097,7 @@ jobs: # read by the runner under its own name; unused in the oidc mode. FULLSEND_INFERENCE_GATEWAY_API_KEY: ${{ secrets.FULLSEND_INFERENCE_GATEWAY_API_KEY }} with: - agent: code - role: coder + agent: review 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 || '' }} @@ -1997,21 +2109,21 @@ jobs: version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} 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 }} + 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 code launch failure - if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github' }} + - name: Report review launch failure + if: ${{ matrix.stage == 'review' && (failure() && !cancelled() && steps.run-review.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 }} + 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 @@ -2029,253 +2141,128 @@ jobs: fi export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" export FULLSEND_FAILURE_NUMBER="${NUMBER}" - export FULLSEND_FAILURE_AGENT="code" - export FULLSEND_FAILURE_ROLE="coder" + 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}" - review: - name: Review - needs: route - if: needs.route.outputs.stage == 'review' - runs-on: ${{ inputs.runner_image }} - concurrency: - group: fullsend-review-${{ github.repository }}-${{ github.event.pull_request.number || github.event.issue.number || needs.route.outputs.pr_number }} - cancel-in-progress: true - permissions: - actions: write - contents: read - id-token: write - issues: write - pull-requests: write - - steps: - - name: Checkout caller repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} - persist-credentials: false - allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} - - - name: Checkout upstream defaults - if: hashFiles('.defaults/action.yml', '.fullsend/.defaults/action.yml') == '' - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - repository: ${{ job.workflow_repository }} - ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - path: .defaults - fetch-depth: 1 - sparse-checkout: | - .github/actions/ - .github/scripts/ - internal/scaffold/fullsend-repo/ - action.yml - - # The review job is separate from route, so it must install its own - # copy before using the CLI to supersede an earlier skip note. - - name: Detect review dedup CLI - id: review-cli-mode - continue-on-error: true - shell: bash - run: | - set -euo pipefail - if [[ -f .fullsend/bin/fullsend ]] && .fullsend/bin/fullsend review-dedup --help >/dev/null 2>&1; then - echo "mode=vendored" >> "${GITHUB_OUTPUT}" - else - echo "mode=upstream" >> "${GITHUB_OUTPUT}" - fi - - - name: Restore fullsend CLI cache for review job - id: review-job-cli-cache - if: steps.review-cli-mode.outputs.mode == 'upstream' - continue-on-error: true - uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ runner.temp }}/fullsend-cache - key: fullsend-review-dedup-cli-${{ steps.review-cli-mode.outputs.mode }}-${{ runner.arch }}-${{ hashFiles('.fullsend/bin/fullsend') }}-${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - - - name: Validate cached fullsend CLI for review job - id: review-job-cli-cache-validation - if: steps.review-cli-mode.outputs.mode == 'upstream' && steps.review-job-cli-cache.outputs.cache-hit == 'true' - continue-on-error: true - shell: bash - run: | - set -euo pipefail - if [[ -x "${RUNNER_TEMP}/fullsend-cache/fullsend" ]] && "${RUNNER_TEMP}/fullsend-cache/fullsend" review-dedup --help >/dev/null 2>&1; then - echo "valid=true" >> "${GITHUB_OUTPUT}" - else - echo "valid=false" >> "${GITHUB_OUTPUT}" - fi - - - name: Install review dedup CLI (vendored) - if: steps.review-cli-mode.outputs.mode == 'vendored' - continue-on-error: true - shell: bash - run: | - set -euo pipefail - mkdir -p "${RUNNER_TEMP}/fullsend-review-dedup" - cp .fullsend/bin/fullsend "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" - chmod +x "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" - - - name: Checkout review dedup CLI installer - if: steps.review-cli-mode.outputs.mode == 'upstream' && (steps.review-job-cli-cache.outputs.cache-hit != 'true' || steps.review-job-cli-cache-validation.outputs.valid != 'true') - continue-on-error: true - timeout-minutes: 5 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - repository: ${{ job.workflow_repository }} - ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - path: .review-dedup-actions - fetch-depth: 1 - sparse-checkout: | - .github/actions/install-fullsend-cli/ - sparse-checkout-cone-mode: false - - - name: Install review dedup CLI (upstream) - if: steps.review-cli-mode.outputs.mode == 'upstream' && (steps.review-job-cli-cache.outputs.cache-hit != 'true' || steps.review-job-cli-cache-validation.outputs.valid != 'true') - continue-on-error: true - timeout-minutes: 5 - uses: ./.review-dedup-actions/.github/actions/install-fullsend-cli - with: - mode: upstream - install_dir: ${{ runner.temp }}/fullsend-review-dedup - add_to_path: 'false' - source_dir: ${{ runner.temp }}/fullsend-review-dedup-src - workflow_repository: ${{ job.workflow_repository }} - workflow_sha: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - github_token: ${{ github.token }} - - - name: Expose cached fullsend CLI for review job - if: steps.review-cli-mode.outputs.mode == 'upstream' && steps.review-job-cli-cache-validation.outputs.valid == 'true' - continue-on-error: true - shell: bash - run: | - set -euo pipefail - install_dir="${RUNNER_TEMP}/fullsend-review-dedup" - mkdir -p "${install_dir}" - cp "${RUNNER_TEMP}/fullsend-cache/fullsend" "${install_dir}/fullsend" - chmod +x "${install_dir}/fullsend" - - - name: Prepare fullsend CLI cache artifact for review job - id: review-job-cli-cache-prepare - if: steps.review-cli-mode.outputs.mode == 'upstream' && (steps.review-job-cli-cache.outputs.cache-hit != 'true' || steps.review-job-cli-cache-validation.outputs.valid != 'true') - continue-on-error: true - shell: bash - run: | - set -euo pipefail - if [[ ! -x "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" ]]; then - echo "ready=false" >> "${GITHUB_OUTPUT}" - exit 0 - fi - mkdir -p "${RUNNER_TEMP}/fullsend-cache" - cp "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" "${RUNNER_TEMP}/fullsend-cache/fullsend" - "${RUNNER_TEMP}/fullsend-cache/fullsend" review-dedup --help >/dev/null 2>&1 - echo "ready=true" >> "${GITHUB_OUTPUT}" - - - name: Save fullsend CLI cache for review job - if: steps.review-cli-mode.outputs.mode == 'upstream' && (steps.review-job-cli-cache.outputs.cache-hit != 'true' || steps.review-job-cli-cache-validation.outputs.valid != 'true') && steps.review-job-cli-cache-prepare.outcome == 'success' && steps.review-job-cli-cache-prepare.outputs.ready == 'true' - continue-on-error: true - uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ runner.temp }}/fullsend-cache - key: fullsend-review-dedup-cli-${{ steps.review-cli-mode.outputs.mode }}-${{ runner.arch }}-${{ hashFiles('.fullsend/bin/fullsend') }}-${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - - - name: Prepare workspace - id: workspace - uses: ./.defaults/.github/actions/prepare-workspace - with: - source_repo: ${{ github.repository }} - - - name: Mint review token - id: app-token - uses: ./.defaults/.github/actions/mint-token - with: - role: review - repos: ${{ steps.workspace.outputs.repo_name }} - mint_url: ${{ inputs.mint_url }} - - - name: Checkout target repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - repository: ${{ github.repository }} - token: ${{ steps.app-token.outputs.token }} - path: target-repo - fetch-depth: 1 - persist-credentials: false - # With no ref, checkout uses github.ref: the default branch on - # pull_request_target, the PR merge commit on pull_request. Keep the - # default branch on pull_request (#9221). - ref: ${{ github.event_name == 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) || '' }} + - name: Setup agent environment + if: matrix.stage == 'retro' + env: + AGENT_PREFIX: RETRO_ + RETRO_TARGET_REPO_DIR: target-repo + RETRO_ANTHROPIC_VERTEX_PROJECT_ID: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} + RETRO_CLOUD_ML_REGION: ${{ inputs.gcp_region }} + # Per-run runtime/model/effort overrides from repository variables + # (FULLSEND_MODEL, RETRO_FULLSEND_MODEL, ...); see docs/runtimes.md. + FULLSEND_REPO_VARS: ${{ toJSON(vars) }} + run: bash .github/scripts/setup-agent-env.sh - - name: Pre-fetch prior review context - id: prior-review + - name: Run retro agent + if: matrix.stage == 'retro' + id: run-retro + uses: ./.defaults/ env: - GH_TOKEN: ${{ steps.app-token.outputs.token }} - SOURCE_REPO: ${{ github.repository }} - PR_NUM: >- - ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number - || fromJSON(needs.route.outputs.event_payload).issue.number }} - ORG_NAME: ${{ github.repository_owner }} - FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} - REVIEW_APP_CLIENT_ID: ${{ vars.FULLSEND_REVIEW_CLIENT_ID }} - FULLSEND_DIR: .fullsend - run: bash "${FULLSEND_DIR:+$FULLSEND_DIR/}scripts/pre-fetch-prior-review.sh" + ORIGINATING_URL: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.html_url || fromJSON(needs.route.outputs.event_payload).issue.html_url }} + RETRO_COMMENT: ${{ fromJSON(needs.route.outputs.event_payload).comment.body || '' }} + REPO_FULL_NAME: ${{ github.repository }} + MINT_REPOS: ${{ steps.workspace.outputs.repo_name }} + OTEL_EXPORTER_OTLP_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_ENDPOINT }} + OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT }} + OTEL_EXPORTER_OTLP_TRACES_HEADERS: ${{ secrets.OTEL_EXPORTER_OTLP_TRACES_HEADERS }} + OTEL_EXPORTER_OTLP_HEADERS: ${{ secrets.OTEL_EXPORTER_OTLP_HEADERS }} + OTEL_EXPORTER_OTLP_CERTIFICATE: ${{ vars.OTEL_EXPORTER_OTLP_CERTIFICATE }} + OTEL_RESOURCE_ATTRIBUTES: ${{ vars.OTEL_RESOURCE_ATTRIBUTES }} + OTEL_SDK_DISABLED: ${{ vars.OTEL_SDK_DISABLED }} + OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: ${{ vars.OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT }} + # OpenAI Workload Identity Federation for the pi runtime (ADR 0092): + # non-secret identifiers the runner exchanges the job's OIDC token + # against. Unset = the openai provider is not usable in this repo. + FULLSEND_OPENAI_AUDIENCE: ${{ vars.FULLSEND_OPENAI_AUDIENCE }} + FULLSEND_OPENAI_IDENTITY_PROVIDER_ID: ${{ vars.FULLSEND_OPENAI_IDENTITY_PROVIDER_ID }} + FULLSEND_OPENAI_SERVICE_ACCOUNT_ID: ${{ vars.FULLSEND_OPENAI_SERVICE_ACCOUNT_ID }} + # Opt-in static key, used only when the three variables above are unset (ADR 0092). + OPENAI_API_KEY: ${{ secrets.FULLSEND_OPENAI_API_KEY }} + # Inference gateway API key for inference.gateway.auth api-key (ADR 0138), + # read by the runner under its own name; unused in the oidc mode. + FULLSEND_INFERENCE_GATEWAY_API_KEY: ${{ secrets.FULLSEND_INFERENCE_GATEWAY_API_KEY }} + with: + agent: retro + 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 || '' }} + jira-email: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_EMAIL || '' }} + jira-client-id: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_ID || '' }} + jira-client-secret: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_SECRET || '' }} + runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} + fullsend-dir: .fullsend + version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} + 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 || '' }} - # A previous unchanged-diff run leaves a PR-visible status note. Once - # this full review is actually dispatched, that note must not continue - # to look like the current verdict. Keep the marker for provenance, but - # replace the stale message with an explicit superseded notice. - - name: Supersede prior review skip note - if: steps.app-token.outcome == 'success' - continue-on-error: true + - name: Report retro launch failure + if: ${{ matrix.stage == 'retro' && (failure() && !cancelled() && steps.run-retro.outcome == 'skipped' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github') }} env: - GH_TOKEN: ${{ steps.app-token.outputs.token }} - SOURCE_REPO: ${{ github.repository }} - PR_NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number || fromJSON(needs.route.outputs.event_payload).issue.number }} - FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} - REVIEW_APP_CLIENT_ID: ${{ vars.FULLSEND_REVIEW_CLIENT_ID }} - REVIEW_HEAD_SHA: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} - shell: bash + 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 - if [[ ! -x "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" ]]; then - echo "::warning::Review deduplication CLI unavailable; skipping supersede" - exit 0 + 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=${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || 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 - "${RUNNER_TEMP}/fullsend-review-dedup/fullsend" review-dedup \ - --repo "${SOURCE_REPO}" \ - --pr "${PR_NUMBER}" \ - --app-set "${FULLSEND_APP_SET}" \ - --app-client-id "${REVIEW_APP_CLIENT_ID}" \ - --head-sha "${REVIEW_HEAD_SHA}" \ - --supersede + 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}" - name: Setup agent environment + if: matrix.stage == 'prioritize' env: - AGENT_PREFIX: REVIEW_ - REVIEW_TARGET_REPO_DIR: target-repo - REVIEW_ANTHROPIC_VERTEX_PROJECT_ID: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} - REVIEW_CLOUD_ML_REGION: ${{ inputs.gcp_region }} + AGENT_PREFIX: PRIORITIZE_ + PRIORITIZE_ORG: ${{ github.repository_owner }} + PRIORITIZE_PROJECT_NUMBER: ${{ inputs.project_number }} + PRIORITIZE_ANTHROPIC_VERTEX_PROJECT_ID: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} + PRIORITIZE_CLOUD_ML_REGION: ${{ inputs.gcp_region }} # Per-run runtime/model/effort overrides from repository variables - # (FULLSEND_MODEL, REVIEW_FULLSEND_MODEL, ...); see docs/runtimes.md. + # (FULLSEND_MODEL, PRIORITIZE_FULLSEND_MODEL, ...); see docs/runtimes.md. FULLSEND_REPO_VARS: ${{ toJSON(vars) }} run: bash .github/scripts/setup-agent-env.sh - - name: Run review agent - id: run-agent + - name: Create empty target-repo directory + if: matrix.stage == 'prioritize' + run: mkdir -p target-repo + + - name: Run prioritize agent + if: matrix.stage == 'prioritize' + id: run-prioritize uses: ./.defaults/ env: GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} - FULLSEND_WORK_ITEM_URL: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.html_url || fromJSON(needs.route.outputs.event_payload).issue.html_url }} - GITHUB_PR_URL: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.html_url || fromJSON(needs.route.outputs.event_payload).issue.html_url }} + FULLSEND_WORK_ITEM_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} REPO_FULL_NAME: ${{ github.repository }} - PR_NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number || fromJSON(needs.route.outputs.event_payload).issue.number }} - PRIOR_REVIEW_SHA: ${{ steps.prior-review.outputs.prior_sha }} - PRIOR_REVIEW_FILE: ${{ steps.prior-review.outputs.prior_review_file }} - PRIOR_REVIEW_PROVENANCE: ${{ steps.prior-review.outputs.prior_review_provenance }} - FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} OTEL_EXPORTER_OTLP_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_ENDPOINT }} OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT }} OTEL_EXPORTER_OTLP_TRACES_HEADERS: ${{ secrets.OTEL_EXPORTER_OTLP_TRACES_HEADERS }} @@ -2296,7 +2283,7 @@ jobs: # read by the runner under its own name; unused in the oidc mode. FULLSEND_INFERENCE_GATEWAY_API_KEY: ${{ secrets.FULLSEND_INFERENCE_GATEWAY_API_KEY }} with: - agent: review + agent: prioritize 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 || '' }} @@ -2308,21 +2295,18 @@ jobs: version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} 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 }} + 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 review launch failure - if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github' }} + - name: Report prioritize launch failure + if: ${{ matrix.stage == 'prioritize' && (failure() && !cancelled() && steps.run-prioritize.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 }} + 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 @@ -2340,19 +2324,26 @@ jobs: fi export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" export FULLSEND_FAILURE_NUMBER="${NUMBER}" - export FULLSEND_FAILURE_AGENT="review" + export FULLSEND_FAILURE_AGENT="prioritize" export FULLSEND_FAILURE_RUN_URL="${RUN_URL}" - FULLSEND_FAILURE_CATEGORY="$([[ "${MINT_OUTCOME}" == "failure" ]] && echo 'token mint' || echo 'workflow setup')" - export FULLSEND_FAILURE_CATEGORY + export FULLSEND_FAILURE_CATEGORY="workflow setup" bash "${script}" - fix: - name: Fix + coder: + name: Coder (${{ matrix.stage }}) needs: route - if: needs.route.outputs.stage == 'fix' + if: needs.route.outputs.stage == 'code' || needs.route.outputs.stage == 'fix' + strategy: + # One expression for the whole matrix, like harness-run: a matrix whose + # values hold expressions can be expanded before route has run, while + # a whole-matrix expression is expanded once this job's needs finish. + matrix: ${{ fromJSON(format('{{"stage":[{0}]}}', toJSON(needs.route.outputs.stage))) }} runs-on: ${{ inputs.runner_image }} concurrency: - group: fullsend-fix-${{ github.repository }}-${{ github.event.pull_request.number || github.event.issue.number }} + # Same group values as the former per-stage jobs: one cancel-in-progress + # group per stage and work item (fullsend-{stage}-…), so a review + # dispatch never cancels triage, code, fix, etc. + group: fullsend-${{ matrix.stage }}-${{ github.repository }}-${{ github.event.pull_request.number || github.event.issue.number || needs.route.outputs.pr_number }} cancel-in-progress: true permissions: actions: write @@ -2398,6 +2389,20 @@ jobs: repos: ${{ steps.workspace.outputs.repo_name }} mint_url: ${{ inputs.mint_url }} + - name: Checkout target repository + if: matrix.stage == 'code' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ${{ github.repository }} + token: ${{ steps.app-token.outputs.token }} + path: target-repo + fetch-depth: 0 + persist-credentials: false + # With no ref, checkout uses github.ref: the default branch on + # pull_request_target, the PR merge commit on pull_request. Keep the + # default branch on pull_request (#9221). + ref: ${{ github.event_name == 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) || '' }} + - name: Resolve bot identity env: GH_TOKEN: ${{ steps.app-token.outputs.token }} @@ -2414,6 +2419,7 @@ jobs: git config --global user.name "${BOT_LOGIN}" - name: Block fork PRs + if: matrix.stage == 'fix' id: fork_guard env: GH_TOKEN: ${{ steps.app-token.outputs.token }} @@ -2448,6 +2454,7 @@ jobs: fi - name: Extract PR number and context + if: matrix.stage == 'fix' id: context env: GH_TOKEN: ${{ steps.app-token.outputs.token }} @@ -2464,279 +2471,127 @@ jobs: if [[ -z "${PR_NUM}" && -n "${INPUT_PR_NUMBER}" ]]; then PR_NUM="${INPUT_PR_NUMBER}" fi - if [[ -z "${PR_NUM}" || ! "${PR_NUM}" =~ ^[1-9][0-9]*$ ]]; then - echo "::error::Could not extract valid PR number from event" - exit 1 - fi - echo "pr_number=${PR_NUM}" >> "${GITHUB_OUTPUT}" - - HEAD_REF="$(echo "${EVENT_PAYLOAD}" | jq -r '.pull_request.head.ref // empty')" - BASE_REF="$(echo "${EVENT_PAYLOAD}" | jq -r '.pull_request.base.ref // empty')" - if [[ -z "${HEAD_REF}" ]]; then - HEAD_REF="$(gh pr view "${PR_NUM}" --repo "${SOURCE_REPO}" --json headRefName --jq '.headRefName' 2>/dev/null || true)" - fi - if [[ -z "${BASE_REF}" ]]; then - BASE_REF="$(gh pr view "${PR_NUM}" --repo "${SOURCE_REPO}" --json baseRefName --jq '.baseRefName' 2>/dev/null || echo 'main')" - fi - if [[ -z "${HEAD_REF}" ]]; then - echo "::error::Could not resolve PR head branch" - exit 1 - fi - echo "head_ref=${HEAD_REF}" >> "${GITHUB_OUTPUT}" - echo "base_ref=${BASE_REF}" >> "${GITHUB_OUTPUT}" - echo "PR #${PR_NUM}: ${HEAD_REF} → ${BASE_REF}" - - INSTRUCTION="none" - if [[ ! "${TRIGGER_SOURCE}" =~ \[bot\]$ ]]; then - COMMENT_BODY="$(echo "${EVENT_PAYLOAD}" | jq -r '.comment.body // empty' | tr -d '\r')" - if [[ -n "${COMMENT_BODY}" ]]; then - INSTRUCTION="${COMMENT_BODY#/fs-fix}" - INSTRUCTION="$(printf '%s\n' "${INSTRUCTION}" | sed 's/^[.,;:!?]*//')" - INSTRUCTION="${INSTRUCTION#"${INSTRUCTION%%[![:space:]]*}"}" - fi - if [[ -z "${INSTRUCTION}" && -n "${INPUT_INSTRUCTION}" ]]; then - INSTRUCTION="${INPUT_INSTRUCTION}" - fi - if [[ -z "${INSTRUCTION}" ]]; then - INSTRUCTION="none" - fi - fi - DELIM="INSTRUCTION_$(openssl rand -hex 8)" - { - echo "instruction<<${DELIM}" - echo "${INSTRUCTION}" - echo "${DELIM}" - } >> "${GITHUB_OUTPUT}" - - FIX_COMMITS="$(gh api "repos/${SOURCE_REPO}/pulls/${PR_NUM}/commits" \ - --paginate 2>/dev/null \ - | jq -s --arg bot_email "${GIT_BOT_EMAIL}" -f .defaults/.github/scripts/count-fix-commits.jq)" \ - || { echo "::warning::Could not count prior fix commits — defaulting to cap"; FIX_COMMITS="${ITERATION_CAP:-5}"; } - ITERATION=$(( FIX_COMMITS + 1 )) - echo "Fix iteration: ${ITERATION} (${FIX_COMMITS} previous fix commits)" >&2 - 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 }} - FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} - PR_NUM: ${{ steps.context.outputs.pr_number }} - SOURCE_REPO: ${{ github.repository }} - run: bash .defaults/.github/scripts/check-fix-eligibility.sh - - - name: Checkout target repository at PR HEAD - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - repository: ${{ github.repository }} - token: ${{ steps.app-token.outputs.token }} - path: target-repo - fetch-depth: 0 - persist-credentials: false - ref: ${{ steps.context.outputs.head_ref }} - - - name: Record pre-agent HEAD - id: pre-agent - working-directory: target-repo - run: | - SHA="$(git rev-parse HEAD)" - echo "Pre-agent HEAD: ${SHA}" - echo "head=${SHA}" >> "${GITHUB_OUTPUT}" - - - name: Pre-fetch review body - id: review-body - env: - GH_TOKEN: ${{ steps.app-token.outputs.token }} - SOURCE_REPO: ${{ github.repository }} - PR_NUM: ${{ steps.context.outputs.pr_number }} - TRIGGER_SOURCE: ${{ needs.route.outputs.trigger_source }} - ORG_NAME: ${{ github.repository_owner }} - FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} - run: bash .defaults/.github/scripts/pre-fetch-review-body.sh - - - name: Setup agent environment - env: - AGENT_PREFIX: FIX_ - FIX_TARGET_REPO_DIR: target-repo - FIX_ANTHROPIC_VERTEX_PROJECT_ID: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} - FIX_CLOUD_ML_REGION: ${{ inputs.gcp_region }} - FIX_PR_NUMBER: ${{ steps.context.outputs.pr_number }} - FIX_TRIGGER_SOURCE: ${{ needs.route.outputs.trigger_source }} - FIX_HUMAN_INSTRUCTION: ${{ steps.context.outputs.instruction }} - FIX_FIX_ITERATION: ${{ steps.context.outputs.iteration }} - FIX_REPO_FULL_NAME: ${{ github.repository }} - # Per-run runtime/model/effort overrides from repository variables - # (FULLSEND_MODEL, FIX_FULLSEND_MODEL, ...); see docs/runtimes.md. - FULLSEND_REPO_VARS: ${{ toJSON(vars) }} - 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 }} - REPO_FULL_NAME: ${{ github.repository }} - TARGET_BRANCH: ${{ steps.context.outputs.base_ref }} - TRIGGER_SOURCE: ${{ needs.route.outputs.trigger_source }} - HUMAN_INSTRUCTION: ${{ steps.context.outputs.instruction }} - FIX_ITERATION: ${{ steps.context.outputs.iteration }} - REVIEW_BODY_FILE: ${{ steps.review-body.outputs.review_file }} - PRE_AGENT_HEAD: ${{ steps.pre-agent.outputs.head }} - OTEL_EXPORTER_OTLP_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_ENDPOINT }} - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT }} - OTEL_EXPORTER_OTLP_TRACES_HEADERS: ${{ secrets.OTEL_EXPORTER_OTLP_TRACES_HEADERS }} - OTEL_EXPORTER_OTLP_HEADERS: ${{ secrets.OTEL_EXPORTER_OTLP_HEADERS }} - OTEL_EXPORTER_OTLP_CERTIFICATE: ${{ vars.OTEL_EXPORTER_OTLP_CERTIFICATE }} - OTEL_RESOURCE_ATTRIBUTES: ${{ vars.OTEL_RESOURCE_ATTRIBUTES }} - OTEL_SDK_DISABLED: ${{ vars.OTEL_SDK_DISABLED }} - OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: ${{ vars.OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT }} - # OpenAI Workload Identity Federation for the pi runtime (ADR 0092): - # non-secret identifiers the runner exchanges the job's OIDC token - # against. Unset = the openai provider is not usable in this repo. - FULLSEND_OPENAI_AUDIENCE: ${{ vars.FULLSEND_OPENAI_AUDIENCE }} - FULLSEND_OPENAI_IDENTITY_PROVIDER_ID: ${{ vars.FULLSEND_OPENAI_IDENTITY_PROVIDER_ID }} - FULLSEND_OPENAI_SERVICE_ACCOUNT_ID: ${{ vars.FULLSEND_OPENAI_SERVICE_ACCOUNT_ID }} - # Opt-in static key, used only when the three variables above are unset (ADR 0092). - OPENAI_API_KEY: ${{ secrets.FULLSEND_OPENAI_API_KEY }} - # Inference gateway API key for inference.gateway.auth api-key (ADR 0138), - # read by the runner under its own name; unused in the oidc mode. - 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 || '' }} - jira-email: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_EMAIL || '' }} - jira-client-id: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_ID || '' }} - jira-client-secret: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_SECRET || '' }} - runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} - fullsend-dir: .fullsend - version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - 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=${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || 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 - if: needs.route.outputs.stage == 'retro' - runs-on: ${{ inputs.runner_image }} - concurrency: - group: fullsend-retro-${{ github.repository }}-${{ github.event.pull_request.number || github.event.issue.number || needs.route.outputs.pr_number }} - cancel-in-progress: true - permissions: - actions: write - contents: read - id-token: write - issues: write + if [[ -z "${PR_NUM}" || ! "${PR_NUM}" =~ ^[1-9][0-9]*$ ]]; then + echo "::error::Could not extract valid PR number from event" + exit 1 + fi + echo "pr_number=${PR_NUM}" >> "${GITHUB_OUTPUT}" - steps: - - name: Checkout caller repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} - persist-credentials: false - allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} + HEAD_REF="$(echo "${EVENT_PAYLOAD}" | jq -r '.pull_request.head.ref // empty')" + BASE_REF="$(echo "${EVENT_PAYLOAD}" | jq -r '.pull_request.base.ref // empty')" + if [[ -z "${HEAD_REF}" ]]; then + HEAD_REF="$(gh pr view "${PR_NUM}" --repo "${SOURCE_REPO}" --json headRefName --jq '.headRefName' 2>/dev/null || true)" + fi + if [[ -z "${BASE_REF}" ]]; then + BASE_REF="$(gh pr view "${PR_NUM}" --repo "${SOURCE_REPO}" --json baseRefName --jq '.baseRefName' 2>/dev/null || echo 'main')" + fi + if [[ -z "${HEAD_REF}" ]]; then + echo "::error::Could not resolve PR head branch" + exit 1 + fi + echo "head_ref=${HEAD_REF}" >> "${GITHUB_OUTPUT}" + echo "base_ref=${BASE_REF}" >> "${GITHUB_OUTPUT}" + echo "PR #${PR_NUM}: ${HEAD_REF} → ${BASE_REF}" - - name: Checkout upstream defaults - if: hashFiles('.defaults/action.yml', '.fullsend/.defaults/action.yml') == '' - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - repository: ${{ job.workflow_repository }} - ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - path: .defaults - fetch-depth: 1 - sparse-checkout: | - .github/actions/ - .github/scripts/ - internal/scaffold/fullsend-repo/ - action.yml + INSTRUCTION="none" + if [[ ! "${TRIGGER_SOURCE}" =~ \[bot\]$ ]]; then + COMMENT_BODY="$(echo "${EVENT_PAYLOAD}" | jq -r '.comment.body // empty' | tr -d '\r')" + if [[ -n "${COMMENT_BODY}" ]]; then + INSTRUCTION="${COMMENT_BODY#/fs-fix}" + INSTRUCTION="$(printf '%s\n' "${INSTRUCTION}" | sed 's/^[.,;:!?]*//')" + INSTRUCTION="${INSTRUCTION#"${INSTRUCTION%%[![:space:]]*}"}" + fi + if [[ -z "${INSTRUCTION}" && -n "${INPUT_INSTRUCTION}" ]]; then + INSTRUCTION="${INPUT_INSTRUCTION}" + fi + if [[ -z "${INSTRUCTION}" ]]; then + INSTRUCTION="none" + fi + fi + DELIM="INSTRUCTION_$(openssl rand -hex 8)" + { + echo "instruction<<${DELIM}" + echo "${INSTRUCTION}" + echo "${DELIM}" + } >> "${GITHUB_OUTPUT}" - - name: Prepare workspace - id: workspace - uses: ./.defaults/.github/actions/prepare-workspace - with: - source_repo: ${{ github.repository }} + FIX_COMMITS="$(gh api "repos/${SOURCE_REPO}/pulls/${PR_NUM}/commits" \ + --paginate 2>/dev/null \ + | jq -s --arg bot_email "${GIT_BOT_EMAIL}" -f .defaults/.github/scripts/count-fix-commits.jq)" \ + || { echo "::warning::Could not count prior fix commits — defaulting to cap"; FIX_COMMITS="${ITERATION_CAP:-5}"; } + ITERATION=$(( FIX_COMMITS + 1 )) + echo "Fix iteration: ${ITERATION} (${FIX_COMMITS} previous fix commits)" >&2 + echo "iteration=${ITERATION}" >> "${GITHUB_OUTPUT}" - - name: Mint retro token - id: app-token - uses: ./.defaults/.github/actions/mint-token - with: - role: retro - repos: ${{ steps.workspace.outputs.repo_name }} - mint_url: ${{ inputs.mint_url }} + - name: Check fix eligibility + if: matrix.stage == 'fix' + id: eligibility + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + TRIGGER_SOURCE: ${{ needs.route.outputs.trigger_source }} + FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + PR_NUM: ${{ steps.context.outputs.pr_number }} + SOURCE_REPO: ${{ github.repository }} + run: bash .defaults/.github/scripts/check-fix-eligibility.sh - - name: Checkout target repository + - name: Checkout target repository at PR HEAD + if: matrix.stage == 'fix' uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ github.repository }} token: ${{ steps.app-token.outputs.token }} path: target-repo - fetch-depth: 1 + fetch-depth: 0 persist-credentials: false - # With no ref, checkout uses github.ref: the default branch on - # pull_request_target, the PR merge commit on pull_request. Keep the - # default branch on pull_request (#9221). - ref: ${{ github.event_name == 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) || '' }} + ref: ${{ steps.context.outputs.head_ref }} + + - name: Record pre-agent HEAD + if: matrix.stage == 'fix' + id: pre-agent + working-directory: target-repo + run: | + SHA="$(git rev-parse HEAD)" + echo "Pre-agent HEAD: ${SHA}" + echo "head=${SHA}" >> "${GITHUB_OUTPUT}" + + - name: Pre-fetch review body + if: matrix.stage == 'fix' + id: review-body + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + SOURCE_REPO: ${{ github.repository }} + PR_NUM: ${{ steps.context.outputs.pr_number }} + TRIGGER_SOURCE: ${{ needs.route.outputs.trigger_source }} + ORG_NAME: ${{ github.repository_owner }} + FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} + run: bash .defaults/.github/scripts/pre-fetch-review-body.sh - name: Setup agent environment + if: matrix.stage == 'code' env: - AGENT_PREFIX: RETRO_ - RETRO_TARGET_REPO_DIR: target-repo - RETRO_ANTHROPIC_VERTEX_PROJECT_ID: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} - RETRO_CLOUD_ML_REGION: ${{ inputs.gcp_region }} + AGENT_PREFIX: CODE_ + CODE_TARGET_REPO_DIR: target-repo + CODE_ANTHROPIC_VERTEX_PROJECT_ID: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} + CODE_CLOUD_ML_REGION: ${{ inputs.gcp_region }} + CODE_ISSUE_NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} # Per-run runtime/model/effort overrides from repository variables - # (FULLSEND_MODEL, RETRO_FULLSEND_MODEL, ...); see docs/runtimes.md. + # (FULLSEND_MODEL, CODE_FULLSEND_MODEL, ...); see docs/runtimes.md. FULLSEND_REPO_VARS: ${{ toJSON(vars) }} run: bash .github/scripts/setup-agent-env.sh - - name: Run retro agent - id: run-agent + - name: Run code agent + if: matrix.stage == 'code' + id: run-code uses: ./.defaults/ env: - ORIGINATING_URL: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.html_url || fromJSON(needs.route.outputs.event_payload).issue.html_url }} - RETRO_COMMENT: ${{ fromJSON(needs.route.outputs.event_payload).comment.body || '' }} + GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} + FULLSEND_WORK_ITEM_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} + FULLSEND_WORK_ITEM_KEY: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} + ISSUE_NUMBER: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} + COMMENT_BODY: ${{ fromJSON(needs.route.outputs.event_payload).comment.body }} REPO_FULL_NAME: ${{ github.repository }} - MINT_REPOS: ${{ steps.workspace.outputs.repo_name }} + CODE_ALLOWED_TARGET_BRANCHES: '' + TARGET_BRANCH: main OTEL_EXPORTER_OTLP_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_ENDPOINT }} OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT }} OTEL_EXPORTER_OTLP_TRACES_HEADERS: ${{ secrets.OTEL_EXPORTER_OTLP_TRACES_HEADERS }} @@ -2757,7 +2612,8 @@ jobs: # read by the runner under its own name; unused in the oidc mode. FULLSEND_INFERENCE_GATEWAY_API_KEY: ${{ secrets.FULLSEND_INFERENCE_GATEWAY_API_KEY }} with: - agent: retro + 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 || '' }} @@ -2769,21 +2625,21 @@ jobs: version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} 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 }} + 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 retro launch failure - if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github' }} + - name: Report code launch failure + if: ${{ matrix.stage == 'code' && (failure() && !cancelled() && steps.run-code.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 }} + 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 @@ -2801,76 +2657,43 @@ jobs: fi export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" export FULLSEND_FAILURE_NUMBER="${NUMBER}" - export FULLSEND_FAILURE_AGENT="retro" + 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}" - prioritize: - name: Prioritize - needs: route - if: needs.route.outputs.stage == 'prioritize' - runs-on: ${{ inputs.runner_image }} - concurrency: - group: fullsend-prioritize-${{ github.repository }}-${{ github.event.issue.number || github.event.pull_request.number }} - cancel-in-progress: true - permissions: - actions: write - contents: read - id-token: write - issues: write - - steps: - - name: Checkout caller repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} - persist-credentials: false - allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} - - - name: Checkout upstream defaults - if: hashFiles('.defaults/action.yml', '.fullsend/.defaults/action.yml') == '' - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - repository: ${{ job.workflow_repository }} - ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - path: .defaults - fetch-depth: 1 - sparse-checkout: | - .github/actions/ - .github/scripts/ - internal/scaffold/fullsend-repo/ - action.yml - - - name: Prepare workspace - id: workspace - uses: ./.defaults/.github/actions/prepare-workspace - with: - source_repo: ${{ github.repository }} - - name: Setup agent environment + if: matrix.stage == 'fix' env: - AGENT_PREFIX: PRIORITIZE_ - PRIORITIZE_ORG: ${{ github.repository_owner }} - PRIORITIZE_PROJECT_NUMBER: ${{ inputs.project_number }} - PRIORITIZE_ANTHROPIC_VERTEX_PROJECT_ID: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} - PRIORITIZE_CLOUD_ML_REGION: ${{ inputs.gcp_region }} + AGENT_PREFIX: FIX_ + FIX_TARGET_REPO_DIR: target-repo + FIX_ANTHROPIC_VERTEX_PROJECT_ID: ${{ secrets.FULLSEND_GCP_PROJECT_ID }} + FIX_CLOUD_ML_REGION: ${{ inputs.gcp_region }} + FIX_PR_NUMBER: ${{ steps.context.outputs.pr_number }} + FIX_TRIGGER_SOURCE: ${{ needs.route.outputs.trigger_source }} + FIX_HUMAN_INSTRUCTION: ${{ steps.context.outputs.instruction }} + FIX_FIX_ITERATION: ${{ steps.context.outputs.iteration }} + FIX_REPO_FULL_NAME: ${{ github.repository }} # Per-run runtime/model/effort overrides from repository variables - # (FULLSEND_MODEL, PRIORITIZE_FULLSEND_MODEL, ...); see docs/runtimes.md. + # (FULLSEND_MODEL, FIX_FULLSEND_MODEL, ...); see docs/runtimes.md. FULLSEND_REPO_VARS: ${{ toJSON(vars) }} run: bash .github/scripts/setup-agent-env.sh - - name: Create empty target-repo directory - run: mkdir -p target-repo - - - name: Run prioritize agent - id: run-agent + - name: Run fix agent + if: matrix.stage == 'fix' + id: run-fix uses: ./.defaults/ env: - GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} - FULLSEND_WORK_ITEM_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} + PR_NUMBER: ${{ steps.context.outputs.pr_number }} REPO_FULL_NAME: ${{ github.repository }} + TARGET_BRANCH: ${{ steps.context.outputs.base_ref }} + TRIGGER_SOURCE: ${{ needs.route.outputs.trigger_source }} + HUMAN_INSTRUCTION: ${{ steps.context.outputs.instruction }} + FIX_ITERATION: ${{ steps.context.outputs.iteration }} + REVIEW_BODY_FILE: ${{ steps.review-body.outputs.review_file }} + PRE_AGENT_HEAD: ${{ steps.pre-agent.outputs.head }} OTEL_EXPORTER_OTLP_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_ENDPOINT }} OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT }} OTEL_EXPORTER_OTLP_TRACES_HEADERS: ${{ secrets.OTEL_EXPORTER_OTLP_TRACES_HEADERS }} @@ -2891,7 +2714,8 @@ jobs: # read by the runner under its own name; unused in the oidc mode. FULLSEND_INFERENCE_GATEWAY_API_KEY: ${{ secrets.FULLSEND_INFERENCE_GATEWAY_API_KEY }} with: - agent: prioritize + 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 || '' }} @@ -2903,18 +2727,21 @@ jobs: version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} 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 }} + 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 prioritize launch failure - if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github' }} + - name: Report fix launch failure + if: ${{ matrix.stage == 'fix' && (failure() && !cancelled() && steps.run-fix.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).issue.number || fromJSON(needs.route.outputs.event_payload).pull_request.number }} + 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 @@ -2932,9 +2759,11 @@ jobs: fi export FULLSEND_FAILURE_REPOSITORY="${REPOSITORY}" export FULLSEND_FAILURE_NUMBER="${NUMBER}" - export FULLSEND_FAILURE_AGENT="prioritize" + export FULLSEND_FAILURE_AGENT="fix" + export FULLSEND_FAILURE_ROLE="coder" export FULLSEND_FAILURE_RUN_URL="${RUN_URL}" - export FULLSEND_FAILURE_CATEGORY="workflow setup" + FULLSEND_FAILURE_CATEGORY="$([[ "${MINT_OUTCOME}" == "failure" ]] && echo 'token mint' || echo 'workflow setup')" + export FULLSEND_FAILURE_CATEGORY bash "${script}" harness-dispatch: diff --git a/docs/contributing/workflow-contracts.md b/docs/contributing/workflow-contracts.md index aeda7b3be2..f0ecea299c 100644 --- a/docs/contributing/workflow-contracts.md +++ b/docs/contributing/workflow-contracts.md @@ -4,7 +4,7 @@ **Secret threading:** GHA reusable workflows do not inherit secrets — they must be explicitly forwarded by every caller. (Repository and organization-level `vars` are automatically visible inside called reusable workflows and do not need forwarding.) When any reusable workflow (`.github/workflows/reusable-*.yml`) adds a new `secrets:` or `inputs:` (`workflow_call`) entry, trace the caller chains and ensure every hop forwards the new entry: -- **Per-repo chain:** shim template → `reusable-dispatch.yml` (stage logic for triage/code/review/fix/retro/prioritize is inlined directly as jobs per [ADR 62](../ADRs/0062-dispatch-version-skew.md) — there is no separate `reusable-.yml` hop for the dispatch path; thread new secrets/inputs into the relevant inline job). Exception: `prioritize.yml` is installed per-repo as a thin caller that receives `workflow_dispatch` from the scheduler and calls the remaining standalone `reusable-prioritize.yml` directly, bypassing the dispatch shim. The per-org scaffold thin callers and standalone stage workflows were removed ([ADR 44](../ADRs/0044-deprecate-per-org-installation-mode.md)). +- **Per-repo chain:** shim template → `reusable-dispatch.yml` (stage logic for triage/code/review/fix/retro/prioritize is inlined directly per [ADR 62](../ADRs/0062-dispatch-version-skew.md), in two stage-matrix jobs: `agent` runs triage, review, retro and prioritize, and `coder` runs code and fix, each with its own steps gated on `matrix.stage` — there is no separate `reusable-.yml` hop for the dispatch path; thread new secrets/inputs into the relevant stage's steps). Exception: `prioritize.yml` is installed per-repo as a thin caller that receives `workflow_dispatch` from the scheduler and calls the remaining standalone `reusable-prioritize.yml` directly, bypassing the dispatch shim. The per-org scaffold thin callers and standalone stage workflows were removed ([ADR 44](../ADRs/0044-deprecate-per-org-installation-mode.md)). **Silent failures and required-flag consistency:** Omitting a secret that is `required: true` at every hop in the chain fails loudly at workflow-call validation time and self-enforces. However, a secret whose `required` flag is `false` at any upstream hop can still arrive as an empty string at a downstream `required: true` consumer — GitHub Actions' required-secret validation only checks key presence, not that the resolved value is non-empty. The standalone prioritize workflow also passes optional GCP inputs to the fullsend action and leaves credential preparation to `fullsend run`, matching dispatch. An explicit `fullsend_version` override with both GCP credentials supplied also runs the compatibility GCP preparation step, so older CLIs continue to support Vertex. Per-repo GCP inputs are optional because an OpenAI-only repository does not use them; for the fleet harnesses' optional GCP mount, `fullsend run` rejects missing credentials before the pre-script on Vertex. Treat a missing forwarding hop as a correctness bug, not a cosmetic issue. diff --git a/docs/guides/dev/behaviour-drivers.md b/docs/guides/dev/behaviour-drivers.md index f3fac49d7b..75a65664a4 100644 --- a/docs/guides/dev/behaviour-drivers.md +++ b/docs/guides/dev/behaviour-drivers.md @@ -97,7 +97,7 @@ Each stub error is a `*drivers.NotImplementedError` (package `pkg/behaviourtest/ - **Run matching:** a run matches by workflow file name, event, and creation time, truncated to whole seconds. Forgejo identifies a workflow by its file name only, so the directory of the workflow path does not matter. The event is the run's `trigger_event` (the workflow's `on` key, for example `pull_request_target`) when Forgejo reports it, and the webhook event otherwise. When no matching run appears, `WaitForWorkflow` returns a `*ci.NotDispatchedError`, so steps retry once with the clock-skew buffer and the failure diagnostics list the repository's runs. `ListRecentRuns` sets `forge.WorkflowRun.Path` to the workflow file name. - **Status:** Forgejo's `success`, `failure`, `cancelled`, and `skipped` become a `completed` run with that conclusion, `running` becomes `in_progress`, `waiting` becomes `queued`, and `blocked` becomes `waiting`. - **Artifacts:** every artifact comes from the run that uploaded it, by the existing names (`fullsend-`, optionally with `.matrix-`). The `...After` downloads scan the runs created since the trigger, newest first, and download from the newest run whose own listing has a match. Agent downloads only use completed runs. The driver never uses a repository-wide artifact listing. An instance that serves artifacts directly from object storage answers the download with a redirect, which the adapter refuses like every redirect of an authenticated request. -- **Agent jobs:** harness agents are recognised by the GitHub Actions job names (`Harness run ()`, or the stage name such as `Triage` for a built-in stage), matched by suffix, or by the agent's artifact in a completed run. +- **Agent jobs:** harness agents are recognised by the GitHub Actions job names (`Harness run ()`, matched by suffix; for a built-in stage `Agent ()` or `Coder ()`, or the legacy stage name such as `Triage` from a workflow pinned to an older commit, matched on the job's own name), or by the agent's artifact in a completed run. - **Empty matrix:** a harness run settles as an empty matrix when it completed, its `Harness dispatch` job succeeded, and no `Harness run ()` job was scheduled. The unexpanded matrix job may be skipped or absent: Forgejo replaces a matrix job with its expanded jobs once the matrix is known. #### Managed forgejo-dev stack diff --git a/docs/guides/user/cel-triggers-reference.md b/docs/guides/user/cel-triggers-reference.md index e80cd1574e..6eb26fe79e 100644 --- a/docs/guides/user/cel-triggers-reference.md +++ b/docs/guides/user/cel-triggers-reference.md @@ -43,7 +43,8 @@ GitLab routes agents through its own built-in router and does not evaluate The review, retro, triage and prioritize agents are the exception on GitHub: a `trigger` you set on the agent's entry in `config.yaml` decides -whether the built-in `Review`, `Retro`, `Triage` or `Prioritize` job starts, +whether the built-in agent job starts for it (shown on the pull request as +`Agent (review)`, `Agent (retro)`, `Agent (triage)` or `Agent (prioritize)`), in place of the stage-based rules. A harness `trigger:` field never changes built-in routing; copy it into `config.yaml` to opt in. See [Routing built-in agents with triggers](#routing-built-in-agents-with-triggers). @@ -303,8 +304,8 @@ same-repository pull request is opened, pushed to, marked ready or labeled `ready-for-review`, and on a `/fs-review` comment. To decide it yourself, give the `review` entry in `.fullsend/config.yaml` a `trigger`: a [CEL expression](#writing-cel-triggers) over the event. The review still -runs in the same `Review` job; the trigger only decides whether that job -starts. +runs in the same `Agent (review)` job; the trigger only decides whether that +job starts. #### Example: review only on `/fs-review` @@ -368,8 +369,8 @@ a trigger you keep in a harness, copy the expression into the `review` entry's `trigger` in `config.yaml`. The kill switch and `enabled: false` on the review entry keep working as before. The `Route` job evaluates the trigger with the fullsend CLI built at the dispatch -workflow's commit; if your workflow call pins `fullsend_version`, the `Review` -job runs that version instead. +workflow's commit; if your workflow call pins `fullsend_version`, the +`Agent (review)` job runs that version instead. #### Known differences from the default rules @@ -480,7 +481,7 @@ A trigger decides which events start a retro, not who may start one: The triage and prioritize agents opt in the same way as review: give the `triage` or `prioritize` entry in `.fullsend/config.yaml` a `trigger`, and that trigger, not the dispatch workflow's built-in rules, decides whether the -`Triage` or `Prioritize` job starts. The rules in +`Agent (triage)` or `Agent (prioritize)` job starts. The rules in [What opts a repository in](#what-opts-a-repository-in) apply to both, with `triage` or `prioritize` in place of `review`. Each agent opts in on its own: a `triage` trigger does not change when prioritize runs. To check either trigger diff --git a/docs/guides/user/customizing-agents.md b/docs/guides/user/customizing-agents.md index b5f793ce9a..d389b1a6a9 100644 --- a/docs/guides/user/customizing-agents.md +++ b/docs/guides/user/customizing-agents.md @@ -571,8 +571,8 @@ requests need a `/fs-review` comment), when the `ready-for-review` label is added, and on a `/fs-review` comment. To decide it yourself, give the `review` entry in `.fullsend/config.yaml` a `trigger`: a [CEL expression](cel-triggers-reference.md) over the event. The review still -runs in the same `Review` job; the trigger only decides whether that job -starts. +runs in the same `Agent (review)` job; the trigger only decides whether that +job starts. To stop the automatic review on every pull request but keep `/fs-review`, add this entry to `.fullsend/config.yaml` on your default branch: diff --git a/internal/scaffold/fork_pr_workflow_run_test.go b/internal/scaffold/fork_pr_workflow_run_test.go index 0ba83c6957..c979654c85 100644 --- a/internal/scaffold/fork_pr_workflow_run_test.go +++ b/internal/scaffold/fork_pr_workflow_run_test.go @@ -784,10 +784,10 @@ func TestForkPRWorkflowRunWiring(t *testing.T) { } } assert.Equal(t, "${{ steps.fork-pr.outputs.number }}", route.Outputs["pr_number"]) - for _, job := range []string{"review", "retro"} { - assert.True(t, strings.HasSuffix(wf.Jobs[job].Concurrency.Group, - "${{ github.event.pull_request.number || github.event.issue.number || needs.route.outputs.pr_number }}"), job) - } + // review and retro run in the agent job, whose concurrency group falls + // back to the fork PR number on workflow_run. + assert.True(t, strings.HasSuffix(wf.Jobs["agent"].Concurrency.Group, + "${{ github.event.pull_request.number || github.event.issue.number || needs.route.outputs.pr_number }}"), "agent") assert.Contains(t, wf.Jobs["harness-dispatch"].If, "github.event_name != 'workflow_run'") assert.NotContains(t, wf.Jobs["harness-run"].If, "workflow_run", "a precomputed matrix may come from any event") } diff --git a/internal/scaffold/pr_trigger_test.go b/internal/scaffold/pr_trigger_test.go index 3cd4b46c2e..e20303dfe7 100644 --- a/internal/scaffold/pr_trigger_test.go +++ b/internal/scaffold/pr_trigger_test.go @@ -74,6 +74,7 @@ func checkoutSteps(t *testing.T, content []byte) map[string][]map[string]string Jobs map[string]struct { Steps []struct { Name string `yaml:"name"` + If string `yaml:"if"` Uses string `yaml:"uses"` With map[string]string `yaml:"with"` } `yaml:"steps"` @@ -86,7 +87,7 @@ func checkoutSteps(t *testing.T, content []byte) map[string][]map[string]string if !strings.HasPrefix(step.Uses, "actions/checkout@") { continue } - with := map[string]string{"name": step.Name} + with := map[string]string{"name": step.Name, "if": step.If} for k, v := range step.With { with[k] = v } @@ -103,7 +104,7 @@ func checkoutSteps(t *testing.T, content []byte) map[string][]map[string]string // - the caller repository at the base SHA (or the default branch, which is // what github.ref was on pull_request_target); // - the reusable workflow's repository at trustedWorkflowSHA; -// - the fix job's explicit PR-head checkout, which runs on pull_request_review. +// - the fix stage's explicit PR-head checkout, which runs on pull_request_review. func TestEveryCheckoutHasTrustedRef(t *testing.T) { for _, file := range []string{".github/workflows/reusable-dispatch.yml", ".github/workflows/reusable-prioritize.yml"} { t.Run(file, func(t *testing.T) { @@ -118,7 +119,8 @@ func TestEveryCheckoutHasTrustedRef(t *testing.T) { case repo == "${{ job.workflow_repository }}": assert.Equal(t, "${{ "+trustedWorkflowSHA+" }}", ref, where) case ref == "${{ steps.context.outputs.head_ref }}": - assert.Equal(t, "fix", job, "%s: only the fix job checks out the PR head", where) + assert.Equal(t, "coder", job, "%s: only the fix stage checks out the PR head", where) + assert.Equal(t, "matrix.stage == 'fix'", with["if"], "%s: only the fix stage checks out the PR head", where) case repo == "": assert.Regexp(t, `github\.event_name == 'pull_request'[ )]`, ref, where) assert.Contains(t, ref, "github.event_name == 'pull_request_target'", where) diff --git a/internal/scaffold/workflow_call_alignment_test.go b/internal/scaffold/workflow_call_alignment_test.go index a3582ac62a..489b4f52d3 100644 --- a/internal/scaffold/workflow_call_alignment_test.go +++ b/internal/scaffold/workflow_call_alignment_test.go @@ -14,6 +14,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" + + "github.com/fullsend-ai/fullsend/internal/config" ) // reusableWorkflow represents the workflow_call interface of a reusable workflow. @@ -33,12 +35,8 @@ func TestReviewWorkflowKeepsThreadFetchAgentOwned(t *testing.T) { content, err := os.ReadFile(filepath.Join("..", "..", ".github", "workflows", "reusable-dispatch.yml")) require.NoError(t, err) workflow := string(content) - start := strings.Index(workflow, "\n review:\n") - require.NotEqual(t, -1, start, "review job must be present") - section := workflow[start:] - if end := strings.Index(section, "\n fix:\n"); end != -1 { - section = section[:end] - } + // The review stage runs in the agent job; check its run step. + section := extractStepSection(t, workflow, "Run review agent") assert.Contains(t, section, "FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }}") assert.NotContains(t, section, "HUMAN_RESOLVED_FILE:") @@ -57,11 +55,15 @@ func TestStartupFailureReportingGuards(t *testing.T) { } assert.Contains(t, dispatchText, "Report harness dispatch failure") assert.Contains(t, dispatchText, "steps.dispatch.outcome != 'success'") + runOutcomeRe := regexp.MustCompile(`steps\.run-[a-z]+\.outcome`) + reporters := 0 for _, line := range strings.Split(dispatchText, "\n") { - if strings.Contains(line, "if: ${{ failure()") && strings.Contains(line, "steps.run-agent.outcome") { + if strings.Contains(line, "if: ${{") && strings.Contains(line, "failure()") && runOutcomeRe.MatchString(line) { + reporters++ assert.Contains(t, line, "!cancelled()", "startup failure reporters must not run after cancellation") } } + assert.GreaterOrEqual(t, reporters, 7, "every stage and harness-run must have a startup failure reporter") assert.Contains(t, dispatchText, "id: fork_guard") assert.Contains(t, dispatchText, "id: eligibility") assert.Contains(t, dispatchText, "steps.fork_guard.outputs.policy_skip != 'true'") @@ -182,29 +184,16 @@ var reusableAgentConcurrencyExpectations = map[string]stageConcurrencyExpectatio } var dispatchStageConcurrencyExpectations = map[string]stageConcurrencyExpectation{ - "triage": { - groupPrefix: "fullsend-triage-", - groupMust: []string{"github.repository", "github.event.issue.number", "github.event.pull_request.number"}, - }, - "code": { - groupPrefix: "fullsend-code-", - groupMust: []string{"github.repository", "github.event.issue.number", "github.event.pull_request.number"}, - }, - "review": { - groupPrefix: "fullsend-review-", - groupMust: []string{"github.repository", "github.event.pull_request.number", "github.event.issue.number"}, + // The built-in stages run in two stage-matrix jobs. The group keeps one + // cancel-in-progress group per stage and work item, with the same values + // the former per-stage jobs used (fullsend-{stage}-{repo}-{number}). + "agent": { + groupPrefix: "fullsend-${{ matrix.stage }}-", + groupMust: []string{"github.repository", "github.event.pull_request.number", "github.event.issue.number", "needs.route.outputs.pr_number"}, }, - "fix": { - groupPrefix: "fullsend-fix-", - groupMust: []string{"github.repository", "github.event.pull_request.number", "github.event.issue.number"}, - }, - "retro": { - groupPrefix: "fullsend-retro-", - groupMust: []string{"github.repository", "github.event.pull_request.number", "github.event.issue.number"}, - }, - "prioritize": { - groupPrefix: "fullsend-prioritize-", - groupMust: []string{"github.repository", "github.event.issue.number", "github.event.pull_request.number"}, + "coder": { + groupPrefix: "fullsend-${{ matrix.stage }}-", + groupMust: []string{"github.repository", "github.event.pull_request.number", "github.event.issue.number", "needs.route.outputs.pr_number"}, }, // harness-run pins today's group key. When #7475 changes the key, update // these fragments in the same PR. @@ -485,7 +474,7 @@ func TestReusableDispatchFixInstructionNormalizesCRLF(t *testing.T) { require.NoError(t, yaml.Unmarshal(content, &workflow)) var script string - for _, step := range workflow.Jobs["fix"].Steps { + for _, step := range workflow.Jobs["coder"].Steps { if step.Name == "Extract PR number and context" { script = step.Run break @@ -1089,8 +1078,8 @@ func TestOTELVariableForwarding(t *testing.T) { }) } -// TestReusableDispatchStageConcurrency validates per-role cancel-in-progress groups -// on all stage jobs in reusable-dispatch.yml (#981, #982, ADR 0033). +// TestReusableDispatchStageConcurrency validates per-stage cancel-in-progress +// groups on the stage-matrix jobs in reusable-dispatch.yml (#981, #982, ADR 0033). func TestReusableDispatchStageConcurrency(t *testing.T) { content, err := os.ReadFile(filepath.Join("..", "..", ".github", "workflows", "reusable-dispatch.yml")) require.NoError(t, err) @@ -1128,6 +1117,96 @@ func TestReusableDispatchStageConcurrency(t *testing.T) { } } +// TestReusableDispatchStageMatrixJobs pins how the built-in stages run in +// reusable-dispatch.yml: two stage-matrix jobs whose check names include the +// stage that ran. A static per-stage job (for example one named "Review") is +// skipped on every event that routes elsewhere, and its skipped check +// replaces a running check of the same name on the pull request, which +// GitHub then treats as passing. +func TestReusableDispatchStageMatrixJobs(t *testing.T) { + type matrixJob struct { + Name string `yaml:"name"` + Needs any `yaml:"needs"` + If string `yaml:"if"` + Strategy struct { + // any: harness-run's matrix is a single fromJSON expression. + Matrix any `yaml:"matrix"` + } `yaml:"strategy"` + Permissions map[string]string `yaml:"permissions"` + Steps []struct { + Name string `yaml:"name"` + If string `yaml:"if"` + } `yaml:"steps"` + } + var workflow struct { + Jobs map[string]matrixJob `yaml:"jobs"` + } + content, err := os.ReadFile(filepath.Join("..", "..", ".github", "workflows", "reusable-dispatch.yml")) + require.NoError(t, err) + require.NoError(t, yaml.Unmarshal(content, &workflow)) + + const stageMatrixExpr = `${{ fromJSON(format('{{"stage":[{0}]}}', toJSON(needs.route.outputs.stage))) }}` + stageJobs := map[string][]string{ + "agent": {"triage", "review", "retro", "prioritize"}, + "coder": {"code", "fix"}, + } + var covered []string + for jobName, stages := range stageJobs { + covered = append(covered, stages...) + t.Run(jobName, func(t *testing.T) { + job, ok := workflow.Jobs[jobName] + require.True(t, ok, "job %q must exist", jobName) + want := strings.ToUpper(jobName[:1]) + jobName[1:] + " (${{ matrix.stage }})" + assert.Equal(t, want, job.Name, "the check name must include the stage that ran") + assert.Equal(t, "route", job.Needs) + // A whole-matrix expression is expanded after route finishes. A + // literal matrix whose values hold expressions can be expanded + // when the run is created, before route has an output (the CI + // GitHub emulator does this), losing the routed stage. + matrix, ok := job.Strategy.Matrix.(string) + require.True(t, ok, "job %q must declare its matrix as one expression", jobName) + assert.Equal(t, stageMatrixExpr, matrix, "the matrix must hold exactly the routed stage") + for _, stage := range stages { + assert.True(t, strings.Contains(job.If, "'"+stage+"'") || strings.Contains(job.If, `"`+stage+`"`), + "job %q must run for stage %q: %s", jobName, stage, job.If) + var run string + for _, step := range job.Steps { + if step.Name == "Run "+stage+" agent" { + run = step.If + } + } + assert.Equal(t, "matrix.stage == '"+stage+"'", run, + "the %s agent step must run only for its stage", stage) + } + }) + } + sort.Strings(covered) + builtins := append([]string(nil), config.ValidAgentNames()...) + sort.Strings(builtins) + assert.Equal(t, builtins, covered, "every built-in stage must run in exactly one stage-matrix job") + + // Complete permission maps: job permissions cannot vary per matrix entry, + // so each job's map is the job token of every stage it runs. agent keeps + // the former triage, retro and prioritize scopes (review writes to pull + // requests with its minted token); only code and fix receive + // contents: write and packages: read (ADR 0114). + assert.Equal(t, map[string]string{ + "actions": "write", "contents": "read", "id-token": "write", "issues": "write", + }, workflow.Jobs["agent"].Permissions) + assert.Equal(t, map[string]string{ + "actions": "write", "contents": "write", "id-token": "write", "issues": "write", + "packages": "read", "pull-requests": "write", + }, workflow.Jobs["coder"].Permissions) + + for name, job := range workflow.Jobs { + for _, stage := range config.ValidAgentNames() { + assert.NotEqualf(t, strings.ToUpper(stage[:1])+stage[1:], job.Name, + "job %q has a static stage name; a skipped run of it hides a running one", name) + assert.NotEqualf(t, stage, name, "built-in stages must not run as static per-stage jobs") + } + } +} + // TestReusableAgentWorkflowConcurrency validates agent-scoped cancel-in-progress // groups on reusable stage workflows. Groups use a distinct -agent- prefix so // they do not collide with dispatch/thin-caller groups on workflow_call parents. @@ -1149,9 +1228,12 @@ func TestReusableAgentWorkflowConcurrency(t *testing.T) { assertLiteralTrue(t, wf.Concurrency.CancelInProgress, fmt.Sprintf("reusable-%s.yml should cancel in-progress runs", stage)) - callerExpect := dispatchStageConcurrencyExpectations[stage] - require.NotEmpty(t, callerExpect.groupPrefix, "missing dispatch expectation for %s", stage) - assert.NotEqual(t, callerExpect.groupPrefix, expect.groupPrefix, + // The dispatch stage-matrix job's group is fullsend-{stage}-…; + // expand it for this stage. + callerExpect := dispatchStageConcurrencyExpectations["agent"] + require.NotEmpty(t, callerExpect.groupPrefix, "missing dispatch expectation for the agent job") + callerPrefix := strings.ReplaceAll(callerExpect.groupPrefix, "${{ matrix.stage }}", stage) + assert.NotEqual(t, callerPrefix, expect.groupPrefix, "reusable-%s.yml must use a distinct agent-scoped group prefix", stage) assert.Contains(t, wf.Concurrency.Group, "-agent-", "reusable-%s.yml group must be agent-scoped, not reuse dispatch/thin-caller prefix", stage) @@ -2390,11 +2472,11 @@ func TestTriageAgentStepExportsAppSet(t *testing.T) { const wantExpr = "${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }}" - reviewEnv := agentStepEnv("review", "Run review agent") + reviewEnv := agentStepEnv("agent", "Run review agent") require.Contains(t, reviewEnv, "FULLSEND_APP_SET", "reference: the review job's run step exports FULLSEND_APP_SET") - triageEnv := agentStepEnv("triage", "Run triage agent") + triageEnv := agentStepEnv("agent", "Run triage agent") require.Contains(t, triageEnv, "FULLSEND_APP_SET", `the triage job's "Run triage agent" step must export FULLSEND_APP_SET`) assert.Equal(t, wantExpr, triageEnv["FULLSEND_APP_SET"], diff --git a/pkg/behaviourtest/drivers/ci/forgejoactions/forgejoactions.go b/pkg/behaviourtest/drivers/ci/forgejoactions/forgejoactions.go index 4d987f1942..469bc435f4 100644 --- a/pkg/behaviourtest/drivers/ci/forgejoactions/forgejoactions.go +++ b/pkg/behaviourtest/drivers/ci/forgejoactions/forgejoactions.go @@ -13,9 +13,10 @@ // every artifact is read from the run that uploaded it, by the existing // Fullsend artifact names ("fullsend-", with an optional // ".matrix-" suffix). Agent jobs are recognised by the same job names -// as on GitHub Actions ("Harness run ()" for a custom harness and -// the stage name, e.g. "Triage", for a built-in stage), matched by -// suffix so a reusable-workflow caller prefix does not matter. +// as on GitHub Actions ("Harness run ()" for a custom harness, +// matched by suffix, and "Agent ()", "Coder ()" or the legacy +// stage name such as "Triage" for a built-in stage, matched on the job's own +// name), so a reusable-workflow caller prefix does not matter. // // The driver implements ci.RunLister, ci.EmptyMatrixWaiter, and // ci.AgentArtifactDownloader. It never delegates to the GitHub Actions or @@ -496,23 +497,39 @@ func harnessJobSuffix(agent string) string { return "Harness run (" + agent + ")" } -// builtinRoleJobName returns the job name of a built-in stage ("Triage" -// for "triage"), or "" when agent is not one. -func builtinRoleJobName(agent string) string { - if agent != "" && slices.Contains(config.ValidAgentNames(), agent) { - return strings.ToUpper(agent[:1]) + agent[1:] +// builtinRoleJobNames returns the job names of a run of a built-in stage: +// the stage-matrix name ("Agent (triage)" for "triage", "Coder (code)" for +// "code" and "fix") and the legacy static name ("Triage") that workflows +// pinned to an older commit still use. It returns nil when agent is not a +// built-in stage. See the githubactions driver for the naming. +func builtinRoleJobNames(agent string) []string { + if agent == "" || !slices.Contains(config.ValidAgentNames(), agent) { + return nil + } + legacy := strings.ToUpper(agent[:1]) + agent[1:] + if agent == "code" || agent == "fix" { + return []string{"Coder (" + agent + ")", legacy} + } + return []string{"Agent (" + agent + ")", legacy} +} + +// jobOwnName returns a job name without a reusable-workflow caller prefix +// ("dispatch / Agent (triage)" → "Agent (triage)"). +func jobOwnName(name string) string { + if i := strings.LastIndex(name, " / "); i >= 0 { + return name[i+len(" / "):] } - return "" + return name } // matchingAgentJobs returns every job of agent: its custom-harness matrix // job or its built-in stage job. func matchingAgentJobs(jobs []forge.WorkflowJob, agent string) []forge.WorkflowJob { suffix := harnessJobSuffix(agent) - builtin := builtinRoleJobName(agent) + builtin := builtinRoleJobNames(agent) var out []forge.WorkflowJob for _, j := range jobs { - if strings.HasSuffix(j.Name, suffix) || (builtin != "" && strings.HasSuffix(j.Name, builtin)) { + if strings.HasSuffix(j.Name, suffix) || slices.Contains(builtin, jobOwnName(j.Name)) { out = append(out, j) } } diff --git a/pkg/behaviourtest/drivers/ci/forgejoactions/forgejoactions_test.go b/pkg/behaviourtest/drivers/ci/forgejoactions/forgejoactions_test.go index ea2fa3e682..ca43af8085 100644 --- a/pkg/behaviourtest/drivers/ci/forgejoactions/forgejoactions_test.go +++ b/pkg/behaviourtest/drivers/ci/forgejoactions/forgejoactions_test.go @@ -523,6 +523,43 @@ func TestAgentArtifactNameMatches(t *testing.T) { assert.False(t, agentArtifactNameMatches("fullsend-a.b", "fullsend-a.b")) } +func TestBuiltinRoleJobNames(t *testing.T) { + t.Parallel() + assert.Equal(t, []string{"Agent (triage)", "Triage"}, builtinRoleJobNames("triage")) + assert.Equal(t, []string{"Coder (fix)", "Fix"}, builtinRoleJobNames("fix")) + assert.Nil(t, builtinRoleJobNames("pr-ping")) + assert.Nil(t, builtinRoleJobNames("")) + + jobs := []forge.WorkflowJob{ + {Name: "dispatch / Agent (triage)"}, {Name: "Triage"}, {Name: "dispatch / Agent (review)"}, + {Name: "dispatch / Agent (${{ matrix.stage }})"}, {Name: "dispatch / Retriage"}, {Name: "Harness run (triage)"}, + } + var names []string + for _, j := range matchingAgentJobs(jobs, "triage") { + names = append(names, j.Name) + } + assert.Equal(t, []string{"dispatch / Agent (triage)", "Triage", "Harness run (triage)"}, names) +} + +// TestLegacyBuiltinJobIsAgentEvidence checks the failure and negative +// paths against a workflow pinned to an older commit, whose built-in jobs +// are named after the stage. +func TestLegacyBuiltinJobIsAgentEvidence(t *testing.T) { + t.Parallel() + d, f := newDriver(t) + f.runs = []fakeRun{harnessRun(2, "failure", trigger)} + f.jobs[2] = []fakeJob{{Name: "Code", Status: "failure"}} + run, err := d.WaitForFailedHarnessAgent(ctx, "o", "r", "code", trigger) + require.NoError(t, err) + assert.Equal(t, 2, run.ID) + + f.update(func(f *fakeForgejo) { + f.runs[0].Status = "success" + f.jobs[2] = []fakeJob{{Name: "Triage", Status: "success"}} + }) + require.ErrorContains(t, d.AssertNoHarnessAgentArtifact(ctx, "o", "r", "triage", trigger), `job "Triage" found in workflow run 2`) +} + func harnessRun(id int, status string, created time.Time) fakeRun { return fakeRun{ID: id, Workflow: "fullsend.yaml", Event: "issues", Status: status, Created: created} } @@ -534,7 +571,7 @@ func TestWaitForHarnessAgent(t *testing.T) { t.Parallel() d, f := newDriver(t) f.runs = []fakeRun{harnessRun(1, "success", trigger.Add(-time.Hour)), harnessRun(2, "success", trigger), harnessRun(3, "success", trigger)} - f.jobs[2] = []fakeJob{{Name: "dispatch / Triage", Status: "success"}} + f.jobs[2] = []fakeJob{{Name: "dispatch / Agent (triage)", Status: "success"}} f.jobs[3] = []fakeJob{{Name: "dispatch / Harness run (other)", Status: "success"}} run, err := d.WaitForHarnessAgent(ctx, "o", "r", "triage", trigger) require.NoError(t, err) @@ -617,7 +654,7 @@ func TestWaitForFailedHarnessAgent(t *testing.T) { t.Parallel() d, f := newDriver(t) f.runs = []fakeRun{harnessRun(2, "failure", trigger)} - f.jobs[2] = []fakeJob{{Name: "Code", Status: "failure"}} + f.jobs[2] = []fakeJob{{Name: "Coder (code)", Status: "failure"}} run, err := d.WaitForFailedHarnessAgent(ctx, "o", "r", "code", trigger) require.NoError(t, err) @@ -636,8 +673,8 @@ func TestAssertNoHarnessAgentArtifact(t *testing.T) { t.Parallel() d, f := newDriver(t) f.runs = []fakeRun{harnessRun(1, "success", trigger.Add(-time.Hour)), harnessRun(2, "success", trigger), harnessRun(3, "skipped", trigger)} - f.jobs[1] = []fakeJob{{Name: "Triage", Status: "success"}} - f.jobs[2] = []fakeJob{{Name: "Triage", Status: "skipped"}, {Name: "Harness run (other)", Status: "success"}} + f.jobs[1] = []fakeJob{{Name: "Agent (triage)", Status: "success"}} + f.jobs[2] = []fakeJob{{Name: "Agent (triage)", Status: "skipped"}, {Name: "Harness run (other)", Status: "success"}} require.NoError(t, d.AssertNoHarnessAgentArtifact(ctx, "o", "r", "triage", trigger)) f.update(func(f *fakeForgejo) { diff --git a/pkg/behaviourtest/drivers/ci/githubactions/dispatch_reads_test.go b/pkg/behaviourtest/drivers/ci/githubactions/dispatch_reads_test.go index 7048637f94..bd0f41e364 100644 --- a/pkg/behaviourtest/drivers/ci/githubactions/dispatch_reads_test.go +++ b/pkg/behaviourtest/drivers/ci/githubactions/dispatch_reads_test.go @@ -266,7 +266,7 @@ func TestCountHarnessDispatches_WaitingRunHoldsCompletedAgentJob(t *testing.T) { func TestCountHarnessDispatches_CompletedRunJobsBecomeVisible(t *testing.T) { t.Parallel() after := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) - for _, firstJob := range []string{"dispatch / Route", "dispatch / Harness run (${{ matrix.agent }})", "dispatch / Fix", "dispatch / Harness run (fix)"} { + for _, firstJob := range []string{"dispatch / Route", "dispatch / Harness run (${{ matrix.agent }})", "dispatch / Coder (fix)", "dispatch / Fix", "dispatch / Harness run (fix)"} { t.Run(firstJob, func(t *testing.T) { client := newDispatchReadsClient(after) run := client.WorkflowRunsList["org/repo/fullsend.yaml"][31] diff --git a/pkg/behaviourtest/drivers/ci/githubactions/githubactions.go b/pkg/behaviourtest/drivers/ci/githubactions/githubactions.go index 77a1b7c3d9..822fff4adf 100644 --- a/pkg/behaviourtest/drivers/ci/githubactions/githubactions.go +++ b/pkg/behaviourtest/drivers/ci/githubactions/githubactions.go @@ -1049,35 +1049,119 @@ func harnessJobSuffix(agent string) string { // dispatch job is still computing the matrix, where no such job exists yet. const harnessJobNameMarker = "Harness run (" -// builtinRoleJobName returns the static job name reusable-dispatch.yml -// assigns to one of fullsend's built-in stages (e.g. "Triage", "Code"), -// or "" if agent is not one of config.ValidAgentNames(). Built-in stages -// run as fixed per-role jobs, unlike a user-registered custom harness, -// which runs as a single matrix job named "Harness run ()" -// (harnessJobSuffix). Both forms are prefixed by the caller job id when -// surfaced through the Jobs API (e.g. "dispatch / Triage", "dispatch / -// Harness run (pr-ping)"), so matching uses HasSuffix either way. +// builtinRoleJobName returns the job name reusable-dispatch.yml gives a +// run of one of fullsend's built-in stages, or "" if agent is not one of +// config.ValidAgentNames(). Built-in stages run in two stage-matrix jobs +// named after the stage that ran: "Coder ()" for code and fix, +// "Agent ()" for the others. When no stage is routed the job is +// skipped under its unexpanded placeholder name ("Agent (${{ matrix.stage +// }})"), which never matches. A user-registered custom harness runs as +// "Harness run ()" (harnessJobSuffix). Both forms are prefixed by the +// caller job id when surfaced through the Jobs API (e.g. "dispatch / Agent +// (triage)", "dispatch / Harness run (pr-ping)"). Built-in jobs are matched +// on the job's own name (isBuiltinRoleJob), which also accepts the legacy +// static name (legacyBuiltinRoleJobName). func builtinRoleJobName(agent string) string { for _, name := range config.ValidAgentNames() { if name == agent && agent != "" { - return strings.ToUpper(agent[:1]) + agent[1:] + if agent == "code" || agent == "fix" { + return "Coder (" + agent + ")" + } + return "Agent (" + agent + ")" } } return "" } +// legacyBuiltinRoleJobName returns the static per-stage job name that +// reusable-dispatch.yml used before the stage-matrix jobs (e.g. "Triage"), +// or "" if agent is not a built-in stage. Workflows pinned to an older +// commit still produce these jobs, and every run listed all six of them. +func legacyBuiltinRoleJobName(agent string) string { + if builtinRoleJobName(agent) == "" { + return "" + } + return strings.ToUpper(agent[:1]) + agent[1:] +} + +// builtinStageJobPrefix returns the name prefix of the stage-matrix job that +// runs agent ("Agent (" or "Coder ("), or "" if agent is not a built-in. +func builtinStageJobPrefix(agent string) string { + name := builtinRoleJobName(agent) + if name == "" { + return "" + } + return name[:strings.Index(name, "(")+1] +} + +// jobOwnName returns a job name without the reusable-workflow caller +// prefix the Jobs API adds ("dispatch / Agent (triage)" → "Agent (triage)"). +func jobOwnName(name string) string { + if i := strings.LastIndex(name, " / "); i >= 0 { + return name[i+len(" / "):] + } + return name +} + +// isBuiltinRoleJob reports whether j is agent's built-in stage job under +// its current name or its legacy static name. The job's own name must match +// exactly, so a placeholder or another stage's job never does. +func isBuiltinRoleJob(j forge.WorkflowJob, agent string) bool { + own := jobOwnName(j.Name) + return own != "" && (own == builtinRoleJobName(agent) || own == legacyBuiltinRoleJobName(agent)) +} + +// builtinStageUnresolved reports whether jobs does not yet show whether +// built-in agent was scheduled. Route picks the stage, and only then does +// the stage-matrix job appear: as agent's concrete job, or as the skipped +// placeholder ("Agent (${{ matrix.stage }})") when another or no stage was +// routed. A run of an older workflow lists every legacy static stage job +// from the start, so seeing agent's legacy job settles it as well. For a +// custom harness agent this is always false. +func builtinStageUnresolved(jobs []forge.WorkflowJob, agent string) bool { + prefix := builtinStageJobPrefix(agent) + if prefix == "" { + return false + } + for _, j := range jobs { + own := jobOwnName(j.Name) + switch { + case isBuiltinRoleJob(j, agent): + return false + case strings.HasPrefix(own, prefix) && !strings.Contains(own, "${{"): + // The stage-matrix job expanded into another stage's job. + return false + case strings.HasPrefix(own, prefix) && j.Status == "completed": + // The unexpanded placeholder ended (skipped): Route routed no + // stage of this job. A placeholder that has not completed may + // still be waiting for Route. + return false + } + } + return true +} + +// agentMatrixUnresolved reports whether a run's job list cannot yet show +// whether agent runs in it: its custom-harness matrix has not resolved +// (harnessMatrixUnresolved) or, for a built-in agent, its stage-matrix job +// has not appeared (builtinStageUnresolved). Route and Harness dispatch +// finish independently, so a visible harness row says nothing about the +// built-in stage job, which only appears after Route completes. +func agentMatrixUnresolved(jobs []forge.WorkflowJob, agent string) bool { + return harnessMatrixUnresolved(jobs) || builtinStageUnresolved(jobs, agent) +} + // matchAgentJob reports whether jobs contains the harness job for agent, // returning the matched job when found. agent may name either a // user-registered custom harness (job "Harness run ()") or one of -// the built-in stages (job named after the stage, e.g. "Triage"); both +// the built-in stages (job "Agent ()" or "Coder ()", e.g. +// "Agent (triage)"; builtinRoleJobName); both // forms are checked (#7957). // // A single job list can contain both forms for the same agent name: a -// built-in stage's static job exists on every run but is skipped (or, on -// a concurrency-group cancellation unrelated to whether a same-named -// custom harness matrix job actually ran, cancelled) when that trigger -// did not schedule the stage, while a same-named user-registered custom -// harness runs as a separate matrix job that can actually execute. +// built-in stage's job can end weak (cancelled by its concurrency group, +// for example) independently of a same-named user-registered custom +// harness, which runs as a separate matrix job that can actually execute. // Scanning stops at the first match regardless of its state would let // job-list order alone decide the outcome: a built-in job that already // succeeded could shadow a same-named custom job that is still running or @@ -1136,18 +1220,17 @@ func jobMatchTier(j forge.WorkflowJob) int { // matchingAgentJobs returns every job in jobs whose name matches the // harness job for agent — either a user-registered custom harness job -// ("Harness run ()") or a built-in stage's static job (e.g. -// "Triage") — per matchAgentJob's doc. Unlike matchAgentJob, which +// ("Harness run ()") or a built-in stage's job (e.g. +// "Agent (triage)") — per matchAgentJob's doc. Unlike matchAgentJob, which // collapses the list down to a single representative job for callers // that need one "best" match, this returns every match so a caller that // must not let one weak match (skipped or cancelled) shadow another can // inspect them independently (AssertNoHarnessAgentArtifact, #7996 review). func matchingAgentJobs(jobs []forge.WorkflowJob, agent string) []forge.WorkflowJob { suffix := harnessJobSuffix(agent) - builtinSuffix := builtinRoleJobName(agent) var matches []forge.WorkflowJob for _, j := range jobs { - if strings.HasSuffix(j.Name, suffix) || (builtinSuffix != "" && strings.HasSuffix(j.Name, builtinSuffix)) { + if strings.HasSuffix(j.Name, suffix) || isBuiltinRoleJob(j, agent) { matches = append(matches, j) } } @@ -1156,8 +1239,8 @@ func matchingAgentJobs(jobs []forge.WorkflowJob, agent string) []forge.WorkflowJ // isWeakJobMatch reports whether j is a completed job that was either // skipped (the built-in stage wasn't scheduled for this trigger) or -// cancelled. A built-in static job and a same-named custom harness -// matrix job run in distinct concurrency groups, so the static job's +// cancelled. A built-in stage job and a same-named custom harness +// matrix job run in distinct concurrency groups, so the stage job's // cancellation says nothing about whether the matrix job executed // (#7957 review, fifth pass): matchAgentJob must let a stronger // (pending, successful, or genuinely failed) match found elsewhere in @@ -1168,11 +1251,11 @@ func isWeakJobMatch(j forge.WorkflowJob) bool { } // isBuiltinRoleMatch reports whether job matched agent through its -// built-in stage name (e.g. "Triage", builtinRoleJobName) rather than +// built-in stage job name (e.g. "Agent (triage)", builtinRoleJobName) rather than // through the user-registered custom-harness matrix job name // ("Harness run ()", harnessJobSuffix). The built-in stage and a -// same-named custom harness run in distinct jobs — one static, one a -// matrix entry computed by the independent Harness dispatch job — so the +// same-named custom harness run in distinct jobs — one routed by the route +// job, one a matrix entry computed by the independent Harness dispatch job — so the // built-in job's own conclusion, whatever it is (success, a genuine // failure, or a weak skip/cancel), says nothing about whether a custom // harness job will also appear for this run until the matrix itself @@ -1362,9 +1445,9 @@ func (d *Driver) harnessPollOnce(ctx context.Context, remaining time.Duration, o hasJob, job, err := d.runHasAgentJob(ctx, owner, repo, r.ID, agent) lookupErrs.record(ctx, err) // builtinRoleJobName (#7957) means hasJob is also true for a - // built-in stage's job that exists on every run but was skipped - // for this particular trigger (e.g. the workflow schedules a - // "Fix" job that only runs conditionally). The run's overall + // built-in stage's job that did not run to completion for this + // trigger (e.g. a "Coder (fix)" job cancelled by its concurrency + // group). The run's overall // failure can come entirely from a sibling job in that case, so // only attribute it to agent when agent's own job actually ran // and concluded a real failure. @@ -1425,8 +1508,8 @@ func (d *Driver) WaitForHarnessAgentRound(ctx context.Context, owner, repo, agen // absence from its current job list does not yet rule out scheduling, so a // later, already-resolved run must not be allowed to win selection instead // (#7957 review). The same unresolved-matrix interval also applies when -// matchAgentJob reports a match on a built-in stage job (e.g. "Triage"): -// that static job exists on every run regardless of whether a same-named +// matchAgentJob reports a match on a built-in stage job (e.g. "Agent +// (triage)"): that job is routed independently of whether a same-named // custom harness matrix job will later run on this candidate, so its // conclusion — skipped, cancelled, a success, or a genuine failure — does // not rule out scheduling until either the run terminates or its matrix @@ -1467,7 +1550,7 @@ func (d *Driver) harnessRoundPollOnce(ctx context.Context, remaining time.Durati return nil, false, nil } hasJob, job := matchAgentJob(jobs, agent) - matrixUnresolved := r.Status != "completed" && harnessMatrixUnresolved(jobs) + matrixUnresolved := r.Status != "completed" && agentMatrixUnresolved(jobs, agent) if !hasJob { if matrixUnresolved { // The dispatch job that computes this run's matrix has @@ -1482,8 +1565,8 @@ func (d *Driver) harnessRoundPollOnce(ctx context.Context, remaining time.Durati continue } if matrixUnresolved && (isWeakJobMatch(job) || isBuiltinRoleMatch(job, agent)) { - // matchAgentJob matched a built-in stage's static job — e.g. - // "Triage" — which exists on every run independent of whether + // matchAgentJob matched a built-in stage's job — e.g. + // "Agent (triage)" — which is routed independently of whether // a same-named custom harness matrix job will run on this // candidate. Until the matrix resolves or the run terminates, // that job's conclusion does not rule out scheduling here, @@ -1581,7 +1664,7 @@ func workflowRunNewer(a, b forge.WorkflowRun) bool { // as inconclusive (return true) so the caller keeps polling instead of // fail-fasting on incomplete information. The same inconclusive treatment // applies when the only match is a skipped or cancelled built-in stage job -// (e.g. "Triage") on a still-executing candidate whose matrix has not +// (e.g. "Agent (triage)") on a still-executing candidate whose matrix has not // resolved: a same-named custom harness matrix job can still appear on it // (matchAgentJob doc), so that conclusion alone does not yet rule the // candidate out as superseding (#7957 review, third pass — mirrors @@ -1608,12 +1691,12 @@ func (d *Driver) hasSupersedingAgentRun(ctx context.Context, owner, repo, agent if job.Status != "completed" || job.Conclusion == "success" { return true } - if (isWeakJobMatch(job) || isBuiltinRoleMatch(job, agent)) && other.Status != "completed" && harnessMatrixUnresolved(jobs) { + if (isWeakJobMatch(job) || isBuiltinRoleMatch(job, agent)) && other.Status != "completed" && agentMatrixUnresolved(jobs, agent) { return true } continue } - if other.Status != "completed" && harnessMatrixUnresolved(jobs) { + if other.Status != "completed" && agentMatrixUnresolved(jobs, agent) { return true } } @@ -1628,7 +1711,7 @@ func (d *Driver) hasSupersedingAgentRun(ctx context.Context, owner, repo, agent // Detection is artifact-first: the fullsend action uploads the agent's // artifact with `if: always()`, so it exists for failed // runs too, and it is the only signal that works for both standard stage -// jobs (named e.g. "Code"/"Fix") and custom-harness matrix jobs (named +// jobs (named e.g. "Coder (code)"/"Coder (fix)") and custom-harness matrix jobs (named // "Harness run ()"). The job-name scan is a fallback for // custom-harness runs that failed before uploading the artifact. // @@ -1829,7 +1912,7 @@ func classifyJobsError(status string, err error) jobsReadOutcome { // trigger time into counted dispatches and pending runs. A run is pending // when its agent job exists but has not completed, or when the run itself // is still executing and the agent's job has not appeared yet. It is also -// pending when the only match is a built-in stage job (e.g. "Triage") on a +// pending when the only match is a built-in stage job (e.g. "Agent (triage)") on a // still-executing run whose matrix has not resolved yet, regardless of // that job's conclusion (skipped, cancelled, a success, or a genuine // failure): a same-named custom harness matrix job can still appear on @@ -1890,7 +1973,7 @@ func (d *Driver) settleHarnessDispatchCount(ctx context.Context, owner, repo, ag switch { case hasJob && job.Status != "completed": pending++ - case hasJob && r.Status != "completed" && harnessMatrixUnresolved(jobs) && (isWeakJobMatch(job) || isBuiltinRoleMatch(job, agent)): + case hasJob && r.Status != "completed" && agentMatrixUnresolved(jobs, agent) && (isWeakJobMatch(job) || isBuiltinRoleMatch(job, agent)): pending++ case hasJob && !isConcurrencySuperseded(job.Conclusion): count++ @@ -2068,7 +2151,7 @@ func (d *Driver) AssertNoHarnessAgentArtifact(ctx context.Context, owner, repo, } // Every matching job is inspected independently here, rather than // through matchAgentJob's single "best" match: a job list can - // contain both a skipped built-in stage job (e.g. "Triage") and a + // contain both a skipped built-in stage job (e.g. "Agent (triage)") and a // cancelled same-named custom harness matrix job for the same // agent, and matchAgentJob's tie-break — which treats skipped and // cancelled as equally "weak" for the fail-fast/superseding paths diff --git a/pkg/behaviourtest/drivers/ci/githubactions/githubactions_test.go b/pkg/behaviourtest/drivers/ci/githubactions/githubactions_test.go index 24b8ef417d..af9a3737d9 100644 --- a/pkg/behaviourtest/drivers/ci/githubactions/githubactions_test.go +++ b/pkg/behaviourtest/drivers/ci/githubactions/githubactions_test.go @@ -468,25 +468,32 @@ func TestCountHarnessDispatches_MatchesBuiltinRoleJobName(t *testing.T) { t.Parallel() // Regression (#7957 review): built-in stages (triage, code, review, - // fix, retro, prioritize) run as a fixed per-role job named after the - // stage (e.g. "Triage"), not as a "Harness run ()" matrix job - // — that naming is only used for user-registered custom harnesses. - after := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) - client := forge.NewFakeClient() - client.WorkflowRuns = map[string]*forge.WorkflowRun{ - "org/repo/fullsend.yaml": { - ID: 10, Status: "completed", Conclusion: "success", - CreatedAt: "2026-01-02T00:00:00Z", - }, - } - client.WorkflowRunJobs = map[int][]forge.WorkflowJob{ - 10: {{ID: 1, Name: "dispatch / Triage", Status: "completed", Conclusion: "success"}}, - } + // fix, retro, prioritize) run as a job named after the stage, not as a + // "Harness run ()" matrix job — that naming is only used for + // user-registered custom harnesses. The stage-matrix name ("Agent + // (triage)") and the legacy static name ("Triage") of workflows pinned + // to an older commit both count. + for _, name := range []string{"dispatch / Agent (triage)", "dispatch / Triage"} { + t.Run(name, func(t *testing.T) { + t.Parallel() + after := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) + client := forge.NewFakeClient() + client.WorkflowRuns = map[string]*forge.WorkflowRun{ + "org/repo/fullsend.yaml": { + ID: 10, Status: "completed", Conclusion: "success", + CreatedAt: "2026-01-02T00:00:00Z", + }, + } + client.WorkflowRunJobs = map[int][]forge.WorkflowJob{ + 10: {{ID: 1, Name: name, Status: "completed", Conclusion: "success"}}, + } - d := newTestDriver(client) - count, err := d.CountHarnessDispatches(context.Background(), "org", "repo", "triage", after) - require.NoError(t, err) - assert.Equal(t, 1, count) + d := newTestDriver(client) + count, err := d.CountHarnessDispatches(context.Background(), "org", "repo", "triage", after) + require.NoError(t, err) + assert.Equal(t, 1, count) + }) + } } func TestCountHarnessDispatches_BuiltinRoleJobNameDoesNotMatchOtherAgent(t *testing.T) { @@ -501,7 +508,7 @@ func TestCountHarnessDispatches_BuiltinRoleJobNameDoesNotMatchOtherAgent(t *test }, } client.WorkflowRunJobs = map[int][]forge.WorkflowJob{ - 10: {{ID: 1, Name: "dispatch / Triage", Status: "completed", Conclusion: "success"}}, + 10: {{ID: 1, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "success"}}, } d := newTestDriver(client) @@ -948,6 +955,90 @@ func TestWaitForHarnessAgentRound_RoutePendingBlocksUnrelatedExpandedMatrix(t *t assert.Equal(t, 100, run.ID, "a pending Route job must keep the earliest run authoritative") } +// stageJobLagClient wraps FakeClient so targetRun's first callsLeft job +// listings show a completed Route and an unrelated custom-harness row, but +// not yet the stage-matrix job that Route scheduled, which only appears +// after Route completes. +type stageJobLagClient struct { + *forge.FakeClient + mu sync.Mutex + targetRun int + callsLeft int +} + +func (c *stageJobLagClient) ListWorkflowRunJobs(ctx context.Context, owner, repo string, runID int) ([]forge.WorkflowJob, error) { + if runID == c.targetRun { + c.mu.Lock() + if c.callsLeft > 0 { + c.callsLeft-- + c.mu.Unlock() + return []forge.WorkflowJob{ + {ID: 1, Name: "dispatch / Route", Status: "completed", Conclusion: "success"}, + {ID: 2, Name: "dispatch / Harness run (pr-ping)", Status: "completed", Conclusion: "success"}, + }, nil + } + c.mu.Unlock() + } + return c.FakeClient.ListWorkflowRunJobs(ctx, owner, repo, runID) +} + +func TestWaitForHarnessAgentRound_CompletedRouteWaitsForStageMatrixJob(t *testing.T) { + t.Parallel() + + // Route and Harness dispatch finish independently, and the built-in + // stage-matrix job only appears after Route completes. A completed Route + // plus an unrelated expanded harness row must not settle the earliest + // run as "agent absent" and let a later successful run win this round. + after := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) + fake := forge.NewFakeClient() + fake.WorkflowRunsList = map[string][]forge.WorkflowRun{ + "org/repo/fullsend.yaml": { + {ID: 200, Status: "completed", Conclusion: "success", CreatedAt: "2026-01-02T01:00:00Z"}, + {ID: 100, Status: "in_progress", CreatedAt: "2026-01-02T00:00:00Z"}, + }, + } + fake.WorkflowRunJobs = map[int][]forge.WorkflowJob{ + 100: { + {ID: 1, Name: "dispatch / Route", Status: "completed", Conclusion: "success"}, + {ID: 2, Name: "dispatch / Harness run (pr-ping)", Status: "completed", Conclusion: "success"}, + {ID: 3, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "success"}, + }, + 200: {{ID: 4, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "success"}}, + } + client := &stageJobLagClient{FakeClient: fake, targetRun: 100, callsLeft: 1} + + run, err := newTestDriver(client).WaitForHarnessAgentRound(context.Background(), "org", "repo", "triage", after, nil) + require.NoError(t, err) + require.NotNil(t, run) + assert.Equal(t, 100, run.ID, "the earliest run stays authoritative until its stage-matrix job appears") +} + +func TestBuiltinStageUnresolved(t *testing.T) { + t.Parallel() + + route := forge.WorkflowJob{Name: "dispatch / Route", Status: "completed", Conclusion: "success"} + for _, tc := range []struct { + name string + jobs []forge.WorkflowJob + agent string + want bool + }{ + {"custom harness agent", nil, "pr-ping", false}, + {"no stage job yet", []forge.WorkflowJob{route}, "triage", true}, + {"own stage job", []forge.WorkflowJob{route, {Name: "dispatch / Agent (triage)", Status: "in_progress"}}, "triage", false}, + {"skipped placeholder", []forge.WorkflowJob{route, {Name: "dispatch / Agent (${{ matrix.stage }})", Status: "completed", Conclusion: "skipped"}}, "triage", false}, + {"placeholder not yet completed", []forge.WorkflowJob{route, {Name: "dispatch / Agent (${{ matrix.stage }})", Status: "queued"}}, "triage", true}, + {"other job's placeholder", []forge.WorkflowJob{route, {Name: "dispatch / Coder (${{ matrix.stage }})", Status: "completed", Conclusion: "skipped"}}, "triage", true}, + {"another stage of the same job", []forge.WorkflowJob{route, {Name: "dispatch / Agent (review)", Status: "in_progress"}}, "triage", false}, + {"legacy static job", []forge.WorkflowJob{{Name: "dispatch / Triage", Status: "queued"}}, "triage", false}, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + assert.Equal(t, tc.want, builtinStageUnresolved(tc.jobs, tc.agent)) + }) + } +} + // skippedBuiltinThenMatrixJobsClient wraps FakeClient so ListWorkflowRunJobs // returns only targetRun's skipped built-in stage job (no "Harness run (" // marker, so the matrix is unresolved) for the first callsLeft calls, then @@ -966,7 +1057,7 @@ func (c *skippedBuiltinThenMatrixJobsClient) ListWorkflowRunJobs(ctx context.Con if c.callsLeft > 0 { c.callsLeft-- c.mu.Unlock() - return []forge.WorkflowJob{{ID: 91, Name: "dispatch / Review", Status: "completed", Conclusion: "skipped"}}, nil + return []forge.WorkflowJob{{ID: 91, Name: "dispatch / Agent (review)", Status: "completed", Conclusion: "skipped"}}, nil } c.mu.Unlock() } @@ -991,7 +1082,7 @@ func (c *cancelledBuiltinThenMatrixJobsClient) ListWorkflowRunJobs(ctx context.C if c.callsLeft > 0 { c.callsLeft-- c.mu.Unlock() - return []forge.WorkflowJob{{ID: 91, Name: "dispatch / Review", Status: "completed", Conclusion: "cancelled"}}, nil + return []forge.WorkflowJob{{ID: 91, Name: "dispatch / Agent (review)", Status: "completed", Conclusion: "cancelled"}}, nil } c.mu.Unlock() } @@ -1002,7 +1093,7 @@ func TestWaitForHarnessAgentRound_SkippedBuiltinMatrixUnresolvedWaits(t *testing t.Parallel() // Regression (#7957 review, second pass): run 100 (earliest, - // in_progress) only shows its skipped built-in "Review" stage job on + // in_progress) only shows its skipped built-in "Agent (review)" stage job on // the first poll — the matrix that would carry a same-named custom // harness job has not resolved yet (no "Harness run (" job present). // matchAgentJob reports a match on that skipped built-in job, so the @@ -1021,7 +1112,7 @@ func TestWaitForHarnessAgentRound_SkippedBuiltinMatrixUnresolvedWaits(t *testing } fake.WorkflowRunJobs = map[int][]forge.WorkflowJob{ 100: { - {ID: 91, Name: "dispatch / Review", Status: "completed", Conclusion: "skipped"}, + {ID: 91, Name: "dispatch / Agent (review)", Status: "completed", Conclusion: "skipped"}, {ID: 92, Name: "dispatch / Harness run (review)", Status: "completed", Conclusion: "success"}, }, 200: {{ID: 2, Name: "dispatch / Harness run (review)", Status: "completed", Conclusion: "success"}}, @@ -1038,7 +1129,7 @@ func TestWaitForHarnessAgentRound_SkippedBuiltinMatrixUnresolvedWaits(t *testing // TestWaitForHarnessAgentRound_CancelledBuiltinMatrixUnresolvedWaits is a // regression test for the #7996 review: like the skipped-builtin case // above, run 100 (earliest, in_progress) only shows its cancelled built-in -// "Review" stage job on the first poll — the matrix that would carry a +// "Agent (review)" stage job on the first poll — the matrix that would carry a // same-named custom harness job has not resolved yet. Before the fix, // isConcurrencySuperseded treated the cancelled conclusion as settled // ("continue"), letting the scan fall through to run 200 (later, already @@ -1058,7 +1149,7 @@ func TestWaitForHarnessAgentRound_CancelledBuiltinMatrixUnresolvedWaits(t *testi } fake.WorkflowRunJobs = map[int][]forge.WorkflowJob{ 100: { - {ID: 91, Name: "dispatch / Review", Status: "completed", Conclusion: "cancelled"}, + {ID: 91, Name: "dispatch / Agent (review)", Status: "completed", Conclusion: "cancelled"}, {ID: 92, Name: "dispatch / Harness run (review)", Status: "completed", Conclusion: "success"}, }, 200: {{ID: 2, Name: "dispatch / Harness run (review)", Status: "completed", Conclusion: "success"}}, @@ -1091,7 +1182,7 @@ func (c *successfulBuiltinThenFailedMatrixJobsClient) ListWorkflowRunJobs(ctx co if c.callsLeft > 0 { c.callsLeft-- c.mu.Unlock() - return []forge.WorkflowJob{{ID: 91, Name: "dispatch / Triage", Status: "completed", Conclusion: "success"}}, nil + return []forge.WorkflowJob{{ID: 91, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "success"}}, nil } c.mu.Unlock() } @@ -1101,7 +1192,7 @@ func (c *successfulBuiltinThenFailedMatrixJobsClient) ListWorkflowRunJobs(ctx co // TestWaitForHarnessAgentRound_SuccessfulBuiltinMatrixUnresolvedWaits is a // regression test for the #7996 review (second pass): the unresolved-matrix // guard previously only protected skipped/cancelled matches. Run 100 -// (earliest, in_progress) shows only its successful built-in "Triage" stage +// (earliest, in_progress) shows only its successful built-in "Agent (triage)" stage // job on the first poll — the matrix that would carry a same-named custom // harness job has not resolved yet. Before the fix, a successful built-in // match fell straight through to the `job.Conclusion == "success"` return, @@ -1122,7 +1213,7 @@ func TestWaitForHarnessAgentRound_SuccessfulBuiltinMatrixUnresolvedWaits(t *test } fake.WorkflowRunJobs = map[int][]forge.WorkflowJob{ 100: { - {ID: 91, Name: "dispatch / Triage", Status: "completed", Conclusion: "success"}, + {ID: 91, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "success"}, {ID: 92, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "failure"}, }, } @@ -1159,7 +1250,7 @@ func (c *completedRoutePendingDispatchThenMatrixJobsClient) ListWorkflowRunJobs( c.mu.Unlock() return []forge.WorkflowJob{ {ID: 90, Name: "dispatch / Route", Status: "completed", Conclusion: "success"}, - {ID: 91, Name: "dispatch / Review", Status: "completed", Conclusion: "skipped"}, + {ID: 91, Name: "dispatch / Agent (review)", Status: "completed", Conclusion: "skipped"}, {ID: 93, Name: "dispatch / Harness dispatch", Status: "in_progress"}, }, nil } @@ -1172,7 +1263,7 @@ func (c *completedRoutePendingDispatchThenMatrixJobsClient) ListWorkflowRunJobs( // is a regression test for the #7996 review: Route and Harness dispatch are // independent jobs, and the custom-harness matrix depends on Harness // dispatch, not Route. Run 100 (earliest, in_progress) shows a completed -// Route job, a skipped static "Review" job, and a still-running Harness +// Route job, a skipped "Agent (review)" job, and a still-running Harness // dispatch job on the first poll — the matrix that would carry a same-named // custom harness job has not expanded yet. Before the fix, // harnessMatrixUnresolved treated the completed Route job as proof the @@ -1194,7 +1285,7 @@ func TestWaitForHarnessAgentRound_CompletedRouteStillWaitsForPendingHarnessDispa fake.WorkflowRunJobs = map[int][]forge.WorkflowJob{ 100: { {ID: 90, Name: "dispatch / Route", Status: "completed", Conclusion: "success"}, - {ID: 91, Name: "dispatch / Review", Status: "completed", Conclusion: "skipped"}, + {ID: 91, Name: "dispatch / Agent (review)", Status: "completed", Conclusion: "skipped"}, {ID: 92, Name: "dispatch / Harness run (review)", Status: "completed", Conclusion: "success"}, }, 200: {{ID: 2, Name: "dispatch / Harness run (review)", Status: "completed", Conclusion: "success"}}, @@ -1229,7 +1320,7 @@ func (c *completedProducersNoMatrixThenMatrixJobsClient) ListWorkflowRunJobs(ctx c.mu.Unlock() return []forge.WorkflowJob{ {ID: 90, Name: "dispatch / Route", Status: "completed", Conclusion: "success"}, - {ID: 91, Name: "dispatch / Review", Status: "completed", Conclusion: "skipped"}, + {ID: 91, Name: "dispatch / Agent (review)", Status: "completed", Conclusion: "skipped"}, {ID: 93, Name: "dispatch / Harness dispatch", Status: "completed", Conclusion: "success"}, }, nil } @@ -1260,7 +1351,7 @@ func TestWaitForHarnessAgentRound_CompletedProducersWithoutMatrixStillWait(t *te fake.WorkflowRunJobs = map[int][]forge.WorkflowJob{ 100: { {ID: 90, Name: "dispatch / Route", Status: "completed", Conclusion: "success"}, - {ID: 91, Name: "dispatch / Review", Status: "completed", Conclusion: "skipped"}, + {ID: 91, Name: "dispatch / Agent (review)", Status: "completed", Conclusion: "skipped"}, {ID: 93, Name: "dispatch / Harness dispatch", Status: "completed", Conclusion: "success"}, {ID: 92, Name: "dispatch / Harness run (review)", Status: "completed", Conclusion: "success"}, }, @@ -1764,7 +1855,7 @@ func TestWaitForFailedHarnessAgent_FromRepositoryArtifact(t *testing.T) { after := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) client := forge.NewFakeClient() // The fullsend action uploads the artifact with if: always(), so a - // failed standard-stage run (job named "Fix", not "Harness run + // failed standard-stage run (job named "Coder (fix)", not "Harness run // (fix)") is still resolvable through its artifact. client.RepositoryArtifacts = map[string][]forge.RepositoryArtifact{ "org/repo": { @@ -1778,7 +1869,7 @@ func TestWaitForFailedHarnessAgent_FromRepositoryArtifact(t *testing.T) { }, } client.WorkflowRunJobs = map[int][]forge.WorkflowJob{ - 77: {{ID: 1, Name: "dispatch / Fix", Status: "completed", Conclusion: "failure"}}, + 77: {{ID: 1, Name: "dispatch / Coder (fix)", Status: "completed", Conclusion: "failure"}}, } d := newTestDriver(client) @@ -1882,10 +1973,10 @@ func TestHarnessPollOnce_SkippedBuiltinJobDoesNotTriggerFailFast(t *testing.T) { t.Parallel() // Regression (#7957 review): builtinRoleJobName makes matchAgentJob - // also match a built-in stage's static job name (e.g. "Fix"), which a + // also match a built-in stage's static job name (e.g. "Coder (fix)"), which a // run's job list carries even when that stage was skipped for this // particular trigger. The run's overall "failure" here comes entirely - // from a sibling "Code" job; the "fix" agent's own job never ran, so + // from a sibling "Coder (code)" job; the "fix" agent's own job never ran, so // it must not be fail-fasted. after := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) client := forge.NewFakeClient() @@ -1898,8 +1989,8 @@ func TestHarnessPollOnce_SkippedBuiltinJobDoesNotTriggerFailFast(t *testing.T) { } client.WorkflowRunJobs = map[int][]forge.WorkflowJob{ 55: { - {ID: 1, Name: "dispatch / Code", Status: "completed", Conclusion: "failure"}, - {ID: 2, Name: "dispatch / Fix", Status: "completed", Conclusion: "skipped"}, + {ID: 1, Name: "dispatch / Coder (code)", Status: "completed", Conclusion: "failure"}, + {ID: 2, Name: "dispatch / Coder (fix)", Status: "completed", Conclusion: "skipped"}, }, } @@ -1947,7 +2038,7 @@ func TestWaitForHarnessAgent_SiblingRunFailureIgnored(t *testing.T) { client.WorkflowRunJobs = map[int][]forge.WorkflowJob{ 100: { {ID: 1, Name: "dispatch / Route", Status: "completed", Conclusion: "success"}, - {ID: 2, Name: "dispatch / Review", Status: "completed", Conclusion: "failure"}, + {ID: 2, Name: "dispatch / Agent (review)", Status: "completed", Conclusion: "failure"}, }, 200: { {ID: 3, Name: "dispatch / Route", Status: "completed", Conclusion: "success"}, @@ -2723,6 +2814,9 @@ func TestWaitForHarnessAgent_NewerSiblingWithoutAgentJobDoesNotSuppressFailFast( 100: {{ID: 1, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "failure"}}, 200: { {ID: 2, Name: "dispatch / Route", Status: "completed", Conclusion: "success"}, + // The stage-matrix job was skipped (route chose no built-in + // stage), so it shows its unexpanded placeholder name. + {ID: 4, Name: "dispatch / Agent (${{ matrix.stage }})", Status: "completed", Conclusion: "skipped"}, {ID: 3, Name: "dispatch / Harness run (review)", Status: "in_progress"}, }, } @@ -2950,7 +3044,7 @@ func TestCountHarnessDispatches_SkippedBuiltinMatchOnUnresolvedMatrixSettles(t * t.Parallel() // Regression (#7957 review, third pass): run 10 exposes only its - // skipped static "Triage" job while its matrix is still unresolved (no + // skipped "Agent (triage)" job while its matrix is still unresolved (no // "Harness run (" job yet) and the run itself has not terminated. // matchAgentJob reports that skipped job as a match, so without the // guard this run was silently classified as neither pending nor @@ -2968,9 +3062,9 @@ func TestCountHarnessDispatches_SkippedBuiltinMatchOnUnresolvedMatrixSettles(t * FakeClient: fake, settleRun: 10, callsLeft: 1, - beforeJobs: []forge.WorkflowJob{{ID: 1, Name: "dispatch / Triage", Status: "completed", Conclusion: "skipped"}}, + beforeJobs: []forge.WorkflowJob{{ID: 1, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "skipped"}}, afterJobs: []forge.WorkflowJob{ - {ID: 1, Name: "dispatch / Triage", Status: "completed", Conclusion: "skipped"}, + {ID: 1, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "skipped"}, {ID: 2, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "success"}, }, } @@ -2983,7 +3077,7 @@ func TestCountHarnessDispatches_SkippedBuiltinMatchOnUnresolvedMatrixSettles(t * // TestCountHarnessDispatches_CancelledBuiltinMatchOnUnresolvedMatrixSettles // is a regression test for the #7996 review: like the skipped-builtin case -// above, run 10 exposes only its cancelled static "Triage" job while its +// above, run 10 exposes only its cancelled "Agent (triage)" job while its // matrix is still unresolved (no "Harness run (" job yet) and the run // itself has not terminated. Before the fix, settleHarnessDispatchCount's // unresolved-matrix guard only matched a "skipped" conclusion, so this @@ -3006,9 +3100,9 @@ func TestCountHarnessDispatches_CancelledBuiltinMatchOnUnresolvedMatrixSettles(t FakeClient: fake, settleRun: 10, callsLeft: 1, - beforeJobs: []forge.WorkflowJob{{ID: 1, Name: "dispatch / Triage", Status: "completed", Conclusion: "cancelled"}}, + beforeJobs: []forge.WorkflowJob{{ID: 1, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "cancelled"}}, afterJobs: []forge.WorkflowJob{ - {ID: 1, Name: "dispatch / Triage", Status: "completed", Conclusion: "cancelled"}, + {ID: 1, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "cancelled"}, {ID: 2, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "success"}, }, } @@ -3023,7 +3117,7 @@ func TestCountHarnessDispatches_CancelledBuiltinMatchOnUnresolvedMatrixSettles(t // a regression test for the #7996 review (second pass): the // unresolved-matrix guard previously only classified a weak (skipped or // cancelled) built-in match as pending. A successful (or genuinely failed) -// built-in match — e.g. a completed "Triage" job — on a still-executing run +// built-in match — e.g. a completed "Agent (triage)" job — on a still-executing run // whose matrix has not resolved yet (no "Harness run (" job and no "Route" // job present) was counted immediately instead, before the independent // Harness dispatch job had a chance to expand a same-named custom harness @@ -3040,7 +3134,7 @@ func TestSettleHarnessDispatchCount_SuccessfulBuiltinMatrixUnresolvedPending(t * }, } fake.WorkflowRunJobs = map[int][]forge.WorkflowJob{ - 10: {{ID: 1, Name: "dispatch / Triage", Status: "completed", Conclusion: "success"}}, + 10: {{ID: 1, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "success"}}, } d := &Driver{Client: fake} @@ -3198,7 +3292,7 @@ func TestHasSupersedingAgentRun(t *testing.T) { CreatedAt: "2026-01-02T00:07:00Z", } // Still executing, and the only match so far is the skipped static - // "Triage" job — present on every run regardless of whether a + // "Agent (triage)" job — present on every run regardless of whether a // same-named custom harness matrix job will still appear. The matrix // has not resolved (no "Harness run (" job yet), so this skipped // match alone must not rule the run out as superseding (#7957 @@ -3218,7 +3312,7 @@ func TestHasSupersedingAgentRun(t *testing.T) { } // Still executing, and the only match so far is a completed failed - // built-in "Triage" job. Its matrix has not resolved, so a same-named + // built-in "Agent (triage)" job. Its matrix has not resolved, so a same-named // custom harness matrix job can still appear; the built-in failure // alone must not rule the run out as superseding (#7996 review). newerFailedBuiltinUnexpanded := forge.WorkflowRun{ @@ -3229,12 +3323,16 @@ func TestHasSupersedingAgentRun(t *testing.T) { client := forge.NewFakeClient() client.WorkflowRunJobs = map[int][]forge.WorkflowJob{ 100: {{ID: 1, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "failure"}}, - 209: {{ID: 12, Name: "dispatch / Triage", Status: "completed", Conclusion: "failure"}}, + 209: {{ID: 12, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "failure"}}, 200: {{ID: 2, Name: "dispatch / Harness run (triage)", Status: "in_progress"}}, 201: {{ID: 3, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "success"}}, 202: {{ID: 4, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "failure"}}, 50: {{ID: 5, Name: "dispatch / Harness run (triage)", Status: "in_progress"}}, - 203: {{ID: 6, Name: "dispatch / Harness run (review)", Status: "in_progress"}}, + 203: { + {ID: 6, Name: "dispatch / Harness run (review)", Status: "in_progress"}, + // Skipped stage-matrix job: route chose no built-in stage. + {ID: 13, Name: "dispatch / Agent (${{ matrix.stage }})", Status: "completed", Conclusion: "skipped"}, + }, // Matrix not expanded yet: only the dispatch job that computes // the matrix has appeared so far. 204: {{ID: 7, Name: "dispatch / Route", Status: "in_progress"}}, @@ -3244,8 +3342,8 @@ func TestHasSupersedingAgentRun(t *testing.T) { {ID: 8, Name: "dispatch / Harness run (other-agent)", Status: "completed", Conclusion: "success"}, {ID: 9, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "skipped"}, }, - 207: {{ID: 10, Name: "dispatch / Triage", Status: "completed", Conclusion: "skipped"}}, - 208: {{ID: 11, Name: "dispatch / Triage", Status: "completed", Conclusion: "cancelled"}}, + 207: {{ID: 10, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "skipped"}}, + 208: {{ID: 11, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "cancelled"}}, } d := newTestDriver(client) var lookupErrs pollErrors @@ -3333,11 +3431,39 @@ func TestAssertNoHarnessAgentArtifact_DetectsAgentJob(t *testing.T) { assert.Contains(t, err.Error(), `expected harness "triage" not to run`) } +// TestAssertNoHarnessAgentArtifact_DetectsBuiltinJob checks that a +// built-in stage job that ran is evidence the agent ran, under both the +// stage-matrix name and the legacy static name of older workflows. +func TestAssertNoHarnessAgentArtifact_DetectsBuiltinJob(t *testing.T) { + t.Parallel() + + for _, name := range []string{"dispatch / Agent (triage)", "dispatch / Triage"} { + t.Run(name, func(t *testing.T) { + t.Parallel() + after := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) + client := forge.NewFakeClient() + client.WorkflowRuns = map[string]*forge.WorkflowRun{ + "org/repo/fullsend.yaml": { + ID: 10, Status: "completed", Conclusion: "success", + CreatedAt: "2026-01-02T00:00:00Z", + }, + } + client.WorkflowRunJobs = map[int][]forge.WorkflowJob{ + 10: {{ID: 1, Name: name, Status: "completed", Conclusion: "success"}}, + } + + err := newTestDriver(client).AssertNoHarnessAgentArtifact(context.Background(), "org", "repo", "triage", after) + require.Error(t, err) + assert.Contains(t, err.Error(), `expected harness "triage" not to run`) + }) + } +} + func TestAssertNoHarnessAgentArtifact_SkippedBuiltinJobIsNotEvidence(t *testing.T) { t.Parallel() // Regression (#7957 review): builtinRoleJobName makes matchAgentJob - // also match a built-in stage's static job name (e.g. "Fix"), which + // also match a built-in stage's static job name (e.g. "Coder (fix)"), which // is present on every run's job list but skipped for a trigger that // never reached that stage. A skipped job must not count as evidence // the agent ran. @@ -3350,7 +3476,7 @@ func TestAssertNoHarnessAgentArtifact_SkippedBuiltinJobIsNotEvidence(t *testing. }, } client.WorkflowRunJobs = map[int][]forge.WorkflowJob{ - 10: {{ID: 1, Name: "dispatch / Fix", Status: "completed", Conclusion: "skipped"}}, + 10: {{ID: 1, Name: "dispatch / Coder (fix)", Status: "completed", Conclusion: "skipped"}}, } d := newTestDriver(client) @@ -3424,7 +3550,7 @@ func TestAssertNoHarnessAgentArtifact_JobsAPIError(t *testing.T) { // TestAssertNoHarnessAgentArtifact_SkippedThenCancelledOrderIndependent is a // regression test for the #7996 review: a job list can contain both a -// skipped built-in stage job (e.g. "Triage") and a cancelled same-named +// skipped built-in stage job (e.g. "Agent (triage)") and a cancelled same-named // custom harness matrix job ("Harness run (triage)") for the same run. // matchAgentJob's single "best" match keeps whichever of the two weak // (skipped/cancelled) jobs it saw first, so before the fix a skipped match @@ -3435,7 +3561,7 @@ func TestAssertNoHarnessAgentArtifact_SkippedThenCancelledOrderIndependent(t *te t.Parallel() after := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) - skipped := forge.WorkflowJob{ID: 1, Name: "dispatch / Triage", Status: "completed", Conclusion: "skipped"} + skipped := forge.WorkflowJob{ID: 1, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "skipped"} cancelled := forge.WorkflowJob{ID: 2, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "cancelled"} t.Run("skipped listed before cancelled", func(t *testing.T) { @@ -3483,21 +3609,45 @@ func TestHarnessJobSuffix(t *testing.T) { func TestBuiltinRoleJobName(t *testing.T) { t.Parallel() - assert.Equal(t, "Triage", builtinRoleJobName("triage")) - assert.Equal(t, "Code", builtinRoleJobName("code")) - assert.Equal(t, "Review", builtinRoleJobName("review")) - assert.Equal(t, "Fix", builtinRoleJobName("fix")) - assert.Equal(t, "Retro", builtinRoleJobName("retro")) - assert.Equal(t, "Prioritize", builtinRoleJobName("prioritize")) + assert.Equal(t, "Agent (triage)", builtinRoleJobName("triage")) + assert.Equal(t, "Coder (code)", builtinRoleJobName("code")) + assert.Equal(t, "Agent (review)", builtinRoleJobName("review")) + assert.Equal(t, "Coder (fix)", builtinRoleJobName("fix")) + assert.Equal(t, "Agent (retro)", builtinRoleJobName("retro")) + assert.Equal(t, "Agent (prioritize)", builtinRoleJobName("prioritize")) assert.Empty(t, builtinRoleJobName("pr-ping"), "custom harness names are not built-in roles") assert.Empty(t, builtinRoleJobName("")) + assert.Equal(t, "Triage", legacyBuiltinRoleJobName("triage")) + assert.Equal(t, "Fix", legacyBuiltinRoleJobName("fix")) + assert.Empty(t, legacyBuiltinRoleJobName("pr-ping")) + + // Workflows pinned to an older commit name built-in jobs after the stage. + for _, name := range []string{"dispatch / Agent (triage)", "dispatch / Triage", "Triage"} { + found, _ := matchAgentJob([]forge.WorkflowJob{{ID: 1, Name: name, Status: "completed", Conclusion: "success"}}, "triage") + assert.True(t, found, "%q is a triage job", name) + } + for _, name := range []string{"dispatch / Agent (review)", "dispatch / Coder (fix)", "dispatch / Prefix", "dispatch / Retriage"} { + found, _ := matchAgentJob([]forge.WorkflowJob{{ID: 1, Name: name, Status: "completed", Conclusion: "success"}}, "triage") + assert.False(t, found, "%q is not a triage job", name) + } + + // A run that routes no stage skips the stage-matrix jobs under their + // unexpanded placeholder names, which are not a run of any stage. + placeholders := []forge.WorkflowJob{ + {ID: 1, Name: "dispatch / Agent (${{ matrix.stage }})", Status: "completed", Conclusion: "skipped"}, + {ID: 2, Name: "dispatch / Coder (${{ matrix.stage }})", Status: "completed", Conclusion: "skipped"}, + } + for _, stage := range []string{"triage", "code", "review", "fix", "retro", "prioritize"} { + found, _ := matchAgentJob(placeholders, stage) + assert.False(t, found, "a skipped placeholder must not match stage %q", stage) + } } func TestMatchAgentJob_BuiltinRoleAndCustomHarness(t *testing.T) { t.Parallel() jobs := []forge.WorkflowJob{ - {ID: 1, Name: "dispatch / Triage"}, + {ID: 1, Name: "dispatch / Agent (triage)"}, {ID: 2, Name: "dispatch / Harness run (pr-ping)"}, } @@ -3514,7 +3664,7 @@ func TestMatchAgentJob_BuiltinRoleAndCustomHarness(t *testing.T) { } // TestMatchAgentJob_PrefersExecutedOverSkipped is a regression test for -// the #7957 review: a skipped built-in stage job (e.g. a static "Triage" +// the #7957 review: a skipped built-in stage job (e.g. a "Agent (triage)" // job present on every run but skipped for this trigger) must not shadow // a same-named, actually-executed matrix job ("Harness run (triage)") // just because it appears first in the job list. Both listing orders are @@ -3522,7 +3672,7 @@ func TestMatchAgentJob_BuiltinRoleAndCustomHarness(t *testing.T) { func TestMatchAgentJob_PrefersExecutedOverSkipped(t *testing.T) { t.Parallel() - skipped := forge.WorkflowJob{ID: 1, Name: "dispatch / Triage", Status: "completed", Conclusion: "skipped"} + skipped := forge.WorkflowJob{ID: 1, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "skipped"} executed := forge.WorkflowJob{ID: 2, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "success"} t.Run("skipped listed before executed", func(t *testing.T) { @@ -3560,7 +3710,7 @@ func TestMatchAgentJob_PrefersExecutedOverSkipped(t *testing.T) { // TestMatchAgentJob_PrefersExecutedOverCancelled is a regression test for // the #7957 review, fifth pass: a cancelled built-in stage job (e.g. a -// static "Triage" job cancelled by its own concurrency group) must not +// "Agent (triage)" job cancelled by its own concurrency group) must not // shadow a same-named, actually-executed or still-pending matrix job // ("Harness run (triage)") just because it appears first in the job // list, the same way a skipped static job was already prevented from @@ -3571,7 +3721,7 @@ func TestMatchAgentJob_PrefersExecutedOverSkipped(t *testing.T) { func TestMatchAgentJob_PrefersExecutedOverCancelled(t *testing.T) { t.Parallel() - cancelled := forge.WorkflowJob{ID: 1, Name: "dispatch / Triage", Status: "completed", Conclusion: "cancelled"} + cancelled := forge.WorkflowJob{ID: 1, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "cancelled"} executed := forge.WorkflowJob{ID: 2, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "success"} t.Run("cancelled listed before executed", func(t *testing.T) { @@ -3619,7 +3769,7 @@ func TestMatchAgentJob_PrefersExecutedOverCancelled(t *testing.T) { func TestMatchAgentJob_PendingAndFailureOutrankSuccess(t *testing.T) { t.Parallel() - builtinSuccess := forge.WorkflowJob{ID: 1, Name: "dispatch / Triage", Status: "completed", Conclusion: "success"} + builtinSuccess := forge.WorkflowJob{ID: 1, Name: "dispatch / Agent (triage)", Status: "completed", Conclusion: "success"} customPending := forge.WorkflowJob{ID: 2, Name: "dispatch / Harness run (triage)", Status: "in_progress"} customFailed := forge.WorkflowJob{ID: 3, Name: "dispatch / Harness run (triage)", Status: "completed", Conclusion: "failure"}