Skip to content

tests: the hybrid routes' slot-directory checks are scoped to their own serve, not to /tmp's glob - #1207

Merged
bong-water-water-bong merged 2 commits into
mainfrom
1bit/hybrid-slot-dir-scope
Nov 6, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
1bit/hybrid-slot-dir-scope

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Root cause

tests/hybrid_route.sh asserted "no handoff file left in the slot directory" with

[ -z "$(ls /tmp/1bit-hybrid-*/ 2>/dev/null)" ]

That glob is every hybrid serve's slot directory on the box, not the one belonging to the serve under test. Another test under ctest -j — or another lane's serve — keeps its own /tmp/1bit-hybrid-* alive with a handoff file in it for exactly the window this check looks at, so the test fails while its own directory is clean. hybrid_kvshare_route.sh had the same shape for its socket check.

Measured

Found by a full ctest -j2 sweep on today's main (29ec80c6), not by reading:

89 passed, 1 tests failed out of 90
  24 - hybrid_route (Failed)        <- "FAIL no handoff file left in the slot directory"
serial: the same test passes, twice, 28 s each

and at the failure the log shows the give-away: two slot directories alive (the slot directory is removed at exit (2 -> 0)) while this serve's own one was empty. A red build on a PR that touches nothing in this route is what a reviewer has to disambiguate by hand — the same cost engine#1070 records for the port race, via a different mechanism.

Deterministic reproducer, no racing needed: mktemp -d /tmp/1bit-hybrid-XXXXXX + a handoff.bin in it, then run the test.

before after
tests/hybrid_route.sh with a foreign slot dir FAIL "no handoff file left in the slot directory" PASS
tests/hybrid_kvshare_route.sh with a foreign kvshare-*.sock FAIL (same glob) PASS
ctest -R hybrid -j2 — 2/2, twice

Fix

Both checks now name the directory the serve under test actually owns, read off its child's argv (--slot-save-path, which the engine sets to its mkdtemp):

slotdir=$(for c in $(pgrep -P "$pid" 2>/dev/null); do
    tr '\0' '\n' <"/proc/$c/cmdline" 2>/dev/null | grep -m1 '^/tmp/1bit-hybrid-'
done | head -1)
  • no handoff file left in the slot directory → [ -n "$slotdir" ] && [ -z "$(ls "$slotdir")" ]
  • the slot directory is removed at exit → [ -n "$slotdir" ] && [ ! -d "$slotdir" ] — it used to count the glob before/after, so it passed whenever any directory vanished, including someone else's.

The [ -n "$slotdir" ] half is deliberate: if the capture ever stops working, both checks fail loudly instead of passing on an empty string.

Teeth kept, checked directly (not assumed): with a file in the serve's own directory the assertion is false; with it empty, true — captured slotdir = /tmp/1bit-hybrid-1ll0Uj in the run.

Not claimed

Same class as engine#1070; part of engine#698.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

#1207 ready for review at 2916909 — MERGEABLE, test-only (2 files, +16/−5). Reproducer and before/after in the body: a planted foreign /tmp/1bit-hybrid-* directory fails the old assertions and passes the scoped ones; ctest -R hybrid -j2 2/2 twice.

…wn serve, not to /tmp's glob

`tests/hybrid_route.sh` asserted "no handoff file left in the slot directory" with

    [ -z "$(ls /tmp/1bit-hybrid-*/ 2>/dev/null)" ]

