Skip to content

cherry-pick: kill hung WSL transcript fs operations via child process (#15381) for 1.8.185-cb42b60 [STA-4360] - #15392

Closed
AmethystLiang wants to merge 1 commit into
adhoc/1.8.185-cb42b60from
adhoc/1.8.185-cb42b60-sta4360-15381
Closed

AmethystLiang wants to merge 1 commit into
adhoc/1.8.185-cb42b60from
adhoc/1.8.185-cb42b60-sta4360-15381

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

Cherry-pick

Cherry-pick of #15381 — "Kill hung WSL transcript filesystem operations via child process with route quarantine" — onto the 1.8.185 adhoc branch for the Release-08-15-2026 · cb42b60 cut.

Upstream PR #15381
Upstream squash SHA 4ec6bbf5884e5bd915b4f49c4602b5e5a88b61ae
Pinned base cb42b60849d81ff58976200baa6b89dc5df99fb7
Target branch adhoc/1.8.185-cb42b60 (tip e0fb833ec0)
Conflicts None — applied clean
Fixes STA-4360 (P1)

Why this is needed on the cut

Two never-settling WSL UNC/9P calls exhaust both scheduler permits for the process lifetime, after which no WSL transcript I/O ever starts — transcript chat, watchers, and AI Vault discovery stall across all healthy distros.

The defect is in wsl-transcript-fs-gate.ts: settleTask is the only path that removes a task from activeTasks, and the stuck deadline (stuckTimer) only sets task.stuck = true and logs — it never releases the permit. Once both permits are held by unabortable syscalls, pumpTasks() can never admit another task and stuckBlocker globally fast-fails every new one.

#15381 fixes this by forking UNC filesystem operations to a child process (ELECTRON_RUN_AS_NODE) that can actually be killed when its deadline expires (30s exact / 60s scan), plus per-route quarantine with exponential backoff and strike decay.

Attribution note

The defect originated in #14090 (7b326e212f, "Gate WSL transcript fs ops with timeout and capacity limits"), not in #14203 as the release tickets currently state. git blame on the exhaustion lines (wsl-transcript-fs-gate.ts:143-145, :196, :271) points at 7b326e212f. #14203 widened gating from access|readdir to stat|lstat|open|read|readfile across 34 source files, which made the latent defect reachable in practice — hence the misattribution. Both are ancestors of the pinned base, so this pick is the correct remedy either way; reverting #14203 would not have fixed it.

Verification on this base

  • Cherry-pick applied with zero conflicts (38 files, +2357/−343 — identical file set to upstream).
  • Diff verified against the upstream patch: byte-identical except two hunk-line offsets and one context line — scanner-wsl-gate.test.ts imports listOpenCodeDatabases from ./scanner on this base (main later moved it to opencode-database-discovery.ts). Git's 3-way merge kept the base's path correctly; the symbol is exported at src/main/opencode-usage/scanner.ts:83.
  • No other commit touched src/main/native-chat/ between cb42b60 and the fix, so there is no interleaving risk.
  • All relative imports in the 18 new files resolve at this base.
  • New child-process entry point is wired into all three build configs: electron.vite.config.ts:226, config/electron-builder.config.cjs:192 (asarUnpack), config/build-plugins/plain-node-entry-guard.ts:26.
  • pnpm lint / typecheck / test / build — deferred to PR CI on this branch.

Release-process caveat

Per adhoc-build-release-checklist.md, the hard authorization gate is not currently satisfied for this cut: adhoc-build-1.8.185.md records the state as "blocked before build authorization", pending an authoritative ordered live-pick list and the #14366 / orca-cloud#370 companion decision. That blocker is about pick ordering and scope, not about this fix.

This PR does not build, dispatch, or soak anything — it only stages the P1 pick for review. Do not dispatch an adhoc build from the merged result until the ordered pick list is recorded and this pick is added to it.

Checklist

  • This PR is small and focused (pure cherry-pick, no manual edits)
  • I explained what changed and why
  • N/A — No UI changes
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (WSL-specific; SSH and local paths keep direct Node APIs)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover)

