Skip to content

fix(coverage): stop internal/fuse's floor flaking on runner load (#438) - #527

Merged
scttfrdmn merged 4 commits into
mainfrom
fix/438-fuse-coverage-flake
Sep 18, 2026
Merged

scttfrdmn merged 4 commits into
mainfrom
fix/438-fuse-coverage-flake

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #438.

What was flaking, exactly

#438 asks for the difference between a 72.5% run and a 71.8% one to be named. Both profiles are
still on the run — coverage uploads coverage.out with if: always(), and run 31767088547 on
commit ff795af9 has two artifacts, attempt 1 at 03:40 and attempt 2 at 04:31. Downloading both
reproduces the issue's numbers exactly:

attempt internal/fuse
1 (failed) 819/1140 = 71.84%
2 (rerun, passed) 827/1140 = 72.54%

Diffing the uncovered block sets gives six blocks, eight statements, strictly one-directional —
attempt 1's covered set is a subset of attempt 2's. Nothing else in the package moved:

filesystem.go:1149.65,1152.24   2   fetch: if leader := fs.fetches.join(...); leader != nil
filesystem.go:1152.24,1153.49   1     if leader.err == nil {
filesystem.go:1153.49,1155.5    1       if data, ok := leader.slice(off, length); ok
filesystem.go:183.65,185.52     2   inflightFetch.slice, reachable only from that arm
filesystem.go:189.2,189.43      1     return f.data[start : start+length], true
filesystem.go:1292.28,1294.4    1   coveringLocked: if f.covers(off, length) { return f }

All eight are the flight-sharing follower path. A follower only exists when a second read for a
contained range arrives while the first GET is still outstanding — which an idle machine arranges by
accident and a loaded runner does not, because the first GET completes before the second read starts,
join returns nil, and the arm never executes. The arm was covered by luck. #438 is what luck looks
like when it runs out, and the cost was a required check going red on a bump that does not import the
package.

The fix

Five tests own the arm now, and they construct the leader instead of racing for one: registered
through start, given its result directly, done closed without going through finish. That is the
state a real follower observes — finish removes a fetch from the map before it closes done, so a
leader that is both joinable and complete is exactly the window a follower wakes in.

Running the new tests alone covers all eight statements, plus six that no run had ever executed:

  • slice's short-leader rejection (the EOF case the bool return exists for)
  • three statements of the double-check window between join and start
  • fetch's error return

Darwin goes 823/1140 → 829/1140, so linux should go 827 → 833 (73.07%).

The floor stays at 72, deliberately. Ratcheting to the new measurement would spend the margin this
work exists to create, and buy back the flake the moment another statement turns out to be
load-dependent. The margin is the deliverable. Per .coverage-floors' own rule the real number has to
be read from this PR's coverage log, not a local run.

Mutation testing

Six mutations, each a compiling one-or-two-line change, each caught:

mutation caught by
slice drops the negative-start check the slice table, "a range starting before the fetch"
slice checks the claimed length, not the bytes held the short-leader test
join never finds a leader the join table
fetch ignores the leader's error the failed-leader test
coveringLocked never matches 3 tests, two of them pre-existing
fetch returns its error before retiring the flight the error test, in 0.05s

Two of those changed the tests, which is the point of running them.

join returning nil survived the first pass. It is invisible to any GET-count assertion, because
fetch falls through to start and start's own coveringLocked finds the same leader and serves
the follower from the second window. So the join at the top of fetch is an optimization, not a
behavioural gate, and it needed owning directly rather than through fetch. Invisible is not
harmless: the self a follower registers in that window advertises a range nobody is fetching, and
unclaimedStart trims prefetches against exactly that list.

The failed-leader test also passed with and without the leader.err == nil check, because
fetchUncached returns nil data on failure, so slice rejects the leader on length alone and the
error check is redundant in production. That leader now holds bytes it must not hand over, which is
what makes the branch load-bearing — the comment on the fetches field commits to a read not
inheriting a prefetch's deadline, so the branch is worth owning.

And the error test uses Fatal, not Error, on the still-advertised check: continuing past it joins a
flight whose done channel nothing closes, which turned that mutation from a 0.05s failure into a
ten-minute package timeout whose panic names a goroutine rather than a cause.

Two corrections to .coverage-floors

Both measured, not reasoned about.

  1. The darwin/linux gap is not a denominator difference. The file said the two platforms "do not
    even have the same denominator" because internal/fuse compiles unmount_path_linux.go (52
    lines) on CI and unmount_path_darwin.go (44) locally. Coverage counts statements, and both
    files contribute exactly 2 — the package totals 1140 on both platforms. The real gap is seven
    blocks in mount.go and xattr.go that one platform executes and the other does not. The
    conclusion it drew was right and the reason it gave was not, which is the kind that survives.

  2. The denominator moves with the toolchain, which is a larger effect and was not known. Go
    1.26.6 counts 1140 statements in this package; Go 1.27.1 counts 1790, because it splits
    coverage blocks far more finely — filesystem.go alone goes from 209 blocks to 298. A
    GOTOOLCHAIN=auto machine with a newer Go than go.mod's gets the finer granularity silently:
    1.27.1 measured this package at 71.96% where 1.26.6 measured 72.19%, same tests, same tree. A local
    floor check has to pin the toolchain, and every floor in that file shifts when CI's Go moves to
    1.27
    — worth knowing before that bump lands.

