an empty response is two different facts, not one
my retry loop kept burning through a refusal that was never going to change, and the fix taught me that classification has to happen before the counter moves.
what it looked like from the outside
for about a week, one stage of the pipeline was eating its whole retry budget every night. the stage drafted outbound copy from lead records, and every so often a record came back from the model call with nothing attached -- no text, no completion, just an empty hull and a generic error. the loop treated empty as failure, incremented, waited, tried again, and by dawn the give-up counter had done its job and the item was dropped.
from the outside this looked like flakiness. the model endpoint was doing heavy traffic, timeouts were plausible, rate limits were plausible, cold starts were plausible. and the evidence fit: most calls succeeded, the failures were scattered across the night with no pattern i could see, and the ones that failed produced the same shape of nothing every time. nothing is nothing. you retry nothing.
the cost was invisible in any dashboard i had, which is its own lesson. the drops looked like a normal error rate. what i didn't see until later was that the retries weren't buying anything -- the same payload came back empty twice, three times, four, and the loop paid full price for each attempt because the answer was never going to be different.
the misleading part was how honest the failure looked. a transient timeout and a flat refusal both arrive as 'no text came back' at the call site, and the call site is exactly where the retry decision lives. i had built a loop that makes decisions at the only altitude where the two cases are indistinguishable.
the wrong theory
my first theory was capacity. the side project runs on one machine and makes calls during hours when the shared endpoint is busiest, so i assumed contention. the fix in that theory is backoff -- wait longer between attempts, jitter the schedule, spread the load. i implemented exponential backoff with a cap and the failure count didn't move. same drops, same shape, same silence.
that should have been the first clue. backoff fixes contention by changing the timing of the request, and if timing doesn't change the outcome, timing isn't the variable. but i'd seen contention produce exactly this signature at work -- scattered failures, identical error shapes -- and pattern-matching to the last problem that looked like this felt like experience. it was actually just recency.
the second wrong theory was payload size. a few of the dropped records were long, so i trimmed inputs and chunked the worst offenders. a couple of them came back fine, which made the theory feel confirmed for a day. then a short, trivial record dropped the same way and the theory collapsed. i had been fitting causes to the sample of failures i happened to inspect, which is a small sample shaped by my own attention.
the deeper error was structural: i had one verb for 'nothing came back' and the loop only knew how to count. a give-up counter can tell me how often a call produced nothing, but nothing about why, and without why it can only do one thing -- spend again.
what actually settled it
i stopped changing anything and instrumented instead. for one full run, the loop logged the raw response envelope for every empty result -- status, headers, error body, everything the call site normally discards on its way to incrementing a counter. i wanted to see the difference i was refusing to look at, and i wanted it across all the drops, not the two i remembered.
then i replayed the dropped payloads by hand, one at a time, outside the loop, against the same endpoint. this was the measurement that decided it. every replayed payload came back empty again, immediately, with the same refusal marker in the error body. no backoff interval, however long, was ever going to change that. the failures weren't scattered by load; they were pinned to content.
i sorted the error bodies into two piles and the split was clean. one pile said the request couldn't complete right now -- timeouts, throttling, the usual weather. the other said this request won't be completed -- a content gate had refused the payload, and the refusal named the category it objected to. same empty shape at my call site, opposite meanings underneath.
the last piece fell out of the content pile: several refused payloads contained addresses pointed at domains reserved for documentation and testing -- the ones the standards body set aside precisely so an address can be written down without belonging to anyone. my own scanner was flagging fixtures as personal data. a refusal caused by my own false positive, retried forever by my own loop.
the fix
the fix moved the classification upstream of the counter. the scanner now runs before dispatch, so every payload gets a verdict before it ever reaches the model call: pass, or blocked with a named reason. refusal-shaped error bodies at the call site route to a third path -- retired, not failed. the retry counter only ever sees the weather pile, and the weather pile alone.
the two piles now go to different places. transient failures retry with backoff as before, because that part of the loop was never wrong. blocked items retire to a visible ledger -- a growing flat file, one line per item, payload id and reason. the point of the ledger is that wrongness shows up instead of going silent; when i later fixed the scanner to stop treating reserved domains as pii, a few hundred previously blocked records sat in that file with reasons attached, ready to be replayed and drained.
the scanner fix itself was two changes, both small. reserved documentation domains became an explicit exemption, on the theory that a reserved address is a fixture by design, not a leak. and the scan stopped accepting the first match as the whole verdict -- a single exemption earlier in the line had been masking everything after it, so now every match gets evaluated.
what i deliberately didn't change: the give-up counter, the backoff curve, the budget. the loop's arithmetic was fine. the bug was that it was counting verdicts it had never asked for. adding classification before counting was enough.
the rule i keep now
any loop with a give-up counter has to know why a call produced nothing before the counter moves, and the cheapest reliable way to know is to ask before dispatch rather than infer after silence. policy refusals are permanent for the exact payload they refused -- every retry costs the same and returns the same -- so they belong in a ledger with reasons attached, not in a counter. the ledger matters as much as the classification: a blocked item with a written reason can be audited, which means a wrong gate eventually surfaces; a silent drop never does. and a scanner's first match is not a verdict -- iterate every match, because one exemption in the middle of a string hides everything after it. the firewall should trip the job that called it only if the loop can't tell a wall from weather, and telling them apart is one gated check and two files.
the rule: classify before counting -- retries are for transient failures, ledgers are for refusals, and a loop that can't tell them apart pays forever for an answer that will never change.