Skip to content

fix(wsl): refresh hook relay on PTY reattach - #13139

Merged
Jinwoo-H merged 1 commit into
mainfrom
fix/wsl-hook-relay-reattach
Aug 8, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
fix/wsl-hook-relay-reattach

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Aug 8, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #12900

Summary

  • recreate the per-distro WSL hook relay when a local daemon PTY reattaches after an Orca restart
  • use the daemon/provider-returned wslDistro as ownership evidence; fresh spawns, native PTYs, SSH PTYs, and legacy results without a distro remain no-ops
  • cover both renderer IPC and runtime-controller spawn paths, including already-materialized stable panes
  • add a repeatable real-WSL benchmark that runs the generated Codex hook against a stale accepted-but-unresponsive endpoint, then verifies endpoint rewrite and delivery through the refreshed production relay

Deterministic reproduction and metrics

Run on a Windows host (the bench hard-requires process.platform === 'win32'; do not run the guest Linux Node binary):

pnpm run bench:wsl-hook-relay-reattach -- --distro <your-distro> --samples 20

Use the installed distro name from wsl.exe --list --quiet (e.g. Ubuntu, not necessarily Ubuntu-24.04). Guest needs Node ≥18 and python3.

If this checkout is a worktree whose .git points at a Windows path, run git / node / pnpm from 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)

Criterion Requirement
Stale phase times out median ≥ ~1s
Reattach delivery N/N delivered (all samples)
Refreshed latency p95 < 1s
Warnings none

The median speedup multiplier is machine-dependent; the three thresholds above are the deterministic proof.

Verified run

Measured on Windows / WSL2 Ubuntu with 20 real generated Codex hook executions per phase (--distro Ubuntu --samples 20), guest Node v22.22.1 / python3 3.14.4:

Criterion Requirement Actual
Stale phase times out median ≥ ~1s 1659.9 ms ✅
Reattach delivery 20/20 delivered 20/20 ✅
Refreshed latency p95 < 1s 269.4 ms ✅
Warnings none [] ✅
phase median p95 delivery
stale persistent endpoint 1,659.9 ms — timeout / fail-open (stalledConnections: 21)
endpoint refreshed on reattach 188 ms 269.4 ms 20/20

Median speedup: 8.8× (stale 1659.9 ms → refreshed 188 ms). Earlier authoring machine showed ~28×; the multiplier is host-dependent. stalledConnections: 21 in 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 rebuilding windows-native-registry when 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
  • changed-file native and type-aware oxlint with --deny-warnings
  • pnpm run check:max-lines-ratchet
  • git diff --check
  • real WSL benchmark above (pass criteria met)

The full src/main/ipc/pty.test.ts run 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.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fix and verification, but it omits the required AI Review Report, Security Audit, Screenshots, and Notes sections. Add the missing template sections, including cross-platform AI review results, security audit findings, visual-change status, and platform-specific notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: refreshing the WSL hook relay during PTY reattachment.
Linked Issues check ✅ Passed The changes address issue #12900 by recreating the per-distro relay during reattach, preserving no-op cases, and validating refreshed hook delivery.
Out of Scope Changes check ✅ Passed The implementation, regression tests, and real-WSL benchmark directly support the linked issue and stated reattach objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
config/scripts/wsl-hook-relay-reattach-benchmark.mjs (1)

263-266: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use POSIX path utilities for guest paths.

These paths target the WSL guest filesystem. Use path.posix.join and path.posix.dirname instead 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.join or 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

📥 Commits

Reviewing files that changed from the base of the PR and between c991bb2 and d021a03.

📒 Files selected for processing (5)
  • config/scripts/wsl-hook-relay-reattach-benchmark.mjs
  • package.json
  • src/main/agent-hooks/wsl-hook-relay-reattach.test.ts
  • src/main/agent-hooks/wsl-hook-relay-reattach.ts
  • src/main/ipc/pty.ts

@Jinwoo-H
Jinwoo-H merged commit 9825706 into main Aug 8, 2026
46 checks passed
@Jinwoo-H
Jinwoo-H deleted the fix/wsl-hook-relay-reattach branch August 8, 2026 09:03
AmethystLiang added a commit that referenced this pull request Aug 8, 2026
…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
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex tool calls become several seconds slower after Orca restarts with existing WSL sessions

3 participants