Skip to content

feat: auto-save untitled request drafts - #8864

Closed
Max-Reisinger wants to merge 3 commits into
usebruno:mainfrom
Max-Reisinger:feature/auto-save-untitled-drafts
Closed

Max-Reisinger wants to merge 3 commits into
usebruno:mainfrom
Max-Reisinger:feature/auto-save-untitled-drafts

Conversation

@Max-Reisinger

@Max-Reisinger Max-Reisinger commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Auto-saves new Untitled request drafts to stable application-managed transient storage and restores their tabs after Bruno restarts. Saving a draft whose requested name already exists now selects the next numeric suffix.

Problem

Closing Bruno with unsaved Untitled requests currently prompts the user and the drafts are not restored on the next launch.

Fixes #8849

Fix

  • Use deterministic transient directories for collections and workspace scratch collections.
  • Persist transient request edits regardless of the global auto-save preference and flush them before quit.
  • Include transient and scratch request tabs in UI snapshots and hydrate them on startup.
  • Resolve save-name collisions with suffixes such as Login (1) and use the resolved pathname in the renderer.
  • Add end-to-end coverage for restart restoration and collision handling.

Testing

  • npm run build:web — passed.
  • Targeted ESLint for all changed files — passed with 0 errors (existing warnings remain).
  • git diff --check — passed.
  • Targeted Jest could not start because the local canvas native module is missing canvas.node.
  • Targeted Playwright could not run because the local dev server hit the EMFILE file-descriptor limit.

Screenshots

Not applicable; this changes persistence behavior without changing the UI.

Before After
Untitled drafts prompt on quit and are lost after restart. Untitled drafts auto-save and their tabs restore after restart.

Contribution Checklist:

  • AI was used 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.
  • I have run the claude code review skill locally.

Summary by CodeRabbit

  • New Features
    • Untitled request drafts now autosave and persist when closing or restarting the app.
    • Drafts restore more reliably when switching workspaces or reopening scratch collections.
    • Saving a request with an existing name automatically creates a numbered filename.
  • Bug Fixes
    • Improved transient request saving and close-flow handling, including saves when autosave is disabled.
    • Newly saved requests open from their actual saved location.
    • Scratch data is preserved only for the active workspace.
  • Tests
    • Added coverage for draft persistence, autosave, workspace restoration, and filename conflict resolution.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Transient requests now autosave as drafts, persist before application quit, restore through workspace snapshots, and save with collision-safe filenames. Shared utilities manage transient directories, and saved requests open from Electron-returned paths.

Changes

Transient draft lifecycle

