Skip to content

fix(process-table): fail a short ps capture loudly, and stop a resume spending 49 of them - #18166

Merged
nwparker merged 1 commit into
mainfrom
nwparker/ps-capture-truncation-and-tui-poll-cost
Sep 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/ps-capture-truncation-and-tui-poll-cost

Conversation

@nwparker

@nwparker nwparker commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​295 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​278
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​52

ELI5

To answer "is the agent still running in this terminal?", Orca asks the OS for the list of every running program and reads it into a buffer. That buffer had no size set, so it got the default 1 MB — and on my machine the list is already 326 KB. On a busier machine it overflows. When it overflows, Orca does not say "I couldn't read the list"; it quietly acts as if the programs it never read simply are not running. That is how "I can't tell" turns into "nothing is there" — the one conversion the execution-boundary rule forbids.

Separately, resuming an agent terminal reads that entire program list over and over — up to 49 times in five seconds — waiting for the agent's process to show up. The first second of that is doing real work. The remaining four seconds are re-asking a question that has already answered "no" forty times.

What changed

Fix 1 — src/shared/process-table-snapshot.ts

  • Sets an explicit maxBuffer of 32 MB, matching the sibling reader in src/main/pty-descendant-termination.ts and its stated reasoning ("truncation would silently drop descendants from the snapshot").
  • Adds a capture-integrity guard: a capture that reaches the buffer ceiling, or that carries no rows at all, now rejects with ProcessTableCaptureError (capture_truncated / empty_capture) instead of being parsed. A ERR_CHILD_PROCESS_STDIO_MAXBUFFER rejection is renamed into the same domain vocabulary.

Fix 2 — src/main/runtime/structured-tui-process-identity.ts

  • The poll interval holds at the caller's interval (default 50 ms) for the first 1 s, then doubles per poll to a 500 ms cap. getFreshProcessTableSnapshot() is retained — the freshness guarantee is what makes "root absent ⇒ root gone" sound, so it was not weakened to the TTL-cached reader.

Correcting the reported premise for Fix 1

The investigation that motivated this said overflow produces "a partial process table presented as a complete one". Measured, that is not what execFile does. Promisified execFile rejects on overflow (ERR_CHILD_PROCESS_STDIO_MAXBUFFER), and every consumer already handles a rejection correctly as unavailable. So the reported false-negative is not reachable through the buffer ceiling today.

The real defects are the two adjacent ones, and both are demonstrated by failing tests:

  • The reader has no integrity guard of its own. Verified by measurement: a capture cut at 4 KB parses to 59 of 1,463 rows with no error, and an empty capture parses to [] with no error. resolveAgentForegroundProcessWithAvailability then answers available: true on that empty table. So the "silently short table" shape is genuinely present — it just needed a non-execFile route to reach it. This PR closes it at the capture boundary so no future exec wrapper can reopen it.
  • The 1 MB ceiling is an availability bug, not a correctness one. At ~3x headroom a busy host fails every capture, so foreground inspection and structured-TUI identification degrade to permanently unverifiable.

Both are fixed; the verdict vocabulary (live / unverifiable / exited) is unchanged and no new synonym was introduced.

Measurements

All on macOS, 1,460 processes, Orca's exact PS_ARGS.

Output size vs buffer limit

value
ps stdout 326,180 bytes
longest single row 5,116 chars
old limit (Node default) 1,048,576 bytes — 3.2x headroom
new limit 33,554,432 bytes — 103x headroom
cost of a capture 0.065 CPU-s (50 captures = 3.25 CPU-s user+sys, incl. the ps child)

A 4,000-process host with ordinary argv produces ~1.14 MB and fails outright on the old limit; the regression test uses exactly that table.

Captures per identification attempt (Fix 2)

Simulated clock, 55 ms measured capture cost, 5 s ceiling:

child appears at captures before captures after settled before settled after
0 ms 1 1 55 ms 55 ms
200 ms 3 3 265 ms 265 ms
500 ms 6 6 580 ms 580 ms
900 ms 10 10 1000 ms 1000 ms
2000 ms 20 15 2050 ms 2525 ms
never (worst case) 49 20 5055 ms 5055 ms

