Files
loki/scripts
cc4e892559 perf(deploy): the pipeline was waiting, not working (#293)
Merge→live measured 14–27 minutes. The irreducible work in that window is
about 80 seconds: build 66s, rsync 4s, restart 4s, verify 7s. Nearly all
of the rest was waiting, so nearly all of the fix is removing waits
rather than making anything faster.

Two waits, measured:

1. The runner drain, 480 of the ship step's 570 seconds. The deploy
   watched one in-flight agent, then restarted anyway at the cap. The
   web app had been live and verified for eight of those minutes. Two
   systems with opposite needs were sharing one job's wall-clock — the
   app wants to be live now, the runner wants to not kill anyone's work
   — and the runner won every time.

   A shorter timeout would only kill agents sooner. The wait itself is
   fine; the place it happened is what cost. Waiting is expensive in CI
   and free on the box, so it now happens on the box: the deploy
   schedules a detached systemd-run unit and returns as soon as the app
   is verified. The drain gets *longer* (1800s, not 480) and cheaper at
   the same time, because nothing is holding a runner open for it.

2. The CD reconciler, up to 10 minutes and 18.6 of #284's 26.8. Deploy
   chains off CI via workflow_run, which never fires for a CI run that
   GITHUB_TOKEN started — i.e. for every auto-merged PR, the only path
   that merges code here. The sweep covered that by reconciling on its
   next tick: correct, self-healing, and late.

   A dispatch is not a push, so it is not subject to the no-cascade
   rule. ci.yml now dispatches Deploy itself the moment main goes green.
   The sweep keeps its reconciler as the safety net, which is the right
   shape for "did something get missed?" and the wrong one for "did
   something just happen?".

Also caches .next/cache across deploys — the build is the one part of
this that is genuinely work, so it is the one part worth shrinking.

Not done, and worth saying: I thought CI and Deploy each built the app,
so the tested artifact was never the shipped one. That was wrong. ci.yml
deliberately skips `next build` because App-Router pages query Postgres
during pre-render; the build happens once, in Deploy. There was no
discarded build and no artifact to pass.

The decoupling has a test, and it asserts the property rather than the
patch: the deploy must not block on a drain, the restart must be
detached, the script must be shipped before it is invoked, and the drain
must stay bounded. Verified the first two assertions fail against the
previous version (4 blocking markers, 0 systemd-run) rather than merely
passing against this one.

Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-15 11:58:29 +00:00
..