which is every hybrid serve's slot directory on the box, not that test's. Another test under `ctest -j` (or
another lane's serve) keeps its own /tmp/1bit-hybrid-* directory alive with a handoff file in it for exactly
the window this check looks, so the test fails while its own directory is clean. Measured, on today's main:

    ctest -j2   89 passed, 1 failed out of 90 -- #24 hybrid_route, "FAIL no handoff file left in the slot
                directory", with two slot dirs alive and this serve's own one empty
    serial      the same test passes (twice, 28 s each), which is how the flake reads as a route failure

Deterministic reproducer, no racing: `mktemp -d /tmp/1bit-hybrid-XXXXXX` plus a `handoff.bin` in it, then run
the test -- it fails on that line before the change and passes after it. The same shape was in
`hybrid_kvshare_route.sh`'s "the socket is gone from the slot directory" (a foreign `kvshare-*.sock`).

Both checks now name the directory the serve under test actually owns, read off its child's argv
(`--slot-save-path`, which is `/tmp/1bit-hybrid-*`), so a foreign file cannot satisfy or fail them:

  * "no handoff file left in the slot directory"  ->  `[ -n "$slotdir" ] && [ -z "$(ls "$slotdir")" ]`
  * "the slot directory is removed at exit"       ->  `[ -n "$slotdir" ] && [ ! -d "$slotdir" ]`
    (this one used to count the glob before/after, so it passed whenever *some* directory vanished)

The `[ -n "$slotdir" ]` half is deliberate: if the capture ever stops working the checks fail loudly instead
of passing on an empty string. Teeth kept, checked directly: with a file in the serve's own directory the
assertion is false, with it empty it is true.

Gates: `tests/hybrid_route.sh` PASS, `tests/hybrid_kvshare_route.sh` PASS, both with a planted foreign slot
directory present (the failing condition), `ctest -R hybrid -j2` 2/2 twice, `bash -n` clean on both.

Same class as engine#1070 (a CI-only concurrency failure that reads as a route failure); different mechanism
(the slot-directory glob, not the port).
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Rebased onto current main (f9c00c3d): head is now 17fea55. Re-ran the reproducer on the rebased tree: hybrid_route PASS and hybrid_kvshare_route PASS with a planted foreign /tmp/1bit-hybrid-* directory present (the condition that failed before the change).

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Composition check, both PRs together on current main (965cb4bc), full suite: cherry-picked e5ba8bd7 + dff5c8f7 (#1203) and 1c169aa8 (#1207) onto a throwaway branch, Release CPU build, ctest -j2:

100% tests passed, 0 tests failed out of 92        (75.15 s; 11 npu_repack_path Skipped -- no NPU ticket)

against 89 passed / 1 failed of 90 for a -j2 sweep on 29ec80c6 before #1207 (that one failure being the box-global /tmp verdict). So the two changes compose and the class of red the sweep was producing is gone. No review comments are outstanding on either PR.

@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 17fea557.

The mechanism checks out at the source, not just in the test:

  • app/serve.cpp:1086-1089 makes the directory with mkdtemp("/tmp/1bit-hybrid-XXXXXX") and inserts "--slot-save-path", l.slot_dir as two argv elements, so tr '\0' '\n' < /proc/$c/cmdline | grep -m1 '^/tmp/1bit-hybrid-' on the child is the right capture and will not miss an --slot-save-path=/tmp/... form (there is none).
  • The two assertions the old code got wrong are the two that were glob-bound: no handoff file left in the slot directory and the slot directory is removed at exit (the second counted any directory vanishing, so another lane's serve ending could satisfy it).
  • The [ -n "$slotdir" ] half is the part I would have asked for: a capture that silently stops working turns both checks red instead of green, which is the opposite of the bug being fixed.

I did not run the suite end to end here (it needs a built 1bit serve and a fake backend, and a ctest -j sweep is the instrument that found it, not one I can reproduce in one session). What I can say without it: the class is real and the deterministic reproducer you describe — a foreign /tmp/1bit-hybrid-XXXXXX with a handoff.bin in it — is exactly what the old glob could not tell apart from this serve's own directory, and the new checks are scoped to the child's own path. If you want it, the cheapest independent confirmation is mktemp -d /tmp/1bit-hybrid-XXXXXX; touch .../handoff.bin; bash tests/hybrid_route.sh on both commits, which I will run if this comes back to me.

@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.

Follow-up to my READY at 17fea557: I ran the deterministic reproducer I said I would, and it is the before/after the body claims.

mktemp: /tmp/1bit-hybrid-foreign + handoff.bin in it (left in place for both arms), same binary `main` 29ec80c6

main's tests      -> FAIL no handoff file left in the slot directory   (and "the slot directory is removed at exit (2 -> 1)" passes for the wrong reason: a foreign dir vanished)
this head's tests -> 33 ok, 0 FAIL, with the foreign directory still sitting there

So the assertion now means what it says: the serve under test owns an empty slot directory, another lane's directory is invisible to it, and the exit check no longer passes because someone else's directory disappeared. The slotdir capture works against this engine's argv in practice (--slot-save-path <dir> from app/serve.cpp:1086-1089), so the [ -n "$slotdir" ] half is not silently turning both checks red.

@bong-water-water-bong
bong-water-water-bong merged commit d4d80e9 into main Nov 6, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/hybrid-slot-dir-scope branch November 6, 2026 03:04
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

1070 - Partially compliant

Compliant requirements:

  • The PR addresses the root cause of the port collision issue by ensuring that each test uses its own slot directory scope
  • The fix prevents false positives in test assertions by using process-specific slot directory detection

Non-compliant requirements:

  • The PR does not implement the suggested RESOURCE_LOCK "route_ports" on tests in CMakeLists.txt
  • The PR does not make freeport() safe by keeping the socket open until the child has bound

Requires further human verification:

  • The fix for port allocation race condition is not fully implemented as per the suggested approach in the ticket
  • The test suite still relies on ctest -j to run tests in parallel without explicit resource locking

698 - Partially compliant

Compliant requirements:

  • The PR does not directly address any of the zero-copy optimization targets

Non-compliant requirements:

  • The PR does not implement any of the zero-copy optimizations

Requires further human verification:

  • The PR does not contribute to the zero-copy optimization targets
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Slot Directory Scope Issue

The test hybrid_route.sh was using a glob pattern to check for handoff files in slot directories, which caused false positives when other tests were running concurrently. The fix correctly identifies the slot directory belonging to the current test's serve process, but the broader issue of concurrent test execution and resource contention remains unaddressed.

check "no handoff file left in the slot directory" '[ -n "$slotdir" ] && [ -z "$(ls "$slotdir" 2>/dev/null)" ]'
Slot Directory Scope Issue

The test hybrid_kvshare_route.sh was using a glob pattern to check for socket files in slot directories, which caused false positives when other tests were running concurrently. The fix correctly identifies the slot directory belonging to the current test's serve process, but the broader issue of concurrent test execution and resource contention remains unaddressed.

check "the socket is gone from the slot directory" '[ -n "$slotdir" ] && ! ls "$slotdir"/kvshare-*.sock 2>/dev/null | grep -q .'

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant