Skip to content

The lane-shape unit test doesn't pin two of the three guards in choose_chain_lane #1879

Closed

Description

@aaj3f

This is a testing gap rather than a product defect, but I think it's a load-bearing one, and it's the reason the annotation lane-cost issue can't currently be settled in-repo.

choose_chain_lane (fluree-db-query/src/default_graph_source.rs:101) makes its decision in three steps, and the first two are categorical early returns, not cost comparisons:

if reifier_bound {
    return ChainLane::Chain;
}
let buffered = edge_first <= BUFFERED_BASE_MAX_ROWS;
if subject_bound {
    return if buffered { ChainLane::Arena } else { ChainLane::Chain };
}
// ... only now the three-way cost comparison

Both guards are there for measured reasons — the comments cite P22/C7/C10 regressing ~200× on the arena for a bound reifier, and P23 going from 46 ms to 192 s on the chain for a fully-bound edge — and lane_choice_matches_measured_starbench_shapes (:1234) is what's supposed to keep them honest. It seems maybe it doesn't, for either of them.

The reifier_bound guard. Claude caught this during the 2026-09-15 review of the originating PR (branch perf/rdf12-annotation-chain-planning), and I'm pasting the observation as recorded: "with the if reifier_bound { return ChainLane::Chain; } guard at :124 deleted, lane_choice_matches_measured_starbench_shapes still passes — this assertion resolves to Chain through the cost comparison anyway (probe_first = 1.0 → chain cost 16) and the one at :1134 is above the buffer ceiling." So the guard can be removed outright and the test that names those shapes stays green.

The subject_bound guard. Same shape, found independently on 2026-09-16 while Claude was testing a candidate relaxation of that guard for the lane-cost issue. Every recorded shape that is subject_bound and not reifier_bound carries probe_first ∈ {100 (P23), 214 (P9/P18), 214 (P19), 30M} — the minimum is 100. A gate placed inside that branch and firing at, say, probe_first <= 16 therefore never fires on anything the test records, and all eight assertions pass unchanged. The pass says only that 16 < 100; it says nothing at all about whether the relaxation is safe.

The thing that makes this worth filing rather than shrugging at is that the harness is perfectly capable of catching it — it just isn't asked to. Raising that same gate to probe_first <= 150 captures P23, flips it to Chain, and the assertion fails exactly where you'd want (left: Chain, right: Arena, at the P23 line). So the green at 16 is a genuine non-firing rather than a dead check, which is the good news and also the whole problem: the test distinguishes "your change is safe" from "your change didn't happen" not at all.

Consequence. Anyone modifying either guard — which is precisely what attempting the lane-cost fix requires — gets a green from the one test whose name promises it covers this, and nothing else in the repo covers it either. That would be true of any test with holes in it, but two things sharpen it here: the guards protect measured catastrophes (192 s, ~200×) rather than ordinary slowdowns, and the corpus those measurements came from is a large private benchmark corpus that is not available in this repository, so there is no fallback if the unit test doesn't hold. Between the private corpus and a test that skips two of three guards, we currently have no way in-repo to tell a safe lane change from an unsafe one. And the obvious way out of that — build a fixture in the shape the guards care about and validate against it instead — has since been tried and doesn't work: a synthetic low-average-fan-out ledger with one 3,345-edge hub subject runs faster on the chain lane in every variant, because at ~23k reifiers over a handful of arena leaves it never reaches the cost regime the guards exist for (the recorded one is ~21.4M reifiers over ~5,200 leaves). So the test really is the only in-repo instrument there is, which is what turns this from hygiene into the thing standing in the way.

Fix. We may want two assertions in the guards' own regimes rather than beside them — something like a subject_bound shape with a small probe_first asserting Arena (so a relaxation there goes red), and a reifier_bound shape whose cost comparison would not independently land on Chain (so deleting that guard goes red). Both are a couple of lines in the block that already exists, and the existing lane/lane_elided helpers take the inputs directly. The harder question is whether we can honestly pick those inputs without the corpus — for reifier_bound I think yes, since the guard's contract is "always Chain regardless of cost", and any shape whose costs favour Arena demonstrates it. For subject_bound the honest input is probably P23's own numbers with the expectation stated as "must stay Arena".

I may well be missing a third place this is covered — if some other test does exercise these branches, this is moot and I'd be glad to be wrong. But if it's right, I'd rather see it closed before anyone leans on that test to justify a lane change, since the failure mode is a false green on a 4,000× regression.

Activity

  1. added
    bug
    P3
    area:query
    on Sep 16, 2026
  2. bplatz commented on Nov 20, 2026

    @bplatz
    Contributor

    Fixed on next by #2017 (merged 2026-10-06, a25d446), which removes the annotation arena and its lanes: choose_chain_lane and FLUREE_ANNOTATION_LANE no longer exist there. Ships in 5.0; main (4.2.x) keeps the old code. The PR's Fixes keyword didn't close this because its base was next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area:querybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions