Skip to content

fix(ci): Deploy to Dev fails when the backend /health probe fails (#2995) - #3051

Merged
vybe merged 6 commits into
devfrom
AndriiPasternak31/issue-2995
Sep 29, 2026
Merged

vybe merged 6 commits into
devfrom
AndriiPasternak31/issue-2995

Conversation

@AndriiPasternak31

Copy link
Copy Markdown
Contributor

Fixes #2995

Cause

deploy-dev.yml's === Health === step ran curl -sf http://localhost:8000/health && echo "Backend: OK" under set -e. set -e never aborts on a command on the left of &&, so a failed probe only skipped the echo. The script carried on, the job went green, and notify-failure never filed its incident.

Scope (what this does and does not fix)

A backend that is never healthy already fails the deploy at Restart. docker compose up -d waits on depends_on: condition: service_healthy (docker-compose.prod.yml) and exits with dependency failed to start: container … is unhealthy. Docker's healthcheck curls the same /health. The false green covered a narrower window: Docker reported the backend healthy at compose time, but the host :8000 probe then failed (the backend crashed or flipped after its first passing probe, or the host-port path is broken). This PR does not claim that a failed migration used to go green on dev. The dev VM runs PostgreSQL, so /health shows that the backend is serving. It does not show that migrations were applied.

Fix

  • The Health block is now a bounded poll: 3 probes with curl -fsS --max-time 30, 20 s apart. If all 3 fail, the script prints filtered diagnostics, then ::error:: and exit 1. The marker in ~/.trinity-last-deployed-sha is not written.
  • It differs from the snippet in the issue on purpose:
  • The old sleep 10 also gave the scheduler its grace period. The scheduler check now polls up to 3 × 5 s instead and stays warn-only.
  • The notify-failure issue body (item 4) now names both failure points: Restart (never healthy) and Health (healthy, then not answering on the host port). It also tells the reader to check host-port reachability.
  • Also added: a learnings fragment (docs/memory/learnings/2026-09-28-…) and a tests/registry.json row.
  • Doc deltas: requirements, architecture and feature-flows need no change. This is a bug fix, no architecture area file owns .github/workflows/, and no feature flow documents deploy-dev.

Proof

  • tests/unit/test_2995_deploy_health_gate.py runs the workflow's own Health slice under bash and sh with stub curl/sleep/sudo/docker. A literal pre-fix control reproduces the false green. Result: 18 passed with -p randomly, and 110 passed across test_2995/2204/2246/2578/2625 at seeds 1 and 99999.
  • Mutation: with the Health block swapped back to the origin/dev bytes, 14 tests fail and 4 pass. The 4 that pass are the pre-fix control and the scheduler warn-only test.
  • Whole-script stub run: the ssh-action script: was extracted with yaml.safe_load and run under bash, sh and dash, with === Health === asserted as reached. Two independent harnesses gave identical results:
version probe exit marker
this PR always fails 1, ::error:: not written
this PR healthy 0, === Done === written
origin/dev always fails 0 (false green) written
  • actionlint reports 0 findings before and after, but it does not lint an ssh-action script:. shellcheck on the extracted script reports 2 findings before and 2 after, both above the Health block, and 0 in the Health block.

Unprovable until the first post-merge Deploy to Dev

The stubs stand in for several things that only a real run exercises: the real ssh-action transport and how the exit code propagates through it, notify-failure's if: failure(), a real 503 from a real curl, the enterprise-mounted paths, and real timing. The expected result on the first run after merge is Backend: OK, Scheduler: healthy, no WARNING, and a green job.

Related: #2986 copies the same curl … && echo line into deploy-prod-nightly.yml. There is no file overlap, so the two PRs can merge in either order.

Lane C (CI workflow): before merge this also needs journey-smoke and frontend-e2e green on the PR.

🤖 Generated with Claude Code

)

`curl -sf .../health && echo "Backend: OK"` under `set -e` never aborted:
the left side of `&&` is exempt, so a failed probe skipped the echo and
the run went green, and notify-failure never filed its incident.

Replace it with a bounded poll (3 probes, 30 s cap each per #1230, 20 s
apart) that prints filtered diagnostics -- and the #2578 STALE line, which
this exit now pre-empts -- before `exit 1`. The leading `sleep 10` goes:
compose `up -d` already waited for the backend to be Docker-healthy.

The test runs the workflow's own Health section under bash and sh with
stub curl/sleep/sudo/docker, and a literal copy of the pre-fix lines as
the control that reproduces the false green.
…2995)

A backend that never becomes healthy fails at `Restart` (compose waits on
`service_healthy`); one compose saw healthy that then misses the host
`:8000` probe fails at `Health`. Item 4 now names both, adds host-port
reachability to the checks and points a STALE Health failure at item 5.
"What this means" no longer implies a Health or seeding failure left the
old code running.
The new exit pre-empts the Error check, so the Health branch prints the
backend's state and log lines itself. The run log is public; the test now
asserts the container state line and the filtered error line appear and
an unfiltered log line does not. Mutation: replacing the filtered tail
with a raw `docker logs --tail 50` turns both shells red.
)

The removed `sleep 10` in the Health section was also the scheduler
check's grace. `up -d` waits on the backend's health only, so it returns
right after starting the scheduler; an immediate inspect reads `starting`
and the warning would print on every healthy deploy. Live run
36327494118: scheduler Started 15:01:10.9, `Scheduler: healthy` at
15:01:21.2, ten seconds later.

Poll the scheduler up to three times, 5 s apart (the same <=10 s window),
stopping at the first healthy answer. Still warn-only (D-B1).
@AndriiPasternak31 AndriiPasternak31 added the ui PR touches the frontend UI — triggers Playwright e2e tests label Sep 28, 2026
@AndriiPasternak31
AndriiPasternak31 marked this pull request as ready for review September 28, 2026 19:47

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train: validated at lane C (validate-pr + review + cso --diff); #2625 expression-cap test green on the dev-merged tree. Merged alone ahead of the train per the deploy-dev.yml rule.

@vybe
vybe merged commit 6adfe51 into dev Sep 29, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants