Skip to content

fix: change transient request directory from os temp to app data#7194

Open
chirag-bruno wants to merge 1 commit intousebruno:release/v3.1.2from
chirag-bruno:fix/transient-location-change
Open

fix: change transient request directory from os temp to app data#7194
chirag-bruno wants to merge 1 commit intousebruno:release/v3.1.2from
chirag-bruno:fix/transient-location-change

Conversation

@chirag-bruno
Copy link
Contributor

@chirag-bruno chirag-bruno commented Feb 18, 2026

Description

Updated transient request target directory

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced transient collection storage by relocating temporary collections from the system temp directory to the app data directory, improving reliability and persistence of temporary requests with better directory management.

Move transient request files from os.tmpdir() to app.getPath('userData')/transient
to prevent data loss when the OS clears temporary files.

Changes:
- Add helper functions for transient directory paths
- Update findCollectionPathByItemPath to use new transient path check
- Update renderer:mount-collection to create temp dirs in app data
- Update renderer:delete-transient-requests prefix validation
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

Walkthrough

This PR refactors transient collection path handling by introducing a new transient directory API (getTransientDirectoryBase, getTransientCollectionPrefix, isTransientPath) that computes paths under the app data directory instead of the system temp directory. All os.tmpdir()-based transient path resolution is replaced with the new API throughout the IPC handler.

Changes

Cohort / File(s) Summary
Transient Directory API Refactor
packages/bruno-electron/src/ipc/collection.js
Introduces transient directory helper functions and replaces system temp directory usage with app-data-based transient path computation in findCollectionPathByItemPath, renderer:mount-collection, and transient cleanup handlers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • bijin-bruno

Poem

🏠 From temp's uncertain ground,
Collections find a home,
In app data's stable zone,
Where transient paths are sound! 📍

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: moving transient request storage from OS temp directory to app data directory.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/bruno-electron/src/ipc/collection.js (2)

1852-1857: existsSync guard before mkdirSync({ recursive: true }) is redundant.

fs.mkdirSync with { recursive: true } does not throw when the directory already exists, so the existsSync check is a no-op.

