Skip to content

fix(mount): persist raw file content in file-index for file mode - #8531

Merged
sid-bruno merged 2 commits into
usebruno:mainfrom
chirag-bruno:fix/file-mode-empty-mountv2
Jul 8, 2026
Merged

sid-bruno merged 2 commits into
usebruno:mainfrom
chirag-bruno:fix/file-mode-empty-mountv2

Conversation

@chirag-bruno

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

Copy link
Copy Markdown
Collaborator

Description

JIRA

In file mode, request nodes were not carrying their raw file content, leaving the raw field empty. This change persists the original file content through the mount pipeline so it is available on request nodes.

Changes

  • parse-file job: return the raw file content as raw alongside the parsed data.
  • file-index: add a raw TEXT column (schema migration v2) and read/write it in entries(), stage(), and the on-disk read path. The migration forces a re-index of existing entries (mtime = 0, hash = '') so the column gets populated.
  • mount manager: propagate raw when updating in-memory state and staging index entries.
  • tree-builder: include raw on request nodes (defaulting to null).
  • collections slice: add raw to FILE_DERIVED_REQUEST_FIELDS so it is treated as a file-derived field.

How to test

  1. Open a collection in file mode.
  2. Verify request nodes now carry their raw file content.

Summary by CodeRabbit

  • New Features

    • Added end-to-end preservation of original raw request/file text, alongside parsed content, across mounting, indexing, and request tree building.
    • File index now stores and returns raw content so views can access it for accurate editing and review.
  • Bug Fixes

    • Improved reload/merge behavior to ensure raw request content is retained instead of being dropped when items are updated or reloaded.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR threads a new raw field through parsing, mount reconciliation, file index storage, tree-node building, and Redux collection merging.

Changes

Raw content propagation

Layer / File(s) Summary
Parse and reconcile raw content
packages/bruno-electron/src/services/pool/jobs/parse-file.js, packages/bruno-electron/src/services/mount/manager.js
parseFile returns raw: content in success and error paths; MountManager#reconcile stores raw alongside data and stages it for added files.
FileIndex schema and storage for raw
packages/bruno-electron/src/services/mount/file-index.js
Adds the raw-column migration, selects and returns raw from entries(), writes raw in stage(), and passes UTF-8 file content as raw from stageParsed().
Expose raw in tree nodes and Redux merge
packages/bruno-electron/src/services/mount/tree-builder.js, packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
buildRequestNode adds raw, and the collections slice preserves raw during derived-field merges.

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

Sequence Diagram(s)

sequenceDiagram
  participant ParseFile
  participant MountManager
  participant FileIndex
  participant TreeBuilder
  participant ReduxStore

  ParseFile->>MountManager: return {data, raw, hash, mtime}
  MountManager->>MountManager: entry.state.set({data, raw})
  MountManager->>FileIndex: stage({op: 'add', data, raw, hash, mtime})
  FileIndex->>FileIndex: persist raw column (SQLite)
  MountManager->>TreeBuilder: buildTree(entries)
  TreeBuilder->>TreeBuilder: buildRequestNode sets raw from entry.raw
  TreeBuilder-->>ReduxStore: tree items with raw
  ReduxStore->>ReduxStore: merge item using FILE_DERIVED_REQUEST_FIELDS (incl. raw)
Loading

Possibly related PRs

  • usebruno/bruno#8258: Updates the collections Redux slice’s raw merge behavior in the same request-item flow.
  • usebruno/bruno#8514: Touches the same mount parse path in parse-file.js and related reconciliation behavior.
  • usebruno/bruno#8258: Adds raw handling in the collections slice, directly overlapping the merge rule changed here.

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

Poem

A little raw went on its way,
From file to store, from night to day.
It parsed, it staged, it found its home,
In tree and merge, no longer prone to roam.
✨

🚥 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 clearly matches the main change: persisting raw file content through file-index and mount flow for file mode.
✨ 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.

@chirag-bruno
chirag-bruno force-pushed the fix/file-mode-empty-mountv2 branch from 30355f3 to d0d9032 Compare July 8, 2026 09:03

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

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)

191-195: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Carry raw into the partial-parse error path. parseFile returns raw for partial parses, but this branch drops it by storing only { data, error }, so entry.raw becomes null in tree-builder.js. Add raw: result.raw here so partial request nodes keep their source text.