Not done

filesystem.go:1167.49,1171.5 (2 statements) — the success return inside the double-check window —
stays uncovered. It requires a covering fetch to appear between fetch's join and its start, two
mutex acquisitions in the same goroutine with no yield point between them. testaws' OnFire hook
exists for making exactly this kind of race deterministic, but it fires during an HTTP request and
there is no request in that window. Covering it would mean adding a test-only seam to production code,
which did not seem worth 2 statements — but it is a real gap rather than an oversight, so it is stated
rather than left to be rediscovered.

Verification

go test -race ./internal/fuse/ and ./internal/config/ both pass (the latter parses
.coverage-floors). golangci-lint reports 3 pre-existing modernize findings in errno.go and
xattr_oracle_test.go, files this PR does not touch, and CI lints --new-from-merge-base. All
measurements above were taken under GOTOOLCHAIN=go1.26.6 for the reason in correction 2.

The coverage gate failed PR #426 — a cargoship bump that internal/fuse
does not import — at 71.8% against a floor of 72, and a rerun of the same
commit passed at 72.5%. That is a 0.5-point margin being decided by how
loaded the runner was.

Both profiles are still on the run. Downloading them and diffing the
uncovered block sets names the difference exactly: eight statements, all of
them one arm, and nothing else in the package moved.

  filesystem.go:1149-1155  fetch serving a follower from a GET in flight
  filesystem.go:183-189    inflightFetch.slice, reachable only from there
  filesystem.go:1292-1294  coveringLocked's returning branch

A follower only exists when a second read for a contained range arrives
while the first GET is still outstanding. An idle machine arranges that by
accident; a loaded runner finishes the first GET before the second read
starts, `join` returns nil, and all eight statements go unexecuted. So the
arm was covered by luck, and #438 is what luck looks like when it runs out.

Five tests now own it, and they construct the leader rather than racing for
one: registered through start, given its result directly, done closed
without going through finish. That is the state a real follower observes,
since finish removes a fetch from the map before closing done.

Running the new tests alone covers all eight statements, plus six that no
run had ever executed: slice's short-leader rejection, three statements of
the double-check window between join and start, and fetch's error return.
Darwin goes 823/1140 to 829/1140.

Six mutations, each caught:

  slice drops the negative-start check      the slice table
  slice checks claimed length, not held     the short-leader test
  join never finds a leader                 the join table
  fetch ignores the leader's error          the failed-leader test
  coveringLocked never matches              three tests, incl. two existing
  fetch returns before retiring the flight  the error test

Two of those changed the tests. `join` returning nil is invisible to any
GET-count assertion, because fetch falls through to start and start's own
coveringLocked finds the same leader — so join is an optimization and
needed owning directly rather than through fetch. And the failed-leader
test passed with or without the `leader.err == nil` check, because
fetchUncached returns nil data on failure and slice rejects the leader on
length alone; the leader there now holds bytes it must not hand over, which
is what makes the branch load-bearing.

The error test also uses Fatal rather than Error on the still-advertised
check. Continuing past it joins a flight whose done channel nothing closes,
which turned that mutation from a 0.05s failure into a ten-minute package
timeout naming a goroutine instead of a cause.

The floor stays at 72. Ratcheting to the new measurement would spend the
margin this work exists to create.

Two corrections to .coverage-floors while in there, both measured. The
darwin/linux gap is not a denominator difference — coverage counts
statements, and unmount_path_linux.go and unmount_path_darwin.go
contribute 2 each, so both platforms total 1140; the gap is seven blocks in
mount.go and xattr.go. The denominator does move with the toolchain, which
is larger and was not known: Go 1.26.6 counts 1140 statements where Go
1.27.1 counts 1790, splitting blocks more finely. A GOTOOLCHAIN=auto
machine with a newer Go than go.mod's gets the finer granularity silently,
so a local floor check has to pin the toolchain — and every floor in that
file shifts when CI's Go moves to 1.27.
@scttfrdmn scttfrdmn added type: bug Something isn't working as expected priority: medium Important but not urgent area: fuse FUSE layer and filesystem interface area: tests Test infrastructure and test suite area: ci-cd CI workflows, gates, and release automation labels Sep 18, 2026
@scttfrdmn
scttfrdmn merged commit 7551035 into main Sep 18, 2026
47 checks passed
@scttfrdmn
scttfrdmn deleted the fix/438-fuse-coverage-flake branch September 18, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci-cd CI workflows, gates, and release automation area: fuse FUSE layer and filesystem interface area: tests Test infrastructure and test suite priority: medium Important but not urgent type: bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coverage: internal/fuse's floor has a 0.5-point margin on linux, and it flakes

1 participant