← Blog
ENGINEERING3 min read

A lint rule for the workflow variable that is empty, not undefined

Aug 7, 2026DekimuAI-generated

A static-analysis rule now catches a bug that had already been fixed three separate times by hand. GitHub Actions sets an unset workflow variable to an empty string, not undefined, so `?? default` silently never fires: a cost cap becomes zero, a target list becomes empty, and the run fails in a way that reads exactly like a broken permission.

The bug that kept coming back

The same shape of defect turned up in three unrelated places in quick succession: a feature flag that was absent rather than explicitly false, a fail-fast check whose failure branch could never actually run, and a price lookup that resolved to empty instead of throwing. Each looked like its own one-off bug at the time. By the third fix it was clear they weren't independent. They were the same failure mode wearing different variable names, and a fourth incident report would have missed the point. So instead of another write-up, the fix became a lint rule.

Why `??` doesn't save you here

The trigger this time was an automated job that reads a per-run limit and a target list from workflow variables, both guarded with `?? default` on the reasonable assumption that an unset variable comes through as `undefined`. GitHub Actions doesn't do that. `env: FOO: ${{ vars.UNSET }}` resolves to the empty string, and `??` only catches `null` and `undefined`, so an empty string sails straight past it. `Number("")` is `0`, so the cap silently became zero and the job processed nothing. `"".split(",").filter(Boolean)` is `[]`, so the target list silently became empty too. The run logged a plausible-looking zero and exited 1, which is indistinguishable from a permissions failure unless you already know to suspect the variable underneath it.

An unset variable and an empty string look identical to every operator except the one built specifically to tell them apart.

Where the rule draws the line

The obvious version of this rule flags every `??` in the codebase, and we deliberately didn't write that version. A `??` guarding a variable that only ever comes from a shell environment or a `.env` file is fine — there, an absent value really is `undefined`, and the operator does exactly what it looks like it does. The bug only exists on variables a workflow file actually injects with `NAME: ${{ ... }}`. Widening the rule past that line would have buried the real hits under a pile of harmless matches — a lesson we'd already learned the hard way from an earlier rule that tried to catch too much and mostly just added noise nobody read.

The rule almost flagged itself

Its own test suite caught it doing the wrong thing twice before we shipped it. First, an early version of the pattern didn't stop matching at the closing parenthesis, so a line that had already been fixed correctly — `(process.env.X ?? "").split(",")` — got its own already-safe default swallowed into the match and reported as a violation. Second, the very first live run flagged fifteen hits across the codebase, and three of them were the rule's own smoke and test fixtures, which necessarily contain the broken shape on purpose so the tests have something to catch. Both are now permanent regression locks in the test file, specifically so nobody quietly "cleans up" the exclusion later and reintroduces the false positive.

The rule ships report-only for now. A dozen pre-existing hits are sitting in the codebase, each harmless today only because the variable behind it happens to be set. Nothing forced it to a hard fail on day one; getting visibility on every hit first mattered more than being strict before anyone had looked at what strictness would actually block.

ENGINEERING

This post was drafted by an AI system from Dekimu's public engineering record and published with automated checks, without per-post human editing.

← Back to blog