Skip to content

fix: the cluster.redis block selects the cache a mount actually uses (#178) - #259

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/178-cache-from-config
Aug 3, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/178-cache-from-config

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #178.

The defect

cache.NewFromConfig — the only reader of cluster.redis.* anywhere in the repository — had no caller. Adapter.Start built a MultiLevelConfig literal of its own instead, so seven cluster keys plus a seven-key redis sub-block were decoded, defaulted, validated and documented while no mount consulted any of them. A deployment that configured a shared Redis cache got a private in-process one, with no error and no warning, and looked correct until two nodes disagreed about a file.

Third instance of the shape #156 and #176 were: a config block whose every layer worked except the one that had to call it.

Both halves are fixed together, because they are the same mistake. NewFromConfig's other arm passed a literal nil to NewMultiLevelCache, discarding the L1/L2 sizing, the TTL, the persistent-cache directory and the eviction policy its argument carried — so even with a caller, most of the cache: block would still have been ignored. The mapping now lives in internal/cache beside the selection rather than in the adapter, since a second copy of it is how the two came to disagree in the first place. Adapter.cache is typed types.Cache: naming the concrete *cache.MultiLevelCache there is what made the function uncallable, as the field could not hold what it returns.

An unreachable Redis fails the mount rather than falling back. Falling back is this same defect one layer out — both nodes come up, both believe the cache is shared, and nothing in either log explains the disagreement.

What wiring it up would have shipped

A contract-violating cache on the read path. So the conformance suite came first, and it found one.

internal/cache/cachetest is a shared suite every types.Cache implementation is now run against. There were five implementations, one contract, and no test in common — each checked against the questions its own author thought to ask. That is why four of them satisfied a rule the fifth violated in the most consequential direction: the Redis cache answered a ten-byte request with two bytes. GETRANGE clamps to the stored value's length, so GETRANGE k 8 17 over a ten-byte value returns two bytes and no indication that eight are missing. internal/fuse passes a non-nil hit to the kernel verbatim as file content, so that is a truncated read reported as a successful one — audit finding H7's shape arriving through a different door. It had ten tests of its own, all passing, none of which asked for a range longer than what was stored.

Ten cases, each stating in its failure message what a caller would observe: exact-range hits, straddling and past-the-end reads as misses, a request longer than the entry as a miss, the open-ended size <= 0 form, the returned slice not aliasing the cache's own storage, a newer Put winning where it overlaps, and Delete removing the key it names and nothing that merely shares a prefix with it. A sixth implementation is one enrollment away.

Tests

Test What only it can show
TestStartReachesTheCacheTheConfigNames that a mount gets the configured cache — drives Adapter.Start against a substrate-backed S3 endpoint plus miniredis, and reads the stored key back out of the Redis server rather than asserting the type alone
TestStartRefusesAnUnreachableRedis the mount does not come up with the wrong cache; asserts which failure, since Start's last step fails anyway on a host with no FUSE helper
TestCacheHonorsTheCacheContract ×5 the contract, asked identically of every implementation
TestNewFromConfigReturnsTheImplementationTheConfigNames which implementation a config selects — the three pre-existing tests asserted NotNil, which holds for either
TestMultiLevelConfigFromMapsEveryConfiguredValue the cache: block reaching the cache, values spelled out rather than recomputed from the input

Mutation-verified, all four ways: reverting Start to the hand-built literal fails both adapter tests; removing the length check in redis.Cache.Get fails exactly the two conformance cases about short answers.

Adapter.Start's mount step is tolerated because a host without a FUSE mount helper cannot perform it, and the cache is built four steps earlier. Skipping would be worse — the wiring under test is testable on every host, and a skip would silently retire the test on the machines that run it most.

Gates

go build · go vet · full go test -race ./... clean · coverage gate 30 packages at or above their floor, with internal/cache ratcheted 82 → 85 and internal/cache/redis 87 → 88 · golangci-lint --new-from-merge-base=origin/main 0 issues · markdownlint on the touched docs.

NewCache and NewFromConfig take a context for the connectivity check, which neither cache retains — a cache lives as long as the mount does, so a startup context stored inside one would cancel every later operation the moment startup returned. The contextcheck finding on the in-process arm is suppressed with the reason at the call site: what ctx would reach there is the prefetch workers, which are stopped by Close on the unmount path and would otherwise never fetch anything.

Docs

docs/index.md's Not yet wired up table loses its Redis row. examples/config.yaml's cluster: comment no longer says NewFromConfig "currently has no caller" and states what setting both flags does, including the refusal.

cache.NewFromConfig — the only reader of cluster.redis.* anywhere in the
repository — had no caller. Adapter.Start built a MultiLevelConfig literal of
its own instead, so seven cluster keys plus a seven-key redis sub-block were
decoded, defaulted, validated and documented while no mount consulted any of
them. A deployment that configured a shared Redis cache got a private
in-process one, with no error and no warning, and looked correct until two
nodes disagreed about a file. Third instance of the shape #156 and #176 were.

Both halves of that mistake are fixed together, because they are the same
mistake. NewFromConfig's other arm passed a literal nil to NewMultiLevelCache,
discarding the L1/L2 sizing, the TTL, the persistent-cache directory and the
eviction policy its argument carried — so even with a caller, most of the
cache: block would still have been ignored. The mapping now lives in
internal/cache beside the selection rather than in the adapter, since a second
copy of it is how the two came to disagree in the first place, and
Adapter.cache is typed as types.Cache: naming the concrete
*cache.MultiLevelCache there is what made the function uncallable, as the
field could not hold what it returns.

An unreachable Redis fails the mount rather than falling back. Falling back is
this same defect one layer out — both nodes come up, both believe the cache is
shared, and nothing in either log explains the disagreement — so the error
names cluster.redis and the mount does not start.

Wiring it up first would have put a contract-violating cache on the read path,
which is why the conformance suite came first. internal/cache/cachetest is a
shared suite every types.Cache implementation is now run against. There were
five implementations, one contract, and no test in common — each was checked
against the questions its own author thought to ask, and that is why four of
them satisfied a rule the fifth violated in the most consequential direction:
the Redis cache answered a ten-byte request with two bytes. GETRANGE clamps to
the stored value's length, so `GETRANGE k 8 17` over a ten-byte value returns
two bytes and no indication that eight are missing. internal/fuse passes a
non-nil hit to the kernel verbatim as file content, so that is a truncated read
reported as a successful one — audit finding H7's shape arriving through a
different door. It had ten tests of its own, all passing, none of which asked
for a range longer than what was stored.

Ten cases, each stating in its failure message what a caller would observe:
exact-range hits, straddling and past-the-end reads as misses, a request
longer than the entry as a miss, the open-ended size <= 0 form, the returned
slice not aliasing the cache's own storage, a newer Put winning where it
overlaps, and Delete removing the key it names and nothing that merely shares
a prefix with it. A sixth implementation is one enrollment away.

The adapter-level test drives Adapter.Start itself against a substrate-backed
S3 endpoint and miniredis, because internal/cache's own tests can show that
NewFromConfig selects a Redis cache and only this one can show that a mount
does — which is the entire defect. It reads the stored key back out of the
Redis server rather than asserting the type alone, and tolerates only the
mount step failing, since that is the one step a host without a FUSE helper
cannot perform and the cache is built four steps earlier.

NewCache and NewFromConfig take a context for the connectivity check, which
neither cache retains: a cache lives as long as the mount does, so a startup
context stored inside one would cancel every later operation the moment
startup returned.

Closes #178
…host does

The two Adapter.Start tests failed in CI and passed locally, and the difference
was the machine rather than the code: buildS3Config deliberately maps no
credential fields, so an adapter built from a Configuration gets its
credentials from the AWS default chain — and on a developer machine that chain
finds the ambient profile. In CI there is none, so it reaches EC2 IMDS,
NewBackend's closing HealthCheck fails, and Start never gets as far as building
the cache.

The probe that convinced me these tests needed no credentials was run in this
shell, with credentials in it, so it could only ever have said yes.

TestMain sets the pair for the whole binary. Not t.Setenv, which cannot be
called from a parallel test and mutates process-wide state that other parallel
tests in the package read. Verified the way CI failed: with the environment
stripped and HOME pointed at an empty directory, the package fails exactly as
the job did, and passes with TestMain restored.
@scttfrdmn
scttfrdmn merged commit 2b7f366 into main Aug 3, 2026
23 checks passed
@scttfrdmn
scttfrdmn deleted the fix/178-cache-from-config branch August 3, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cache.NewFromConfig has no caller, so the entire cluster/redis config block is unreachable

1 participant