Skip to content

fix(mount): survive large and corrupt files when mounting collections - #8514

Merged
sid-bruno merged 2 commits into
usebruno:mainfrom
chirag-bruno:fix/mount-large-and-corrupt-file-handling
Jul 8, 2026
Merged

sid-bruno merged 2 commits into
usebruno:mainfrom
chirag-bruno:fix/mount-large-and-corrupt-file-handling

Conversation

@chirag-bruno

@chirag-bruno chirag-bruno commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Opening a collection with very large or malformed .bru files could crash the app (JavaScript heap out of memory) or make corrupted requests show up blank.

Fix

  • Large files: requests ≥ 512KB are parsed with the body redacted first (stripped from the raw text, then reinserted), so the grammar parser never runs on multi-MB input. This avoids the OOM and is far faster (~1–15ms vs ~2s).
  • Safety net: each parse worker now has a heap limit, so a runaway parse fails just that one file (recoverable) instead of aborting the whole app.
  • Corrupted files: when a parse fails we keep the file's name/type/seq (from its meta block) and show it as a partial node, instead of falling back to the bare filename.
  • Collection settings: the collection root now carries its file path (previously empty).

Summary by CodeRabbit

  • New Features

    • Large request files are now handled more gracefully, with request bodies redacted before parsing when needed.
    • Parsed request metadata is now more consistently extracted and preserved.
  • Bug Fixes

    • Failed file parses now keep partial details instead of dropping all parsed data.
    • Error results now retain more context, improving visibility into parsing issues.
    • File tree entries now include a more complete path reference for loaded items.

Mounting a collection containing multi-MB or malformed .bru files could crash
the app or drop request detail. Four related changes to the mount parse
pipeline:

- Redact request bodies >= 512KB before parsing. The grammar parser's memory
  scales badly with input, so full-parsing large .bru files OOMs the pool's
  worker threads (~2s and OOM for a 2MB file on a small worker heap). Body
  blocks are stripped from the raw text before parsing and reinserted after
  (~1-15ms). Mirrors utils/parse.js, at a lower threshold since the worker
  heap is much smaller than the watcher's main thread.

- Cap each pool worker's heap (resourceLimits.maxOldGenerationSizeMb). A job
  that still exceeds it is terminated with a recoverable ERR_WORKER_OUT_OF_MEMORY
  that rejects only that job -- the file is flagged as errored and the mount
  continues -- instead of a V8 process abort that took the whole app down.

- Recover partial meta (name/type/seq) when a full parse fails and keep it in
  the tree state, so a corrupt request shows its real identity as a partial
  node instead of collapsing to the bare filename.

- Attach the collection-root file pathname to tree.root so collection settings
  no longer shows an empty path.
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes affect mount reconciliation error-state persistence, tree root pathname assignment, worker pool thread memory limits, and file-parsing logic that adds redaction for large Bruno request bodies plus structured error handling with partial results on parse failure.

Changes

Mount, Pool, and Parse Fixes

Layer / File(s) Summary
Mount manager error state and tree root pathname
packages/bruno-electron/src/services/mount/manager.js, packages/bruno-electron/src/services/mount/tree-builder.js
Reconcile now persists both data and error on parse failure instead of only error; tree-builder sets tree.root.pathname when tree.root is an object.
Worker pool memory limit configuration
packages/bruno-electron/src/services/pool/index.js
Adds workerThreadOpts.resourceLimits.maxOldGenerationSizeMb set to 512 for thread workers.
Large Bruno request redaction and parse error handling
packages/bruno-electron/src/services/pool/jobs/parse-file.js
Introduces REDACT_BODY_THRESHOLD, parseLargeBruRequest, and extractBruMeta for redacting large request bodies and extracting meta; parseContent accepts byteSize; parseFile wraps parsing in try/catch, returning partial results with error info on failure.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: helloanoop, lohit-bruno, naman-bruno, bijin-bruno

Poem

A rabbit hopped through parse and pool,
Redacting bodies to keep things cool,
Errors now carry data along,
Pathnames set where they belong,
Threads get more room to grow —
Ship it clean, and off we go! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: mounting collections now handles large and corrupt files more safely.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-electron/src/services/mount/manager.js (1)

