Repository navigation
fix: re-roll freePort picks that collide in claude-native hook e2e - #1653
Conversation
Linux bind(0) can hand out the same port twice (~1.3e-4/pair measured); when portB === portA the hook correctly attaches and the test premise silently dies, failing the release CI run with 'spawned — not attached to A'. freePort() now takes an exclusion set and re-rolls; the two-port e2e passes [portA]. Fixes #1652
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1605-pr.1653.51f680eThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1653.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Reviewing (verifying, not redoing — this is completed agent work per protocol). Status so far:
Will follow up with the full review conclusion (issue-direction check, regression inventory, CI status) once the control lands. |
Review complete — verdict: mergeable (merging stays human-only). ① Original issue (#1652) — direction check. Root-cause analysis verified against code at current master:
② Regression review — existing behaviors touched by the diff (diff touches exactly one file,
③ Code review. Re-roll loop trivially correct: the loop is unbounded only if the exclude set covered the entire ephemeral range (1 element here — effectively impossible; worst case one extra bind/close cycle). ④ Test validity. The fixed subtest pins the two-port non-attach behavior (B must spawn its own instance on its own port, distinct pid). The re-roll helper itself has no unit test — acceptable for a file-private helper whose logic is trivially inspectable; the regression evidence is the documented forced-collision A/B (pre-fix red with byte-for-byte CI signature / post-fix green), which is the practical substitute for a probabilistic ~1.3e-4/pair bug. ⑤ Diff cleanliness. One file, every line relevant to the fix; no whitespace churn, no generated artifacts, no lockfile drift. CI status (head d65472b): all 12 check runs Auto-merge gate (§7.4): pure Regression verdict: none introduced by this PR — zero-arg helper paths unchanged, target subtest passes locally and in CI, and the only local failures reproduce identically on clean master. 中文摘要:修复了 claude-native hook e2e 中 |
Fixes #1652
What
freePort()intests/claude-native.test.tsgains an exclusion set (freePort(exclude: readonly number[] = [])) and re-rolls until the pick misses it. The two-port hook e2e ("a healthy proxy on ANOTHER port is never attached (static URL)") now picksportB = await freePort([portA]). All other call sites keep the zero-arg form — identical behavior.Why (root cause)
Release CI run 36519443543 (v0.1.171) failed attempt 1 on this single subtest:
Linux
bind(0)can return the SAME port twice — measured 26 adjacent pick-close-pick repeats in 200 000 trials (≈1.3e-4/pair), 5 re-hits of the first port in the next 20 000 picks. WhenportB === portA, hook B resolvesplan.port === A's port,pickAttachable(src/launcher.ts:2555,c.inst.port === opts.portunder strictPort) correctly matches A and attaches — the product behaves right, the test premise silently dies, and the assertion fails.Forced-collision repro (locally setting
portB := portA) reproduces the CI failure byte-for-byte (same assertion line :943, sameattaching to running proxyactual) — see issue #1652.Pre-flight
tests/claude-native.test.ts48/48 ✔ underACP_TEST_CLAUDE_NATIVE=1npm run typecheck✔ ·npm run build✔opencode-native/dsh-native— control experiment on CLEAN master (fix stashed) reproduces the identical failure set, i.e. pre-existing environmental flakiness (tests/claude-native.test.ts linux live-E2E subtests fail/hang in shared multi-agent sandboxes #1248 class), unrelated to this diff (which touches one test file's helper only)