Repository navigation
fix(wsl): refresh hook relay on PTY reattach - #13139
Conversation
📝 WalkthroughWalkthroughAdds conditional WSL hook relay setup for valid PTY reattachments without an existing connection ID. Integrates the helper into stable-pane, runtime-controller, and IPC spawn flows. Adds tests for distro filtering and repeated reattachments. Adds a Windows/WSL benchmark that measures stale endpoint timeouts, refreshed hook delivery, latency statistics, threshold compliance, and cleanup. Adds a package script to run the benchmark. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
config/scripts/wsl-hook-relay-reattach-benchmark.mjs (1)
263-266: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse POSIX path utilities for guest paths.
These paths target the WSL guest filesystem. Use
path.posix.joinandpath.posix.dirnameinstead of assembling paths with/.Proposed change
-import { join } from 'node:path' +import { join, posix } from 'node:path' ... - const benchmarkRoot = `${guestHome}/.orca-wsl/benchmarks/${instanceKey}` - const scriptPath = `${benchmarkRoot}/.orca/agent-hooks/codex-hook.sh` - const endpointPath = `${guestHome}/.orca-wsl/agent-hooks/instance-${instanceKey}/endpoint.env` - const cleanupPaths = [benchmarkRoot, `${guestHome}/.orca-wsl/agent-hooks/instance-${instanceKey}`] + const guestOrcaRoot = posix.join(guestHome, '.orca-wsl') + const benchmarkRoot = posix.join(guestOrcaRoot, 'benchmarks', instanceKey) + const scriptPath = posix.join(benchmarkRoot, '.orca', 'agent-hooks', 'codex-hook.sh') + const endpointPath = posix.join( + guestOrcaRoot, + 'agent-hooks', + `instance-${instanceKey}`, + 'endpoint.env' + ) + const cleanupPaths = [benchmarkRoot, posix.dirname(endpointPath)]As per coding guidelines, use
path.joinor Node path utilities for file paths; never assume/or\.Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 17a7503d-8dfe-42a8-a981-5b141fea0937
📒 Files selected for processing (5)
config/scripts/wsl-hook-relay-reattach-benchmark.mjspackage.jsonsrc/main/agent-hooks/wsl-hook-relay-reattach.test.tssrc/main/agent-hooks/wsl-hook-relay-reattach.tssrc/main/ipc/pty.ts
…3260) * test(wsl): drive hook-relay reattach bench through real PTY spawn Follow-up to #13139: stop calling ensureWslHookRelayForReattach from the benchmark and instead reattach a surviving WSL PTY via main's registerPtyHandlers path, so a missing or misplaced integration in pty.ts fails the bench. * refactor(bench): isolate reattach relay refresh measurement and verify s - Wrap benchmark in try-finally for reliable cleanup - Add jiti module graph duplication detection to catch missing pty.ts integration - Track relay refreshes only during reattach phase to avoid false positives from earlier phases - Disable agent-status hooks during PTY spawn (reattach path doesn't gate on them) - Improve error messages and make cleanup safe with optional chaining
…ablyai#13260) * test(wsl): drive hook-relay reattach bench through real PTY spawn Follow-up to stablyai#13139: stop calling ensureWslHookRelayForReattach from the benchmark and instead reattach a surviving WSL PTY via main's registerPtyHandlers path, so a missing or misplaced integration in pty.ts fails the bench. * refactor(bench): isolate reattach relay refresh measurement and verify s - Wrap benchmark in try-finally for reliable cleanup - Add jiti module graph duplication detection to catch missing pty.ts integration - Track relay refreshes only during reattach phase to avoid false positives from earlier phases - Disable agent-status hooks during PTY spawn (reattach path doesn't gate on them) - Improve error messages and make cleanup safe with optional chaining
Fixes #12900
Summary
wslDistroas ownership evidence; fresh spawns, native PTYs, SSH PTYs, and legacy results without a distro remain no-opsDeterministic reproduction and metrics
Run on a Windows host (the bench hard-requires
process.platform === 'win32'; do not run the guest Linux Node binary):Use the installed distro name from
wsl.exe --list --quiet(e.g.Ubuntu, not necessarilyUbuntu-24.04). Guest needs Node ≥18 andpython3.If this checkout is a worktree whose
.gitpoints at a Windows path, rungit/node/pnpmfrom the Windows side (PowerShell or Win32 Node via WSL interop). Running them only inside the WSL shell can fail against that pointer.Pass criteria (machine-independent)
The median speedup multiplier is machine-dependent; the three thresholds above are the deterministic proof.
Verified run
Measured on Windows / WSL2
Ubuntuwith 20 real generated Codex hook executions per phase (--distro Ubuntu --samples 20), guest Node v22.22.1 / python3 3.14.4:[]stalledConnections: 21)Median speedup: 8.8× (stale 1659.9 ms → refreshed 188 ms). Earlier authoring machine showed ~28×; the multiplier is host-dependent.
stalledConnections: 21in the stale phase, then a clean 20/20 after refresh, is exactly the stale-endpoint-then-refresh behavior this fix targets.The benchmark uses the same stable endpoint path before and after restart, asserts the stale timeout path was exercised, checks p95 stays below 1 second after refresh, and fails unless every refreshed hook reaches the host.
Note on
pnpm install: root postinstall may fail rebuildingwindows-native-registrywhen Visual Studio C++ Build Tools are absent. That module is not on the bench path (build:relay+ jiti-loaded relay/reattach/hook-service). Packages still link; install VS Build Tools only if you need a fully green install for Electron builds.Verification
pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/wsl-hook-relay-reattach.test.ts src/main/agent-hooks/wsl-hook-relay-manager.test.ts(19 passed, 3 platform-skipped)pnpm run typecheck:node--deny-warningspnpm run check:max-lines-ratchetgit diff --checkThe full
src/main/ipc/pty.test.tsrun on this Windows host completed 435 passing / 19 skipped and reported three unrelated existing Windows-path/resume assertions. The touched reattach gate and relay-manager suites pass cleanly; PR CI provides the Linux full-suite oracle.