Bug 508494 - When quit via the shutdown process, Kate has forgotten all open files on the next launch
Summary: When quit via the shutdown process, Kate has forgotten all open files on the ...
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: sessions (other bugs)
Version First Reported In: Git
Platform: Flatpak Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
: 502007 506797 (view as bug list)
Depends on:
Blocks:
 
Reported: 2025-08-19 23:36 UTC by Nate Graham
Modified: 2025-09-24 04:34 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
diff (4.20 KB, patch)
2025-08-26 17:55 UTC, Nate Graham
Details
Before (11.02 KB, text/plain)
2025-08-26 17:56 UTC, Nate Graham
Details
After (9.08 KB, text/plain)
2025-08-26 17:56 UTC, Nate Graham
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nate Graham 2025-08-19 23:36:01 UTC
STEPS TO REPRODUCE
1. Install Kate from the nightly Flatpak repo (https://cdn.kde.org/flatpak/kate-nightly/org.kde.kate.flatpakref)
2. Launch Kate, set up a session, and configure it to remember the last-used session
3. Open some files
4. Quit the app
5. Re-launch the app -> files remembered, yay!
6. Restart the computer
7. Launch Kate


OBSERVED RESULT
Kate has remembered the session, but all of the files that were open have been lost.


EXPECTED RESULT
Kate remembered the open files as well as the session


SOFTWARE/OS VERSIONS
Operating System: KDE Linux 2025-08-19
KDE Plasma Version: 6.4.80
KDE Frameworks Version: 6.18.0
Qt Version: 6.9.1
Kernel Version: 6.16.0-arch2-1 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 7840U w/ Radeon™ 780M Graphics
Memory: 16 GiB of RAM (14.9 GiB usable)
Graphics Processor: AMD Radeon 780M Graphics


ADDITIONAL INFORMATION
This always worked in the past with Kate from git master compiled normally. It appears to be an issue specific to the git master Flatpak build.
Comment 1 Waqar Ahmed 2025-08-26 15:48:12 UTC
I have tried quitting Kate with SIGTERM and SIGKILL, but it seems to always restore the session correctly.

Can you check the contents of ~/.local/share/kate/sessions/$YOUR_SESSION? The path will likely be different for you, on my system flatpak-kate saves its data in /home/waqar/.var/app/org.kde.kate/data. This will tell us if the session data is there or not.

somewhat related probably https://github.com/flathub/org.kde.kate/issues
Comment 2 Nate Graham 2025-08-26 17:55:29 UTC
Created attachment 184469 [details]
diff

Yes, unfortunately I can still reproduce the issue with yesterday's nightly Flatpak build. Here's a diff of the session files before and after rebooting while Kate is open.
Comment 3 Nate Graham 2025-08-26 17:56:23 UTC
Created attachment 184470 [details]
Before

And here's the raw contents of the session files before rebooting.
Comment 4 Nate Graham 2025-08-26 17:56:39 UTC
Created attachment 184471 [details]
After

…and after rebooting.
Comment 5 Waqar Ahmed 2025-08-26 20:29:15 UTC
seems like the stashed documents survived, but not the other ones.
Comment 6 Waqar Ahmed 2025-08-27 16:04:57 UTC
Tried to reproduce without success today.

Would it be possible for you to do the following:
-> restart pc
-> copy the session files before launching kate
-> launch kate
-> copy the session files again after launching kate

this will tell us if the bug is in session restoration or session saving. My guess is that something goes wrong during session session restore.
Comment 7 Waqar Ahmed 2025-09-03 10:40:42 UTC
I have added some debug logging for session which can be enabled by setting the following env var:

QT_LOGGING_RULES="kate*=true"
Comment 8 Andreas Hartmetz 2025-09-03 14:21:41 UTC
I have tried to reproduce it about 15 times with some changes in what was in the desktop session and the Kate session, logout and reboot... and I couldn't make it happen. Let's see if it happens again during normal use in the next week or two.
Comment 9 Waqar Ahmed 2025-09-03 15:14:56 UTC
I think logout/login will just work, shutdown will trigger it. I will try with shutdown myself again soon.
Comment 10 Andreas Hartmetz 2025-09-16 09:23:13 UTC
It didn't happen for one or two weeks, now it happened twice on two consecutive days. So, unfortunately the bug is still there.
Comment 11 Andreas Hartmetz 2025-09-16 09:31:36 UTC
Unfortunately no log output, it's on a different computer than the one where I enabled it. I have now also enabled it on the other one. The log output works and looks potentially useful on the computer where it's been enabled.
Comment 12 Andreas Hartmetz 2025-09-16 10:04:23 UTC
+    // Save session now, else if the user never opens a new doc or closes one session-autosave will never trigger and
+    // the session will only get saved if Kate is properly closed and not if it gets killed.
+    // Do it delayed, don't block the startup
+    QTimer::singleShot(100, this, [this] {
+        sessionManager()->saveActiveSession(true);
+    });
+

That one looks suspicious and the timing (change added / problem appeared) seems about right. If at all possible, better to add the call into some code that will run at the right time or attach it to a signal that signals the right startup phase.
Comment 13 Andreas Hartmetz 2025-09-20 22:08:26 UTC
It happened again - last boot in log, I've included the rest in case it's useful. Kate opened with the session chooser dialog. The last used session contained zero files and also apparently no other configuration, upon opening it.

-- Boot 1b7877ba00894a99b6bbfaf93ac66ccc --
Sep 20 12:27:07 rechenplan systemd[2322]: Started app-org.kde.kate@6a95b0e951504dd7baf6506ba55f85b1.service - Kate - Erweiterte>
Sep 20 12:27:07 rechenplan kate[3200]: kate.time: QApplication initialized in 76 ms
Sep 20 12:27:07 rechenplan kwrite[3204]: kate: void KateSessionManager::updateSessionList()
Sep 20 12:27:07 rechenplan kate[3200]: kate: void KateSessionManager::updateSessionList()
Sep 20 12:27:07 rechenplan kwrite[3204]: kate: activateSession: name: , closeAndSaveLast: 0, loadNew: 1
Sep 20 12:27:07 rechenplan kwrite[3204]: kate: activateSession name: , closeAndSaveLast: 0, loadNew: 1
Sep 20 12:27:07 rechenplan kwrite[3204]: kate: loadSession: name:
Sep 20 12:27:07 rechenplan kwrite[3204]: kate: KateApp::init() save session on startup
Sep 20 12:27:07 rechenplan kwrite[3204]: kate: saveActiveSession session: , rememberAsLast: 1 isAutoSave: 1
Sep 20 12:27:07 rechenplan kwrite[3204]: kate: saveSessionTo: isAutoSave: 1
Sep 20 12:27:07 rechenplan kwrite[3204]: kate: KateDocManager::saveDocumentList: Count: 1
Sep 20 12:27:07 rechenplan kwrite[3204]: kate: saveSessionTo sessionSaved
Sep 20 12:27:12 rechenplan kwrite[3204]: kate: SessionAutoSave triggered
Sep 20 12:27:12 rechenplan kwrite[3204]: kate: saveActiveSession session: , rememberAsLast: 1 isAutoSave: 1
Sep 20 12:27:12 rechenplan kwrite[3204]: kate: saveSessionTo: isAutoSave: 1
Sep 20 12:27:12 rechenplan kwrite[3204]: kate: KateDocManager::saveDocumentList: Count: 1
Sep 20 12:27:12 rechenplan kwrite[3204]: kate: saveSessionTo sessionSaved
Sep 20 12:37:06 rechenplan kate[3200]: kate: activateSession name: dkadler, closeAndSaveLast: 1, loadNew: 1
Sep 20 12:37:06 rechenplan kate[3200]: kate: activateSession: save active session
Sep 20 12:37:06 rechenplan kate[3200]: kate: loadSession: name: dkadler
Sep 20 12:37:06 rechenplan kate[3200]: kate: KateDocManager::restoreDocumentList: Count: 0
Sep 20 12:37:07 rechenplan kate[3200]: kate.time: KateApp initialized in 600851 ms
Sep 20 12:37:07 rechenplan kate[3200]: kate: KateApp::init() save session on startup
Sep 20 12:37:07 rechenplan kate[3200]: kate: saveActiveSession session: dkadler, rememberAsLast: 1 isAutoSave: 1
Sep 20 12:37:07 rechenplan kate[3200]: kate: saveSessionTo: isAutoSave: 1
Sep 20 12:37:07 rechenplan kate[3200]: kate: KateDocManager::saveDocumentList: Count: 105
Sep 20 12:37:07 rechenplan kate[3200]: kate: stashDocuments
Sep 20 12:37:07 rechenplan kate[3200]: kate: saveSessionTo sessionSaved
Sep 20 12:37:07 rechenplan kate[3200]: kate: void KateSessionManager::updateSessionList()
Sep 20 12:37:23 rechenplan kwrite[3204]: kate: queryClose save active session
Sep 20 12:37:23 rechenplan kwrite[3204]: kate: saveActiveSession session: , rememberAsLast: 1 isAutoSave: 0
Sep 20 12:37:23 rechenplan kwrite[3204]: kate: saveSessionTo: isAutoSave: 0
Sep 20 12:37:23 rechenplan kwrite[3204]: kate: saveSessionTo: clearing KConfigGroups
Sep 20 12:37:23 rechenplan kwrite[3204]: kate: KateDocManager::saveDocumentList: Count: 1
Sep 20 12:37:23 rechenplan kwrite[3204]: kate: saveSessionTo sessionSaved
Sep 20 12:37:23 rechenplan kwrite[3204]: kate: void KateSessionManager::updateJumpListActions()
Sep 20 12:56:30 rechenplan kwrite[46606]: kate: void KateSessionManager::updateSessionList()
Sep 20 12:56:30 rechenplan kwrite[46606]: kate: activateSession: name: , closeAndSaveLast: 0, loadNew: 1
Sep 20 12:56:30 rechenplan kwrite[46606]: kate: activateSession name: , closeAndSaveLast: 0, loadNew: 1
Sep 20 12:56:30 rechenplan kwrite[46606]: kate: loadSession: name:
Sep 20 12:56:30 rechenplan kwrite[46606]: kate: KateApp::init() save session on startup
Sep 20 12:56:30 rechenplan kwrite[46606]: kate: saveActiveSession session: , rememberAsLast: 1 isAutoSave: 1
Sep 20 12:56:30 rechenplan kwrite[46606]: kate: saveSessionTo: isAutoSave: 1
Sep 20 12:56:30 rechenplan kwrite[46606]: kate: KateDocManager::saveDocumentList: Count: 1
Sep 20 12:56:30 rechenplan kwrite[46606]: kate: saveSessionTo sessionSaved
Sep 20 12:56:35 rechenplan kwrite[46606]: kate: SessionAutoSave triggered
Sep 20 12:56:35 rechenplan kwrite[46606]: kate: saveActiveSession session: , rememberAsLast: 1 isAutoSave: 1
Sep 20 12:56:35 rechenplan kwrite[46606]: kate: saveSessionTo: isAutoSave: 1
Sep 20 12:56:35 rechenplan kwrite[46606]: kate: KateDocManager::saveDocumentList: Count: 1
Sep 20 12:56:35 rechenplan kwrite[46606]: kate: saveSessionTo sessionSaved
Sep 20 12:58:52 rechenplan kwrite[46606]: kate: queryClose save active session
Sep 20 12:58:52 rechenplan kwrite[46606]: kate: saveActiveSession session: , rememberAsLast: 1 isAutoSave: 0
Sep 20 12:58:52 rechenplan kwrite[46606]: kate: saveSessionTo: isAutoSave: 0
Sep 20 12:58:52 rechenplan kwrite[46606]: kate: saveSessionTo: clearing KConfigGroups
Sep 20 12:58:52 rechenplan kwrite[46606]: kate: KateDocManager::saveDocumentList: Count: 1
Sep 20 12:58:52 rechenplan kwrite[46606]: kate: saveSessionTo sessionSaved
Sep 20 12:58:52 rechenplan kwrite[46606]: kate: void KateSessionManager::updateJumpListActions()
Sep 20 13:53:28 rechenplan kwrite[54261]: kate: void KateSessionManager::updateSessionList()
Sep 20 13:53:28 rechenplan kwrite[54261]: kate: activateSession: name: , closeAndSaveLast: 0, loadNew: 1
Sep 20 13:53:28 rechenplan kwrite[54261]: kate: activateSession name: , closeAndSaveLast: 0, loadNew: 1
Sep 20 13:53:28 rechenplan kwrite[54261]: kate: loadSession: name:
Sep 20 13:53:28 rechenplan kwrite[54261]: kate: KateApp::init() save session on startup
Sep 20 13:53:28 rechenplan kwrite[54261]: kate: saveActiveSession session: , rememberAsLast: 1 isAutoSave: 1
Sep 20 13:53:28 rechenplan kwrite[54261]: kate: saveSessionTo: isAutoSave: 1
Sep 20 13:53:28 rechenplan kwrite[54261]: kate: KateDocManager::saveDocumentList: Count: 1
Sep 20 13:53:28 rechenplan kwrite[54261]: kate: saveSessionTo sessionSaved
Sep 20 13:53:33 rechenplan kwrite[54261]: kate: SessionAutoSave triggered
Sep 20 13:53:33 rechenplan kwrite[54261]: kate: saveActiveSession session: , rememberAsLast: 1 isAutoSave: 1
Sep 20 13:53:33 rechenplan kwrite[54261]: kate: saveSessionTo: isAutoSave: 1
Sep 20 13:53:33 rechenplan kwrite[54261]: kate: KateDocManager::saveDocumentList: Count: 1
Sep 20 13:53:33 rechenplan kwrite[54261]: kate: saveSessionTo sessionSaved
Sep 20 14:19:59 rechenplan kwrite[54261]: kate: queryClose save active session
Sep 20 14:19:59 rechenplan kwrite[54261]: kate: saveActiveSession session: , rememberAsLast: 1 isAutoSave: 0
Sep 20 14:19:59 rechenplan kwrite[54261]: kate: saveSessionTo: isAutoSave: 0
Sep 20 14:19:59 rechenplan kwrite[54261]: kate: saveSessionTo: clearing KConfigGroups
Sep 20 14:19:59 rechenplan kwrite[54261]: kate: KateDocManager::saveDocumentList: Count: 1
Sep 20 14:19:59 rechenplan kwrite[54261]: kate: saveSessionTo sessionSaved
Sep 20 14:19:59 rechenplan kwrite[54261]: kate: void KateSessionManager::updateJumpListActions()
Sep 20 15:51:34 rechenplan kate[3200]: kate: queryClose save active session
Sep 20 15:51:34 rechenplan kate[3200]: kate: saveActiveSession session: dkadler, rememberAsLast: 1 isAutoSave: 0
Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo: isAutoSave: 0
Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo: clearing KConfigGroups
Sep 20 15:51:34 rechenplan kate[3200]: kate: KateDocManager::saveDocumentList: Count: 105
Sep 20 15:51:34 rechenplan kate[3200]: kate: stashDocuments
Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo sessionSaved
Sep 20 15:51:34 rechenplan systemd[2322]: Stopping app-org.kde.kate@6a95b0e951504dd7baf6506ba55f85b1.service - Kate - Erweitert>
Sep 20 15:51:34 rechenplan kate[3200]: kate: void KateSessionManager::updateSessionList()
Sep 20 15:51:34 rechenplan kate[3200]: kate: KateApp::shutdownKate save session
Sep 20 15:51:34 rechenplan kate[3200]: kate: saveActiveSession session: dkadler, rememberAsLast: 1 isAutoSave: 0
Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo: isAutoSave: 0
Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo: clearing KConfigGroups
Sep 20 15:51:34 rechenplan kate[3200]: kate: KateDocManager::saveDocumentList: Count: 0
Sep 20 15:51:34 rechenplan kate[3200]: kate: stashDocuments
Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo sessionSaved
Sep 20 15:51:34 rechenplan kate[3200]: kate: void KateSessionManager::updateJumpListActions()
Sep 20 15:51:35 rechenplan systemd[2322]: Stopped app-org.kde.kate@6a95b0e951504dd7baf6506ba55f85b1.service - Kate - Erweiterte>
Sep 20 15:51:35 rechenplan systemd[2322]: app-org.kde.kate@6a95b0e951504dd7baf6506ba55f85b1.service: Consumed 11.050s CPU time,>
-- Boot 02c1840ab02f49c3bbe33728643bec6b --
Sep 20 23:46:47 rechenplan systemd[2326]: Started app-org.kde.kate@f7d2358b2c4a43ddbcf44d376e5ec386.service - Kate - Erweiterte>
Sep 20 23:46:47 rechenplan kate[3238]: kate.time: QApplication initialized in 63 ms
Sep 20 23:46:47 rechenplan kate[3238]: kate: void KateSessionManager::updateSessionList()
Comment 14 Waqar Ahmed 2025-09-21 10:04:12 UTC
> +    QTimer::singleShot(100, this, [this] {
> +        sessionManager()->saveActiveSession(true);
> +    });

This is old code, things have changed a bit now. This was the culprit for some related issues, but not this one it seems.
Comment 15 Waqar Ahmed 2025-09-21 10:19:46 UTC
Analyzing the logs:

Shutdown starts here:

> Sep 20 15:51:34 rechenplan kate[3200]: kate: queryClose save active session
> Sep 20 15:51:34 rechenplan kate[3200]: kate: saveActiveSession session: dkadler, rememberAsLast: 1 isAutoSave: 0
> Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo: isAutoSave: 0
> Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo: clearing KConfigGroups
> Sep 20 15:51:34 rechenplan kate[3200]: kate: KateDocManager::saveDocumentList: Count: 105
> Sep 20 15:51:34 rechenplan kate[3200]: kate: stashDocuments
> Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo sessionSaved

Uptill here, the session seems to be saved correctly with 105 documents.

> Sep 20 15:51:34 rechenplan systemd[2322]: Stopping app-org.kde.kate@6a95b0e951504dd7baf6506ba55f85b1.service - Kate - Erweitert>
> Sep 20 15:51:34 rechenplan kate[3200]: kate: void KateSessionManager::updateSessionList()

Then we start triggering shutdown code once again. Probably as a result of a terminate signal?

> Sep 20 15:51:34 rechenplan kate[3200]: kate: KateApp::shutdownKate save session
> Sep 20 15:51:34 rechenplan kate[3200]: kate: saveActiveSession session: dkadler, rememberAsLast: 1 isAutoSave: 0
> Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo: isAutoSave: 0
> Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo: clearing KConfigGroups

The document list is 0 when saving the session this time:

> Sep 20 15:51:34 rechenplan kate[3200]: kate: KateDocManager::saveDocumentList: Count: 0
> Sep 20 15:51:34 rechenplan kate[3200]: kate: stashDocuments
> Sep 20 15:51:34 rechenplan kate[3200]: kate: saveSessionTo sessionSaved
> Sep 20 15:51:34 rechenplan kate[3200]: kate: void KateSessionManager::updateJumpListActions()

AFAICT, The only reason documentList could be 0 is if a window is closed and the setting "Close documents with the window they belong to" (in Session settings) is true (true by default). The KateMainWindow destructor closes all documents in that window that are not open in other windows.

@Nate @Andreas Hartmetz Can you try to disable that setting and see if the issue goes away?

I think a simple fix could be to not close the documents if we have just 1 main window. Or perhaps we should uninstall the signal handler

@Christoph have any thoughts or a better idea?
Comment 16 Andreas Hartmetz 2025-09-21 13:50:59 UTC
(In reply to Waqar Ahmed from comment #15)
Does that also explain losing (apparently) all other settings in the session? As I mentioned, it's not only the document list that is lost.
Comment 17 Christoph Cullmann 2025-09-21 15:54:19 UTC
> I think a simple fix could be to not close the documents if we have just 1 main window. Or perhaps we should uninstall the signal handler

I think we need to avoid that during session closing, makes only sense for user actions.
Comment 18 Waqar Ahmed 2025-09-21 17:57:24 UTC
Yeah(In reply to Andreas Hartmetz from comment #16)
> (In reply to Waqar Ahmed from comment #15)
> Does that also explain losing (apparently) all other settings in the  session? As I mentioned, it's not only the document list that is lost.

yeah.

> I think a simple fix could be to not close the documents if we have just 1 main window. 

Did some testing, this won't fix much. We will be able to keep the document list but the rest of the session will get wiped out. This is because how we save sessions i.e., we wipe old session data, and then save the session to avoid accumulating outdated entries/data in the session. If the session saving is done too late e.g., after the mainwindows are gone then there won't be anything left to save and on next start the session will be empty.

So I think the solution is to block unix signal handling when we are done saving everything and ready to die.
Comment 19 Christoph Cullmann 2025-09-21 18:50:10 UTC
(In reply to Waqar Ahmed from comment #18)
> Yeah(In reply to Andreas Hartmetz from comment #16)
> > (In reply to Waqar Ahmed from comment #15)
> > Does that also explain losing (apparently) all other settings in the  session? As I mentioned, it's not only the document list that is lost.
> 
> yeah.
> 
> > I think a simple fix could be to not close the documents if we have just 1 main window. 
> 
> Did some testing, this won't fix much. We will be able to keep the document
> list but the rest of the session will get wiped out. This is because how we
> save sessions i.e., we wipe old session data, and then save the session to
> avoid accumulating outdated entries/data in the session. If the session
> saving is done too late e.g., after the mainwindows are gone then there
> won't be anything left to save and on next start the session will be empty.
> 
> So I think the solution is to block unix signal handling when we are done
> saving everything and ready to die.

I guess we could just disable the signal handler we install during shutdown, then it is anyways pointless.
Comment 20 Bug Janitor Service 2025-09-22 05:32:48 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1892
Comment 21 Waqar Ahmed 2025-09-22 17:30:39 UTC
Git commit bdf3af4afc73485cd78ad135864250c27aba665e by Waqar Ahmed.
Committed on 22/09/2025 at 05:31.
Pushed by cullmann into branch 'master'.

Ignore unix signals when quitting

If a signal comes after we have quit and closed the mainWindow, we try
to save the session again. When saving a session we clear old saved
session data and then save the session. But if this is done too late,
then we end up saving nothing and loosing all data in the session.

M  +12   -1    apps/lib/kateapp.cpp
M  +5    -0    apps/lib/kateapp.h
M  +2    -0    apps/lib/katemainwindow.cpp

https://invent.kde.org/utilities/kate/-/commit/bdf3af4afc73485cd78ad135864250c27aba665e
Comment 22 Andreas Hartmetz 2025-09-22 20:36:04 UTC
Thanks! Running the new version now, logging still enabled just in case. Not that I expect trouble.
Comment 23 Waqar Ahmed 2025-09-23 07:21:17 UTC
Thanks to you for collecting the data and helping us understand the bug, thats the difficult part :)
Comment 24 Waqar Ahmed 2025-09-24 04:34:35 UTC
*** Bug 506797 has been marked as a duplicate of this bug. ***
Comment 25 Waqar Ahmed 2025-09-24 04:34:49 UTC
*** Bug 502007 has been marked as a duplicate of this bug. ***