Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{"ts":"2026-11-30T16:00:28.237Z","reviewId":"address-2320","id":"f1","signature":"74a10e299fb7","agent":"code-review","category":"correctness","severity":7,"file":".github/workflows/stage-smoke-test.yml","message":"Workflow-level concurrency with cancel-in-progress lets a skipped or failed Update staging run cancel a real smoke test in progress. The new run then skips its own job, so the new staging build is never checked and no failure email goes out.","outcome":"accepted"}
{"ts":"2026-11-30T16:00:28.238Z","reviewId":"address-2320","id":"f2","signature":"607d24de024a","agent":"testing","category":"determinism","severity":4,"file":"scripts/stage-smoke-test.sh","message":"`curl ... | grep -q` under `set -o pipefail` can report failure even when grep matched, because grep -q exits early and curl may die with exit 23 (SIGPIPE/write error). The same pattern is used for the Okta and GraphQL checks, so the smoke test can flake red or time out after 40 minutes on a healthy deploy.","outcome":"accepted"}
{"ts":"2026-11-30T16:00:28.238Z","reviewId":"address-2320","id":"f3","signature":"9b3b55d34e90","agent":"code-review","category":"correctness","severity":4,"file":"scripts/stage-smoke-test.sh","message":"No curl call sets a timeout, so a hung connection runs into the 45-minute job timeout instead of the script's own error message.","outcome":"accepted"}
{"ts":"2026-11-30T16:00:28.238Z","reviewId":"address-2320","id":"f5","signature":"fd774164337c","agent":"code-review","category":"correctness","severity":4,"file":"scripts/stage-smoke-test.sh","message":"The Sign In check greps case-insensitively for 'sign in', which also matches help text, so it passes even if the button is gone.","outcome":"accepted"}
{"ts":"2026-11-30T16:00:28.238Z","reviewId":"address-2320","id":"f6","signature":"fc6b4aa71c5f","agent":"security","category":"supply-chain-ci","severity":3,"file":".github/workflows/stage-smoke-test.yml","message":"The workflow has no `permissions:` block, so the GITHUB_TOKEN gets the repo default scope, which may be write. The job only needs to read the repo.","outcome":"accepted"}
{"ts":"2026-11-30T16:00:28.238Z","reviewId":"address-2320","id":"f7","signature":"98b64c25f95a","agent":"code-review","category":"security","severity":3,"file":".github/workflows/stage-smoke-test.yml","message":"The workflow has no permissions block, so it gets the default token scope though it only reads.","outcome":"accepted"}
{"ts":"2026-11-30T16:00:28.238Z","reviewId":"address-2320","id":"f8","signature":"d2d88a145952","agent":"code-review","category":"correctness","severity":3,"file":".github/workflows/stage-smoke-test.yml","message":"A git ls-remote failure inside the echo is swallowed, so the next step fails with a misleading 'commit sha required' message.","outcome":"accepted"}
{"ts":"2026-11-30T16:00:28.238Z","reviewId":"address-2320","id":"f10","signature":"f05ff3ccc280","agent":"code-review","category":"correctness","severity":3,"file":"scripts/stage-smoke-test.sh","message":"Page checks run on a second /login fetch that is not verified to be the new build.","outcome":"accepted"}
{"ts":"2026-11-30T16:00:28.238Z","reviewId":"address-2320","id":"f11","signature":"a066efd6ac71","agent":"code-review","category":"correctness","severity":3,"file":"scripts/stage-smoke-test.sh","message":"If the manifest is missing, grep exits 1 under pipefail and set -e kills the script before the fail message prints.","outcome":"accepted"}
{"ts":"2026-11-30T16:00:28.238Z","reviewId":"address-2320","id":"f4","signature":"0cabc3708852","agent":"code-review","category":"correctness","severity":4,"file":"scripts/stage-smoke-test.sh","message":"The build-live check depends on the commit SHA appearing in /login HTML, which reportedly only happens through the Datadog RUM config. If that config changes, every run waits 40 minutes and blames Amplify.","outcome":"dismissed","dismissalReason":"intentional","dismissalDetail":"the page embeds the build SHA through the RUM config and the error message now says to check that too"}
{"ts":"2026-11-30T16:00:28.238Z","reviewId":"address-2320","id":"f9","signature":"4816ecf45c4b","agent":"code-review","category":"correctness","severity":3,"file":"scripts/stage-smoke-test.sh","message":"On busy days the 40-minute wait may be shorter than Amplify's queue, causing false failures.","outcome":"dismissed","dismissalReason":"intentional","dismissalDetail":"WAIT_SECONDS is configurable and 40 minutes is well past normal Amplify build time"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{"ts":"2026-11-30T16:13:18.334Z","reviewId":"address-2320","id":"f1","signature":"da048dd7501d","agent":"code-review","category":"correctness","severity":5,"file":"scripts/stage-smoke-test.sh","message":"The poll loop keeps partial /login HTML when curl fails (for example a timeout after the head arrives), so a matching SHA can break the loop and later checks fail with a misleading reason.","outcome":"accepted"}
{"ts":"2026-11-30T16:13:18.339Z","reviewId":"address-2320","id":"f2","signature":"3ebdb3f4d4b6","agent":"code-review","category":"correctness","severity":4,"file":".github/workflows/stage-smoke-test.yml","message":"A newer non-skipped run still cancels an older run that is checking a real deploy, so the author of the earlier breaking change gets no failure email.","outcome":"accepted"}
{"ts":"2026-11-30T16:13:18.339Z","reviewId":"address-2320","id":"f3","signature":"4694d0edf24a","agent":"code-review","category":"correctness","severity":4,"file":"scripts/stage-smoke-test.sh","message":"Because fetch uses curl -f, a /login that returns 5xx yields no body, so the loop waits the full WAIT_SECONDS and blames the Amplify build.","outcome":"accepted"}
{"ts":"2026-11-30T16:13:18.339Z","reviewId":"address-2320","id":"f4","signature":"8ca2ef11a134","agent":"code-review","category":"correctness","severity":4,"file":"scripts/stage-smoke-test.sh","message":"The post-live checks now have a 30 second timeout with a single try, so one slow cold start or brief 502 fails an otherwise healthy deploy.","outcome":"accepted"}
{"ts":"2026-11-30T16:13:18.339Z","reviewId":"address-2320","id":"f7","signature":"d6d4ff2deda8","agent":"code-review","category":"correctness","severity":3,"file":"scripts/stage-smoke-test.sh","message":"Network failures on the providers and GraphQL checks become empty strings, so the error annotation describes a content problem instead of a request failure.","outcome":"accepted"}
{"ts":"2026-11-30T16:13:18.339Z","reviewId":"address-2320","id":"f5","signature":"1587f4304d08","agent":"code-review","category":"conventions","severity":3,"file":".github/workflows/stage-smoke-test.yml","message":"Commit fee4a992c bundles about nine unrelated fixes, which goes against the one-logical-change-per-commit rule.","outcome":"dismissed","dismissalReason":"intentional","dismissalDetail":"one commit per review round keeps the fix commits easy to find"}
{"ts":"2026-11-30T16:13:18.339Z","reviewId":"address-2320","id":"f6","signature":"de2a7ea7a436","agent":"code-review","category":"correctness","severity":3,"file":"scripts/stage-smoke-test.sh","message":"The exact `>Sign In<` match fails on non-Okta sites where the button text differs, giving a misleading no-button error.","outcome":"dismissed","dismissalReason":"intentional","dismissalDetail":"stage.mpdx.org always uses Okta and its button text is Sign In"}
33 changes: 33 additions & 0 deletions .github/workflows/stage-smoke-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Stage smoke test

on:
# update-staging pushes with GITHUB_TOKEN, which never fires a push event, so follow its run instead
workflow_run:
workflows: [Update staging]
types: [completed]
push:
branches: [staging]
workflow_dispatch:

permissions:
contents: read

jobs:
smoke:
if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
# Job level so skipped runs never join. GitHub keeps one pending run, so a burst of deploys gets the newest one checked
concurrency:
group: stage-smoke-test
cancel-in-progress: false
runs-on: ubuntu-latest
timeout-minutes: 50
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Find the staging commit
id: sha
run: |
sha="$(git ls-remote origin refs/heads/staging | cut -f1)"
[ -n "$sha" ] || { echo "::error::Could not read the staging branch"; exit 1; }
echo "sha=$sha" >> "$GITHUB_OUTPUT"
- name: 🔥 Smoke test stage
run: scripts/stage-smoke-test.sh "${{ steps.sha.outputs.sha }}"
85 changes: 85 additions & 0 deletions docs/safety-nets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Safety nets: alerts, self-healing, rollback, smoke test

What catches a bad deploy, who hears about it, and how to undo it.

## Who gets told

| What breaks | What notices | Who hears |
| --------------------------------------- | -------------------------------------------------------- | ---------------------------------------- |
| Users hit errors on mpdx.org | Datadog RUM monitors `MPDX React ... [prod]` | Caleb Cox, by email |
| One prod page makes users rage-click | `MPDX React frustration rate by page [prod]` | Caleb, plus the self-healing agent |
| Someone runs the alert-path check below | `MPDX React safety-net test [stage]` | Caleb, plus the self-healing agent |
| mpdx.org sign-in or main pages break | Datadog synthetic `MPDX React Production Synthetic Test` | PagerDuty `MPDX` |
| A stage deploy breaks sign-in | GitHub workflow `Stage smoke test` | Whoever started the run, by GitHub email |

Real stage errors (about a dozen a day, mostly hydration warnings and crawlers) alert no one. The stage monitor only fires on the test error, so it proves the alert path without daily noise.

The RUM monitors live in `cru-terraform` at `applications/mpdx/web-react/datadog.tf`. Change who gets told there (`local.rum_alert_handle`), not in the Datadog UI. The prod synthetic is not in Terraform: it is managed in the Datadog UI as test [`dbu-dqa-6nj`](https://app.datadoghq.com/synthetics/details/dbu-dqa-6nj).

For mpdx.org, Datadog sees front-end errors only through the browser RUM SDK (`pages/_document.page.tsx`), and the monitors read RUM. The app also reports errors to Rollbar (`pages/_app.page.tsx`, `pages/api/utils/rollBar.ts`), but those stay in Rollbar: the Rollbar alerts Datadog gets come from the `mpdx_api` project, not this app. Thresholds come from `yarn calibrate-safety-nets`; see `scripts/safety-nets/README.md`.

## Self-healing agent

Caleb's agent runs outside this repo. Monitors that mention `@webhook-self-healing-agent` send it the alert. It looks into the cause and opens a PR here as `app/cru-self-healing-agent`, with the safety-net monitor id in its title. Review those PRs like any other.

## Check the alert path

Run this after changing a monitor, a webhook, or the RUM setup.

The `MPDX React safety-net test [stage]` monitor comes from [CruGlobal/cru-terraform#13703](https://github.com/CruGlobal/cru-terraform/pull/13703). Until that PR is applied, step 3 below gets no email and no agent PR.

1. Open https://stage.mpdx.org/login.
2. In the browser console run `DD_RUM.addError(new Error('Safety net test'))`.
3. Within 5 minutes Caleb gets a `MPDX React safety-net test [stage]` email and the agent opens one PR. Close that PR without merging.

The monitor matches the words `Safety net test` exactly (`local.rum_canary_search` in `datadog.tf`). Change both together.

## Smoke test after each stage deploy

`.github/workflows/stage-smoke-test.yml` runs after every staging update. It waits for stage.mpdx.org to serve the new commit (Amplify takes about 10 minutes), then runs `scripts/stage-smoke-test.sh`, which checks:

- `/login` renders a Sign In button
- the build's JavaScript loads
- Okta sign-in is offered
- the stage GraphQL API answers

Run it by hand from the Actions tab, or locally:

```bash
scripts/stage-smoke-test.sh "$(git ls-remote origin refs/heads/staging | cut -f1)"
```

It stops at the Okta button because CI has no test account. The prod synthetic signs in and opens Contacts, Tasks and Donations every 15 minutes, so a broken logged-in page is caught within 15 minutes of reaching mpdx.org.

## Roll back

Amplify (app `d3dytjb8adxkk5`) builds `main` to mpdx.org and `staging` to stage.mpdx.org. Each push builds and deploys in about 10 minutes.

**Fastest: redeploy the last good build.** Needs AWS console access to the Amplify account.

1. AWS console > Amplify > mpdx-react > the `main` (or `staging`) branch.
2. Open the last build that worked and choose **Redeploy this version**.
3. The site serves the old build in a few minutes. `main` still has the bad commit, so revert it next or the next merge ships it again.

**Always works: revert the commit.** Anyone who can merge a PR can do this.

1. On a new branch, revert the commit the PR landed as: `git revert <commit>` for a squash merge, or `git revert -m 1 <merge commit>` for a merge commit. Push and open a PR.
2. Once it merges to `main`, Amplify rebuilds mpdx.org and `update-staging.yml` carries the revert to stage.

**Stage only.** If the bad change only went to stage through the `On Staging` label, remove the label and revert its merge on `staging`:

```bash
git switch staging && git pull
git revert -m 1 <merge commit of the PR into staging>
git push origin staging
```

Stage is a shared branch. Revert only the merge you mean to, and never force-push it.

To bring the change back to stage later, revert the revert (`git revert <revert commit>`) and push. Re-adding the label does not work: git sees the PR as already merged.

## Drill log

| Date | Env | What | Time to roll back | Notes |
| ---------- | ----- | ---------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| 2026-11-30 | stage | `git revert` of the latest AIGS-26 merge on `staging` (6594f88b4), then a revert of the revert (34ad2b97d) | 9 min to live (17:38:54 push, 17:47:57 live and smoke test passed, UTC). Restore took 8.5 min | Both "Stage smoke test" workflow runs passed on their own. No Amplify console access needed. |
2 changes: 2 additions & 0 deletions scripts/safety-nets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ caveats).
- **Alerting is email, not paging.** Critical breaches notify
`local.rum_alert_handle` in `datadog.tf`; warnings are visible in Datadog but
notify no one.

Who gets alerted, the self-healing agent, the stage smoke test and how to roll back: see `docs/safety-nets.md`.
65 changes: 65 additions & 0 deletions scripts/stage-smoke-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
# Post-deploy smoke test for stage: waits for the new build, then checks the sign-in path end to end.
# Usage: scripts/stage-smoke-test.sh <commit sha> [site url] [api url]
set -euo pipefail

SHA="${1:?commit sha required}"
SITE="${2:-https://stage.mpdx.org}"
API="${3:-https://api.stage.mpdx.org/graphql}"
WAIT_SECONDS="${WAIT_SECONDS:-2400}"
POLL_SECONDS="${POLL_SECONDS:-30}"

fail() {
echo "::error::$1"
exit 1
}

fetch() {
curl -fsS --max-time 30 --retry 3 --retry-all-errors "$@"
}

echo "Waiting up to ${WAIT_SECONDS}s for ${SITE} to serve ${SHA}"
deadline=$((SECONDS + WAIT_SECONDS))
login_html=""
last_status=""
server_errors=0
while true; do
if html="$(curl -fsS --max-time 30 "${SITE}/login")"; then
login_html="${html}"
server_errors=0
[[ "${login_html}" == *"${SHA}"* ]] && break
else
last_status="$(curl -s -o /dev/null -w '%{http_code}' --max-time 30 "${SITE}/login" || true)"
if [[ "${last_status}" == 5* ]]; then
server_errors=$((server_errors + 1))
# A deploy swap can blip once; ten in a row means /login itself is broken
((server_errors >= 10)) && fail "/login keeps returning ${last_status}, so the page is broken, not the Amplify build"
else
server_errors=0
fi
fi
if ((SECONDS >= deadline)); then
fail "${SITE} never served ${SHA} (last /login status: ${last_status}). Check the Amplify build for the staging branch, and that the page still embeds the build SHA in its Datadog RUM config."
fi
sleep "${POLL_SECONDS}"
done
echo "Live: ${SITE} is serving ${SHA}"

[[ "${login_html}" == *">Sign In<"* ]] || fail "/login rendered without a Sign In button"
echo "OK: /login renders"

manifest="$(grep -oE '/_next/static/[^"]+/_buildManifest\.js' <<<"${login_html}" | head -1 || true)"
[[ -n "${manifest}" ]] || fail "/login has no build manifest script"
fetch -o /dev/null "${SITE}${manifest}" || fail "Build assets did not load: ${manifest}"
echo "OK: build assets load"

providers="$(fetch "${SITE}/api/auth/providers")" || fail "GET /api/auth/providers failed"
[[ "${providers}" == *'"okta"'* ]] || fail "/api/auth/providers has no Okta provider, so nobody can sign in"
echo "OK: Okta sign-in is offered"

graphql="$(fetch -X POST "${API}" -H 'content-type: application/json' -d '{"query":"{__typename}"}')" ||
fail "The GraphQL API request to ${API} failed"
[[ "${graphql}" == *'"Query"'* ]] || fail "The GraphQL API at ${API} did not answer"
echo "OK: GraphQL API answers"

echo "Smoke test passed for ${SHA}"
Loading