Skip to content

refactor(process-table): extract the correlation indexes into their own module - #18246

Merged
nwparker merged 1 commit into
mainfrom
fix/process-table-snapshot-max-lines
Sep 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
fix/process-table-snapshot-max-lines

Conversation

@nwparker

@nwparker nwparker commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​126 $\color{#cf222e}{\Huge{\mathbf{−}}}$​123 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3

ELI5

main is red. A lint rule caps a TypeScript file at 300 code lines, and process-table-snapshot.ts is at 308. Every open PR inherits the failure, so nobody can get a clean run.

Nobody did anything wrong to cause it — two separate PRs each grew the file a bit, and neither one crossed the line on its own. This moves one self-contained piece into its own file.

Why main went red without anyone's CI catching it

This is the interesting part, and it will happen again if only the eight lines get fixed.

src/shared/process-table-snapshot.ts:463:2: File has too many lines (308).

Two PRs grew the same file, and neither crossed the 300-line cap on its own:

raw lines
before 392
after #18151 (perf(windows): stop asking the process table for memory…) 427
after #18166 (fix(process-table): fail a short ps capture loudly…) 463 → 308 code lines, over the cap

#18166's static analysis passed legitimately. CI lints the merge result, but against the base as it stood when CI ran — and main moved in between:

event time
#18166's static analysis runs 20:07:08Z
#18151 lands on main (+35 lines to the same file) 20:08:01Z
#18166 merges 20:22:25Z

53 seconds. #18166 was linted against a main that did not yet contain #18151, so the tree CI checked was ~428 raw lines and passed. #18151 landed just after, #18166 merged 14 minutes later, and the combined result is 463 → 308 code lines.

That this is a stale-base race rather than anything about PR-head-vs-merge-ref is confirmed by the PRs failing right now: one has the 427-line file on its own head and still fails with the 463-line error, because it is being linted against today's main.

So: two green PRs, a base that moved between check and merge, and a red main. Nothing linted the sum until it existed. This is not specific to line counts — any repo-wide budget or cross-file invariant can break the same way, and the usual mitigation is requiring a branch to be current with its base before it can merge.

Why the file grew, and why this is the seam

Not taste — the two PRs that grew it grew two different responsibilities, which is why neither author could see the other coming. Their hunks do not overlap at all:

PR hunks in process-table-snapshot.ts concern
#18151 perf(windows): stop asking the process table for memory… @@ -124, -161, -169, -180, -195 — all five inside the index block generalizing the index over the row shape so Windows shares one pass
#18166 fix(process-table): fail a short ps capture loudly… @@ -10, @@ -388 ps capture constants and capture validation

Every line #18151 added is inside the block this PR extracts. Every line #18166 added is outside it. Two unrelated concerns, growing in parallel, sharing one budget — so each author was under the cap in the part of the file they were looking at, and the total crossed it.

After this split, #18151-shaped work lands in process-table-index.ts and #18166-shaped work in process-table-snapshot.ts, and they stop sharing a line budget. That is what makes this a fix rather than a deferral.

Headroom, not a shave: 308 → 237 code lines against the 300 cap, leaving 63 lines. Three PRs touched this file today, so getting it to 299 would have put it one small change from red again.

One thing I deliberately did not do. createProcessTableSnapshotReader is also generic (a TTL + in-flight-dedupe memoizer over <T>, ~100 lines) and is arguably a third responsibility. I left it: neither growth site touched it, so extracting it would be speculative rather than evidence-led, and this PR is unblocking a red main. Worth revisiting on its own merits, not here.

The change

A pure move. No behaviour change, no suppression. No max-lines disable and no per-file budget bump — AGENTS.md forbids both, and suppressing here would hide exactly the signal that caught this.

The seam is a real one rather than an arbitrary cut. process-table-index.ts takes the correlation-index machinery, which is already fully generic over the row shape so POSIX ps and the Windows process table share one pass:

  • ProcessTableIndexStats, ProcessIdentityRow, ProcessTableIndexOf
  • buildProcessTableIndex, collectDescendantsFromIndex
  • lookupProcessTableIndex, getProcessTableIndex and its WeakMap

ProcessTableIndex (the ProcessTableRow specialization) and scoreForegroundCandidateRow (reads row.stat) stay in process-table-snapshot.ts. That is deliberate: it leaves the new module with no import back, so the split introduces no cycle and the generic machinery stays free of ps-specific types.

Six consumers get their imports split rather than a barrel re-export, so the module boundary is real:

agent-foreground-process-batch.ts / .test.ts, agent-foreground-process.ts, windows-foreground-process-rows.ts, relay/pty-shell-utils.ts, process-table-snapshot.test.ts.

Proof it is a pure move

Normalizing both sides (strip blank lines, comments, and import statements; sort), the pre-change file is byte-identical to the concatenation of the two post-change files:

diff <(norm before) <(norm after)   →   no output

Verification

Run on my base and again on the merged tree (git merge --no-commit --no-ff origin/main, verify, abort), since a merge is what produced the problem in the first place:

gate before after
oxlint --format github (the failing CI step) 5 warnings, 1 error 5 warnings, 0 errors
check:max-lines-ratchet — OK, 12 grandfathered, no new bypasses
pnpm tc — clean
check:code-quality:changed — 0 new findings across 8 files
check:react-doctor:changed — clean
check:reliability-gates — 102 gates pass
check:ts-nocheck-ratchet / check:runtime-electron-ratchet / check:zustand-selector-fanout — pass
gh-spawn-boundary (new in #18239) — pass

Tests over everything touching the moved code — process-table-snapshot, foreground-process-selection, src/main/providers, relay/pty-shell-utils — 83 files, 892 tests, all passing, and again on the merged tree (889 tests; the delta is #18231 arriving in main, not a behaviour change here).

The 5 remaining oxlint warnings are pre-existing exhaustive-deps findings in the GitLab item dialog, untouched by this PR and present on main before it.

Negative user-facing trade-offs

None. Pure module move on a hot path; the diff is mechanical. No runtime behaviour, wire format, persisted state, platform path, or public signature changes — the same functions with the same bodies are exported from a different file.

…wn module

`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.
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 6e60e816-4bc8-49eb-a7ed-1f6c013daec3

📥 Commits

Reviewing files that changed from the base of the PR and between a0de2fd and bc1e877.

📒 Files selected for processing (8)
  • src/main/providers/agent-foreground-process-batch.test.ts
  • src/main/providers/agent-foreground-process-batch.ts
  • src/main/providers/agent-foreground-process.ts
  • src/main/providers/windows-foreground-process-rows.ts
  • src/relay/pty-shell-utils.ts
  • src/shared/process-table-index.ts
  • src/shared/process-table-snapshot.test.ts
  • src/shared/process-table-snapshot.ts

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.

@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

  • Module extraction — process-table-index.ts is a leaf module (no import back) carrying the correlation-index machinery: ProcessTableIndexStats, ProcessIdentityRow, ProcessTableIndexOf, buildProcessTableIndex, collectDescendantsFromIndex, lookupProcessTableIndex, and getProcessTableIndex with its WeakMap.
  • process-table-snapshot.ts slimmed — keeps ProcessTableIndex (the ProcessTableRow specialization) and scoreForegroundCandidateRow, importing only type ProcessTableIndexOf back; the max-lines violation is cleared.
  • Six consumers rewired — imports split across agent-foreground-process(-batch) (plus test), windows-foreground-process-rows.ts, relay/pty-shell-utils.ts, and process-table-snapshot.test.ts; no barrel re-export, so the boundary is real.

Verified independently: both touched test files pass (37 tests), pnpm tc:node is clean, and oxlint on both split files reports 0 warnings / 0 errors. This is a mechanical move with no behavioral surface — no runtime, wire, persisted-state, or public-signature change.

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

@nwparker
nwparker merged commit 0886db2 into main Sep 2, 2026
33 checks passed
nwparker added a commit that referenced this pull request Sep 2, 2026
Takes #18246 (process-table max-lines) and #18250 (i18n keys) so this PR's
merge ref is recomputed against a green base.
nwparker added a commit that referenced this pull request Sep 2, 2026
Takes #18246 (process-table max-lines) and #18250 (i18n keys) so this PR's
merge ref is recomputed against a green base.
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