Skip to content

feat: implement multi window session hot exit restore with auto save/backup capabilities#497

Open
FreddyFunk wants to merge 1 commit intopop-os:masterfrom
FreddyFunk:feature/hotexit-cache
Open

feat: implement multi window session hot exit restore with auto save/backup capabilities#497
FreddyFunk wants to merge 1 commit intopop-os:masterfrom
FreddyFunk:feature/hotexit-cache

Conversation

@FreddyFunk
Copy link
Copy Markdown

I really like COSMIC Edit for quick note taking during development, but when tinkering with kernel drivers, desktop environments and GPU drivers, I sometimes have to hard reset my machine and then lose those notes. This annoyed me so I tried to come up with a fully featured, full multi window session recovery that is as resilient as possible.

Summary

Implements hot exit functionality for COSMIC Edit, enabling session restoration and automatic backup of unsaved work across crashes and unexpected closures.

Features

  • Session Restoration: Automatically saves and restores open tabs and projects when the application closes/reopens
  • Crash Recovery: Detects orphaned sessions from crashed instances and offers to restore them
  • Auto-save: Optional auto-save feature that saves files after a configurable period of inactivity (disabled by default)
  • Document Backup: Continuously backs up unsaved document content to enable recovery of work in progress
  • Multi-window Support: Handles session management across multiple COSMIC Edit windows
  • Restore Options Dialog: When orphaned sessions are detected, users can choose to:
    • Discard all sessions
    • Restore up to N sessions (configurable via hot_exit_max_auto_restore)
    • Restore all sessions in separate windows

Configuration Options

New settings added to App Settings:

  • reopen_on_start: Reopen projects and tabs on start (default: true)
  • auto_save: Automatically save files after inactivity (default: false)
  • auto_save_interval_secs: Interval between auto-saves in seconds (default: 2)
  • hot_exit_max_auto_restore: Maximum sessions to auto-restore without prompting

Warning

Session restoration and auto save / auto backup capabilities are non-trivial with many edge case. I tried to make to cover every edge case I could think of, but I still recommend thorough testing.

supersedes #146
closes #94
closes #134
closes #150

