yeti labs

field note 016 · 2026-08-15 · deploys, monitoring

a deploy script redeployed the same stale code 16,089 times, and the fix couldn't deploy itself

we run infrastructure for a blockchain data-indexing company. a fix we'd merged didn't show up in production, and that's how we found out three api boxes had been serving july 23 code for three weeks, rebuilding and reloading it once a minute, with every health check green.

deploys, one box
16,089
new commits shipped
0
restarts an hour
60-62
alerts fired
0

the loop

each box runs a deploy script from cron every minute. it fetches, and if main has moved it pulls, runs npm i, builds, and does a pm2 reload. simple enough, and it had worked for a long time.

npm i is allowed to rewrite package-lock.json, and on a box that never commits, that rewrite just sits there. the next tick's git pull --ff-only refused to overwrite it. the script had no set -e, so it sailed past the failed pull and ran npm i again (re-dirtying the lockfile), built, and reloaded. same commit, every 60 seconds, indefinitely. one box's deploy log had the merge error in it 11,319 times and had grown to 16 MB.

why nobody noticed

every signal we had read healthy. the ping endpoint returned 200, the load balancer's health checks were green, pm2 said "online", and the deploy log ended on a clean npm run build. the one tell was cheap and nobody was looking at it: Starting API on port 8080 showed up in the logs 60, 62, and 62 times an hour on the three boxes. a healthy fleet restarts when it deploys and that's about it.

the fix for exactly this ("harden deploy-check against a dirty working tree") had been diagnosed on aug 4 and merged. it was one of the three commits stuck behind the freeze. a fix to the deploy path ships through the deploy path, so it sat there with everything else. we discarded the lockfile and pulled by hand on each box, once. the next cron tick did not reload.

then we broke it the other way

the hardened script added set -e and stashed box-local drift so it could never block a pull again. it also opened with a bare git fetch. these boxes reach the code host over ssh with a dedicated deploy key that isn't the default identity, and nothing pointed git at it. permission denied, set -e, abort on line 3. 600 of 600 consecutive cron runs did nothing, and the fleet sat on one commit for two days while main moved on.

the restart-rate check we'd built two days earlier was blind to it, because these boxes restarted never. and the one box we could ssh to without a cloud tunnel had a default key with repo access, so it deployed normally the whole time. spot-checking it proved nothing about the rest.

16,089 deploys, and not one shipped anything new

deploy runs and process restarts on a second box, counted from its deploy log and pm2, over about 11 days starting aug 4

05,00010,00015,000deploy runs16,089"done" lines16,089api restarts15,842worker 1 restarts14,363worker 2 restarts14,384worker 3 restarts13,671each run ended "done".the commit underneathnever moved off jul 23.one a minute, ~11.2 days.
source: the box's deploy log and pm2 restart counters, read aug 15yeti labs · field note 016

the second box

on aug 15 we were gut-checking a different service's box after an unrelated incident and found the same loop, word for word. its log had 16,089 "deploying" lines and 16,089 "done" lines, 16 MB of them. the loop started about aug 4, the day the next pull request merged on that repo, and it had been stuck on a july 23 commit ever since, three merged pull requests behind. nothing alerted because the wrapper that reports cron jobs to our health checks wasn't installed on that box at all.

the local lockfile diff was byte-identical to the incoming one (5 insertions, 4 deletions), so throwing it away lost nothing. we pulled, ran npm ci, and rebuilt. the restart counters froze and the log's growth went from 1 KB a minute to zero.

aug 12 freezeaug 14 freeze
what the script didrebuilt and reloaded the stale commitaborted on line 3
restarts an hour60-62 per boxnone
how longthree weekstwo days
restart-rate checkcatches itcan't see it
booted-commit checksees itsees it

checking what's running

restart rate catches one failure and misses its mirror image, so we added a check that asks the code directly. the api now has a version endpoint that returns the commit each process booted from (resolved once at boot, since the checkout moves a full reload before the running code does) and which box answered. the health check samples it 25 times through the load balancer and compares against main. a box that never answers counts as a warning, because the balancer is lopsided: one run of 15 samples came back 10, 4, and 1.

the restart-rate check fails at 10 an hour even though the real wedge runs 60-62. settled logs show the full rate, but the weekly run reads fresh ones, and ingestion lag makes those read about 10. a healthy box sits under 1 an hour.

what we'd do instead

  1. use npm ci in any deploy script. it installs exactly what the lockfile pins and never writes it, so the deploy can't dirty its own tree.
  2. fail loudly. a failed fetch, pull, install, or build should exit non-zero before it gets anywhere near a reload, and the cron job should report to something that pages. npm ci removes the cause, and failing loudly stops the next cause from going infinite.
  3. ask every box which commit it booted from, and compare that to main. a 200 from the ping endpoint means something is serving.
  4. plan the manual unstick. a fix to the deploy path can't ride the deploy path, so merge it, then unwedge each box by hand once. check the log's modified time, since a clean run prints nothing and old errors sit at the tail forever.
  5. turn a churn alert on only once the box is healthy. a check that's red from the day it's installed teaches people to ignore it.
got a deploy pipeline nobody's looked at in a while?

we'll find out what's really running.

talk to the agent →