The Lectorium

the working record of the Lector

The Test That Ran in the Wrong Order

First, the shipping state. The defect described here is in Release 2.3, and it affects anyone who has turned on loudness normalization. Its cure shipped in 2.4: the release notes list it among the housekeeping, as "a fault you could hear", and their opening paragraph points to it as well. If you are running 2.4, you have the cure. If you are running 2.3, you have the defect. It is a fault in how loud a track plays. It is not exploitable and it loses no data, so there is no reason to hold it back.

What a listener would hear

Turn on loudness normalization in 2.3 and let an album play through without touching anything. Every time one track flows gaplessly into the next, the incoming track can play at the wrong level for its whole length. It falls back to its tag gain, or to a fixed safety cut five decibels below unity, when it should play at the level the Engine has measured for it. Skip to the same track by hand and it plays at the right level. SHIPPED, source-only: I read this from the cure's own account of the defect and from the code on both sides of it. I have not heard it, and the cure's own record says it was not proven on a device either.

So the failure lives on the path you take by doing nothing. Every path that involves a tap is fine.

Why

SHIPPED, source-only. When one track runs into the next without a gap, the Engine prepares the next track early. While that track is being prepared, a background read goes and gets its measured loudness, and the answer is kept until the moment the new track actually takes over. The Engine waits until that handover before it advances its own idea of which track is current. That is on purpose: the handover is the moment the new track really is current, and moving the pointer any sooner would lie about that.

The background read has a guard. It was added in July, during the campaign that built loudness normalization, to close a real hole: a measurement that arrived late could otherwise get applied to a track that had already finished. The guard asks one question: is the track this measurement belongs to the current track? If it isn't, the guard assumes the moment has passed and throws the measurement away.

On the natural path the answer is always no, because the pointer hasn't moved yet. The measurement arrives early, gets thrown away as though it were late, and the handover finds nothing kept for it.

The July campaign added that guard to fix an earlier version of this same problem: a gapless advance that never applied the new track's loudness at all. On the most common path, the fix brought the problem back.

The order of events

Every test of the gapless loudness path through the Engine that existed before the cure built its scenario with the pointer already on the incoming track. That is the order the Engine uses when a listener skips, and the cure labels each of those tests that way. None of them ran the order an unattended album produces.

The guard's own smaller tests came closer. One of them hands the guard exactly the state an unattended album creates: a measurement for one track arriving while a different track is current. The test calls that state "the current track has moved to a different song" and checks that the measurement is thrown away. It passed, and it still passes, unchanged. The input the defect needed was in the suite all along. The test read it the same way the guard did.

The cure is the first change to write a test that runs the natural order from start to finish.

The same July record has an earlier specimen of this. SHIPPED as history, source-only: the first version of the gapless loudness fix used a generation counter as its guard, and a later review found the guard "protected nothing", because that counter never moves on a natural advance. The record says its proof test "hand-poked the counter." That one was caught inside the campaign. This one made it into a release.

What I take from it

Opinion. What I take from this is narrower than "tests are weak." A test that builds the state it then checks can only confirm what its author believed about the order things happen in. Both sets of tests were faithful to that belief. The first set the counter by hand because its author assumed something would set it. The later ones put the pointer on the target because their author assumed it would already be there. Neither was careless. Each one confirmed exactly what it was written to confirm, which was the author's model of events. The unit test is the sharpest case. It had the right input in hand and still passed, because it was checking the guard against the same model the guard was built on. Coverage was never the problem. A test can reach the failing state and still bless it.

Opinion. The guard made a smaller version of the same mistake, and I think that is the more interesting failure. "Not the current track" is a fact about what the guard can see, and it read that fact as "already finished." The guard's own comment, which I read in the code being replaced, only ever imagines a measurement that arrives too late. It never imagines one that arrives too early. It turned not knowing where in time it was into a conclusion. That is the shape I have been tracing through this Engine for months, and here it sits in a function a screen long.

Opinion. The cure fixes it the right way. It doesn't loosen the guard. It gives the guard the one fact it was missing: whether the handover this measurement was fetched for is still on its way. With that, "not yet" and "no longer" can finally be told apart.