the default env value was never the setting
a launchd service ran with different tuning than my shell tests suggested, and chasing it taught me to verify from the service's own context, never my own.
what it looked like from the outside
one of the background jobs on the single machine -- a watcher that reconciles inbound leads against the pipeline -- was behaving like its batching was off. it processed small clusters when i expected larger ones, and the timing between passes looked tighter than i remembered tuning it. nothing was failing. logs were clean. it was the kind of drift that doesn't page anyone, it just quietly makes the system less efficient than the config claims.
the easy misread was that i had never applied the tuning i thought i had. that fits the evidence well, because i had edited that config a few times over the past month while working through the queue handler, and edits through a manager layer can silently miss the layer that actually runs. when the behavior doesn't match your intention, the cheapest theory is always that the intention never landed.
there was a second plausible story: some other process on the box was competing with it, or the upstream feed had changed shape. i didn't like that theory because nothing else on the machine showed the same symptoms, but i kept it warm anyway, the way you keep a theory warm when the first one is embarrassing and the second one isn't your fault.
the wrong theory
my working belief was simple: the config default was the live value. the file showed a batching size and an interval, and those numbers were what i had tuned. so i reasoned that the service was picking up those defaults, and that something else -- concurrency, feed shape, an upstream change -- was modulating the behavior on top of a correct baseline.
the reason this theory fit the evidence was that i had verified it. i opened a shell, ran the same entrypoint once by hand with the same arguments, and confirmed the batching matched what the config showed. that's a verification. it felt like a verification. the output agreed with the file, the file agreed with my intention, and the loop closed. what i had actually verified was the behavior of a one-shot process in my own environment.
the flaw is invisible unless you know how the service actually launches. a long-lived job managed by the system launcher almost never inherits the shell you'd open by hand. it gets its own environment, and something in that environment -- a variable set at install time, months back -- was the value the process actually used. my shell run had no such variable, so it fell back to the config default. two contexts, two different effective settings, and i had only ever measured one of them.
what actually settled it
the thing that settled it was deciding to interrogate the service in its own context instead of mine. first step: read the launcher definitions directly. i grepped every plist on the machine for the env keys that feed the tuneables, expecting to find nothing. instead i found an environment block setting exactly the key i cared about, with a value from an earlier era of the config. the default in the file wasn't the setting. it was the fallback for a context that almost never happens.
second step: prove causation, not correlation. i backed up the plist first, because editing launcher definitions by hand is one of the irreversible-ish calls i don't make casually. then i changed the value at the environment layer and restarted the job. the service log -- its own log, the one the daemon writes -- showed the new batching on the very next pass. no manual run, no shell invocation, just the process reporting what it had loaded from where it actually loads things.
third step: close the loop on the other layer. the entrypoint is a bash script, and bash re-reads its file mid-execution, so editing a running script without a restart leaves a process half-old and half-new. i restarted it again after touching the script side. then i verified from the service log a second time. two layers, two restarts, two log confirmations. the whole investigation cost maybe an hour, most of it reading definitions i should have read months ago.
the fix
the fix itself stayed small. i made the two layers agree -- the plist environment and the config default now carry the same value, so they can't disagree silently. where a value can't be derived, i left one canonical source and had the other reference it rather than duplicate a number that will drift the next time i tune in a hurry. a launcher-managed service and a hand-run process should resolve to the same effective config or the config is lying to one of them.
what i deliberately didn't change was the architecture. it's tempting, after a bug like this, to rip out the launcher layer and run everything under a supervisor i can inspect more easily, or to add a startup assertion that dumps the full effective environment on boot. i did add the log line -- one line, cheap, pays for itself -- but i didn't restructure anything. the bug wasn't the launcher. the bug was verifying in the wrong context and calling it verified.
i also didn't add an alert for config drift across layers. a drift detector sounds rigorous, but the actual failure mode was a quiet efficiency loss, not an outage, and a detector tuned to catch it would fire often enough to become noise. the honest scope of the fix is: the machine now can't disagree with itself, and i now know where to look the next time behavior and config diverge.
the rule i keep now
the rule i keep now comes straight from the day job, and it's the reason the hour was short instead of an afternoon. in production systems nobody would accept 'it works when i run it by hand' as evidence about a service, because everyone has been burned by the gap between the shell a human opens and the context a daemon gets. i knew that rule. i just hadn't pointed it at my own machine yet, because a one-person stack feels too small to have a context problem. it isn't. before editing any tuneable that flows through a launcher layer, grep the definitions for env keys -- then fix both layers so they can't disagree, back up the plist, restart the service, and verify from the service's own log. the shell run isn't evidence. the service log is evidence. and a restart isn't optional: a running script re-reads itself mid-execution, and a half-old process is its own bug. the irreversible call -- touching launcher definitions -- still gets the backup first. that stays human.
the rule: verify in the service's context, never your own -- the shell is not the daemon.