Layer / File(s) Summary
Transient directory management
packages/bruno-electron/src/utils/transient-directory.js, packages/bruno-electron/src/utils/write-file-with-suffix.js, packages/bruno-electron/src/ipc/collection.js, packages/bruno-electron/src/services/mount/manager.js, packages/bruno-electron/src/app/collection-watcher.js, packages/bruno-electron/src/utils/write-file-with-suffix.spec.js
Shared utilities create transient directories with metadata. Saves use collision-safe filenames. Mounting uses the shared utilities, and watchers process existing files.
Transient request saving
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js, packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js, packages/bruno-electron/src/ipc/collection.js, packages/bruno-app/src/components/SaveTransientRequest/index.js, tests/snapshots/basic.spec.ts
Silent saves persist transient requests. Existing names receive numeric suffixes. Saved metadata and opening paths use the resolved filename and path.
Draft autosave and workspace restoration
packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/*, packages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/*, packages/bruno-app/src/utils/snapshot/index.js, packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js
Transient requests remain scheduled when autosave is disabled. Active scratch collections and tabs participate in snapshot serialization and restoration.
Quit-time draft persistence
packages/bruno-app/src/providers/App/ConfirmAppClose/*, packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
The quit flow silently saves transient drafts, flushes the snapshot, logs failures, and continues to close confirmation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant AutosaveMiddleware
  participant ReduxStore
  participant ElectronIPC
  participant Snapshot
  User->>ReduxStore: edit transient request
  ReduxStore->>AutosaveMiddleware: schedule persistent save
  AutosaveMiddleware->>ElectronIPC: save transient request
  ElectronIPC->>ElectronIPC: choose collision-free filename
  ElectronIPC-->>AutosaveMiddleware: return resolved pathname
  AutosaveMiddleware->>Snapshot: persist draft state
Loading

Possibly related PRs

Suggested labels: size/XXL

Suggested reviewers: bijin-bruno

Poem

Untitled drafts persist,
Timers keep their promise.
Scratch tabs return with state,
Collisions gain a suffix.
Resolved paths open requests.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: automatic saving of untitled request drafts.
Linked Issues check ✅ Passed The changes implement draft autosaving, restoration, close-flow persistence, and numeric suffixes for name collisions requested by issue #8849.
Out of Scope Changes check ✅ Passed The changes support draft persistence, restoration, collision handling, and required test coverage without unrelated functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 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: 5

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/ipc/collection.js (1)

609-638: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Make collision-safe creation atomic.

Two concurrent saves can both observe that the same pathname is free. Both handlers then await serialization and write the same file. The later write overwrites the earlier draft instead of receiving the next suffix.

Create the target with exclusive creation and retry on EEXIST. Add a concurrent-save regression test.

🤖 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/ipc/collection.js` around lines 609 - 638, The
collision check around targetPathname is not atomic, allowing concurrent saves
to overwrite one another. Update the save flow using writeFile to create the
target exclusively, retrying the serialization/write operation with the next
filename when an EEXIST error occurs; preserve the existing suffix naming
behavior and add a regression test covering concurrent saves.
🤖 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-app/src/providers/ReduxStore/middlewares/autosave/middleware.js`:
- Around line 289-294: Preserve pending transient saves scheduled by the
persistAlways branch in the autosave middleware when the app/updatePreferences
disable branch clears ordinary timers. Track persistent timers separately or
exclude them from cancellation, and add coverage that disables autosave
immediately after editing a transient request and still verifies the deferred
save executes.

In
`@packages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.js`:
- Around line 186-190: Update the filtering condition in serializeSnapshot so
scratch collections are retained only when collection.uid matches
activeWorkspace?.scratchCollectionUid; continue applying
activeWorkspaceCollectionPaths to non-scratch collections. Add a regression test
covering snapshots with scratch collections from two workspaces and verify only
the active workspace scratch collection is serialized.

In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 291-294: Update the save-operation handling around Promise.all and
flushSnapshotNow so every operation settles before the snapshot is flushed by
replacing Promise.all with Promise.allSettled. Preserve
flushSnapshotNow(getState) in the finally path, then propagate a rejection after
all saves have settled if any operation failed.

In `@packages/bruno-electron/src/ipc/collection.js`:
- Around line 630-635: Update both syncExampleUidsCache calls in the save flow
to use targetPathname instead of sourcePathname, so cache entries are created
under the pathname where the request is written; leave the mergedRequest and
serialization logic unchanged.

In `@tests/snapshots/basic.spec.ts`:
- Around line 7-11: Remove the trailing comma from the final imported symbol,
saveTransientViaModal, in the import declaration while preserving the existing
import list and formatting.

---

Outside diff comments:
In `@packages/bruno-electron/src/ipc/collection.js`:
- Around line 609-638: The collision check around targetPathname is not atomic,
allowing concurrent saves to overwrite one another. Update the save flow using
writeFile to create the target exclusively, retrying the serialization/write
operation with the next filename when an EEXIST error occurs; preserve the
existing suffix naming behavior and add a regression test covering concurrent
saves.
🪄 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 Plus

Run ID: 6d1b8b98-880e-4b23-b29a-719cf4a4305b

📥 Commits

Reviewing files that changed from the base of the PR and between 51d609a and 8c55596.

📒 Files selected for processing (14)
  • packages/bruno-app/src/components/SaveTransientRequest/index.js
  • packages/bruno-app/src/providers/App/ConfirmAppClose/SaveRequestsModal.js
  • packages/bruno-app/src/providers/App/ConfirmAppClose/index.js
  • packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js
  • packages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js
  • packages/bruno-app/src/utils/snapshot/index.js
  • packages/bruno-electron/src/app/collection-watcher.js
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/services/mount/manager.js
  • packages/bruno-electron/src/utils/transient-directory.js
  • tests/snapshots/basic.spec.ts

Comment on lines +7 to +11
createTransientRequest,
fillRequestUrl,
openRequest,
openCollection,
saveTransientViaModal,

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the trailing comma from this import.

The project rule does not allow trailing commas.

As per coding guidelines, "Do not use trailing commas".

🤖 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 `@tests/snapshots/basic.spec.ts` around lines 7 - 11, Remove the trailing comma
from the final imported symbol, saveTransientViaModal, in the import declaration
while preserving the existing import list and formatting.

Source: Coding guidelines

@pull-request-size pull-request-size Bot added size/XL and removed size/L labels Aug 4, 2026

@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: 2

🤖 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-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.spec.js`:
- Around line 137-168: Update the test fixtures around serializeSnapshot to
build workspace and scratch collection path values with path.join(os.tmpdir(),
...) instead of hardcoded /tmp paths. Reuse the same generated scratch path
values in the collectionPaths assertions, and ensure the required path and os
utilities are available.

In `@packages/bruno-electron/src/utils/write-file-with-suffix.js`:
- Around line 8-14: Constrain the path built in the filename-generation flow
before the writeFile call: validate or sanitize basename and extension so they
cannot contain path separators, absolute paths, or traversal segments, and
ensure path.join(dirname, filename) remains inside dirname. Preserve the
existing suffix generation and exclusive write behavior, and reject invalid
inputs rather than allowing writes outside the target directory.
🪄 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 Plus

Run ID: 7f76601f-cd4d-4aa3-854f-050b0064f6e3

📥 Commits

Reviewing files that changed from the base of the PR and between 8c55596 and d36b1d9.

📒 Files selected for processing (8)
  • packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js
  • packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.spec.js
  • packages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.js
  • packages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/utils/write-file-with-suffix.js
  • packages/bruno-electron/src/utils/write-file-with-suffix.spec.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js

@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

🤖 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/utils/write-file-with-suffix.spec.js`:
- Around line 33-51: Add Windows drive-letter absolute-path cases to the
existing parameterized test for both basename and extension, using values such
as C:\\temp\\Login and C:\\temp\\bru. Keep the assertions verifying rejection
with the appropriate Invalid basename/extension message and ensure createContent
is not called, covering the validatePathSegment path.win32.isAbsolute branch.
🪄 Autofix

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 Plus

Run ID: c01d8b0c-8cdb-4d2e-8e3f-f3d084e3e785

📥 Commits

Reviewing files that changed from the base of the PR and between d36b1d9 and 55a2c39.

📒 Files selected for processing (4)
  • packages/bruno-app/src/components/SaveTransientRequest/index.js
  • packages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.spec.js
  • packages/bruno-electron/src/utils/write-file-with-suffix.js
  • packages/bruno-electron/src/utils/write-file-with-suffix.spec.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.spec.js

Comment on lines +33 to +51
it.each([
['basename', '../Login', 'bru'],
['basename', '..\\Login', 'bru'],
['basename', '/tmp/Login', 'bru'],
['extension', 'Login', '../bru'],
['extension', 'Login', '..\\bru']
])('rejects an unsafe %s before creating content', async (label, basename, extension) => {
const createContent = jest.fn(async () => {
throw new Error('createContent should not run');
});

await expect(writeFileWithSuffix({
dirname,
basename,
extension,
createContent
})).rejects.toThrow(`Invalid ${label}`);
expect(createContent).not.toHaveBeenCalled();
});

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.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Cover Windows absolute paths.

validatePathSegment checks path.win32.isAbsolute(), but these cases do not include a drive-letter path. Add basename and extension cases such as C:\\temp\\Login so this validation branch cannot regress.

As per coding guidelines, “Cover successful behavior as well as realistic errors, edge cases, and degraded-mode behavior.” As per path instructions, “Bruno is a cross-platform Electron desktop app that runs on macOS, Windows, and Linux.”

🤖 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/utils/write-file-with-suffix.spec.js` around
lines 33 - 51, Add Windows drive-letter absolute-path cases to the existing
parameterized test for both basename and extension, using values such as
C:\\temp\\Login and C:\\temp\\bru. Keep the assertions verifying rejection with
the appropriate Invalid basename/extension message and ensure createContent is
not called, covering the validatePathSegment path.win32.isAbsolute branch.

Sources: Coding guidelines, Path instructions

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.

Auto-save new requests as Untitled drafts

1 participant