Skip to content

tests: hybrid_kvshare_route asserts the share path, not a sub-millisecond clock (engine #852) - #858

Merged
bong-water-water-bong merged 6 commits into
mainfrom
1bit/852-share-path-not-clock
Nov 3, 2026
Merged

bong-water-water-bong merged 6 commits into
mainfrom
1bit/852-share-path-not-clock

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #852.

tests/hybrid_kvshare_route.sh:62 asserts "the handoff ran (share + adopt, not the file route)" with
grep -q "hybrid: .* share 0\.[0-9]* ms, first byte", but app/serve.cpp:2087 logs that duration with %.3f:

1bit serve: hybrid: 30 prompt tokens: prefill 22 ms, restore 0 ms, share 5.929 ms, first byte 33 ms

So the check only passes when the share took less than a millisecond, which is a statement about the box's load,
not about the path.

The same regex is also a weaker negative arm

:76 reuses it as ! grep -q ... for "no share/adopt line was reported". There it 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. Both sites
now match the path and any duration.

Evidence — real engine path, not a synthetic log

Reproduced on the box with the engine's own hybrid route (CPU, fake provider, no device, --llama-server pointed at the
test's own backend with a 5 ms delay in its ?action=share handler, which is what system load does to that handoff
naturally):

assertion against share 5.929 ms, first byte 33 ms
old :62 no match → the check FAILS on a handoff that ran (the flake #852 reports)
new :62 match → passes
new :76 (negated) correctly fails on a log that carries a share line

Regex arms over the reported values, both directions:

line old :62 new :62 old :76 new :76
share 0.412 ms pass pass pass pass
share 3.900 ms fail pass pass (wrong) fail (correct)
no share line fail fail pass pass

What I did not change

  • No threshold is asserted. tests: hybrid_kvshare_route asserts a sub-millisecond share time, so it fails on a loaded box (not a code failure) #852 offers "if a latency bound is wanted, give it a threshold the box can hold"; the
    minimal fix is to stop asserting a clock in a check about the path, so the number is gone rather than re-tuned.
    A latency row, if wanted, belongs beside the numbers on an idle box (~0.1–0.4 ms) and needs its own control.
  • The 8 runs of the unmodified script on this box after the fix all passed, and so did 8 of the unmodified
    origin/main script — the share was sub-millisecond on an idle box, which is exactly why this flake is intermittent
    and why the failure above needed a loaded share to appear.
  • shellcheck -S warning reports one pre-existing SC2034 at :74 (reply unused); unchanged here.

bash -n clean. One file, +3/−2.

…cond clock (engine #852)

The handoff check matched "share 0\.[0-9]* ms" while serve logs the share
duration with %.3f, so any share of 1 ms or more -- which is what a loaded box
produces -- made "the handoff ran" fail on a run where the handoff did run.

The same regex is the negative arm at :76 ("no share/adopt line was reported"),
where it fails the other way: a share line at 3.900 ms does not match, so the
negated grep succeeds and a log that did carry a share line was reported clean.
Both sites now match the path and any duration.
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 5fafff7)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

852 - Partially compliant

Compliant requirements:

  • The test now asserts the handoff path instead of a sub-millisecond clock
  • The regex now matches any duration (e.g., [0-9.]* ms) rather than only sub-millisecond values
  • The test correctly identifies when share/adopt occurred vs when fallback happened

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Test assertion logic fix

The test now correctly asserts the hybrid handoff path (share + adopt) instead of incorrectly asserting a sub-millisecond latency threshold. This prevents test failures due to hardware load variations while maintaining the ability to detect when the share/adopt path was taken versus when fallback occurred.

# the share time is logged with %.3f ms, so a sub-millisecond match would assert the box's load, not the path
check "the handoff ran (share + adopt, not the file route)" 'grep -q "hybrid: .* share [0-9.]* ms, first byte" "$scratch/a.log"'
check "no fallback happened" '! grep -q "the backend prefills this request itself" "$scratch/a.log"'
check "the provider got one readable fd per region" \
    'python3 -c "import json,sys; d=json.load(open(sys.argv[1])); sys.exit(0 if d[\"fds\"]==1 and d[\"readable\"]==[16] and d[\"n_ctx\"]==4096 else 1)" "$scratch/provider.json" 2>/dev/null'
check "the socket is gone from the slot directory" '! ls /tmp/1bit-hybrid-*/kvshare-*.sock 2>/dev/null | grep -q .'
stop

# the adopt must carry the share_id: the fake backend refuses a wrong or missing one, so a provider that runs
# but whose id does not come back leaves the request to the backend -- that is the fallback this checks
check "serve starts with a provider that refuses the protocol" \
    'start "$scratch/b.log" ONEBIT_KV_SHARE=1 ONEBIT_HYBRID_PREFILL=/bin/false'
reply=$(ask)
check "the reply still comes through" '[[ "$reply" == *Paris* ]]'
check "the fallback is named once" 'grep -q "the backend prefills this request itself" "$scratch/b.log"'
check "no share/adopt line was reported" '! grep -q "hybrid: .* share [0-9.]* ms, first byte" "$scratch/b.log"'

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at f5900b4ee

The defect and the fix both check out, and I reproduced the regex arms directly instead of taking the table:

line old :63 new :63 old negated :77 new negated :77
share 0.412 ms, first byte match match pass pass
share 5.929 ms, first byte no match match pass (wrong) fail (correct)
share 3.900 ms, first byte no match match pass (wrong) fail (correct)
no share line no match no match pass pass

So the old pattern asserted a sub-millisecond duration (the %.3f in app/serve.cpp prints 0.412 or
5.929), and the same regexp as a negation quietly passed on a log that carried a share line — both halves are
real, both halves are fixed, and no other site in the tree still carries the share 0\. form.

Run for real at this head, CPU, fake backend, no device: tests/hybrid_kvshare_route.sh <1bit> ->
11/11 checks ok, PASS, including both of the changed ones. bash -n clean; shellcheck -S warning reports
exactly the one pre-existing SC2034 at :74 (reply, read inside an eval) that the body names.

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 88f1475

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at 88f1475d6 (re-posted; my verdict is a gate only at the head it names).

Head moved by update-branch only: 88f1475d6 is Merge branch 'main' into 1bit/852-share-path-not-clock, parents f5900b4ee (the head I verdicted) and 1f2dfe99f. The PR's own commit is untouched and its single file blob is identical at both heads, so the earlier evidence applies verbatim: the two regex arms reproduced by hand on the four real log lines (the old :63 arm fails on share 5.929 ms, the old negated :77 arm wrongly passes on it; both new arms correct), and tests/hybrid_kvshare_route.sh run for real -> 11/11 ok, PASS.

CI on this head: build SUCCESS, four Analyze jobs SUCCESS, hw_gate SKIPPED, pr_agent SUCCESS.

Note: the branch is one main commit behind 801a4a60c; MERGEABLE, nothing conflicts, and the merge walk will update-branch it if main moves again.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit a6f1000

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 40fd4cd

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY

At 40fd4cdd9 (the branch updated onto 692cfa25c), superseding my line at 88f1475d6.

The update added nothing of its own: 40fd4cdd9 is Merge branch 'main' into 1bit/852-share-path-not-clock with parents
a6f10006a + 692cfa25c, and the PR's own change is byte-identical at both heads —
git rev-parse 88f1475d6:tests/hybrid_kvshare_route.sh = pr858:tests/hybrid_kvshare_route.sh = f32f3421b691…, own
diff tests/hybrid_kvshare_route.sh +3/-2 either way.

Re-ran the gate rather than carrying it, with the two fake helpers extracted from this head as well (tests/fake_backend.py,
tests/fake_kvshare_provider.py; a first attempt with only the test file failed "backend 0 did not become ready", which was
my scratch dir, not the PR):

ok   serve starts with the shared route on            ok   serve starts with a provider that refuses the protocol
ok   the reply comes through                          ok   the reply still comes through
ok   the request was pinned to slot 0                 ok   the fallback is named once
ok   the handoff ran (share + adopt, not the file route)   ok   no share/adopt line was reported
ok   no fallback happened
ok   the provider got one readable fd per region
ok   the socket is gone from the slot directory
PASS   (11/11)

CI at 40fd4cdd9: build success, CodeQL + Analyze x4 success, pr_agent success, hw_gate skipped.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit d547e5e

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY

At d547e5eb4 (merge of 7e64bbd2b into 40fd4cdd9), superseding my line at 40fd4cdd9. The branch's own change is
still the single 3-line edit to tests/hybrid_kvshare_route.sh (blob f32f3421b691… at every head since 88f1475d6),
and I re-ran that script at 40fd4cdd9 with the two fake helpers from the same head: 11/11 PASS. CI at
d547e5eb4: build success.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 5fafff7

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY

At 5fafff7e0 (merge of 5f816a989 into d547e5eb4), superseding my line at d547e5eb4. Own file
tests/hybrid_kvshare_route.sh is blob-identical to the head I ran (f32f3421b691…), own diff still +3/−2, and that
script gave 11/11 PASS at 40fd4cdd9 with the two fake helpers from the same head. CI at 5fafff7e0: build success
(02:26Z).

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Independent confirmation that this is the right fix, from CI rather than from a stub: #859's run just failed on the exact
row this PR rewrites
, on a docs-only branch whose build otherwise passed.

21/67 Test #21: hybrid_kvshare_route .... ***Failed 4.58 sec
FAIL the handoff ran (share + adopt, not the file route)
1bit serve: hybrid: 30 prompt tokens: prefill 23 ms, restore 0 ms, share 1.069 ms, first byte 27 ms

share 1.069 ms — one millisecond and sixty-nine microseconds on a loaded runner — is the sub-millisecond clock assertion
being read as "the handoff did not run", which is the same false red I reproduced by hand on the old :63 arm
(share 5.929 ms failing it) and the reason :77's negated arm wrongly passed. On the same commit minutes earlier the
test passed (4.38 sec), so it is load-dependent, not deterministic — i.e. main carries a flaky ctest entry right now and
this PR removes it.

Run: https://github.com/1bit-MONSTER/engine/actions/runs/41565718288 (branch docs/puppy-os-2026-11-02, head 13b126edc,
the only failing test of 67).

Nothing changes about my READY at 5fafff7e0; this is evidence for merging it sooner rather than later.

@bong-water-water-bong
bong-water-water-bong merged commit a77aa66 into main Nov 3, 2026
8 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/852-share-path-not-clock branch November 3, 2026 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review effort 2/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant