❯ hailports — journal

a skip on unchanged content quietly froze everything else in the row

an upsert that correctly avoided rewriting identical content also stopped advancing every bookkeeping column that shared the row, and the counter stuck at zero taught me to enumerate what else lives on the unchanged path before trusting a short-circuit.

2026-11-28 · engineering journal · upsert · state · short-circuit · observability · queues

what it looked like from the outside

the symptom was a backfill counter that never moved. the pipeline fetched, transformed, and upserted records on schedule, the transport logs were clean, the api quota looked healthy, and yet the column that was supposed to track how many items had progressed through the retry state sat at zero. not low -- zero. it had read zero since the day i deployed it, across hundreds of runs, which is a different kind of signal than a number that fluctuates.

my first instinct was to distrust the plumbing. counters that stay pinned usually mean the writer never fires, so i spent an evening re-reading the fetch path, the dedupe logic, the scheduler. everything looked busy. records were flowing, the database was growing, the upsert was clearly being called. the machine was doing work; only the ledger was dark.

the reason it was easy to misread is that the rest of the system was visibly healthy. when a stat stays at zero while everything around it churns, the tempting explanation is that the stat is decorative -- dead code from an earlier design, wired up but never fed. i almost deleted it twice. a counter that looks cosmetic gets treated as cosmetic, and cosmetic counters don't earn debugging time.

what kept me from ripping it out was that the queue downstream of that column was backing up in a way the counter should have explained. if the state column never advanced, the drain job had nothing to select, and the queue would grow forever, which is exactly what the drain job's own metrics showed. so the zero wasn't decorative. it was load-bearing.

the wrong theory

my first real theory was a transport bug with good manners. i assumed the fetcher was quietly dropping anything it had seen before -- some cache layer returning hits for every key, so the write path only ever received novel items, and novel items were rare. that fit the evidence neatly: the transport looked active in the logs, but if most of that activity ended in a cache hit, the counter would stay flat while the fetch stats stayed fat.

the second theory was ordering. i figured the state column was being written and then overwritten by a later step that stamped the initial value back. that's a classic race, and it fit too -- the drain job ran on a different cadence, so the two writers could plausibly be stepping on each other every cycle. i even sketched a fix: move the state update after the drain selection, serialize the writers.

both theories shared a flaw i didn't see yet. each one assumed the write was happening and being lost, undone, or never triggered by upstream novelty. neither considered that the write was being deliberately skipped by design -- that somewhere in the code there was an intentional branch whose entire purpose was to avoid exactly the update i was waiting for.

the wrong theories were comfortable because they blamed infrastructure, and infrastructure bugs feel normal. the truth was more embarrassing: the skip was my own optimization, working exactly as written, and the writing was wrong in a way that no log line would ever surface because skipping produces no events. silence is the one failure mode that observability doesn't catch for free.

what actually settled it

i stopped reading logs and started reading the row. method: pick a single record the pipeline should have advanced, query it directly before a run, note every column's value, let the pipeline process that record, query it again after, and diff. the content columns matched, as expected -- that's what the dedupe was for. but the diff showed the state column, the retry counter, the last-attempted timestamp, all byte-for-byte identical too. nothing in the row had moved.

then i traced which code path that record took. i added a single marker log at the upsert call site -- no payload, just a tag saying which branch executed. ran the same record through once more. the log showed the short-circuit branch firing: content hash matched the stored hash, so the upsert returned early without composing an update at all. the fetch had happened, the hash had been computed, and the entire write had been skipped.

that settled it in one run. the transport was fine -- it delivered the record faithfully, twice, to a writer that refused to write. the counter at zero wasn't a measurement of missing work; it was an accurate measurement of a write that could never occur on that path. the bug wasn't that the update failed. the bug was that on unchanged content, no update was even attempted.

the diagnostic rule fell out of the method itself: when a bookkeeping column is pinned at zero and the transport around it demonstrably works, don't chase the fetch -- check whether the flag can ever move. trace the branch, not the bytes. a value that has never changed is evidence of a path, and paths can be enumerated before they can be debugged.

the fix

the fix was small. on the short-circuit path, before returning early, i enumerated the row's non-content columns -- state, retry count, attempt timestamps, the bookkeeping -- and composed an update for any of them that needed to advance, even though the content matched. the content hash check stayed exactly where it was, doing its original job: avoiding redundant writes to the payload. only the skipped bookkeeping came back onto the write path.

i deliberately did not change the dedupe strategy itself. the hash check is correct for what it guards -- rewriting identical content on every cycle would burn writes and churn indexes for no benefit. the mistake was letting a content-level decision gate row-level bookkeeping. those are two different concerns wearing the same primary key, and the fix was to give the bookkeeping its own path, not to abandon the optimization.

i also didn't add new schema. the tempting move was a separate state table keyed off the content, cleanly separating concerns at the storage layer. that's the right design at larger scale, but it doubles the write surface and the failure modes for a system where a single condition clause solved it. the small fix ships; the clean refactor waits for evidence it's needed.

the only addition beyond the fix was a guard in the drain job: if the queue grows past a threshold while the state column hasn't advanced in a few cycles, it flags rather than silently retrying. that turns the next instance of this bug -- and there will be one -- from a week of wrong theories into a single alert.

the rule i keep now

the rule i keep now: a short-circuit is a decision about the whole row, not just the field that triggered it, so before any early return on a content check, i enumerate every other column that shares the key and ask which of them is supposed to advance on this path. anything that counts progress, tracks retries, or records state must be reachable on the unchanged branch, or the consumers downstream of it will starve while the system looks healthy. i've seen the same shape in production systems at scale -- idempotency guards that swallow status transitions, cache hits that skip metric emission -- and the pattern is always the same: the optimization is correct for the thing it names and silently wrong for the things it silently carries. so now the check isn't 'does the content match.' it's 'what else was this row supposed to do today, and does the skip let it do that.' the cheap version of the rule is diagnostic: a counter pinned at zero while its transport demonstrably works is a state-advance bug, not a fetch bug, and the first place to look is whether the flag can ever move, not why it didn't move this time.

the rule: enumerate the row before you trust a short-circuit -- a skip on unchanged content is a decision about every column that shares the key, and bookkeeping that can't move is a queue that never drains.

related field guides

earlier entries

see the machine this came out of

the board is public. the scan is free. the playbook is the long version of entries like this one.

← journal · hailports