The File on My Server Was Not the File in My Repo
My repo lied to me for weeks. Two deploy guards caught it. This is the story of why I now dump server bytes before I trust a source file. The setup I run my portfolio on a one-shot patch worker pattern: every
My repo lied to me for weeks. Two deploy guards caught it. This is the story of why I now dump server bytes before I trust a source file.
The setup
I run my portfolio on a one-shot patch worker pattern: every change ships as a small PHP worker that does a dry run, checks its needles, backs up, patches, verifies, and deletes itself. It's the closest thing a one-person team has to a second set of eyes.
Last week one article was serving the generic OG preview card instead of its own. The cards come from og.php. I have a repo for that tool. I'd built workers against that repo before. I knew the code cold.
Two guards, two aborts
Worker one used exact anchors from the repo source: find this function, patch inside it.
// needle from the repo source
$needle = 'function bh_og_build_card(';
if (substr_count($src, $needle) !== 1) {
abort('needle not found'); // ← this fired
}
Zero matches. Fine - code drifts. That's what the guards are for.
Worker two was written layout-agnostic. No function names, no anchors, just structural invariants any version of the file should satisfy - a manifest load, a cache write, a slug parameter. Zero matches.
That's the moment that matters. Two rewrites don't both miss by accident. The guards weren't saying "the file drifted." They were saying this file is not what you think it is.
The peek
So I shipped a worker that patches nothing. It reads og.php off the server and dumps it back to me. Cost: five minutes.
What came back settled it. The host file was ~3KB of flat procedural PHP with a marker comment I'd never seen, titles loaded from og-manifest.json, cache keys built as md5(slug|title). The repo version had a different structure, different config, different cache layout. Different everything.
The repo wasn't a stale copy of production. It was documentation for a file that had been replaced at some point and never reconciled.
And here's the part that keeps me up: a patch careless enough to "succeed" against the repo would have overwritten whatever is actually generating my cards right now. The guards failing was the best outcome available.
The fix
The final worker was a full-file replacement built from the peeked bytes, not the repo: same manifest schema, same cache behavior, same query handling, because all of that is load-bearing on the live host. Its one needle - the marker the peek found - was guaranteed to exist, because it came from the real file instead of my memory of it.
Backup, verify, self-delete, row in the receipts ledger. Both aborted workers had cleaned up after themselves, which is the only reason this is a story instead of an incident.
The rule
My deploy rule has always been: verify the served bytes, not the receipt. But that rule covered the output side. This incident added the input side:
Dump the host bytes first, before any needle is written.
A needle guard can only tell you that your assumption failed. It can't tell you what the truth is. Only the real file can do that - and reading it first costs one worker. Not reading it costs however many rewrites you spend defending a mental model that was already wrong.
Question for the comments: when you patch production, what are you actually patching against - the repo, or the server? Have you checked lately that they're the same thing?
This is a Live Verified post - my series on deploy discipline with receipts. The on-site original lives at bryanhamilton.info/writing, the change ledger for my sites is at the receipts feed, and the worker pattern itself - token-gated, dry-run first, needle-guarded, self-deleting - is open-sourced as guarded-deploy-workers.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.