Repository navigation
perf(wsl): stop the idle profile-state writer thread on WSL hosts - #34545
Conversation
|
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 1 minute. View limit details
No actionable comments were generated in the recent review.
|
There was a problem hiding this comment.
Actionable comments posted: 2

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:
f408aaaf-6a5c-4ebf-8a6d-454bd3ba9240
Files selected for processing: 8-
src/main/managed-server/install/orcad-remote-launch-setsid.test.tssrc/main/orcad/orcad-profile-state-startup.test.tssrc/main/orcad/orcad-profile-state-startup.tssrc/main/persistence/loading-store/profile-state-maintenance-fixture.tssrc/main/persistence/profile-state/profile-state-live-store-factory.tssrc/main/persistence/profile-state/profile-state-startup-authority.tssrc/main/persistence/profile-state/profile-state-worker-authority-idle-stop.test.tssrc/main/persistence/profile-state/profile-state-worker-authority.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.
-
| if (this.writer) { | ||
| this.writer.assertWritable() |
There was a problem hiding this comment.
Keep durable mutations admissible while the idle writer stops.
If a durable mutation starts after the idle timer calls writer.close() but before the stop completes, this delegation throws profile-state-writer-closed. runDurableMutation calls assertWritable before it submits a write, so the mutation fails instead of waiting for the writer to reopen. Treat an idle stop as writable while preserving genuine writer failures and final-close rejection. (raw.githubusercontent.com)
The writer thread holds ~13-15 MB while orcad sits idle. On WSL hosts the authority now closes it after a minute without a command and reopens it, at the last acknowledged revision, for the next one (~22 ms). The desktop and SSH hosts keep the always-on writer. Also covers an empty and a misnamed keep-existing launch value.
Writes arriving just over the idle window apart would churn the writer thread unnoticed. Each reopen now counts, with one log line per ten minutes so the field shows it.
51ea04c to
53b7fb2
Compare
A failed reopen (spawn failure, thread exit, EMFILE) left the faulted writer in place, so every later write was refused until orcad restarted. A non-conflict initialize failure now rejects that one command and puts the authority back in the stopped state; the next command retries at once, repeated failures back off up to a minute, and a revision conflict stays terminal. Abort no longer waits a tick when nothing is stopping.
…y terminal reopen failures A final or maintenance flush now gets one reopen attempt even inside a backoff, so shutdown never drops state for a transient spawn failure. A retriable reopen failure is logged as a warning naming the retry delay instead of reporting that saving has stopped; only a revision conflict reaches onFailure.
The no-option case waited in real time to show the writer stayed open. With no idle timer armed nothing can close it later, so assert that directly.
ELI5
The Orca server inside WSL keeps a background thread whose only job is saving profile state, such as projects, worktrees and layout. It sits idle almost all the time but still holds 13–15 MB. On WSL hosts the thread now shuts down after a minute with nothing to save and starts again, in about 22 ms, the next time something needs saving.
What Changed
ProfileStateWorkerAuthoritygainswriterIdleStopMs. orcad sets it to 60 s only when it runs as a WSL host (isWslHostOrcadProcess). The desktop app and SSH-host orcad don't set it and keep today's always-on writer.reportInitializationFailure), and waits forready.assertWritable()counts the authority as writable.close(),pauseForMaintenance()/resume(),quarantineDatabase()andabort()all handle the stopped state. An abort while stopped leaves the authority failed, as it would with a live writer.profile-state-revision-conflictstays terminal, as with maintenance resume.drainBackups(true)) get one reopen attempt even inside a backoff, so shutdown never drops state over a transient failure.reportInitializationFailure: false. A retriable failure is aconsole.warnnaming the retry delay. Only the terminal revision conflict reachesonFailure("saving has stopped").ProfileStateWriterReopenPolicy.writerReopenCount. A[persistence] Reopened the idle profile writer (N reopens so far)line is logged at most once per 10 minutes. Steady writes just over 60 s apart, which churn the thread, therefore show up in orcad's log without flooding it.GLIBC_TUNABLES(treated as unset) and for a misnamedkeep-existingentry being refused.Why
The gate is PSS summed over Orca's process tree in the distro. Measured on a linux-arm64 container build in WSL-host mode (
ORCA_WSL_ORCAD_HOST=1, managed launch with warm compile cache, #34187 launch env). Workload: 2 shells, an idle agent-like process, one repo, 120 s idle. Three runs each:Same-process A/B. One orcad process each time, so run-to-run noise drops out; main's separate runs spread 18 MB. This is orcad's smaps PSS in MB, sampled every 10 s, in 3 processes:
The median tree PSS across separate runs drops by 14 MB, and orcad RSS goes from 174–191 to 160–161 MB. In an earlier probe, starting a new writer took 21–23 ms (×6): worker start, SQLite open and revision check. That cost is paid once, by the first write after a stop.
How often the writer would actually restart:
Not measured:
Why this approach:
User-risk:
profile-state-revision-conflictand reports it throughonFailure. That's the same safe refusal maintenance resume gives today.Flag-off: inert unless
writerIdleStopMsis set, and only WSL-host orcad sets it.Linked Issue
Internal WSL host memory work (D3 bar, PSS gate).
Visual Proof
N/A: no UI change. Persistence internals only.
Testing
New
profile-state-worker-authority-idle-stop.test.ts, against the real writer worker and SQLite. Each case:onFailureand warns with its retry delay;profile-state-revision-conflict, reported once, and leaves the authority unwritable;New
profile-state-writer-reopen-policy.test.ts: immediate first retry, then exponential backoff capped at a minute; reset on success; revision conflict terminal; reopen log rate limit.orcad-profile-state-startup.test.ts: 60 s on a WSL host, nothing elsewhere.Launch tests: an empty value counts as unset, and a misnamed
keep-existingentry is refused.Suites under
pnpm test:src/main/persistence/profile-stateandsrc/main/persistence/loading-store/profile-state*pass (987).profile-state-database/-documents, which this PR doesn't touch, and it fails identically when run alone.pnpm tc,pnpm run typecheck:ci, andpnpm run check:code-quality:changedpass.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)