diff --git a/internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml b/internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml index a2c7164cc4..f47dfd4e2d 100644 --- a/internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml +++ b/internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml @@ -1,4 +1,4 @@ -# lint-workflow-size: max-lines=390 +# lint-workflow-size: max-lines=415 # Dispatcher workflow that routes events to agent workflows based on stage. # Routing logic determines the stage from event context — the shim only # forwards the raw event. Adding a new stage requires only a case branch @@ -324,6 +324,29 @@ jobs: comment: (.comment // null | if . then {body: .body[:4096]} else null end) }' "$GITHUB_EVENT_PATH") + # Deduplicate retro dispatches — if a retro workflow run is + # already queued or in-progress for the same source repo + PR, + # skip this dispatch. Multiple shim runs for the same PR close + # event each call dispatch independently; this check prevents + # all but the first from launching a redundant retro run. + if [[ "$STAGE" == "retro" ]]; then + RETRO_PR=$(echo "$EVENT_PAYLOAD" | jq -r '(.pull_request.number // .issue.number) | tostring') + if [[ -n "$RETRO_PR" && "$RETRO_PR" != "null" ]]; then + ACTIVE_IDS=$(gh api "repos/${DISPATCH_REPO}/actions/workflows/retro.yml/runs?per_page=10" \ + --jq '[.workflow_runs[] | select(.status == "queued" or .status == "in_progress") | .id] | .[]' 2>/dev/null || true) + for rid in $ACTIVE_IDS; do + RUN_INPUTS=$(gh api "repos/${DISPATCH_REPO}/actions/runs/${rid}" --jq '.inputs' 2>/dev/null || echo '{}') + RUN_SRC=$(echo "$RUN_INPUTS" | jq -r '.source_repo // empty') + RUN_PR=$(echo "$RUN_INPUTS" | jq -r '.event_payload' 2>/dev/null \ + | jq -r '(.pull_request.number // .issue.number) | tostring' 2>/dev/null || true) + if [[ "$RUN_SRC" == "$SOURCE_REPO" && "$RUN_PR" == "$RETRO_PR" ]]; then + echo "::notice::Retro already active for ${SOURCE_REPO}#${RETRO_PR} (run ${rid}) — skipping duplicate dispatch" + exit 0 + fi + done + fi + fi + echo "Scanning for workflows with stage: $STAGE" dispatched=0