CPU saved per resume

case before after saved
failed identification (worst case) 49 x 0.065 = 3.19 CPU-s 20 x 0.065 = 1.30 CPU-s 1.89 CPU-s (59%)
slow success (child at 2 s) 1.30 CPU-s 0.98 CPU-s 0.33 CPU-s
normal success (child < 1 s) unchanged unchanged 0

Note the corrected worst case is 49 captures, not 100: each capture costs ~55 ms of wall time on top of the 50 ms sleep, so a 5 s window fits ~48 iterations, not 100.

Negative user-facing trade-offs

None.

  • Structured-TUI identification is not delayed in any user-visible case. The table above is the evidence: for a child appearing at 0 / 200 / 500 / 900 ms, both the capture count and the settle time are identical before and after — the backoff does not begin until 1 s has elapsed. A real shell publishes its codex/claude child in well under that, and the capture itself already imposes a ~105 ms effective granularity, so the first second was never finer-grained than the fix leaves it.
  • Past 1 s the added latency is bounded by one interval (≤ 500 ms), reached only by a child already 20x slower than normal, on a background resume proof whose own caller then waits up to 30 s for tui-idle. There is no interactive surface on this path.
  • The 5 s ceiling, PS_ARGS, the 500 ms TTL, and every cadence tier are untouched.
  • Fix 1 strictly widens availability: a capture that used to fail on a busy host now succeeds. The only new rejections are for captures that were already unusable, and they turn a false "no agent" into an honest unavailable.

Reliability contract

  • Invariant: process-table.capture-completeness — a process-table snapshot is either whole or unreadable; it is never partially delivered as complete. And agent-session.foreground-availability — an unreadable capture yields available: false, never a positive claim about what is running.
  • Failure source: 3.2x buffer headroom at 1,460 processes; a lenient parser that discards unparseable rows silently.
  • Oracle: consumer-observable. getProcessTableSnapshot() rejects rather than resolving with a short array; the busy-host table parses to all 4,000 rows. Both fail on main.
  • Provider/platform coverage: macOS/Linux covered (this is the POSIX reader). Windows unaffected — src/main/windows/windows-process-table.ts supplies its own runPs to createProcessTableSnapshotReader via a Toolhelp32 snapshot, forks no child and has no buffer ceiling; readStructuredTuiProcessIdentity's win32 branch uses queryWindowsProcessRowsFresh and shares only the poll cadence, which changes identically on all three platforms. SSH/relay covered — the relay imports the same shared reader, and pty-handler.listProcesses already maps a capture failure to table_unreadable evidence.
  • Performance budget: capture counts per identification are asserted deterministically in the test, not benchmarked. No timer, listener, subprocess or scan was added; one subprocess-per-poll was removed 29 times over.
  • Residual gaps: the 1 MB ceiling is not reachable on the machine measured here, so the busy-host case is proved by an execFile mock that reproduces Node's exact buffering semantics rather than by a genuinely 4,000-process host.

Tests

Six new regression tests, all verified red on main:

src/shared/process-table-snapshot.test.ts

  • reads a busy host whose table overflows execFile 1MB default — red: "promise rejected 'stdout maxBuffer length exceeded' instead of resolving"
  • reports a truncated capture as unreadable rather than a silently short table — red: "promise resolved [200 rows] instead of rejecting"
  • names a buffer-ceiling rejection as truncation on both views — red
  • reports an empty capture as unreadable rather than an empty process table — red: "promise resolved [] instead of rejecting"

src/main/runtime/structured-tui-process-identity.test.ts

  • does not spend a hundred ps captures on an identification that never resolves — red: "expected 49 to be less than or equal to 20"
  • keeps identification latency identical while a child can still plausibly appear — passes both before and after by design: it is the guard proving the fast path did not move.

