From 76ae5f799c9409ccfb04e4cbef864b1fc558456f Mon Sep 17 00:00:00 2001 From: Jesper Terkelsen Date: Thu, 12 Nov 2026 00:35:43 +0100 Subject: [PATCH] perf(argocd-wait-sync-multi): refresh and poll apps in parallel The initial refresh and every poll ran `argocd app get` once per app, sequentially (~2.6s each). For monorepo-typescript's 18-app deploys the refresh took ~47s before the first poll and each poll sweep 15-25s, so the recorded per-app `end` was late by up to a sweep. Both now background each app's call and `wait`; the state machine reads the fetched status from a temp dir and is otherwise unchanged. With a 1s fake argocd and 10 healthy apps the script runs in 3s instead of 23s. Co-Authored-By: Claude Opus 5.5 (1M context) --- .github/actions/argocd-wait-sync-multi/README.md | 7 +++++-- .../argocd-wait-sync-multi/wait-sync-multi.sh | 16 ++++++++++++++-- CLAUDE.md | 3 +++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/actions/argocd-wait-sync-multi/README.md b/.github/actions/argocd-wait-sync-multi/README.md index 8fe75494..e0126d88 100644 --- a/.github/actions/argocd-wait-sync-multi/README.md +++ b/.github/actions/argocd-wait-sync-multi/README.md @@ -73,8 +73,11 @@ commit — the same for every app in the run). from your revision — or when the overall `timeout` elapses with any app not yet healthy. Transient `Unknown` (≤30s) and `ComparisonError` (≤60s, with a hard refresh) are tolerated. -- **Refresh first**: every app is refreshed up front so ArgoCD detects the new - revision immediately instead of on its next reconciliation. +- **Refresh first**: every app is refreshed up front, in parallel, so ArgoCD + detects the new revision immediately instead of on its next reconciliation. +- **Parallel polls**: each poll fetches every unfinished app's status in + parallel, so an app's `end` is accurate to one `poll-interval` however many + apps are waited on. - **Supersede-aware**: if a newer bump moved an app past your revision, the action confirms your commit is an ancestor (`compare … = ahead`) and treats it as success (bundled). diff --git a/.github/actions/argocd-wait-sync-multi/wait-sync-multi.sh b/.github/actions/argocd-wait-sync-multi/wait-sync-multi.sh index 4ae6918c..582e7850 100755 --- a/.github/actions/argocd-wait-sync-multi/wait-sync-multi.sh +++ b/.github/actions/argocd-wait-sync-multi/wait-sync-multi.sh @@ -85,6 +85,9 @@ done < <(echo "$APPS_JSON" | jq -r '.[] | [.app, .revision, (.name // .app)] | @ N=${#APP_NAMES[@]} +INFO_DIR=$(mktemp -d) +trap 'rm -rf "$INFO_DIR"' EXIT + # Per-app state. STATE ∈ pending | started | done STATE=() START_AT=() # ArgoCD operationState.startedAt (ISO) @@ -168,8 +171,9 @@ fail_out() { echo "Triggering ArgoCD refresh on all apps..." for ((i = 0; i < N; i++)); do - refresh_app "${APP_NAMES[$i]}" + refresh_app "${APP_NAMES[$i]}" & done +wait echo "" # --- main concurrent poll loop ---------------------------------------------- @@ -188,6 +192,14 @@ while true; do ALL_DONE=true + # Fetched in parallel so each app's END_AT is accurate to one poll interval, + # not to a sequential sweep over every app. + for ((i = 0; i < N; i++)); do + [ "${STATE[$i]}" = "done" ] && continue + get_app_info "${APP_NAMES[$i]}" > "$INFO_DIR/$i.json" & + done + wait + for ((i = 0; i < N; i++)); do [ "${STATE[$i]}" = "done" ] && continue ALL_DONE=false @@ -196,7 +208,7 @@ while true; do expected="${EXPECTED_REVS[$i]}" display="${DISPLAY_NAMES[$i]}" - info=$(get_app_info "$app") + info=$(cat "$INFO_DIR/$i.json") sync_status=$(echo "$info" | jq -r '.status.sync.status // "Unknown"') health_status=$(echo "$info" | jq -r '.status.health.status // "Unknown"') op_phase=$(echo "$info" | jq -r '.status.operationState.phase // ""') diff --git a/CLAUDE.md b/CLAUDE.md index 750e6f29..b8a76afd 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -5,6 +5,9 @@ - **Latest SHA**: 84fb68d (check for newer commits) - **Changes**: new `pnpm-dependency-submission.yml` and `pnpm-dependency-graph` action for pnpm 12 lockfiles +## Recent Changes (2026-11-12) +1. **`argocd-wait-sync-multi` refreshes and polls apps in parallel**: the initial refresh and each poll ran `argocd app get` once per app, one after another (~2.6 s each). With monorepo-typescript's 18 apps the refresh took ~47 s before the first poll, and a poll sweep 15-25 s, so an app's `end` was late by up to a sweep. Both now run every app's call in the background and `wait`; the per-app state machine then reads the fetched status from a temp dir, unchanged. Against a 1 s fake `argocd` with 10 already-healthy apps the script went from 23 s to 3 s. Offline tests unchanged and passing. + ## Recent Changes (2026-11-09) 1. **Recovery pull request after a failed Terraform apply**: `terraform-stack.yml` takes an optional `recovery-token` secret. When an apply fails, it pushes `terraform-recover/` with the failed run's URL in `/recover.tf` and opens a draft pull request, so the leftover gets a normal reviewed plan and applies on merge. `command: recover` plans and applies unreviewed, which is what this replaces (monta-app/terraform#440). The branch is cut from the default branch only when no recovery pull request is open; otherwise the file is updated on the open one, so a fix pushed there is never reset. Commits go through the contents API, so no git credentials are needed on the runner. The token cannot be `GITHUB_TOKEN`: pull requests it opens never trigger workflows. Any successful apply of the stack closes the open recovery pull request. A missing reviewed plan fails before the apply step and still needs `recover`.