This post is about one pattern that kept showing up while I was building a local-first meeting-notes app for macOS, mostly with coding agents doing the typing. A fair number of checks in that project (tests, pre-commit gates, the verification of a fix, a performance budget) couldn’t go red for the right reason, which in practice meant one of three things: the check stayed green while the bug was there, it couldn’t go red at all and just hung, or it went red when nothing was wrong. The tests that were never seen failing are what I wrote about in TDD and mutation testing when agents write the tests, so here we’ll look at the other shapes, since each of them looked like a reasonable way to check the thing.
Measuring the thing next to the thing
The first one stayed green because it measured a property that sits next to the one the bug broke. The app records a call as a stereo file, system audio on the left and the microphone on the right, and after a fix that finally got the mic recorded, the fix was verified by looking at the mic channel’s RMS and checking that it had a non-zero number of samples. Both looked healthy, so the fix was called done.
The next three real meetings came out 1.92x, 1.92x and 1.89x as long as the meetings themselves. All of the audio was there, which is why RMS and sample counts were fine, but about half of each channel was exact zeros, because the code that wrote the two sources into one file padded whichever side had less data with silence on every callback, so the voices took turns with silence about every half second. Loudness can’t see inserted silence, and nothing in the verification compared the file’s length with the time that had passed.
The check that replaced it is a manual acceptance step that does exactly that. It compares the WAV’s duration (from afinfo) with the meeting’s elapsed time in the database, allowing at most 1 s over and 20 s under, and it counts runs of exact zeros longer than 250 ms in each channel, which should only appear where nobody was talking or nothing was playing. The zero-run part is a few lines of Python, roughly:
samples = data[channel::2] # 16-bit stereo, one channel
zeros = runs = run = 0
for value in samples:
if value == 0:
zeros += 1
run += 1
continue
runs += run >= 4_000 # 250 ms at 16 kHz
run = 0
After the fix, a 54-minute call came out at 3,213.99 s against 3,214.3 s elapsed. One detail from the written step is worth copying, too. The recorder logs fileFrames and elapsedFrames at stop, and they’re always equal, because the new writer is driven by elapsed time, so the step says plainly that this line only confirms you’re reading the right log, and that the afinfo comparison is the length check that can fail. When we verify a fix, it pays to ask which property the bug breaks (here, “the file is as long as the meeting”) and check that one, from a source the code under test doesn’t control.
A pattern that matches nothing
The repo also has a few grep-style pre-commit gates, written in shell and awk, that block things like print(), logging of transcript text or meeting titles, Combine and ObservableObject. An agent added them in one commit whose message said they “pass clean”, and they kept passing for about four months.
Three of the eight used \b for word boundaries, and the awk that ships with macOS (version 20200816) doesn’t support it, it reads \b as a backspace character, so those patterns could never match:
awk 'BEGIN{print ("import Combine" ~ /\bCombine\b/)}'
# prints 0
That was about 215 commits of gates reporting “ok” without looking at anything. It came up while an agent was extending the logging gate to cover people’s names and noticed its new rule couldn’t fire. The first fix swapped \b for a [^A-Za-z0-9_] class and added a self-test, and the self-test still let bypasses through, a title in the second interpolation of a log call, or a logger that wasn’t named logger. What made it hold is a rule that a gate doesn’t count until it has caught a known violation and let a near miss through, with both kinds of case written down next to the gate.
A gate that matches nothing looks exactly like a clean tree. Once the patterns could match, the tree turned out to have no violations, which was a relief, since for those four months nothing would have stopped one from going in.
Fakes built the way the code wanted
Two bugs got past the tests because the test doubles behaved the way the code assumed the real thing did. The first was about notification buttons. Every button press arrives through one AsyncStream that lives as long as the app, and its only for await loop sat inside the meeting-detection service. When detection restarted after a settings change, the restart cancelled the task running that loop, and cancelling the task that iterates an AsyncStream finishes the stream for good (later yields return .terminated, and a new loop ends at once), so from then on every notification button did nothing until relaunch. No test drove a restart through the real notification manager, so nothing noticed, and the obvious way to fake it, a fake that builds a fresh stream on each start, passes this bug by design. The regression tests now use the real notification manager over a fake Notification Center and go through a real detection restart.
The second was two detection triggers arriving in quick succession. The router cancelled the in-flight start when it scheduled the newer one, and one proposed fix was “first start wins”: let the cancelled start carry on, and refuse the second because the first already holds the app. Its test passed. The real meeting store writes through GRDB 7’s async API, which calls Task.checkCancellation() before running the write, so in the app the cancelled start threw at the database insert after its audio capture had already started, stopped the capture, and the second trigger had already been refused, so neither one recorded anything. The fake store just ignored cancellation. It now has a switch that makes it behave like the real one (abridged):
/// When set, writes throw `CancellationError` from a cancelled task,
/// as the real store does: GRDB's async write checks cancellation first.
var honoursCancellation = false
func createMeeting(...) async throws -> Meeting {
if honoursCancellation {
try Task.checkCancellation()
}
// ...
}
In the end the router stopped cancelling starts and runs them one after another instead. What I’d take from both cases is that a fake has to copy the real dependency’s behaviour in exactly the place the code relies on it, and that it helps to fake only the lowest boundary a test can’t run (the OS’s Notification Center, here) and keep the layers above it real.
A test that hangs instead of failing
This test could see its bug and still couldn’t go red. The notification manager has to re-read the notification permission before each prompt, because if the user turned notifications off, the prompt has to fall back to an in-app alert. The regression test revokes the permission, shows a prompt, and then waits on the response stream for the answer from the fallback alert. With the bug put back, the manager used its cached “authorized” status, posted to Notification Center again, showed no alert, and never yielded a response, so the test sat on responses.next() forever. A hung test is a timeout in CI at best, and locally it looks like a slow run you kill and forget about.
The fix was to assert something the bug breaks before waiting on something the bug prevents. The test now requires the fallback alert to exist first, and with the bug back it fails in 0.004 s (abridged):
let alert = try #require(await capture.lastRequest)
#expect(alert.title == "Meeting Detected")
let response = await responses.next()
This test and the others that wait on that stream carry Swift Testing’s .timeLimit(.minutes(1)) trait as a backstop, with a comment saying a lost response would hang rather than fail. A time limit is worth having, but it isn’t proof that the test can fail, since it only works in whole minutes and only ends a wait that responds to cancellation (an AsyncStream does, a continuation nobody resumes doesn’t).
A measurement noisier than the effect
The last check went red with nothing wrong. The app runs Apple’s on-device SoundAnalysis classifier during a recording to notice that nobody has spoken for a while, and the plan had budgets for it, under 1% of a core, at most 80 MB of memory, and at most 400 ms of analysis per check. They were measured as two real recordings, one with the feature on and one with it off, and the difference between them. That A/B run failed all three, by a lot (+3.5% of a core, +186 MB, and a p95 of 3-4 seconds per check).
A sample of both runs showed why. Both were dominated by live whisper transcription in the same process, whose load depends on how much people said in each recording, and the per-check time was wall time on the main actor, including the wait for CPU behind transcription. The difference between two such runs mostly measured how talkative each meeting was. The fix was to make the feature report its own cost, logging its own thread’s CPU time and footprint changes when a recording stops:
checks=102, threadCpuMsTotal=21859, threadCpuMsP50=154, threadCpuMsP95=362
Over a 53-minute recording that’s 0.69% of a core on the analyzing thread, and per check a p95 of 362 ms of CPU, so the CPU and analysis budgets passed. Thread CPU can’t see work the feature causes on other threads, so the same line also logged the CPU of all threads during checks, 1.43%, as an upper bound that includes transcription. Memory passed only as a bound of about 14 MB (creating the classifiers added 1.9 MB), and the +186 MB in the A/B run was transcription’s buffer, which swung by about 165 MB a dozen times in one recording. The wall time per check stayed long (a p95 of 5.45 s) because it still waits behind transcription, which is fine for a check that runs every 30 seconds, but it’s a different number from the one the budget was about. When the noise from everything else in the process is bigger than the thing we’re measuring, an on/off comparison can’t answer the question, and it’s easier to let the feature count its own work, while being clear about what that count can’t see.
Summary
None of these checks were lazy, each looked like a reasonable way to verify the thing, and most were written or proposed by an agent and accepted by me without much pushback. For the three that stayed green, the habit that would have caught them is to write down, for each check we add, the specific bug it should catch, then make that bug happen once and watch the check go red on an assertion, not on a compile error or a timeout. A test that only hangs needs an assertion on something the bug breaks before it waits, and a measurement that goes red with nothing wrong needs a number the rest of the process can’t move. If a check still can’t be made to fail on its bug, I’d suspect the check before the code.