Verification

  • pnpm tc — clean
  • npx oxlint <changed files> — clean
  • npx vitest run --config config/vitest.config.ts src/shared src/main/runtime src/main/providers — 13,478 passed, plus the relay snapshot consumers (pty-shell-utils, pty-handler-inventory-process-evidence) for 13,511 passed total

@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The structured TUI process identity reader now uses adaptive polling with a 1,000 ms fast-poll window and a 500 ms maximum delay. Tests cover timeout duration, capture counts, and child detection latency. The process-table snapshot module now uses a 32 MB buffer ceiling and rejects truncated or empty captures with explicit errors. Tests cover large tables, buffer overflow, truncation, and empty output.

Merge Risk: 🟡 Moderate · up to df870

The change improves process discovery reliability and reduces repeated polling, but the current implementation can still misclassify header-only captures as empty tables and reject complete captures at the exact size limit, causing incorrect process-status results. These bounded correctness issues should be fixed or explicitly accepted before merge.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description gives detailed ELI5, change rationale, implementation scope, reliability considerations, platform coverage, measurements, and test results. However, it omits the required Linked Issue,… Add a linked issue using the required Fixes # format. Add the Visual Proof section with N/A and a reason if no visual or interaction change exists. Complete the Agent skill upstream boundary and Checklist sections, and state AI disclosure d…
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes both primary changes: stricter process-table capture handling and reduced resume polling. It is specific and related to the changeset.
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 gives detailed ELI5, change rationale, implementation scope, reliability considerations, platform coverage, measurements, and test results. However, it omits the required Linked Issue, Visual Proof or an explicit N/A explanation, Agent skill upstream boundary, and checklist sections.

Resolution

Add a linked issue using the required Fixes # format. Add the Visual Proof section with N/A and a reason if no visual or interaction change exists. Complete the Agent skill upstream boundary and Checklist sections, and state AI disclosure details when applicable.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 3b1b164c-564a-4149-a89d-0dda174ad31b

📥 Commits

Reviewing files that changed from the base of the PR and between e5a1e79 and 31547e1.

📒 Files selected for processing (4)
  • src/main/runtime/structured-tui-process-identity.test.ts
  • src/main/runtime/structured-tui-process-identity.ts
  • src/shared/process-table-snapshot.test.ts
  • src/shared/process-table-snapshot.ts

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

