Repository navigation
fix(wsl): close the session scanner's post-stop boot gaps - #35729
Conversation
An OpenCode/ZCode WSL reader that exits notes its distro may have stopped, so a respawn needs a settled running read. The Devin sessions.db opens only on a running list from the transcript lease. Queued transcript reads re-admit right before they run, and reads on open 9P handles re-admit too. WSL roots and extra Codex homes come from a confirmed running list (E9).
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 3 minutes. View limit details
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 |
[Medium impact] The changes affect Windows workflows that scan session history stored in WSL. The PR needs fixes before merging: deleted sessions can return, and both previous findings remain unresolved. Findings
SummaryThe PR adds WSL checks before reader restarts, database opens, and queued transcript reads.
Reviews (2) · Last reviewed commit: "fix(wsl): a failed running-list probe ke..." · Reviewed by Greptile |
| child.stderr.on('error', fault) | ||
| child.on('exit', (code) => { | ||
| if (!retired) { | ||
| options.onUnexpectedExit?.() |
There was a problem hiding this comment.
Reader errors hide stopped distros
If a reader error arrives before its exit, the new stop notice is skipped. For example, writing a request after the distro stops can fail with a broken pipe before the child reports its exit. fault() makes the request queue destroy the transport, setting retired = true. The exit handler then skips onUnexpectedExit.
The replacement reader can trust the old five-second running answer and boot the stopped distro. Notify the WSL client on unexpected transport failures too, before the queue can start another reader.
| if ( | ||
| distro && | ||
| !wasWslDistroLastSeenRunningSettled(distro, { maxAgeMs: WSL_TRANSCRIPT_RUNNING_LEASE_MS }) | ||
| ) { | ||
| return { index: null, unreadable: true } |
There was a problem hiding this comment.
Slow scans drop Devin metadata
The sidecar stat happens during discovery, which waits for all sources before parsing. If another source takes more than five seconds, an unchanged Devin transcript with a changed database goes straight to metadata enrichment without another WSL check. This guard rejects the expired answer instead of refreshing it, even when the distro is still running.
The session then loses its database title and working directory, and a hidden session can appear again. Refresh admission in the async enrichment path before this synchronous open.
…oots Background discovery keeps confirmed-only WSL roots, but an unconfirmed probe now carries over the last confirmed WSL rows (marked partial) instead of dropping them. Path checks for user acts (delete, subagents, transcript lookup) use last-known-good roots, since checking a path against a root reads nothing.
| const result = carryOverUnconfirmedWslSessions( | ||
| key, | ||
| { ...attachAiVaultScopeCwdAliases(scanned, scope), scanId }, | ||
| wslConfirmed | ||
| ) |
There was a problem hiding this comment.
carryOverUnconfirmedWslSessions saves rows before the generation check. A scan can read a WSL session, finish after that session is deleted, and restore the deleted row to the carryover map. The next failed WSL check then brings it back into the list.
Only let scans from the current generation update the carryover map.
| const result = carryOverUnconfirmedWslSessions( | ||
| key, | ||
| { ...attachAiVaultScopeCwdAliases(scanned, scope), scanId }, | ||
| wslConfirmed | ||
| ) |
There was a problem hiding this comment.
Carryover rows exceed requested limits
The merged carryover list bypasses the requested depth. After a deep confirmed scan, an unconfirmed request with limit: 100 can append thousands of saved WSL rows to its 100 fresh rows. The first caller receives all of them, while the next cache hit trims the same result to 100.
Apply truncateAiVaultListResult after merging, before returning and caching the result.
Flag-off: this is not WSL-host-specific. It applies to the session scanner on any Windows desktop with WSL distros, flag on or off.
User-risk: low.
wsl --list --runningfails, the scan lists no WSL roots (and no extra WSL Codex homes) for that scan, rather than reusing an old answer.wsl --list --runningprobe after it.ELI5
After you stop a WSL distro, Orca's chat-history scanner could still start it again. A reader process that died with the distro was restarted. A database was opened over the distro's file share. Reads that had queued up before the stop ran afterwards. An old "these distros are running" answer was reused. Now each of those checks that the distro really is running first, and leaves it alone if it isn't.
What Changed
Four gaps that wsl-e9-preflight found on main after #35367, all in session-history reading:
session-scanner-opencode-sqlite-process-client.ts,session-scanner-opencode-wsl-client.ts).wsl.exe --exec, and the admission check trusted a running read from up to 5 s earlier, so the respawn booted the distro. This is the likeliest cause of verify-18 (a).onUnexpectedExithook, and the WSL client callsnoteWslDistroMayHaveStopped(distro)from it. The respawn's admission then needs a running list probed after that exit's 500 ms settle window.sessions.dbover 9P (session-scanner-devin-db.ts).wasWslDistroLastSeenRunningSettled(distro, { maxAgeMs: 5 s })(the transcript lease). The sidecar stat just before it has just taken such a list. Otherwise the database counts as unreadable for this scan and is retried on the next one.native-chat/wsl-transcript-fs-access.ts).cached-session-list.ts,wsl/wsl-home-unless-stopped.ts).listRunningWslHomeDirsUnlessStoppeduseslistConfirmedRunningWslDistros, and the extra Codex homes userequireConfirmed. A failed probe lists no WSL roots for that scan.Why
Linked Issue
Internal WSL tracker, E9; Windows verification verify-18 (a); gaps found by wsl-e9-preflight's sweep. The chat/bridge part (c) is #35707, which this PR does not overlap.
Visual Proof
N/A: no UI change.
Testing
Each new case fails with its source change reverted (checked file by file):
session-scanner-wsl-stop-gaps.test.ts, with a mockedwsl.exeandwin32:session-scanner-opencode-sqlite-process.test.ts(real Node child): an unexpected exit reports throughonUnexpectedExit, and a retirement does not.wsl-transcript-running-admission.test.ts:Also run:
The ai-vault, native-chat and wsl suites pass (6,455 tests). The only failures were one test that also fails on another branch (
structured-agent-session-at-rest-commands) and two load flakes that pass alone.Load rule:
pnpm tc,typecheck:ci,check:code-quality:changed, the anti-slop lint and the ast-grep gates.Not run on Windows. A re-run of verify-18 (a) on a build with this is the device check.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)