187-208: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Persist the partial/error state in the index

entry.state keeps the parse failure in memory, but this.#getIndex().entries() only restores { data } from disk. After a reload, that node comes back as a normal request instead of a partial one. Persist an error/partial marker alongside data so corrupted files reopen with the same state.
packages/bruno-electron/src/services/mount/manager.js:191-194

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-electron/src/services/mount/manager.js` around lines 187 -
208, The index update path in the mount manager is only persisting successful
parses, while parse failures are kept only in entry.state and lost on reload.
Update the transaction in manager.js around the parsed/removed loop to stage and
restore an explicit partial/error marker alongside data for failed parses, so
`#getIndex`().entries() can reconstruct the same state after reopening. Use the
existing entry.state handling and `#getIndex`().stage call as the places to
persist and replay this marker for each relativePath.
🧹 Nitpick comments (1)
packages/bruno-electron/src/services/pool/jobs/parse-file.js (1)

8-77: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add unit tests for the new redaction and partial-recovery logic.

parseLargeBruRequest, extractBruMeta, and the parseFile try/catch fallback are new, isolated, and easily testable pure(ish) functions handling the core bug this PR fixes (large/corrupt .bru files). No accompanying tests were included. As per coding guidelines, "Add tests for any new functionality or meaningful changes," and "Prioritise high-value tests over maximum coverage... testing behaviour that is critical, complex, or likely to break."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-electron/src/services/pool/jobs/parse-file.js` around lines 8
- 77, Add unit tests covering the new recovery path in parseFile, especially the
parseLargeBruRequest redaction flow, extractBruMeta fallback, and the try/catch
partial result behavior. Test that large .bru requests route through
parseLargeBruRequest and preserve extracted body fields, that corrupt .bru
request content falls back to extractBruMeta with partial:true and error
details, and that non-request or non-bru parse failures still return the partial
shape from parseFile. Use the function names parseLargeBruRequest,
extractBruMeta, and parseFile to locate the new logic.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bruno-electron/src/services/pool/index.js`:
- Around line 16-20: The workerpool created in the pool initializer should
recover when a worker dies from a resourceLimits/OOM exit so the pool does not
permanently shrink. Update the pool setup around the workerpool.pool call to
detect worker exit/failure in the pool management logic and recreate or replace
the dead worker so the pool maintains the configured maxWorkers. Use the
existing pool class and its initialization path to add this resilience without
changing the public API.

---

Outside diff comments:
In `@packages/bruno-electron/src/services/mount/manager.js`:
- Around line 187-208: The index update path in the mount manager is only
persisting successful parses, while parse failures are kept only in entry.state
and lost on reload. Update the transaction in manager.js around the
parsed/removed loop to stage and restore an explicit partial/error marker
alongside data for failed parses, so `#getIndex`().entries() can reconstruct the
same state after reopening. Use the existing entry.state handling and
`#getIndex`().stage call as the places to persist and replay this marker for each
relativePath.

---

Nitpick comments:
In `@packages/bruno-electron/src/services/pool/jobs/parse-file.js`:
- Around line 8-77: Add unit tests covering the new recovery path in parseFile,
especially the parseLargeBruRequest redaction flow, extractBruMeta fallback, and
the try/catch partial result behavior. Test that large .bru requests route
through parseLargeBruRequest and preserve extracted body fields, that corrupt
.bru request content falls back to extractBruMeta with partial:true and error
details, and that non-request or non-bru parse failures still return the partial
shape from parseFile. Use the function names parseLargeBruRequest,
extractBruMeta, and parseFile to locate the new logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d95421ed-ac81-49cb-af29-8488b4469dd7

📥 Commits

Reviewing files that changed from the base of the PR and between 4592d2c and ce39c73.

📒 Files selected for processing (4)
  • packages/bruno-electron/src/services/mount/manager.js
  • packages/bruno-electron/src/services/mount/tree-builder.js
  • packages/bruno-electron/src/services/pool/index.js
  • packages/bruno-electron/src/services/pool/jobs/parse-file.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants