Skip to content

tests: hybrid_kvshare_route asserts a sub-millisecond share time, so it fails on a loaded box (not a code failure) #852

Closed

Description

@bong-water-water-bong

tests/hybrid_kvshare_route.sh:62 asserts the handoff path with a regex that also asserts a sub-millisecond
latency
:

check "the handoff ran (share + adopt, not the file route)" \
    'grep -q "hybrid: .* share 0\.[0-9]* ms, first byte" "$scratch/a.log"'

The serve logs the share duration with %.3f ms, so share 0\.[0-9]* ms matches only share 0.xxx ms. Any run
where the share takes ≥1 ms fails a test whose stated subject is "share + adopt, not the file route".

Measured on strixhalo, 2026-11-02, one binary (~/wt/mosaic/build-p4/1bit, branch npu/plan-p4-target @ 97bd257,
i.e. main 40d9632 + the NPU P4 refactor that touches no hybrid code), box load ~9.9 with other lanes' serves:

run result serve line
ctest -j4 (full suite) Failed hybrid: 30 prompt tokens: prefill 105 ms, restore 0 ms, share 3.900 ms, first byte 123 ms
ctest -R hybrid_kvshare_route Passed (share < 1 ms)
ctest -R hybrid_kvshare_route Passed (share < 1 ms)
ctest -R hybrid_kvshare_route Failed same shape

Regex check, both directions: share 3.900 ms → no match, share 0.412 ms → match. So it is the threshold, not
the path: in the failing run the log line proves the share did run (share 3.900 ms, and no fallback happened
and the provider got one readable fd per region both passed).

Proposed fix: assert the path, not the clock — e.g. match hybrid: .* share [0-9.]+ ms, first byte (or the
share/adopt markers the test's own name mentions) and, if a latency bound is wanted, give it a threshold the box
can hold (the 12:38 numbers on an idle NPU were ~0.1-0.4 ms; 3.9 ms appeared only under load).

Why it matters beyond this test: ci.yml:80 runs the whole ctest suite, so a loaded dev box reports a red gate for
something the code did right, and re-running to "make it pass" trains people to ignore the suite. Found while gating
an NPU PR that cannot reach this code path.

Activity

  1. added
    bug
    on Nov 2, 2026
  2. bong-water-water-bong commented on Nov 2, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Triaged: bug added (the repo's perf/hrx/npu/os set had no label on this one). Fix is up as PR #858
    (one file, +3/−2), verified on the engine's own hybrid route rather than on a synthetic log.

    One finding beyond the report, and it is the more dangerous half: the same regex is also the negative arm.

    :62   check "the handoff ran ..."          'grep -q  "hybrid: .* share 0\.[0-9]* ms, first byte" a.log'
    :76   check "no share/adopt line was reported" '! grep -q "hybrid: .* share 0\.[0-9]* ms, first byte" b.log'
    

    At :76 the sub-millisecond pattern fails the other way: a log that did carry share 3.900 ms does not match, so the
    negated grep succeeds and the check reports a clean log. Measured both directions — share 3.900 ms: old :62 FAIL,
    old :76 PASS (wrong), new /share [0-9.]* ms/ correct at both sites.

    Reproduction on the real path (CPU, fake provider, no device): engine at main with --llama-server pointed at the
    test's own fake_backend.py plus a 5 ms sleep in its ?action=share handler — which is what system load does to that
    handoff naturally (app/serve_hybrid.h:417 times t0 → fds received, app/serve.cpp:2087 logs it with %.3f):

    1bit serve: hybrid: 30 prompt tokens: prefill 22 ms, restore 0 ms, share 5.929 ms, first byte 33 ms
      old :62 -> no match  => "the handoff ran" FAILS on a handoff that ran   <- this issue
      new :62 -> match
    

    Why it looked intermittent: 8 runs of the unmodified script and 8 of the fixed one all passed on this box, because the
    share is sub-millisecond when the box is quiet — 0.05–0.4 ms. The failure needs a loaded share, which is exactly what a
    ctest -j4 run produces.

    No threshold is asserted instead. If a latency bound is wanted it is a separate row with its own control (the report's
    idle-box numbers are the right ones to set it from), not a hidden side effect of a check about the path.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions