Skip to content

refactor(memory-safety): group the shared bounding primitives into one folder - #10824

Draft
nwparker wants to merge 2 commits into
mainfrom
oom-slice-0-foundation
Draft

nwparker wants to merge 2 commits into
mainfrom
oom-slice-0-foundation

Conversation

@nwparker

@nwparker nwparker commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

First slice of the re-landed memory-safety work (replaces the oversized #10548). No behavior change — this is a pure move plus import updates, so it can be reviewed by reading the README and skimming the path rewrites.

Why

Six primitives whose entire purpose is bounding memory growth were scattered through src/shared/ next to unrelated modules. There was nowhere to write down when a new ceiling is warranted — and the previous attempt at this work (#10179, reverted in #10255) added a great many that were not.

Grouping them gives that doctrine a home, and gives the follow-up slices a stable place to import from.

What moves

Module Bounds
bounded-map.ts Caches/maps that must not grow forever (count + byte ceiling, LRU)
node-bounded-file-reader.ts Reading a file whose size you don't control
node-bounded-json-stringify.ts Serializing when the result could be huge
bounded-secure-json-file.ts Writing a secret-bearing JSON file within a ceiling
json-text-structure-limit.ts Guarding JSON.parse against depth/token amplification
utf8-byte-limits.ts Measuring/truncating UTF-8 without materializing the string

git mv throughout, so history and blame follow the files.

The README

Carries the rules the next slices are held to:

  • Bound at ingress, not in the interior. A second ceiling behind an existing one isn't defense in depth — it's a second thing that can be wrong, and every ceiling is a new user-visible failure mode when hit.
  • Set limits far above real use. A limit a normal user reaches is a bug.
  • Decide overload behavior explicitly — reject, evict, or truncate. Silent truncation of user data is the worst option.
  • Never copy an accumulator on every update. The crash that started this wasn't only an unbounded Map; it rebuilt itself on every status ping.
  • Prefer fixing measured growth over adding a speculative ceiling.

It states plainly that none of this is lint-enforced today — it's a review standard, not tooling.

Risk

Low, but the failure mode here is real and worth calling out: a vi.mock() left pointing at an old path silently stops applying — the test keeps running against the real module and quietly asserts nothing. Two such mocks needed moving with their modules (git-uncommitted-line-stats.test.ts, git/status.test.ts); the suite caught both. I then swept for every remaining string-literal reference to the six module names in any syntactic form (import, vi.mock, require, dynamic import, JSON/config) and confirmed zero stale paths outside the new folder.

Verification

  • pnpm run typecheck — clean
  • oxlint src/ mobile/src/ — 0 errors (27 warnings, all pre-existing on main)
  • 18,668 tests passing across src/shared and src/main
  • All 42 tests for the moved primitives pass at their new location

Two unrelated failures seen during the run, both confirmed against clean main: managed-hook-local-filesystem.test.ts fails identically on main, and persistence.test.ts passes in isolation (417 tests) under load flake. Neither references any moved module.

Made with Orca 🐋

…e folder

The six primitives that exist to stop unbounded memory growth were scattered
through `src/shared/` next to unrelated modules, so there was nowhere to state
when a new ceiling is warranted — and the last attempt at this work added many
that were not.

Moves them under `src/shared/memory-safety/` and adds a README carrying the
doctrine: bound at ingress, not in the interior; set limits far above real use;
decide overload behavior explicitly; and prefer fixing measured growth over
adding a speculative ceiling.

No behavior change. Pure move plus import-path updates across 48 files, with
`git mv` preserving history. Includes two `vi.mock` paths that had to move with
their modules — a mock left on the old path silently stops applying, which the
suite caught.

Verified: typecheck clean, oxlint 0 errors, 18,668 tests passing across
src/shared and src/main.
@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@nwparker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 seconds

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c317638f-e28f-4333-84e9-564ae5410fd2

📥 Commits

Reviewing files that changed from the base of the PR and between f10b6de and ded5b22.

📒 Files selected for processing (54)
  • src/main/agent-state-file-reader.test.ts
  • src/main/agent-state-file-reader.ts
  • src/main/daemon/terminal-history-file-reader.ts
  • src/main/git/status.test.ts
  • src/renderer/src/components/terminal-pane/pty-eager-buffer-clamp.ts
  • src/renderer/src/components/terminal-pane/terminal-shutdown-layout-capture.test.ts
  • src/renderer/src/components/terminal-pane/terminal-shutdown-layout-capture.ts
  • src/shared/agent-hook-listener.ts
  • src/shared/agent-status-types.ts
  • src/shared/browser-screencast-protocol.ts
  • src/shared/commit-message-agent-spec.ts
  • src/shared/ephemeral-vm-recipes.ts
  • src/shared/ephemeral-vm-runtime-store.ts
  • src/shared/external-automation-jobs-file.ts
  • src/shared/fetch-response-body.ts
  • src/shared/git-uncommitted-line-stats.test.ts
  • src/shared/git-uncommitted-line-stats.ts
  • src/shared/html-to-pdf-memory-limit.ts
  • src/shared/linux-proc-port-scan-limits.ts
  • src/shared/markdown-document-listing-limits.ts
  • src/shared/mcp-config-inspection-limits.ts
  • src/shared/memory-safety/README.md
  • src/shared/memory-safety/bounded-map.test.ts
  • src/shared/memory-safety/bounded-map.ts
  • src/shared/memory-safety/bounded-secure-json-file.ts
  • src/shared/memory-safety/json-text-structure-limit.test.ts
  • src/shared/memory-safety/json-text-structure-limit.ts
  • src/shared/memory-safety/node-bounded-file-reader.test.ts
  • src/shared/memory-safety/node-bounded-file-reader.ts
  • src/shared/memory-safety/node-bounded-json-stringify.test.ts
  • src/shared/memory-safety/node-bounded-json-stringify.ts
  • src/shared/memory-safety/utf8-byte-limits.ts
  • src/shared/node-bounded-file-reader-sync.test.ts
  • src/shared/orca-yaml-file-limit.ts
  • src/shared/persisted-state-file-bounds.test.ts
  • src/shared/persisted-state-file-bounds.ts
  • src/shared/pull-request-generation.ts
  • src/shared/quick-open-install-rg.ts
  • src/shared/relay-json-admission.ts
  • src/shared/relay-version-marker.test.ts
  • src/shared/relay-version-marker.ts
  • src/shared/remote-runtime-memory-limits.ts
  • src/shared/remote-runtime-request-frames.ts
  • src/shared/runtime-bootstrap.ts
  • src/shared/runtime-environment-store.ts
  • src/shared/serve-update-handoff.ts
  • src/shared/setup-script-import-codex-environment.ts
  • src/shared/setup-script-import-limits.ts
  • src/shared/ssh-retained-payload-admission.test.ts
  • src/shared/ssh-retained-payload-admission.ts
  • src/shared/terminal-stream-protocol.ts
  • src/shared/text-search.ts
  • src/shared/workspace-session-terminal-buffers.test.ts
  • src/shared/workspace-session-terminal-buffers.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.

@OrcaWin
OrcaWin marked this pull request as draft October 27, 2026 09:44
@OrcaWin

OrcaWin commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Moving this PR to draft because it has been untouched for more than 80 days (latest recorded PR activity or commit timestamp: 2026-07-28T03:18:06Z; checked on 2026-10-27). This keeps the review queue focused on active work while preserving the proposal. Please mark it ready for review when work resumes.

This branch has not been deployed

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

2 participants