🤖 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 191 -
195, The partial-parse error path in the mount manager is dropping the source
text returned by parseFile, which causes entry.raw to be null later. Update the
error branch in manager.js where entry.state is set for result.error so it
stores raw: result.raw alongside data and error, matching the success path and
preserving partial request content for tree-builder.js.
🧹 Nitpick comments (2)
packages/bruno-electron/src/services/mount/file-index.js (2)

33-35: 🧹 Nitpick | 🔵 Trivial | 💤 Low value

One-time full re-parse across all collections. Resetting mtime=0/hash='' for every row (all collections, not just the mounted one) forces a complete re-walk and re-parse on the next launch. Intentional for backfill, but worth a heads-up: on large/multi-collection setups this adds a noticeable one-time startup cost after upgrade. Consider confirming this is acceptable or scoping the reset if it proves too heavy.

🤖 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/file-index.js` around lines 33 -
35, The migration in `file-index.js` is resetting `mtime` and `hash` for every
`file_index_entries` row, which triggers a full re-parse across all collections
on next launch. Review the `up` migration block and either confirm this
all-collection backfill is intentionally required, or change the `UPDATE` in the
migration logic to scope the reset to only the mounted collection if the startup
cost is too heavy.

167-167: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Storage footprint doubles per entry. Persisting full raw text alongside the parsed data JSON roughly doubles the on-disk size per request in mount-snapshots.db. getCacheSize() will report the larger value and cache-clear expectations may shift. Fine functionally — flagging so the size impact is a conscious tradeoff.

🤖 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/file-index.js` at line 167, The
snapshot record in file-index.js is persisting both raw text and parsed data,
which roughly doubles storage per entry; decide whether raw is truly needed and,
if not, remove it from the persisted mount-snapshots.db shape or make it
optional/lazy in the snapshot-building flow around the readFileSync/raw
assignment. If raw must stay, update getCacheSize() expectations and any
cache-clearing logic/tests to reflect the larger per-entry footprint and keep
the schema change intentional.
🤖 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.

Outside diff comments:
In `@packages/bruno-electron/src/services/mount/manager.js`:
- Around line 191-195: The partial-parse error path in the mount manager is
dropping the source text returned by parseFile, which causes entry.raw to be
null later. Update the error branch in manager.js where entry.state is set for
result.error so it stores raw: result.raw alongside data and error, matching the
success path and preserving partial request content for tree-builder.js.

---

Nitpick comments:
In `@packages/bruno-electron/src/services/mount/file-index.js`:
- Around line 33-35: The migration in `file-index.js` is resetting `mtime` and
`hash` for every `file_index_entries` row, which triggers a full re-parse across
all collections on next launch. Review the `up` migration block and either
confirm this all-collection backfill is intentionally required, or change the
`UPDATE` in the migration logic to scope the reset to only the mounted
collection if the startup cost is too heavy.
- Line 167: The snapshot record in file-index.js is persisting both raw text and
parsed data, which roughly doubles storage per entry; decide whether raw is
truly needed and, if not, remove it from the persisted mount-snapshots.db shape
or make it optional/lazy in the snapshot-building flow around the
readFileSync/raw assignment. If raw must stay, update getCacheSize()
expectations and any cache-clearing logic/tests to reflect the larger per-entry
footprint and keep the schema change intentional.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3ea7e56f-0aa3-451e-9f7a-aca90e1acee8

📥 Commits

Reviewing files that changed from the base of the PR and between da707ea and d0d9032.

📒 Files selected for processing (5)
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-electron/src/services/mount/file-index.js
  • packages/bruno-electron/src/services/mount/manager.js
  • packages/bruno-electron/src/services/mount/tree-builder.js
  • packages/bruno-electron/src/services/pool/jobs/parse-file.js

sid-bruno
sid-bruno previously approved these changes Jul 8, 2026
@sid-bruno

Copy link
Copy Markdown
Collaborator

Tests

cchirag added 2 commits July 8, 2026 18:33
Store the original file content as a `raw` column in the file-index and
propagate it through the parse pipeline, mount manager, and tree builder so
request nodes carry their raw content in file mode. Adds a migration to add
the column and force a re-index of existing entries.
@sid-bruno
sid-bruno merged commit 55c3003 into usebruno:main Jul 8, 2026
18 of 21 checks passed
ravindra-bruno pushed a commit to ravindra-bruno/bruno that referenced this pull request Jul 9, 2026
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