* evidence and must fail loudly on both views.
*/
function assertWholeCapture(stdout: string): string {
if (Buffer.byteLength(stdout, 'utf-8') >= PS_MAX_BUFFER_BYTES) {

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Confirm the declared Node runtime accepts stdout exactly equal to maxBuffer.
fd -HI '(\.nvmrc|\.node-version|package\.json|\.tool-versions)$' . -x sh -c \
  'echo "--- $1"; sed -n "1,120p" "$1"' sh {}

node <<'NODE'
const { execFile } = require('node:child_process')

const limit = 32 * 1024 * 1024
execFile(
  process.execPath,
  ['-e', `process.stdout.write('x'.repeat(${limit}))`],
  { encoding: 'utf-8', maxBuffer: limit },
  (error, stdout) => {
    console.log({
      node: process.version,
      errorCode: error?.code ?? null,
      stdoutBytes: Buffer.byteLength(stdout ?? '', 'utf-8')
    })
    process.exit(error ? 1 : 0)
  }
)
NODE

Repository: stablyai/orca

Length of output: 19858


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- process-table-snapshot.ts relevant definitions and callers'
rg -n -A18 -B12 'PS_MAX_BUFFER_BYTES|assertWholeCapture|ERR_CHILD_PROCESS_STDIO_MAXBUFFER|execFile' src/shared/process-table-snapshot.ts

printf '%s\n' '--- process-table-snapshot.test.ts exact-limit test'
sed -n '535,585p' src/shared/process-table-snapshot.test.ts

Repository: stablyai/orca

Length of output: 7210


Do not reject complete captures at the exact buffer limit.

execFile allows stdout whose UTF-8 size equals PS_MAX_BUFFER_BYTES, but assertWholeCapture classifies it as capture_truncated. Remove this size check. Keep the existing ERR_CHILD_PROCESS_STDIO_MAXBUFFER mapping for actual overflow, and add a test for an exact-limit capture.

🧰 Tools
🪛 ast-grep (0.45.2)

[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFile as execFileCb } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(detect-child-process-typescript)

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

✅ No new issues found.

Reviewed changes

  • process-table-snapshot.ts — 32 MB maxBuffer + whole-capture integrity guard. The POSIX ps capture now sets an explicit maxBuffer (matching the sibling pty-descendant-termination.ts reader) and adds assertWholeCapture, which rejects a capture that reaches the buffer ceiling (capture_truncated) or carries no rows (empty_capture). ERR_CHILD_PROCESS_STDIO_MAXBUFFER is renamed into the same domain vocabulary. This closes the "silently short table" path (lenient parser drops an unparseable tail → false "no agent") at the capture boundary so no future exec wrapper can reopen it.
  • structured-tui-process-identity.ts — adaptive poll backoff. The poll holds the caller's interval for the first 1 s, then doubles per poll to a 500 ms cap, cutting the worst-case capture count per identification from ~49 to ~20. The first-second detection latency is byte-identical; past it, added latency is bounded by one interval. getFreshProcessTableSnapshot() is retained, keeping the "root absent ⇒ root gone" freshness guarantee intact.
  • Tests — six red-on-main regression guards. The busy-host overflow, truncated/empty capture, and buffer-ceiling-rename cases all fail against the pre-change behavior and pass now; the poll-cost case asserts captures ≤ 20 deterministically on a simulated clock.

The verdict vocabulary (live / unverifiable / exited) is untouched and no new synonym was introduced. Lenient-view consumers (agent-foreground-process.ts, pty-shell-utils.ts) already wrap reads in try/catch and degrade to available:false/null on the new rejections; the relay's pty-handler.listProcesses maps an unreadable capture to table_unreadable evidence. Windows is unaffected (its Toolhelp32 reader forks no child). I verified the six tests are meaningful rather than tautological: each would still pass only because the fix landed, and none use a loose >=/truthiness assertion where an exact one belongs.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

…me spending 49 of them

The POSIX process-table capture ran `execFile('ps', ...)` with no `maxBuffer`,
inheriting Node's 1MB default. Measured at 1,460 processes the capture is 326KB
with a 5,116-char longest row — ~3x headroom, which a busy host clears.

Two separate defects follow, fixed here:

1. `parseProcessTableRows` drops unparseable lines, so any short capture reads
   as a COMPLETE table whose missing processes simply are not running. Verified:
   a capture cut at 4KB parses to 59 of 1,463 rows, and an empty capture parses
   to `[]`, both with no error — and `resolveAgentForegroundProcessWithAvailability`
   then answers `available: true`. That is the `unverifiable` -> `exited` collapse
   the execution boundary forbids. The capture now rejects with
   `ProcessTableCaptureError` on a ceiling-length or row-less capture, so both the
   lenient and strict views fail loudly and callers report unavailable.

2. `maxBuffer` is now an explicit 32MB, matching the sibling reader in
   `pty-descendant-termination.ts` and its stated reasoning. Without it a 4,000-
   process host fails EVERY capture, degrading the whole subsystem permanently.

Separately, `readStructuredTuiProcessIdentity` polled a fresh whole-machine `ps`
every 50ms for up to 5s. Each capture costs ~0.065 CPU-s, and the 5s ceiling is
only reached when the child never appears — where the tight interval buys
nothing. The interval now holds at 50ms for the first second, then doubles to a
500ms cap. Identification latency is unchanged for any child appearing inside
that window, and the 5s ceiling is unchanged.
@nwparker
nwparker force-pushed the nwparker/ps-capture-truncation-and-tui-poll-cost branch from 31547e1 to df870fd Compare September 2, 2026 20:06
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker

nwparker commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Readiness review (batch G). Merging. Both things I was asked to be strict about check out.

The new guards cannot manufacture a false "no agent." I traced every consumer of the capture:

  • agent-foreground-process.ts:187 — catch { return { available: false, processName: fallbackProcess } }. A ProcessTableCaptureError becomes unverifiable, and the caller keeps the last recognized agent.
  • agent-foreground-process.ts:117 (isShellForegroundConfirmed) — catch { return false }, i.e. missing proof, never a thrown confirmation.
  • structured-tui-process-identity.ts — a throw propagates to orca-runtime-prove-recovered-structured-tui-pty-process.ts:71, which logs and returns false, which becomes throw new Error('The owning agent terminal could not be recovered.') at orca-runtime-structured-agent-session-recover-tui-owner.ts:127. Nothing kills a PTY, nothing writes an exited verdict.
  • relay/pty-shell-utils.ts:223 — already maps a capture failure to table_unreadable evidence.

The empty_capture case in particular is not a fail-faster regression: on main an empty table reaches readStructuredTuiProcessIdentity's !rows.some(row => row.pid === input.rootPid) and throws on the very first poll too. Same abort, better error text. And a rejection is never cached — createProcessTableSnapshotReader.runSnapshot assigns cached only on success — so a transient failure retries rather than poisoning the TTL.

The fast path is genuinely byte-identical, and the guard proving it is not vacuous. Setting STRUCTURED_TUI_PROCESS_FAST_POLL_WINDOW_MS from 1_000 to 0 immediately trips it:

× keeps identification latency identical while a child can still plausibly appear
    AssertionError: expected 315 to be less than or equal to 305
× waits for a shell-delivered Codex child before binding ownership
    AssertionError: expected [ 25, 50 ] to deeply equal [ 25, 25 ]

So the 0/200/500/900 ms rows in your table are held by a real assertion. Also confirmed pollDelayMs = Math.max(pollDelayMs, Math.min(pollDelayMs * 2, 500)) never drops below an explicitly slower caller interval, and that the doubling is evaluated after the sleep so the first widened interval lands strictly after the 1 s window.

All five claimed regression tests reproduce red on main, with the exact failures you quoted:

× reads a busy host whose table overflows execFile 1MB default
    promise rejected "stdout maxBuffer length exceeded" instead of resolving
× reports a truncated capture as unreadable rather than a silently short table
    promise resolved "[ { pid: 1000, ppid: 1, …(4) }, …(199) ]" instead of rejecting
× names a buffer-ceiling rejection as truncation on both views
× reports an empty capture as unreadable rather than an empty process table
    promise resolved "[]" instead of rejecting
× does not spend a hundred ps captures on an identification that never resolves

Windows is unaffected as claimed — windows-process-table.ts supplies its own runPs and never reaches assertWholeCapture; only the shared poll cadence changes, identically on all platforms.

Rebased onto main; 6,994 tests pass across src/shared/process-table-snapshot, src/main/runtime, src/main/providers, src/relay/pty-shell-utils. Typecheck clean.

@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

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 4cac7dcf-ace1-4f02-8c4a-fe0ca5240e25

📥 Commits

Reviewing files that changed from the base of the PR and between 89bd189 and df870fd.

📒 Files selected for processing (4)
  • src/main/runtime/structured-tui-process-identity.test.ts
  • src/main/runtime/structured-tui-process-identity.ts
  • src/shared/process-table-snapshot.test.ts
  • src/shared/process-table-snapshot.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/runtime/structured-tui-process-identity.ts
  • src/shared/process-table-snapshot.test.ts
  • src/main/runtime/structured-tui-process-identity.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Comment on lines +376 to +378
if (!/\S/.test(stdout)) {
throw new ProcessTableCaptureError('empty_capture')
}

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 8 \
  '\.lenient\s*\(\)|ProcessTableCapture|parseProcessTableRows|assertWholeCapture' \
  src --glob '*.ts'

rg -n -C 8 \
  'empty_capture|header-only|assertWholeCapture' \
  src/shared/process-table-snapshot.test.ts src --glob '*.ts'

Repository: stablyai/orca

Length of output: 50369


Reject captures with no parseable process rows.

A header-only or otherwise non-matching stdout can pass assertWholeCapture because it contains non-whitespace text. The lenient path then calls parseProcessTableRows and returns [], while only the strict path rejects zero rows. Reject the capture when the lenient parser returns no rows, and add a header-only regression test.

🧰 Tools
🪛 ast-grep (0.45.2)

[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFile as execFileCb } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(detect-child-process-typescript)

@nwparker
nwparker merged commit 6b1cbe5 into main Sep 2, 2026
28 checks passed
nwparker added a commit that referenced this pull request Sep 2, 2026
…wn module (#18246)

`src/shared/process-table-snapshot.ts` is 308 code lines against the 300
cap for `**/*.ts`, so `static analysis` is red on `main` and every open PR
inherits it.

Neither PR that grew the file crossed the cap alone. #18151 took it to 427
raw lines; #18166 added ~35 more. #18166's branch predated #18151, so the
head CI linted was 428 raw lines and passed, while the squash onto main is
463 -> 308 code lines. The gate lints the PR head, not the merge result, so
nothing linted the sum until it was on main.

Pure move, no behaviour change: the generic index machinery
(ProcessIdentityRow, ProcessTableIndexOf, buildProcessTableIndex,
collectDescendantsFromIndex, lookupProcessTableIndex, getProcessTableIndex
and its WeakMap) moves to process-table-index.ts. `ProcessTableIndex` and
`scoreForegroundCandidateRow` stay behind because they need
`ProcessTableRow`, which keeps the new module free of any import back and
so introduces no cycle.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…me spending 49 of them (stablyai#18166)

The POSIX process-table capture ran `execFile('ps', ...)` with no `maxBuffer`,
inheriting Node's 1MB default. Measured at 1,460 processes the capture is 326KB
with a 5,116-char longest row — ~3x headroom, which a busy host clears.

Two separate defects follow, fixed here:

1. `parseProcessTableRows` drops unparseable lines, so any short capture reads
   as a COMPLETE table whose missing processes simply are not running. Verified:
   a capture cut at 4KB parses to 59 of 1,463 rows, and an empty capture parses
   to `[]`, both with no error — and `resolveAgentForegroundProcessWithAvailability`
   then answers `available: true`. That is the `unverifiable` -> `exited` collapse
   the execution boundary forbids. The capture now rejects with
   `ProcessTableCaptureError` on a ceiling-length or row-less capture, so both the
   lenient and strict views fail loudly and callers report unavailable.

2. `maxBuffer` is now an explicit 32MB, matching the sibling reader in
   `pty-descendant-termination.ts` and its stated reasoning. Without it a 4,000-
   process host fails EVERY capture, degrading the whole subsystem permanently.

Separately, `readStructuredTuiProcessIdentity` polled a fresh whole-machine `ps`
every 50ms for up to 5s. Each capture costs ~0.065 CPU-s, and the 5s ceiling is
only reached when the child never appears — where the tight interval buys
nothing. The interval now holds at 50ms for the first second, then doubles to a
500ms cap. Identification latency is unchanged for any child appearing inside
that window, and the 5s ceiling is unchanged.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…wn module (stablyai#18246)

`src/shared/process-table-snapshot.ts` is 308 code lines against the 300
cap for `**/*.ts`, so `static analysis` is red on `main` and every open PR
inherits it.

Neither PR that grew the file crossed the cap alone. stablyai#18151 took it to 427
raw lines; stablyai#18166 added ~35 more. stablyai#18166's branch predated stablyai#18151, so the
head CI linted was 428 raw lines and passed, while the squash onto main is
463 -> 308 code lines. The gate lints the PR head, not the merge result, so
nothing linted the sum until it was on main.

Pure move, no behaviour change: the generic index machinery
(ProcessIdentityRow, ProcessTableIndexOf, buildProcessTableIndex,
collectDescendantsFromIndex, lookupProcessTableIndex, getProcessTableIndex
and its WeakMap) moves to process-table-index.ts. `ProcessTableIndex` and
`scoreForegroundCandidateRow` stay behind because they need
`ProcessTableRow`, which keeps the new module free of any import back and
so introduces no cycle.
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