Repository navigation
refactor(process-table): extract the correlation indexes into their own module - #18246
Conversation
…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.
|
Warning Review limit reachedNext included review available in 13 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (8)
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. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Module extraction —
process-table-index.tsis a leaf module (no import back) carrying the correlation-index machinery:ProcessTableIndexStats,ProcessIdentityRow,ProcessTableIndexOf,buildProcessTableIndex,collectDescendantsFromIndex,lookupProcessTableIndex, andgetProcessTableIndexwith itsWeakMap. process-table-snapshot.tsslimmed — keepsProcessTableIndex(theProcessTableRowspecialization) andscoreForegroundCandidateRow, importing onlytype ProcessTableIndexOfback; themax-linesviolation is cleared.- Six consumers rewired — imports split across
agent-foreground-process(-batch)(plus test),windows-foreground-process-rows.ts,relay/pty-shell-utils.ts, andprocess-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.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…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.

ELI5
mainis red. A lint rule caps a TypeScript file at 300 code lines, andprocess-table-snapshot.tsis 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
mainwent red without anyone's CI catching itThis is the interesting part, and it will happen again if only the eight lines get fixed.
Two PRs grew the same file, and neither crossed the 300-line cap on its own:
perf(windows): stop asking the process table for memory…)fix(process-table): fail a short ps capture loudly…)#18166's
static analysispassed legitimately. CI lints the merge result, but against the base as it stood when CI ran — and main moved in between:static analysisruns20:07:08Zmain(+35 lines to the same file)20:08:01Z20:22:25Z53 seconds. #18166 was linted against a
mainthat 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:
process-table-snapshot.tsperf(windows): stop asking the process table for memory…@@ -124,-161,-169,-180,-195— all five inside the index blockfix(process-table): fail a short ps capture loudly…@@ -10,@@ -388pscapture constants and capture validationEvery 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.tsand #18166-shaped work inprocess-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.
createProcessTableSnapshotReaderis 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 redmain. Worth revisiting on its own merits, not here.The change
A pure move. No behaviour change, no suppression. No
max-linesdisable 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.tstakes the correlation-index machinery, which is already fully generic over the row shape so POSIXpsand the Windows process table share one pass:ProcessTableIndexStats,ProcessIdentityRow,ProcessTableIndexOfbuildProcessTableIndex,collectDescendantsFromIndexlookupProcessTableIndex,getProcessTableIndexand itsWeakMapProcessTableIndex(theProcessTableRowspecialization) andscoreForegroundCandidateRow(readsrow.stat) stay inprocess-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 ofps-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:
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:oxlint --format github(the failing CI step)check:max-lines-ratchetpnpm tccheck:code-quality:changedcheck:react-doctor:changedcheck:reliability-gatescheck:ts-nocheck-ratchet/check:runtime-electron-ratchet/check:zustand-selector-fanoutgh-spawn-boundary(new in #18239)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 inmain, not a behaviour change here).The 5 remaining
oxlintwarnings are pre-existingexhaustive-depsfindings in the GitLab item dialog, untouched by this PR and present onmainbefore 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.