Skip to content

fix(wsl): session history reads never boot a stopped WSL distro (E9) - #35367

Merged
nwparker merged 5 commits into
mainfrom
nwparker/wsl-scanner-no-boot
Oct 29, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/wsl-scanner-no-boot

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​409 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​393
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​236 $\color{#cf222e}{\Huge{\mathbf{−}}}$​52 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​184

Flag-off: This is not WSL-host-specific. On main it affects any Windows desktop that has WSL distros: the bridge, which is the default, and WSL hosts alike. Bridge users on main boot a terminated distro today whenever these background reads run: AI Vault history listing, session titles, native-chat transcript tails, the opt-in session-search reconcile (every 20 s) and the OpenCode WSL reader. This PR fixes it for both.
User-risk: Low.

  • History that lives in a stopped distro drops out of a background scan until the distro runs again. In its place is a "WSL distro 'X' is not running" issue.
  • Opening a chat still starts the distro and shows its history. So do paging its history and resuming a session from AI Vault.
  • Running distros cost at most one wsl --list --running per 5 s of transcript reads, shared per process.

ELI5

After you stop a WSL distro (wsl --terminate Ubuntu), Orca's history scanner could start it again a few seconds later, just by reading old chat logs stored inside it. Orca must never start a stopped distro unless you ask (rule E9). Now the scanner checks whether the distro is running right before each read, and leaves stopped distros alone.

What Changed

  • Before: the session scanner, which runs in its own process, and the transcript readers got a list of WSL homes once per scan. Every file touch on \\wsl.localhost\<distro>\… started the distro if it had stopped since, and so did every wsl.exe --exec (the OpenCode SQLite reader, its setup, HOME and realpath probes). Nothing re-checked. Windows verification on main (verify-18 a) saw the distro running again 9 s after wsl --terminate, with wsl.exe spawned from the session-scanner process.
  • After: every new transcript touch of a WSL path asks first whether its distro is running. That covers stat, lstat, readdir, open, access and readFile, in main and in the scanner process. So do the OpenCode reader spawn, its preparation, the HOME probe and the realpath probe. A stopped or unverifiable distro is refused with a WslTranscriptFsError ("WSL distro 'X' is not running…"), which existing callers already contain per root. Reads on an already open handle and closes are unchanged, because they can't boot anything.

Mechanism

  • New native-chat/wsl-transcript-running-admission.ts (admitWslTranscriptPath). It uses blockedWslDistroForPath from fix(wsl): background repo probes, PR refresh and worktree scans never start a stopped distro (E9) #34632/fix(wsl): never boot a terminated distro off a list taken while it was still stopping #35143, which applies the settled running read: it never trusts a list taken while the distro was still stopping. Its lease is 5 s instead of 60 s, because the scanner process hears of no stop by itself; main's stop signals (relay and watcher exits) don't reach it.
  • blockedWslDistroForPath takes an optional leaseMs. The default is unchanged.
  • wsl-transcript-fs-access admits before scheduling a UNC operation.
  • The OpenCode reader beforeSpawn and prepareOpenCodeWslReaders use the admission instead of the unsettled filterPathsToRunningWslDistrosAsync.
  • AI Vault and transcript-path WSL homes use a new listRunningWslHomeDirsUnlessStopped, built on the existing wslHomeUnlessStopped. The guest realpath probe is admitted first.
  • User-opened chats still start their distro (new native-chat/native-chat-open-wake.ts). Before the read, nativeChat:readSession (open and page) and nativeChat:subscribe (a chat pane opening) start the transcript's distro if it is stopped, as a user act. The distro comes from the transcript's \\wsl.localhost path, or else from the WSL hook relay that reported the session. The start is one runAsWslUserAct touch of the distro root. After it, the normal gated reads find the distro running. aiVault:prepareSessionResume does the same for the session file's distro.
  • What counts as the user act: a chat pane becoming visible, which is when it subscribes and reads. That includes a pane restored as the visible tab at launch. This matches the focused-WSL-workspace wake policy in fix(wsl): background preflight and agent detection never boot a stopped WSL distro (E9) #35411 and is intended. Panes that are not visible never subscribe, so they never start a distro.
  • What stays background: the watch and resolve polls after the pane opens, AI Vault scans, titles, the first-prompt preview, and the search reconcile. None of these start a stopped distro.
  • The scanner process hears main's stop and wake notes. noteWslDistroMayHaveStopped, noteWslDistroWoken and main's own --list --running stop detection are forwarded to the scanner child over its existing IPC channel (a new wslDistroNote parent message, session-scanner-service-wsl-notes.ts). The child applies them to its own gate, so a terminate that main saw is honoured at once, not after the 5 s lease.

Why

  • Gate at the shared transcript filesystem layer rather than in each scanner. Every reader (scanner, search index, titles, native-chat tails) goes through it, so none can slip past.
  • A short lease plus forwarded stop notes, rather than piping main's running list into the utility process. The child still probes for itself, so a lost note is covered by the 5 s lease. The notes close the window for any stop main saw.
  • Start the distro once at open, rather than running the whole read inside a user act. The pane's first read happens in a watch drain after the subscribe call returns, where a user-act scope would already have ended. Starting the distro up front lets that read, and only that read, go through.
  • Refuse rather than silently skip. Callers already contain the refusal to one root, so other agents' history still lists.

Linked Issue

Internal WSL tracker, E9; Windows verification verify-18 (a).

Visual Proof

N/A: no UI change. A stopped distro's history shows the existing per-root "unavailable" issue.

Testing

  • New wsl-transcript-running-admission.test.ts (mocked wsl.exe and process.platform = win32):

    • a background read of a stopped distro is refused and never reaches the filesystem helper;
    • a running distro is read;
    • after a wsl --terminate that nothing reported, a running read older than the 5 s lease is re-checked and the read refused;
    • a user act on the distro reads through.
      The first and third cases fail without the fix (checked by reverting wsl-transcript-fs-access.ts).
  • New native-chat-wsl-open-wake.test.ts (the distro's share backed by a temp dir; any touch starts it):

    • nativeChat:readSession on a stopped distro starts it and returns the history;
    • nativeChat:subscribe starts it and paints the snapshot;
    • the same read with no user act is refused and touches nothing.
      The first two fail with the ipc/native-chat.ts change reverted.
  • New session-scanner-service-wsl-notes.test.ts: main's stop and wake notes reach a live scanner child. It fails with the client change reverted.

  • ai-vault-resume.test.ts: a WSL resume starts the session file's distro before the resume is prepared. It fails with the wake in ipc/ai-vault-resume.ts removed.

  • The OpenCode reader and preparation tests now go through the admission gate. The AI Vault and native-chat path-policy tests mock the gate, because they test root selection.

  • The ai-vault, native-chat, ai-vault-search, wsl, claude, codex, kimi, skills and ipc/filesystem suites pass (1,301 files). The exceptions also fail on an exact main baseline: session-search-indexer "stops everything on close", and the two real @parcel/watcher tests.

  • Load rule: pnpm tc, typecheck:ci, oxlint, the anti-slop lint, oxfmt, check:code-quality:changed, and the ast-grep gates.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Windows only. Off Windows, blockedWslDistroForPath returns null, so nothing changes. SSH transcripts take their own path. The phone is unaffected.
  • Re-check needed: the Windows re-run of verify-18 (a), wsl --terminate, then 60 s with no boot.
  • Out of scope here: main-process wsl.exe --exec callers outside session history (codex rate-limit fetcher, account helpers and others). They were not in this report; I'll audit them if wanted.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The changes add running-state admission for WSL transcript operations and stop-aware WSL home lookup. Native chat reads and subscriptions resolve transcript paths and can wake the associated distro. AI Vault preparation and scanner startup use transcript admission. WSL stop and wake notes are forwarded to scanner child processes and handled by the service entry point. Tests cover admission, chat wake behavior, note forwarding, and updated WSL helper usage.

Priority: Normal

Merge Risk: Moderate · up to bf944

Some chat sessions may be unavailable until their WSL distro is started manually, while background reads can still restart a stopped distro. These issues should be addressed before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description follows the repository template. It has ELI5, What Changed, Why, Testing, Notes, and Checklist sections, plus a Visual Proof section marked N/A with a reason. It explains the before an… 1. Link an actual issue in the 'Linked Issue' section, replacing the 'Internal WSL tracker, E9' note and the empty 'Fixes #' line. Outside contributors need a real issue link. 2. Fill in the 'AI Disclosure' section, or state that it does no…
Docstring Coverage Warning Docstring coverage is 65.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title "fix(wsl): session history reads never boot a stopped WSL distro (E9)" matches the main change. The changeset adds a running-state admission gate to WSL transcript filesystem access and Open…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(wsl): session history reads never boot a stopped WSL distro (E9)" matches the main change. The changeset adds a running-state admission gate to WSL transcript filesystem access and OpenCode reader probes so background reads do not start stopped distros, and it keeps user-opened chats waking their distro. The title uses a conventional commit prefix and one sentence. It does not name the mechanism, and the 'E9' tag is an internal reference, but both are minor.

Full details: Description check

Explanation

The description follows the repository template. It has ELI5, What Changed, Why, Testing, Notes, and Checklist sections, plus a Visual Proof section marked N/A with a reason. It explains the before and after behavior, the mechanism, and the alternatives considered. Gaps: the 'Linked Issue' section has no real issue link (only 'Internal WSL tracker, E9' and 'Fixes #' remains unfilled), the 'AI Disclosure' section is missing, and the 'Testing' checklist box for manual testing is unchecked while the 'Windows re-run of verify-18 (a)' is still outstanding. The 'pnpm lint, typecheck, test, build' checklist item is unchecked. The description also has a large scope (17 prod files), which conflicts with the 'PR is small and focused' box being checked.

Resolution

  1. Link an actual issue in the 'Linked Issue' section, replacing the 'Internal WSL tracker, E9' note and the empty 'Fixes #' line. Outside contributors need a real issue link. 2. Fill in the 'AI Disclosure' section, or state that it does not apply. 3. Confirm the manual test status. The Windows re-run of verify-18 (a) is still outstanding, so either complete it or leave the manual-test box unchecked with an explanation. 4. Complete or explain the unchecked 'pnpm lint, typecheck, test, and build' item. 5. Reconsider the 'This PR is small and focused' checkbox, or split the change, since it touches 17 production files and a new mechanism.
Full details: Docstring Coverage

Explanation

Docstring coverage is 65.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 23 functions across 28 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect Windows users whose chat history lives in WSL distros.

The PR still needs the queued-read fix before merging because waiting history reads can restart a stopped distro.

Findings

  1. P1 Queued reads restart stopped distros ▶
  2. P2 Cancelled reads keep waiting ▶
  3. P2 Earlier calls satisfy this test ▶

Summary

The PR adds running-state checks to WSL history reads and forwards stop and wake notes to the scanner process.

  • Background WSL history reads check that their distro is running before touching its files.
  • Opening a chat or resuming a session starts its stopped WSL distro before reading its history.
  • The scanner child receives WSL stop and wake notes from the main process.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Background[Background history read] --> Admission[Check whether distro runs]
  Admission -->|Running| Queue[Queue filesystem work]
  Admission -->|Stopped or unverifiable| Refusal[Return unavailable error]
  Queue --> Read[Read transcript]
  Open[User opens chat or resumes session] --> Wake[Start transcript distro if needed]
  Wake --> Admission
  Main[Main observes stop or wake] --> Note[Send note to scanner]
  Note --> Scanner[Update scanner running-state checks]
Loading

Reviews (5) · Last reviewed commit: "Merge branch 'main' into nwparker/wsl-sc..." · Reviewed by Greptile

Comment on lines +45 to +48
? admitWslTranscriptPath(request.path).then(() =>
runWslTranscriptFsTask(
{ operation: request.operation, path: request.path, priority, signal },
(taskSignal) =>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Queued reads restart stopped distros

admitWslTranscriptPath finishes before the request joins the filesystem queue. A scan can wait behind another scan for longer than the five-second lease. If the user stops the distro during that wait, the queued request still touches its files without another running check and can start it again.

Run admission inside the scheduled callback, immediately before dispatch. Apply the same change to openAdmittedWslTranscriptFile.

priority: WslTranscriptFsTaskPriority,
signal?: AbortSignal
): Promise<TranscriptFileHandle> {
await admitWslTranscriptPath(path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Cancelled reads keep waiting

The new admission wait does not observe signal. If WSL discovery stalls, cancelling a read leaves its promise waiting through discovery and its retry instead of rejecting promptly. An already-aborted request also starts admission unnecessarily.

Check cancellation before admission and race the wait against signal, as the OpenCode callers already do. Cover both reusable operations and opens.

Knowledge Base Used: AI Vault sessions

Transcript and session-history reads touched \\wsl.localhost shares, and ran
`wsl.exe --exec` probes, for any distro the root list named. Those touches are
the OpenCode reader, its setup, HOME and realpath probes, and the session
scanner and search index. Nothing re-checked that the distro still ran. A
`wsl --terminate` mid-scan, or a list taken while the distro was still
stopping, let background work boot it again.

Every UNC transcript touch (stat, readdir, open, access, readFile) and every
scanner `--exec` now asks a settled running read first. That read is no older
than 5 s, because the scanner process hears of no stop by itself. A user act on
the distro still passes.
…n's stop notes

A user-opened chat, a history page and an AI Vault resume start the
transcript's stopped WSL distro once, as a user act, so its history
shows; watch and scan reads stay background. Main forwards WSL stop and
wake notes to the session-scanner process so a terminate main saw is
honoured there at once.
@nwparker
nwparker force-pushed the nwparker/wsl-scanner-no-boot branch from f46b56a to a819908 Compare October 28, 2026 22:43

@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: 2

🔇 Additional comments: 1
src/main/native-chat/native-chat-open-wake.ts-29-30: 1

29-30: Minor · Functional Correctness · Quick win

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Match the relay row to the opened transcript.

If a local transcript and a WSL relay row share a session ID, this lookup selects the relay even when its transcript path differs. Opening the local chat then starts an unrelated stopped distro. Match providerSession.transcriptPath to the resolved path before using a relay as fallback; do not select an arbitrary row when the path is absent and multiple relays match. (raw.githubusercontent.com)


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6733cc2d-1afe-4e4f-b4db-8ee4cb289ea2
Commits

Reviewing files that changed from the base of the PR and between 3f56b8f and a819908.

Files selected for processing: 27
  • src/main/ai-vault/cached-session-list.test.ts
  • src/main/ai-vault/cached-session-list.ts
  • src/main/ai-vault/opencode-wsl-runtime-preparation.test.ts
  • src/main/ai-vault/opencode-wsl-runtime-preparation.ts
  • src/main/ai-vault/session-scanner-opencode-wsl-client.test.ts
  • src/main/ai-vault/session-scanner-opencode-wsl-client.ts
  • src/main/ai-vault/session-scanner-service-client.ts
  • src/main/ai-vault/session-scanner-service-entry.ts
  • src/main/ai-vault/session-scanner-service-protocol.ts
  • src/main/ai-vault/session-scanner-service-wsl-notes.test.ts
  • src/main/ai-vault/session-scanner-service-wsl-notes.ts
  • src/main/ipc/ai-vault-resume.ts
  • src/main/ipc/native-chat-wsl-open-wake.test.ts
  • src/main/ipc/native-chat.ts
  • src/main/native-chat/host-readable-transcript-path.test.ts
  • src/main/native-chat/host-readable-transcript-path.ts
  • src/main/native-chat/native-chat-open-wake.ts
  • src/main/native-chat/session-file-resolver-wsl-scan-gate.test.ts
  • src/main/native-chat/session-file-resolver-wsl.test.ts
  • src/main/native-chat/transcript-watch-wsl-exact-path.test.ts
  • src/main/native-chat/wsl-transcript-fs-access.ts
  • src/main/native-chat/wsl-transcript-fs-error.ts
  • src/main/native-chat/wsl-transcript-running-admission.test.ts
  • src/main/native-chat/wsl-transcript-running-admission.ts
  • src/main/wsl-background-distro-gate.ts
  • src/main/wsl/wsl-home-unless-stopped.ts
  • src/main/wsl/wsl-unc-access-gate.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

*/
export function forwardWslDistroNotesToChild(child: () => ChildProcess | null): () => void {
return onWslDistroGateNote((note) =>
child()?.send({ type: 'wslDistroNote', ...note }, () => undefined)

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.

Major · Stability & Availability · Heavy lift

Supported by static analysis

Script executed:

set -eu
printf '%s\n' '--- diff for relevant files ---'
git diff --unified=80 96038ecfdd6f3671655bd4f692a3c87ad07dbacf a8199086e09137ed9d141ccd21d32b2164860c96 -- \
  src/main/ai-vault/session-scanner-service-wsl-notes.ts \
  src/main/ai-vault/session-scanner-service.ts \
  src/main/wsl-background-distro-gate.ts \
  src/main/ai-vault/session-scanner-service*.ts
printf '%s\n' '--- references ---'
rg -n -F --glob '*.ts' -e 'forwardWslDistroNotesToChild' -e 'wslDistroNote' -e 'wslDistroGate' src/main src/shared || test "$?" -eq 1
printf '%s\n' '--- relevant file listings ---'
rg --files src/main/ai-vault src/main | rg 'session-scanner|wsl-background-distro-gate'

Repository: stablyai/orca

Length of output: 41545


Script executed:

set -eu
printf '%s\n' '--- diff for relevant files ---'
git diff --unified=80 96038ecfdd6f3671655bd4f692a3c87ad07dbacf a8199086e09137ed9d141ccd21d32b2164860c96 -- \
  src/main/ai-vault/session-scanner-service-wsl-notes.ts \
  src/main/ai-vault/session-scanner-service.ts \
  src/main/wsl-background-distro-gate.ts \
  'src/main/ai-vault/session-scanner-service*.ts'
printf '%s\n' '--- references ---'
rg -n -F --glob '*.ts' -e 'forwardWslDistroNotesToChild' -e 'wslDistroNote' -e 'wslDistroGate' src/main src/shared || test "$?" -eq 1
printf '%s\n' '--- relevant file listings ---'
rg --files src/main/ai-vault src/main | rg 'session-scanner|wsl-background-distro-gate'

Repository: stablyai/orca

Length of output: 41336


Script executed:

git show a8199086e09137ed9d141ccd21d32b2164860c96:src/main/ai-vault/session-scanner-service-wsl-notes.ts
printf '\n--- callers ---\n'
rg -n -C 8 -F --glob '*.ts' 'forwardWslDistroNotesToChild' src
printf '\n--- note producer ---\n'
rg -n -C 12 -F --glob '*.ts' 'wslDistroNote' src/main
printf '\n--- gate symbols ---\n'
rg -n -C 8 --glob '*.ts' 'stop-settle|settle|wsl.*running|running.*wsl|Wsl.*Note|wslDistro' src/main/wsl-background-distro-gate.ts src/main/ai-vault

Repository: stablyai/orca

Length of output: 41639


Script executed:

set -eu
printf '%s\n' '--- client child startup ---'
nl -ba src/main/ai-vault/session-scanner-service-client.ts | sed -n '185,340p'
printf '%s\n' '--- gate exact definitions ---'
nl -ba src/main/wsl-background-distro-gate.ts | sed -n '1,180p'
printf '%s\n' '--- WSL scanner consumers ---'
rg -n -C 12 --glob '*.ts' -e 'settledWslRunningReadAnchor' -e 'wasWslDistroLastSeenRunningSettled' -e 'filterPathsToRunningWslDistrosAsync' -e 'running read' src/main/ai-vault src/main

Repository: stablyai/orca

Length of output: 42019


Script executed:

set -eu
nl -ba src/main/native-chat/wsl-transcript-running-admission.ts
printf '%s\n' '--- filesystem gate ---'
nl -ba src/main/native-chat/wsl-transcript-fs-access.ts | sed -n '1,240p'

Repository: stablyai/orca

Length of output: 10782


Script executed:

set -eu
nl -ba src/main/wsl/wsl-unc-access-gate.ts | sed -n '1,260p'

Repository: stablyai/orca

Length of output: 5070


Replay WSL gate state when the scanner child starts.

forwardWslDistroNotesToChild drops a note when child() is null. If a stop note arrives before processFactory() returns, a child that starts and probes within the 500 ms settle interval has no stop timestamp. Its running probe can therefore admit the distro, and the transcript reader can touch the UNC path.

Retain the latest stop or wake note for each distro and apply that state before the child processes its first scan. Add a regression test where the stop note precedes child startup.

taskSignal,
wslTranscriptFsLaneKey(request.path, priority)
)
? admitWslTranscriptPath(request.path).then(() =>

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.

Major · Stability & Availability · Quick win

Recheck admission when a queued filesystem task starts.

If a task waits in runWslTranscriptFsTask for more than the five-second lease, its admission can expire before the filesystem operation starts. If the distro stops during that wait, the queued operation can touch its UNC path and start it. The same gap affects openAdmittedWslTranscriptFile at Line 137. Keep the admission before submission, but repeat it inside each scheduled operation before filesystem access. The scheduler permits waits longer than the lease and does not recheck running state when it starts an operation. (raw.githubusercontent.com)

… wake

Keeps node:child_process out of the new scanner-notes module (the
process-host import check) and adds a test that fails if an AI Vault
resume stops starting the session's WSL distro.
})

// Resuming is a user act: its stopped distro must start before the transcript's gated reads.
it('starts the session file distro before preparing a WSL resume', async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Earlier calls satisfy this test

On Windows, the earlier test already calls wakeMock('Ubuntu'). Because clearMocks is false and this mock is never cleared, toHaveBeenCalledWith('Ubuntu') can pass even if this resume never wakes the distro, or wakes it too late. That leaves the new test unable to catch those regressions on Windows.

Clear wakeMock before this test so it checks this resume's call.

Suggested change
it('starts the session file distro before preparing a WSL resume', async () => {
it('starts the session file distro before preparing a WSL resume', async () => {
wakeMock.mockClear()

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (3)

Major · Wake the WSL distro before runtime transcript access. · wsl-transcript-running-admission.ts:14-20

src/main/native-chat/wsl-transcript-running-admission.ts:14-20
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Wake the WSL distro before runtime transcript access.

Runtime-owned reads, paging, and subscriptions call the handlers in src/main/runtime/rpc/methods/native-chat.ts without waking a stopped WSL distro. WSL admission can therefore return Transcript unavailable.

Project the path with runtime.getAgentProviderSessionRows(), wake the distro derived from that same path, and preserve the existing abort and cleanup checks.

Suggested fix
 import {
   readNativeChatTranscriptTail,
   subscribeNativeChatTranscript,
   type NativeChatTranscriptSubscription,
   type SubscribeNativeChatTranscriptArgs
 } from '../../../native-chat/transcript-watch'
+import {
+  nativeChatTranscriptDistro,
+  wakeNativeChatTranscriptDistro
+} from '../../../native-chat/native-chat-open-wake'
 import { nativeChatTranscriptPathOnExecutionHost } from '../../../native-chat/ssh-transcript-path'
@@
     params: NativeChatSession,
     handler: async (params, { runtime, clientKind, signal }) => {
       const limit = params.limit ?? MOBILE_NATIVE_CHAT_DEFAULT_WINDOW
+      const statusRows = runtime.getAgentProviderSessionRows()
+      const transcriptPath = nativeChatTranscriptPathOnExecutionHost(
+        statusRows,
+        params.sessionId,
+        params.transcriptPath
+      )
+      await wakeNativeChatTranscriptDistro(
+        nativeChatTranscriptDistro(statusRows, params.sessionId, transcriptPath)
+      )
+      signal?.throwIfAborted()
       const result = await readNativeChatTranscriptTail(
         {
           agent: params.agent,
           sessionId: params.sessionId,
-          transcriptPath: nativeChatTranscriptPathOnExecutionHost(
-            runtime.getAgentProviderSessionRows(),
-            params.sessionId,
-            params.transcriptPath
-          ),
+          transcriptPath,
@@
       if (closed) {
         return
       }
+      const statusRows = runtime.getAgentProviderSessionRows()
+      const transcriptPath = nativeChatTranscriptPathOnExecutionHost(
+        statusRows,
+        params.sessionId,
+        params.transcriptPath
+      )
+      await wakeNativeChatTranscriptDistro(
+        nativeChatTranscriptDistro(statusRows, params.sessionId, transcriptPath)
+      )
+      if (closed || signal?.aborted) {
+        runtime.cleanupSubscription(subscriptionId)
+        return
+      }
       const subscribeArgs: SubscribeNativeChatTranscriptArgs = {
         agent: params.agent,
         sessionId: params.sessionId,
-        transcriptPath: nativeChatTranscriptPathOnExecutionHost(
-          runtime.getAgentProviderSessionRows(),
-          params.sessionId,
-          params.transcriptPath
-        ),
+        transcriptPath,
Minor · Recheck the stop floor after the probe. · wsl-background-distro-gate.ts:159

src/main/wsl-background-distro-gate.ts:159
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Recheck the stop floor after the probe.

If a stop note arrives while this probe is in flight, the probe can return a pre-stop running result. The transcript admission can then touch the UNC path and restart the distro, despite receiving the note. Recheck the stop floor after the probe and retry if it changed. (raw.githubusercontent.com)

Minor · Carry the persisted WSL distro through native-chat resume reads. · native-chat-open-wake.ts:20-31

src/main/native-chat/native-chat-open-wake.ts:20-31
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Carry the persisted WSL distro through native-chat resume reads.

A persisted WSL session can provide a Linux guest transcript path from record.location.wslDistro. When its live WSL relay row is absent, nativeChatTranscriptDistro returns null, so the user-visible open skips the wake. Resolution then excludes the stopped distro and can return Transcript unavailable.

Carry record.location.wslDistro through the native-chat open flow. Use it for both the wake operation and transcript resolution.

Nitpick comments: 1
src/main/ipc/ai-vault-resume.test.ts: 1

60-60: Trivial · Maintainability & Code Quality · Quick win

Isolate the wake assertion from prior tests.

The preceding WSL-path test calls the shared wakeMock('Ubuntu'), and automatic mock clearing is disabled. This test can therefore pass without a wake call from the resume under test. Clear the mock before starting the test.

Suggested fix
 it('starts the session file distro before preparing a WSL resume', async () => {
+  wakeMock.mockClear()
   const platform = Object.getOwnPropertyDescriptor(process, 'platform')

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5acd8347-1334-4de9-81bd-6c712f14a6c8
Commits

Reviewing files that changed from the base of the PR and between a819908 and bf9447f.

Files selected for processing: 3
  • src/main/ai-vault/session-scanner-service-wsl-notes.ts
  • src/main/ipc/ai-vault-resume.test.ts
  • src/main/wsl-background-distro-gate.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

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.

1 participant