… route quarantine (#15381)

* fix(native-chat): kill hung WSL operations via child process

Stalled UNC file operations hold libuv permits even after the gate
timeout expires, blocking Chat tab recovery. Two stalled operations
fill both permits and freeze all WSL access until restart.

Fork file I/O for UNC paths into a separate child process. On deadline
expiry, kill the process to force the hung syscall to exit. This frees
the permit for the affected tab's next read. Temporarily quarantine the
stalled route to avoid retry storms.

* chore: drop internal review artifact from the repo root

* fix(native-chat): harden the WSL transcript fs sidecar

Review follow-ups on the sidecar isolation change:

- Only the deadline may abort running gate work. The sole waiter's
  same-duration timeout fired first, killed healthy children on caller
  abandonment, and settled the task before the deadline could quarantine
  a stalled route - leaving the back-off dead for every dedupe:false op.
- Resolve the fork entry from out/main/chunks too: the resolver compiles
  into a shared chunk, and the scanner service child has no
  process.resourcesPath, so packaged WSL vault scans threw entry-not-found
  (masked as an empty tree).
- Allowlist the fork env instead of spreading process.env; ambient
  NODE_OPTIONS would halt or --require code into every child.
- Wrap transport faults (spawn failure, child death) in
  WslTranscriptFsError('unavailable') so discovery reports them as scan
  issues instead of misreading them as missing paths or empty trees.
- Gate the vitest in-process fallback on the vitest worker global so a
  leaked VITEST=true cannot revert production to in-process UNC syscalls.
- Reap idle sidecar processes after 60s instead of holding them for the
  app session.
- Split 'open' into its own protocol union member so the reusable-call
  Exclude actually strips it from the pooled-process API.
- Guard kill('SIGKILL') against the teardown race where an exiting child
  emits an unlistened 'error', and dispatch reads by handle kind before
  path spelling.

* fix(native-chat): probe stalled WSL routes instead of a fixed quarantine

Remaining review follow-ups:

- Escalating route quarantine: first strike lifts after 5s so a distro
  that was cold-booting when its op hit the deadline recovers on the
  next poll (~35s total instead of ~90s); repeat stalls double the
  back-off toward the prior 2x-timeout cap, and any settle the deadline
  did not force clears the strikes. Queued same-route tasks fail fast
  at quarantine instead of stranding one waiter deadline per file in
  sequential scans.
- Single request implementation: the vitest in-process fallback now runs
  the child's own dispatcher (WslTranscriptFsProcessOperations + decode),
  so unit suites exercise exactly what the forked process executes and
  the per-call-site fallback closures are gone. Dirent fixtures gained
  the full kind-flag set the serializer reads.
- Dropped the production-dead per-route close queue; UNC FileHandles
  (test fallback only) mirror the process-handle close contract.
- Error class, messages, and factories move to wsl-transcript-fs-error
  (re-exported from the gate) to keep the gate under the lines budget.

* fix(native-chat): harden WSL transcript fs with route quarantine strike

Extract quarantine logic into a dedicated module with strike decay: stalls older
than 5 minutes restart from base back-off, and concurrent-lane timeouts count as
one incident. Allow joining live in-flight tasks on quarantined routes (they cost
no new I/O). Preserve quarantine across transport faults (child death). Handle
file shrinking during tail reads by detecting short reads and returning empty.
Defer file closes that arrive mid-read instead of refusing, preventing slot
leaks. Separate process slot and boundary-finding concerns into focused modules.

* fix(native-chat): enforce route quarantine windows and isolate lanes per

A late result arriving after the deadline was incorrectly lifting the route
quarantine, allowing subsequent work to start before the back-off period
expired. Now late results are correctly recognized as stale and never cut
the quarantine short.

Process work is now isolated per (route, priority) lane so a scan stall
cannot block exact reads on the same distro. Each lane gets its own client
and process pool; late results and handle faults stay scoped to their lane.

Tests now fake performance.now() alongside timers (the quarantine clock
depends on it) and wait for the full back-off window to expire rather than
advancing by 0. Gate state is reset between test cases since late releases
never lift the quarantine.

---------

Co-authored-by: OrcaWin <[email protected]>
(cherry picked from commit 4ec6bbf)
@AmethystLiang

Copy link
Copy Markdown
Contributor Author

Closing staging PR; cherry-pick #15381 will be applied directly to the assembled adhoc branch as tracked in STA-4816.

@AmethystLiang
AmethystLiang deleted the adhoc/1.8.185-cb42b60-sta4360-15381 branch August 19, 2026 00:51
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.

2 participants