♻️ Proposed simplification
-      // Ensure the transient base directory exists
-      const transientBase = getTransientDirectoryBase();
-      if (!fs.existsSync(transientBase)) {
-        fs.mkdirSync(transientBase, { recursive: true });
-      }
-      tempDirectoryPath = fs.mkdtempSync(getTransientCollectionPrefix());
+      // Ensure the transient base directory exists before creating a temp subdir
+      fs.mkdirSync(getTransientDirectoryBase(), { recursive: true });
+      tempDirectoryPath = fs.mkdtempSync(getTransientCollectionPrefix());
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-electron/src/ipc/collection.js` around lines 1852 - 1857,
Remove the redundant existsSync guard before creating the transient base
directory: instead of checking fs.existsSync(transientBase) call
fs.mkdirSync(transientBase, { recursive: true }) directly (keep
getTransientDirectoryBase() to compute transientBase), then proceed to create
the temp dir with tempDirectoryPath =
fs.mkdtempSync(getTransientCollectionPrefix()); this simplifies the block around
getTransientDirectoryBase, fs.mkdirSync, tempDirectoryPath and fs.mkdtempSync by
eliminating the no-op existsSync check.

1024-1032: LGTM — but note: upgrade sessions with stale os.tmpdir() temp dirs will silently skip cleanup.

Post-upgrade, any renderer holding a tempDirectory from the old os.tmpdir() location will have its requests silently skipped by the new prefix check. The behaviour is safe, but transient files from those sessions will linger in the old temp path until the OS clears them. No action needed unless you want to add a one-time migration sweep.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-electron/src/ipc/collection.js` around lines 1024 - 1032, The
current handler for 'renderer:delete-transient-requests' uses
getTransientCollectionPrefix() (brunoTempPrefix) and rejects tempDirectory
values that don't start with it, causing older renderer sessions referencing the
previous os.tmpdir() location to be skipped; update the validation in
ipcMain.handle('renderer:delete-transient-requests') to accept legacy temp paths
by either checking normalizedTempDir against both brunoTempPrefix and the
previous temp-prefix (constructable from os.tmpdir() + the transient suffix) or
call a one-time migration utility (e.g., migrateOldTransientDir) that will
sweep/translate old tempDirectory locations into the new prefix before running
the delete logic, ensuring normalizedTempDir and brunoTempPrefix (and the legacy
prefix) are used when populating results.deleted / results.skipped /
results.errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/bruno-electron/src/ipc/collection.js`:
- Around line 96-99: The isTransientPath function incorrectly uses
filePath.startsWith(transientBase) which matches sibling paths; change the
second condition to an equality check (filePath === transientBase) so the
function returns true only when filePath is exactly the transient base or is
inside it (keep the existing startsWith(transientBase + path.sep) check),
referencing the isTransientPath function and getTransientDirectoryBase and
path.sep.

---

Nitpick comments:
In `@packages/bruno-electron/src/ipc/collection.js`:
- Around line 1852-1857: Remove the redundant existsSync guard before creating
the transient base directory: instead of checking fs.existsSync(transientBase)
call fs.mkdirSync(transientBase, { recursive: true }) directly (keep
getTransientDirectoryBase() to compute transientBase), then proceed to create
the temp dir with tempDirectoryPath =
fs.mkdtempSync(getTransientCollectionPrefix()); this simplifies the block around
getTransientDirectoryBase, fs.mkdirSync, tempDirectoryPath and fs.mkdtempSync by
eliminating the no-op existsSync check.
- Around line 1024-1032: The current handler for
'renderer:delete-transient-requests' uses getTransientCollectionPrefix()
(brunoTempPrefix) and rejects tempDirectory values that don't start with it,
causing older renderer sessions referencing the previous os.tmpdir() location to
be skipped; update the validation in
ipcMain.handle('renderer:delete-transient-requests') to accept legacy temp paths
by either checking normalizedTempDir against both brunoTempPrefix and the
previous temp-prefix (constructable from os.tmpdir() + the transient suffix) or
call a one-time migration utility (e.g., migrateOldTransientDir) that will
sweep/translate old tempDirectory locations into the new prefix before running
the delete logic, ensuring normalizedTempDir and brunoTempPrefix (and the legacy
prefix) are used when populating results.deleted / results.skipped /
results.errors.

Comment on lines +96 to +99
const isTransientPath = (filePath) => {
const transientBase = getTransientDirectoryBase();
return filePath.startsWith(transientBase + path.sep) || filePath.startsWith(transientBase);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

isTransientPath second condition is too broad — can match unrelated sibling paths.

filePath.startsWith(transientBase) will return true for any path that shares the prefix string, including a directory like <transientBase>-other that is not inside the transient dir. The rest of the file consistently uses the startsWith(base + sep) || equals(base) idiom (e.g., line 133).

🐛 Proposed fix
 const isTransientPath = (filePath) => {
   const transientBase = getTransientDirectoryBase();
-  return filePath.startsWith(transientBase + path.sep) || filePath.startsWith(transientBase);
+  return filePath.startsWith(transientBase + path.sep) || filePath === transientBase;
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isTransientPath = (filePath) => {
const transientBase = getTransientDirectoryBase();
return filePath.startsWith(transientBase + path.sep) || filePath.startsWith(transientBase);
};
const isTransientPath = (filePath) => {
const transientBase = getTransientDirectoryBase();
return filePath.startsWith(transientBase + path.sep) || filePath === transientBase;
};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-electron/src/ipc/collection.js` around lines 96 - 99, The
isTransientPath function incorrectly uses filePath.startsWith(transientBase)
which matches sibling paths; change the second condition to an equality check
(filePath === transientBase) so the function returns true only when filePath is
exactly the transient base or is inside it (keep the existing
startsWith(transientBase + path.sep) check), referencing the isTransientPath
function and getTransientDirectoryBase and path.sep.

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

Comments