Bug 497478 - Kate forgets names and paths of unsaved files on session restore.
Summary: Kate forgets names and paths of unsaved files on session restore.
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: sessions (show other bugs)
Version: 24.12.0
Platform: Arch Linux Linux
: NOR major
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords: regression
: 499085 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-12-14 23:39 UTC by Arttu
Modified: 2025-02-12 11:57 UTC (History)
13 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report: https://crash-reports.kde.org/organizations/kde/issues/116767/events/304f856aedca44c297f0125dd8f4ea0d/


Attachments
Video of the bug (961.12 KB, video/mp4)
2025-01-09 18:14 UTC, valdikss
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Arttu 2024-12-14 23:39:37 UTC
SUMMARY
After updating to 24.12.0, restoring sessions with "Automatically save and restore: Files with unsaved changes" enabled, unsaved files names are replaced as "Document #" and save paths changed to "~/.local/share/kate/stash/Main.katesession/" with 'Main' being the name of the session I was using.

This also seems to just happen randomly when the files are left open in another tab.

Newly-created unsaved files are also affected if the corresponding option is enabled.

STEPS TO REPRODUCE
1. Enable "Automatically save and restore: Files with unsaved changes".
2. Create and save a session if not already in one.
3. Create & save a file anywhere.
4. Make changes to the file but don't save them.
5. Reload the session, e.g. by restarting Kate.

OBSERVED RESULT
Filenames and paths are forgotten and files are renamed to "Document #" with # being an incremented number for every file.

EXPECTED RESULT
Filenames and paths are remembered.

SOFTWARE/OS VERSIONS
KDE Frameworks Version: 6.9.0
Qt Version: 6.8.1
Comment 1 Peter Ped Helcmanovsky 2024-12-25 11:46:56 UTC
I can confirm this, the "Automatically save and restore: Files with unsaved changes" makes the editor rename any edited file to "Document #" randomly when switching tabs or opening other files, etc (I guess whenever it does refresh saved session data).

This makes this setting in my use case completely unusable, as I often have 30+ tabs open with different .asm files and editing 2-3 files at same time, so I would end up editing files in kate session folder instead of the file I started to edit.

(updated KDE neon, Kate 24.12.0)
Comment 2 Grósz Dániel 2024-12-30 06:46:40 UTC
Same here with 24.12.0, it worked well until recently (probably before the 24.12.0 update).
Comment 3 Grósz Dániel 2025-01-06 14:24:12 UTC
This also occasionally happens without quitting and restoring. I've just found that a tab I'd edited a few minutes ago had mutated into Document 4 corresponding to some katesession file, while I didn't close Kate in the meantime. I think it's also happened a few other times.