@jackpot51 jackpot51 requested review from a team January 22, 2026 19:01
Lcstyle added a commit to Lcstyle/cosmic-edit that referenced this pull request Jan 23, 2026
- Update Cargo.toml to use Lcstyle/cosmic-text fork with rope-buffer feature
- Add patch section to redirect all cosmic-text dependencies to fork
- Add comprehensive FORK_BUILD_INSTRUCTIONS.md documenting:
  - All patches required (cosmic-text, onig)
  - Features included (PR pop-os#497, pop-os#479, large file fixes)
  - Troubleshooting common build issues
- Include fresh Cargo.lock with correct dependency resolution

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Lcstyle added a commit to Lcstyle/cosmic-edit that referenced this pull request Jan 23, 2026
Integrates feature/rope-buffer-integration branch which adds:
- RopeBuffer for efficient viewing of very large files (>1MB)
- Scrollbar improvements with proper thumb sizing for large files
- Line number offset support for windowed buffer display
- ScrollChanged message handler for incremental window refresh

Combined with existing features:
- Session restore + auto-save (PR pop-os#497)
- Save As duplicate tab fix (PR pop-os#479)
- Large file memory fix (Issue pop-os#457)
- Skip content hash for large files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Lcstyle
Copy link
Copy Markdown

Lcstyle commented Jan 23, 2026

I implemented this in my fork but then changed the behavior so it doesn't bother me..

Just works, thanks this is a good feature.

f848be6

Copy link
Copy Markdown

@garrettjwilke garrettjwilke left a comment

Choose a reason for hiding this comment

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

works as expected.

opened new edit window -> made changes, did not save -> reboot -> loaded unsaved editor windows

attempted with multiple tabs as well, also works

checked against an existing file but not saved -> also works

Checklist:

Basic operations

  • Type three lines of text (no trailing newline).
  • Copy the last two lines.
  • Paste at the end of the third line (file should now have four lines).
  • Ctrl-Z to undo the paste.
  • Press Enter to add a trailing newline.
  • Paste again (file should now have five lines).
  • Ctrl-Z to undo the paste.
  • Ctrl-Shift-Z to redo the paste.
  • Save the file.
  • Ctrl-F and search for something that has a match.
  • Press Esc twice to exit the Find dialog.
  • Press Ctrl-X to cut the selected search result.
  • Paste the cut text on a new line (file should now have six lines).
  • Re-save the file.
  • Narrow the window until the lines start wrapping (make a line longer if necessary to observe line wrapping).
  • Turn word wrapping off.
  • Scroll right to the end of the document, then left to the beginning again.
  • Click and drag to select some text past the horizontal edge of the window.
  • Close the file, open COSMIC Edit again, and open the file via the recents list.
  • Close the file again, open COSMIC Edit again, and open the file via the Open dialog.
  • Turn word wrapping back on.

Settings

  • Open View -> Settings.
  • All Appearance settings work.
  • Vim bindings work.

Projects & Git Management

  • Clone the cosmic-edit Git repo and open its directory as a project.
  • Edit -> Find in project... works.
  • Make a change in a file.
  • File -> Git management shows the change and staging it works.
  • Make another change while Git management's open; it updates to show the new change.

@FreddyFunk
Copy link
Copy Markdown
Author

great news to here that the tests are successful :) is there anything else I can do?

@jacobgkau
Copy link
Copy Markdown
Member

It looks like this has a Cargo.lock conflict that'll need to be resolved. This will also need engineering review.

It would be good to get a look from @pop-os/ux as well. It looks like two GUI settings are being added. They look like this:

Screenshot_2026-03-09_12-21-37

Not sure if a more specific title than "App Settings" would be good there.

Regarding the first setting, Reopen projects and tabs on start, that setting doesn't seem to apply if I quit the application normally. It only applies if the application's killed (or e.g. the computer shuts off while it's open). We probably need to word that setting more clearly if it only applies to unexpected closes and not to normal closes (otherwise, it sounds like it could just be a more general session restore feature for projects).

@jacobgkau jacobgkau requested a review from a team March 9, 2026 18:29
@FreddyFunk FreddyFunk force-pushed the feature/hotexit-cache branch from e50cced to ce2afa1 Compare March 9, 2026 18:52
@FreddyFunk
Copy link
Copy Markdown
Author

I rebased to the latest master and resolved the conflicts.

Yes, it might be a good idea to rename those settings. Do you have any suggestions?

Regarding the Reopen projects and tabs on start setting. I was focused so much on the backup/restore of unsaved changes that I did not think about this rather common use case. It would be easy to extend the functionality to restore tabs without unsaved content as well and I think it makes sense. What do you think?

@maria-komarova
Copy link
Copy Markdown
Contributor

Regarding the first setting, Reopen projects and tabs on start, that setting doesn't seem to apply if I quit the application normally. It only applies if the application's killed (or e.g. the computer shuts off while it's open). We probably need to word that setting more clearly if it only applies to unexpected closes and not to normal closes (otherwise, it sounds like it could just be a more general session restore feature for projects).

I second this. Might be a good idea to extend the functionality.

It would be easy to extend the functionality to restore tabs without unsaved content as well and I think it makes sense.

I agree, it makes sense to make the setting more general.

I wonder if "Startup and recovery" might be more specific than "App settings". I'd also suggest using "Automatically save files" as the main label and dropping the caption. I omitted period of inactivity after thinking more about it. The reason is that this is essentially what's going to happen. We just need to make sure that files are also saved at the app closing. That probably won't impact new documents that haven't been named yet as we'd still need to ask if people would want to save changes and prompt to choose the location. There might be a more elegant way to deal with that last case but that could be a future improvement.

@jackpot51
Copy link
Copy Markdown
Member

This PR will require a careful code review, so I have not been able to allocate time to it yet. It is still a desired feature.

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.

[Feature] Autosave and recovery behaviour [Feature] Restore session Backup Unsaved Changes

6 participants