You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(orcad): guard an idle WSL-host orcad tree's resident memory in the node-server lane - #35772
A WSL host's memory gate (≤ 1 GB, Orca-attributable) is only checked by hand on a real Windows box. This adds an automatic Linux check: it starts the real built server the way a WSL host launch does, opens two terminals, waits 90 s idle, and fails if the server's whole process tree uses more than 400 MB of memory. Today it uses about 251 MB.
What Changed
New test:src/main/orcad/orcad-idle-memory-budget.integration.test.ts. It is test-only; no product code changes.
Startup: boots the packaged out/orcad with the same runtime flags a WSL host launch passes (ORCAD_RUNTIME_V8_FLAGS), the WSL-only malloc tunables launch env (hostMallocTunablesLaunchEnv), and the WSL-host markers. The idle profile-writer stop (perf(wsl): stop the idle profile-state writer thread on WSL hosts #34545) is on, as it is on a WSL host.
Workload: a git repo, a worktree and 2 terminals, created through the packaged CLI over the pairing offer, followed by 90 s of idle.
Measurement: sums /proc/<pid>/smaps_rollup RSS over orcad and every descendant (daemon, helpers, shells).
Assertion: the sum is under 400 MB. On failure the message lists each process's RSS, named by its entry script, so the regression is visible in the log.
Skips: off Linux. Without the out/orcad slot it skips, or fails if the lane declares the artifact required.
Lane wiring: registered in config/scripts/node-server-test-paths.mjs with the other artifact tests, so pnpm test:node-server --artifact runs it in the Headless Node server lane.
Why
The flag-on memory gate is the Orca-attributable total (Windows Orca processes plus orcad's tree in the distro) ≤ 1 GB, measured on a device. Device runs are rare, so this lane check catches a large regression between them, such as a new always-on worker or a retained buffer.
Measured: in a Linux container with this exact test, the tree was 250.8 MB: orcad 174.1, daemon 66.5, three shells at 3.4 each.
Why 400 MB: it leaves headroom for runner noise and cold compile, so the test won't flake, while still catching a regression of 150 MB or more.
Alternatives considered:
PSS: less noisy, but the agreed gate is resident memory.
Lower budget: would flake on busy runners.
Linked Issue
Follow-up to the WSL host memory gate (flag-on checklist).
Visual Proof
N/A: test-only.
Testing
Ran pnpm test:node-server --artifact src/main/orcad/orcad-idle-memory-budget.integration.test.ts in a linux-arm64 container against a built orcad. It passes in about 93 s.
With the budget temporarily set to 100 MB, it fails with the per-process breakdown shown above, which proves the guard trips.
pnpm tc, pnpm run typecheck:ci, pnpm run check:code-quality:changed, oxlint, the anti-slop oxlint, both ast-grep steps, and check-test-file-runners all pass.
The 90 s idle is a deliberate real-time wait, marked ast-grep-ignore with a reason. The 240 s per-test timeout carries a reason comment.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
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
User-risk: none (test-only).
Flag-off: not applicable, since nothing ships. The test sets the WSL-host markers only inside its own child process environment.
Lane cost: about 95 s added to the Linux node-server jobs. On macOS and Windows lanes it skips at once.
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)
…he node-server lane
Boot the built orcad the way a WSL host launch does, open a repo and two
terminals, idle 90 s, and assert the whole process tree stays under
400 MB of RSS (about 251 MB today). It catches a new always-on worker or
a retained buffer between device runs of the 1 GB memory gate.
The reason will be displayed to describe this comment to others. Learn more.
Missing memory samples pass
residentMb treats every failed read as zero memory. If orcad exits with an exit code during the 90-second wait, processTree still returns its old PID, the missing /proc entry becomes zero RSS, and the budget assertion passes. Unreadable memory samples can also make the total too small.
Check that the server is alive before sampling, and fail when a live process's memory cannot be read.
The reason will be displayed to describe this comment to others. Learn more.
Cleanup stalls after signal exits
If the server has already died from a signal, exitCode remains null and its exit event has already fired. This hook then waits for an event that will never arrive. Cleanup times out before stopping the daemon or removing the temporary directory.
Also check signalCode before waiting, as killChildAndWait already does.
Adds the orcad idle-memory-budget integration test to the artifact test paths. On Linux, when the required built orcad slot is available, the test creates a repository, worktree, and two terminals. It waits 90 seconds, sums RSS across the orcad process tree, and fails if the total is 400 MB or more. The test includes process cleanup and a 240-second timeout.
Priority: Low
Merge Risk: Low · up to 2229a
The new memory-budget test can miss a regression if it cannot read a process’s memory. This is a bounded test reliability risk that can be fixed before merge or tracked as a follow-up.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 20.00% 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 checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly identifies the test-only Orcad resident-memory guard and its node-server lane scope.
Description check
The description is mostly complete. It explains the change, purpose, implementation, testing, scope, and risks. The Linked Issue section lacks an actual issue link, and the Review section is empty, bu…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description is mostly complete. It explains the change, purpose, implementation, testing, scope, and risks. The Linked Issue section lacks an actual issue link, and the Review section is empty, but the description is not largely incomplete.
Full details: Docstring Coverage
Explanation
Docstring coverage is 20.00% 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 5 functions across 2 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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Supported by static analysis
Script executed:
sed -n '1,110p' src/main/orcad/orcad-idle-memory-budget.integration.test.ts
sed -n '190,251p' src/main/orcad/orcad-idle-memory-budget.integration.test.ts
Repository: stablyai/orca
Length of output: 5591
Script executed:
nl -ba src/main/orcad/orcad-idle-memory-budget.integration.test.ts | sed -n '68,102p;220,252p'
Repository: stablyai/orca
Length of output: 2632
Fail on non-exit /proc measurement errors.
residentMb returns 0 for any read failure and for a missing Rss: line. The caller sums that value for every process, including the root orcad process. An incomplete measurement can therefore pass the 400 MB budget check. Preserve only ENOENT and ESRCH exit races; rethrow other errors and reject a missing Rss: line.
Suggested fix
--- "a/src/main/orcad/orcad-idle-memory-budget.integration.test.ts"+++ "b/src/main/orcad/orcad-idle-memory-budget.integration.test.ts"@@ -82,14 +82,23 @@
return [...tree]
}
function residentMb(pid: number): number {
try {
const rollup = readFileSync(`/proc/${pid}/smaps_rollup`, 'utf8')
- return Number(/^Rss:\s+(\d+)/m.exec(rollup)?.[1] ?? 0) / 1024- } catch {- return 0+ const kb = /^Rss:\s+(\d+)/m.exec(rollup)?.[1]+ if (kb === undefined) {+ throw new Error(`No Rss line in /proc/${pid}/smaps_rollup`)+ }+ return Number(kb) / 1024+ } catch (error) {+ // Exited between the tree scan and this read.+ const code = (error as NodeJS.ErrnoException).code+ if (code === 'ENOENT' || code === 'ESRCH') {+ return 0+ }+ throw error
}
}
function commandOf(pid: number): string {
try {
Tools
OpenGrep (1.30.2)
[ERROR] 88-88: A nonliteral argument is passed to exec/execSync. Identify the receiver: Node child_process methods execute shell commands, while regular-expression and database methods have different contracts. For shell execution, prefer execFile or spawn with an argument array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
A WSL host's memory gate (≤ 1 GB, Orca-attributable) is only checked by hand on a real Windows box. This adds an automatic Linux check: it starts the real built server the way a WSL host launch does, opens two terminals, waits 90 s idle, and fails if the server's whole process tree uses more than 400 MB of memory. Today it uses about 251 MB.
What Changed
src/main/orcad/orcad-idle-memory-budget.integration.test.ts. It is test-only; no product code changes.out/orcadwith the same runtime flags a WSL host launch passes (ORCAD_RUNTIME_V8_FLAGS), the WSL-only malloc tunables launch env (hostMallocTunablesLaunchEnv), and the WSL-host markers. The idle profile-writer stop (perf(wsl): stop the idle profile-state writer thread on WSL hosts #34545) is on, as it is on a WSL host./proc/<pid>/smaps_rollupRSS over orcad and every descendant (daemon, helpers, shells).out/orcadslot it skips, or fails if the lane declares the artifact required.config/scripts/node-server-test-paths.mjswith the other artifact tests, sopnpm test:node-server --artifactruns it in the Headless Node server lane.Why
The flag-on memory gate is the Orca-attributable total (Windows Orca processes plus orcad's tree in the distro) ≤ 1 GB, measured on a device. Device runs are rare, so this lane check catches a large regression between them, such as a new always-on worker or a retained buffer.
Alternatives considered:
Linked Issue
Follow-up to the WSL host memory gate (flag-on checklist).
Visual Proof
N/A: test-only.
Testing
Ran
pnpm test:node-server --artifact src/main/orcad/orcad-idle-memory-budget.integration.test.tsin a linux-arm64 container against a built orcad. It passes in about 93 s.With the budget temporarily set to 100 MB, it fails with the per-process breakdown shown above, which proves the guard trips.
pnpm tc,pnpm run typecheck:ci,pnpm run check:code-quality:changed, oxlint, the anti-slop oxlint, both ast-grep steps, andcheck-test-file-runnersall pass.The 90 s idle is a deliberate real-time wait, marked
ast-grep-ignorewith a reason. The 240 s per-test timeout carries a reason comment.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
User-risk: none (test-only).
Flag-off: not applicable, since nothing ships. The test sets the WSL-host markers only inside its own child process environment.
Lane cost: about 95 s added to the Linux node-server jobs. On macOS and Windows lanes it skips at once.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)