Skip to content

test(orcad): guard an idle WSL-host orcad tree's resident memory in the node-server lane - #35772

Merged
nwparker merged 1 commit into
mainfrom
nwparker/orcad-idle-memory-lane
Oct 29, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/orcad-idle-memory-lane

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​251 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​251
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1

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

  • 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.
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Low impact] The changes reach only artifact-enabled node-server test runs.

The PR appears safe to merge, with non-blocking fixes recommended for missing memory samples and cleanup after signal exits.

Findings

  1. P2 Missing memory samples pass ▶
  2. P2 Cleanup stalls after signal exits ▶

Summary

Adds a Linux memory guard for a built orcad running with WSL-host settings.

  • The node-server artifact lane checks idle WSL-host memory.

Reviews (1) · Last reviewed commit: "test(orcad): guard an idle WSL-host orca..." · Reviewed by Greptile

Comment on lines +85 to +91
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
}

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


afterEach(async () => {
for (const server of servers.splice(0)) {
if (server.exitCode === null) {

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

Suggested change
if (server.exitCode === null) {
if (server.exitCode === null && server.signalCode === null) {

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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 Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the test-only Orcad resident-memory guard and its node-server lane scope.
Description check Passed 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 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: 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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


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: 3bb5fdcd-2f09-4c25-9205-0597ff914470
Commits

Reviewing files that changed from the base of the PR and between a7f9888 and 2229aa8.

Files selected for processing: 2
  • config/scripts/node-server-test-paths.mjs
  • src/main/orcad/orcad-idle-memory-budget.integration.test.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.

Comment on lines +85 to +92
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
}
}

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.

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.

(coderabbit.command-injection.exec-js)

@nwparker
nwparker merged commit 3633c1b into main Oct 29, 2026
47 checks passed
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