I haven't been able to figure out when it happens. The things I did before it included making a Git stash (from the terminal) involving edits to that tab, making some more edits to that tab and amending the last commit (from Kate's Git plugin), popping the stash (from the terminal) which needed merging (with git mergetool invoked from the terminal). I opened the Quick Open tool just before I noticed the Document # bug, but IIRC I didn't open any file from it. I use a split view, and I think the file in question was open on both sides.
Comment 4 Filip 2025-01-09 12:36:45 UTC
Just to comment further on Daniel's observations. I'm having the same issue he describes: Kate randomly switching to the stashed version of my open tabs (e.g. "~/Documents/file.txt" suddenly becomes "~/.local/share/kate/stash/Default.katesession/Document xx"). I couln't find the logic behind when it happens, it's intermittent, but doesn't happen that frequently. I don't open files from Git repos in Kate, so I can confirm that it has nothing to do with Git.
Comment 5 Grósz Dániel 2025-01-09 15:57:40 UTC
(In reply to Grósz Dániel from comment #3)
> This also occasionally happens without quitting and restoring. I've just
> found that a tab I'd edited a few minutes ago had mutated into Document 4
> corresponding to some katesession file, while I didn't close Kate in the
> meantime. I think it's also happened a few other times.
> 
> I haven't been able to figure out when it happens. The things I did before
> it included making a Git stash (from the terminal) involving edits to that
> tab, making some more edits to that tab and amending the last commit (from
> Kate's Git plugin), popping the stash (from the terminal) which needed
> merging (with git mergetool invoked from the terminal). I opened the Quick
> Open tool just before I noticed the Document # bug, but IIRC I didn't open
> any file from it. I use a split view, and I think the file in question was
> open on both sides.

I'm still not sure exactly what triggers it, but it's often just starting to edit a file (maybe something related to automatic saving?), and it happens quite frequently lately, making Kate nearly unusable.
Comment 6 valdikss 2025-01-09 18:14:47 UTC
Created attachment 177234 [details]
Video of the bug

Here's the video how it happens. It usually occurs if you open the file and start immediately edit it, especially paste anything from the clipboard.

I lost many data due to this, and constantly have to check whether the file has been saved.
Comment 7 valdikss 2025-01-09 18:23:26 UTC
Most probably it happens only with "Kate configuration - Session - Automatically save-restore: files with unsaved changes" checkbox ticked.
Comment 8 Waqar Ahmed 2025-01-13 11:45:46 UTC
Most likely a regression from "periodically saving a session".

The `Automatically save and restore` options are experimental atm.
Comment 9 Tom Sutherland 2025-01-14 23:37:14 UTC
Same here - seems to be directly related to "Automatically save and restore: Newly-created unsaved files" setting being enabled.
Comment 10 Waqar Ahmed 2025-01-24 09:55:57 UTC
*** Bug 499085 has been marked as a duplicate of this bug. ***
Comment 11 navid.zamani+kde 2025-01-29 10:59:03 UTC
I found the trigger:

I can reliably reproduce it happening without a need to close Kate or reload a session. 
All you need, is to be in a session, open a document, and change it.
it is *instantly* renamed to “Document #”, with # being the number of opened documents, starting at 0.
And the on-disc location is set to „$HOME/.local/share/kate/stash/${session}.katesession/Document #”.
 
So it is impossible to save the changes, and closing the file LOSES THE CHANGES.
(Technically, they are saved to “Document #”, but opening any other file that happens to re-named to that, will of course overwrite it.)
I literally cannot edit that file with Kate anymore. I had to use another editor!

@Developers: Can you look in the logic that checks if the document has been changed (compared to the on-disk version)? 
In there, inside a conditional that checks if we are in a session, the bug should be found.
(I can verify that it doesn’t happen if we’re not in a session. Even with the same exact file being opened and changed.)
Comment 12 Grósz Dániel 2025-01-29 14:39:20 UTC
(In reply to valdikss from comment #7)
> Most probably it happens only with "Kate configuration - Session -
> Automatically save-restore: files with unsaved changes" checkbox ticked.

Yes, I disabled that (as well as the presumably related "Newly-created unsaved files" just in case), and it hasn't happened since then.

(In reply to navid.zamani+kde from comment #11)
> I found the trigger:
> 
> I can reliably reproduce it happening without a need to close Kate or reload
> a session. 
> All you need, is to be in a session, open a document, and change it.

I don't think that *always* triggered it for me, when I had the above options enabled.
Comment 13 Waqar Ahmed 2025-02-04 13:37:31 UTC
*** Bug 499482 has been marked as a duplicate of this bug. ***
Comment 14 Waqar Ahmed 2025-02-12 11:52:59 UTC
Git commit 41ee6adfdc3f94099ac40b47e2d12b2187eb37f5 by Waqar Ahmed.
Committed on 12/02/2025 at 11:51.
Pushed by waqar into branch 'master'.

Fix documents being stashed during session

We must use a temp doc otherwise we overwrite the url of the active doc.
Related: bug 499482

M  +11   -1    apps/lib/katestashmanager.cpp

https://invent.kde.org/utilities/kate/-/commit/41ee6adfdc3f94099ac40b47e2d12b2187eb37f5
Comment 15 Waqar Ahmed 2025-02-12 11:57:57 UTC
Git commit 48dbbdb3cd2628df73a2b9391ff767de4798f10d by Waqar Ahmed.
Committed on 12/02/2025 at 11:56.
Pushed by waqar into branch 'release/24.12'.

Fix documents being stashed during session

We must use a temp doc otherwise we overwrite the url of the active doc.
Related: bug 499482
(cherry picked from commit 41ee6adfdc3f94099ac40b47e2d12b2187eb37f5)

M  +11   -1    apps/lib/katestashmanager.cpp

https://invent.kde.org/utilities/kate/-/commit/48dbbdb3cd2628df73a2b9391ff767de4798f10d