Bug 487912

Summary: plasma X11 session is not restored after logout/login
Product: [Plasma] plasmashell Reporter: Vence <wenzezlaus>
Component: Session ManagementAssignee: Plasma Bugs List <plasma-bugs>
Status: REOPENED ---    
Severity: normal CC: akontsevich, asturm, dkxls23, edzis, idarktemplar, imaginator, kairo, kde, KDE, kishore96, kollix, mapatrapa, natalie_clarius, nate, omosnacek, umar, wenzezlaus, zb4ng, zmogas
Priority: NOR Keywords: regression
Version: 6.1.4   
Target Milestone: 1.0   
Platform: Arch Linux   
OS: Linux   
See Also: https://bugs.gentoo.org/show_bug.cgi?id=938925
https://bugs.kde.org/show_bug.cgi?id=488853
https://bugs.kde.org/show_bug.cgi?id=488520
https://bugs.kde.org/show_bug.cgi?id=436318
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Vence 2024-06-02 07:37:28 UTC
SUMMARY
With plasma-workspace upgraded from 6.0.5 to 6.0.5.1, plasma X11 session is not restored after logout/login regardless of "Desktop Session" options (last logout or manual saved) in System Setting.

STEPS TO REPRODUCE
1. Upgrade plasma -workspace to 6.0.5.1, 
2. Set "Desktop Session" option  to "last logout" or "manual saved" in System Setting
3. Logout and login

OBSERVED RESULT
New session starts as empty one. 
There are several messages "Qt: Session management error: None of the authentication protocols specified are supported" in  journalctl and no other errors.

EXPECTED RESULT
The previous session saved at last logout or manually is restored

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux
KDE Plasma Version: 6.0.5
KDE Frameworks Version: 5.2
Qt Version: 6.7.1
Comment 1 Vence 2024-06-02 07:53:03 UTC
The bug is presumably caused by recent changes in plasma-workspace made in 6.0.5.1, namely, in ksmserver (server.cpp and server.h).

plasma-workspace 6.0.5 is free of this bug
Comment 2 Kishore Gopalakrishnan 2024-06-02 07:59:37 UTC
I also have this bug. Interestingly, applications are still opened correctly (preserving their previous state) when resuming an activity.
Comment 3 Kishore Gopalakrishnan 2024-06-02 09:20:27 UTC
(In reply to Kishore Gopalakrishnan from comment #2)
> ... Interestingly, applications are still opened correctly
> (preserving their previous state) when resuming an activity.

Scratch that. Activity supension/resumption also doesn't work for me.

When I suspend an activity, I can see using htop that those applications are still running (and thus, they still appear if I resume the same activity without rebooting). However, attempting to resume the activity after rebooting, one is indeed presented with just an empty activity.
Comment 4 Kishore Gopalakrishnan 2024-06-02 09:26:26 UTC
Installing the xorg-iceauth package does not help for me.
Comment 5 Kishore Gopalakrishnan 2024-06-02 09:35:16 UTC
After enabling 'full debug' output for ksmserver and rebooting, I get the following messages in `journalctl -b -0 --user` (I have only reproduced a segment that seems relevant)
```
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Started KDE Daemon 6.
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: org.kde.kf6.ksmserver: "/run/user/1000/KSMserver"
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Starting KDE Configuration Module Initialization (Phase 1)...
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: Failed to write ice auth file entry
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: Failed to write xsmp ice auth file entry
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: Failed to write ice auth file entry
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: Failed to write xsmp ice auth file entry
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: org.kde.kf6.ksmserver: KSMServer::restoreSession  "saved at previous logout"
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Started KDE Session Management Server.
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Starting KDE Plasma Workspace...
Jun 02 14:59:53 kishorearchtestingVM kcminit_startup[550]: Initializing  "/usr/lib/qt6/plugins/plasma/kcms/systemsettings/kcm_touchpad.so"
Jun 02 14:59:53 kishorearchtestingVM kcminit_startup[550]: kcm_touchpad: Using X11 backend
Jun 02 14:59:53 kishorearchtestingVM kcminit_startup[550]: Initializing  "/usr/lib/qt6/plugins/plasma/kcms/systemsettings_qwidgets/kcm_kgamma.so"
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Finished KDE Configuration Module Initialization (Phase 1).
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: org.kde.libkbolt: Failed to connect to Bolt manager DBus interface:
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: org.kde.bolt.kded: Couldn't connect to Bolt DBus daemon
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Started KDE Window Manager.
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: org.kde.plasma.printmanager.kded: unable to register service to dbus
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: QDBusObjectPath: invalid path "/modules/plasma-session-shortcuts"
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: kf.dbusaddons: The kded module name "plasma-session-shortcuts" is invalid!
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Starting KActivityManager Activity manager Service...
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: QDBusObjectPath: invalid path "/modules/kded_plasma-welcome"
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: kf.dbusaddons: The kded module name "kded_plasma-welcome" is invalid!
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: kcm_touchpad: Using X11 backend
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: org.kde.kf6.ksmserver: KSMConnection::count 1
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: org.kde.kf6.ksmserver: ICE Connection rejected!
Jun 02 14:59:53 kishorearchtestingVM plasmashell[607]: Qt: Session management error: None of the authentication protocols specified are supported
```
Comment 6 Kishore Gopalakrishnan 2024-06-02 09:57:12 UTC
In ksmserver/server.cpp, I see (around line 365)
```
            if (IceWriteAuthFileEntry(fp, file_entry) != 0) {
                qWarning("Failed to write ice auth file entry");
            }
```
but the documentation for IceWriteAuthFileEntry ( https://www.x.org/releases/X11R7.7/doc/libICE/ICElib.html#IceWriteAuthFileEntry ) says "The function returns a nonzero status if the operation was successful. "

I suppose this means the 'Failed to write ice auth file entry' messages in my logs in comment 5 may be misleading.
Comment 7 Kishore Gopalakrishnan 2024-06-02 11:48:25 UTC
I can at least confirm that my iceauth file (/run/user/1000/iceauth_XXXXXX , where XXXXXX is some apparently random string) is empty, so perhaps ksmserver is indeed failing to write the 'magic cookie' (whatever that is) to that file.
Comment 8 Jesus 2024-06-02 19:36:43 UTC
Confirmed, this happens with the latest version of plasma-workspace 6.0.5.1, if I install the previous 6.0.5 the session restoration works again
Comment 9 Eduardo 2024-06-03 11:50:20 UTC
I can confirm this, luckily I could revert to 6.0.5, heavily rely on session restore functionality.
I even restored home FS to a snapshot before I logged in with broken session restore, to be sure.
Comment 10 Eduardo 2024-06-03 11:55:03 UTC
(In reply to Kishore Gopalakrishnan from comment #7)
> I can at least confirm that my iceauth file (/run/user/1000/iceauth_XXXXXX ,
> where XXXXXX is some apparently random string) is empty, so perhaps
> ksmserver is indeed failing to write the 'magic cookie' (whatever that is)
> to that file.

I don't even have this file on my system with 6.0.5 where everything works just fine. So I would not be so sure that the issue is there.
Comment 11 i.Dark_Templar 2024-06-03 15:16:48 UTC
(In reply to Eduardo from comment #10)
> (In reply to Kishore Gopalakrishnan from comment #7)
> > I can at least confirm that my iceauth file (/run/user/1000/iceauth_XXXXXX ,
> > where XXXXXX is some apparently random string) is empty, so perhaps
> > ksmserver is indeed failing to write the 'magic cookie' (whatever that is)
> > to that file.
> 
> I don't even have this file on my system with 6.0.5 where everything works
> just fine. So I would not be so sure that the issue is there.

That is the issue. With new release this file is created, written, but not flushed or closed, so it stays empty. And new env variable ICEAUTHORITY pointing to this file is set up. Flushing or closing file fixed issue for me with plasma workspace 5.27.11.1 as in https://bugs.kde.org/show_bug.cgi?id=487936#c3.
Comment 12 Vence 2024-06-03 15:38:20 UTC
(In reply to i.Dark_Templar from comment #11)
> 
> That is the issue. With new release this file is created, written, but not
> flushed or closed, so it stays empty. And new env variable ICEAUTHORITY
> pointing to this file is set up. Flushing or closing file fixed issue for me
> with plasma workspace 5.27.11.1 as in
> https://bugs.kde.org/show_bug.cgi?id=487936#c3.

Could you explain how can one close or flush this file?
Comment 13 Kishore Gopalakrishnan 2024-06-03 16:04:08 UTC
*** Bug 487936 has been marked as a duplicate of this bug. ***
Comment 14 Eduardo 2024-06-03 16:04:54 UTC
(In reply to i.Dark_Templar from comment #11)
> That is the issue. With new release this file is created, written, but not
> flushed or closed, so it stays empty. And new env variable ICEAUTHORITY
> pointing to this file is set up. Flushing or closing file fixed issue for me
> with plasma workspace 5.27.11.1 as in
> https://bugs.kde.org/show_bug.cgi?id=487936#c3.

Good catch!
Comment 15 Vence 2024-06-04 07:27:03 UTC
After plasma workspace 6.0.5.1 is rebuilt with the following patch applied, everything seems to be quite right: 
-- $ICEAUTHORITY=/run/user/1000/iceauth_XXXXX
-- file iceauth_XXXXX does exist and is not empty
-- plasma X11 session is saved and restored correctly.

--- a/ksmserver/server.cpp<---->2024-05-31 15:48:02.000000000 +0300
+++ b/ksmserver/server.cpp<---->2024-06-04 08:47:52.966458262 +0300
@@ -397,6 +397,7 @@
         IceSetPaAuthData(2, &(*authDataEntries)[i]);
     }
.
+    (void)fclose(fp);
     return (1);
 }
Comment 16 Bug Janitor Service 2024-06-04 07:46:42 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4405
Comment 17 David Edmundson 2024-06-04 08:08:11 UTC
Thanks for following up so quickly.
Comment 18 Vence 2024-06-04 08:14:34 UTC
In addition to Comment 15:
There are still the following messages in journalctl:

ksmserver[983]: Failed to write ice auth file entry
ksmserver[983]: Failed to write xsmp ice auth file entry
ksmserver[983]: Failed to write ice auth file entry
ksmserver[983]: Failed to write xsmp ice auth file entry

However, iceauth command shows that all the entries are is written correctly into the /run/user/1000/iceauth_XXXXX file.

Kishore Gopalakrishnan in Comment #6 notices that the function IceWriteAuthFileEntry returns a nonzero status if the operation was successful. 
So the condition "if (IceWriteAuthFileEntry(fp, file_entry) != 0)" in ksmserver/server.cpp (lines 367,391) should be "if (IceWriteAuthFileEntry(fp, file_entry) = 0)"
Comment 19 Fushan Wen 2024-06-04 11:58:13 UTC
Git commit 0dcf34458d99b07a3d9054ae0c86c656e0dfa7aa by Fushan Wen, on behalf of Tomáš Trnka.
Committed on 04/06/2024 at 11:39.
Pushed by fusionfuture into branch 'master'.

Fix writing ICEAuthority file

Commit 9398f6cf8933055b31506ba155aef2fc2b3561d7 "Remove iceauth
dependency" introduced two bugs:

1) "fp" is never closed, so the generated auth data stays buffered in
   memory for some indeterminate time and the file stays empty on disk.
   This completely breaks authentication and thus also session restore.

2) Checking the return value of IceWriteAuthFileEntry() is inverted (the
   function returns non-zero on success), so warnings are printed iff
   everything goes well.

M  +7    -2    ksmserver/server.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/0dcf34458d99b07a3d9054ae0c86c656e0dfa7aa
Comment 20 Fushan Wen 2024-06-04 12:50:09 UTC
Git commit 0857d18dfc3fc870a7f768731fdf46dc3abc5f8f by Fushan Wen.
Committed on 04/06/2024 at 12:17.
Pushed by fusionfuture into branch 'Plasma/6.1'.

Fix writing ICEAuthority file

Commit 9398f6cf8933055b31506ba155aef2fc2b3561d7 "Remove iceauth
dependency" introduced two bugs:

1) "fp" is never closed, so the generated auth data stays buffered in
   memory for some indeterminate time and the file stays empty on disk.
   This completely breaks authentication and thus also session restore.

2) Checking the return value of IceWriteAuthFileEntry() is inverted (the
   function returns non-zero on success), so warnings are printed iff
   everything goes well.


(cherry picked from commit 0dcf34458d99b07a3d9054ae0c86c656e0dfa7aa)

Co-authored-by: Tomáš Trnka <tomastrnka@gmx.com>

M  +7    -2    ksmserver/server.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/0857d18dfc3fc870a7f768731fdf46dc3abc5f8f
Comment 21 Fushan Wen 2024-06-04 12:50:20 UTC
Git commit 1181acfe30557d6646511df8d98d82589878a570 by Fushan Wen.
Committed on 04/06/2024 at 12:18.
Pushed by fusionfuture into branch 'Plasma/5.27'.

Fix writing ICEAuthority file

Commit 9398f6cf8933055b31506ba155aef2fc2b3561d7 "Remove iceauth
dependency" introduced two bugs:

1) "fp" is never closed, so the generated auth data stays buffered in
   memory for some indeterminate time and the file stays empty on disk.
   This completely breaks authentication and thus also session restore.

2) Checking the return value of IceWriteAuthFileEntry() is inverted (the
   function returns non-zero on success), so warnings are printed iff
   everything goes well.


(cherry picked from commit 0dcf34458d99b07a3d9054ae0c86c656e0dfa7aa)

Co-authored-by: Tomáš Trnka <tomastrnka@gmx.com>

M  +7    -2    ksmserver/server.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/1181acfe30557d6646511df8d98d82589878a570
Comment 22 S. Umar 2024-06-04 14:35:09 UTC
I have also noticed that gtk apps that are on the desktop (I use gkrellm) multiply after logout/login or reboot. I have gkrellm on the desktop and I noticed many copies of it running. I killed them all started one and tested again and they keep multiplying. I will test to see if this patch fixes that too.
Comment 23 S. Umar 2024-06-04 14:46:21 UTC
No it did not. I will open a new case
Comment 24 Antonio Rojas 2024-06-06 10:48:32 UTC
This needs to be backported to 6.0 too (and a 6.0.5.2 tarball released). Currently there is a security advisory asking users to upgrade to a broken version.
Comment 25 S. Umar 2024-06-06 12:48:25 UTC
Fedora 40 included these patches in a new version. However, it seems to break the logout from KDE plasma. When I select logout (on multiple computers) I get a black screen with the mouse cursor showing only.
Comment 26 David Edmundson 2024-06-09 08:40:51 UTC
Git commit 918cb38c3522ffcc241ac6a22b6741e41cdd3c30 by David Edmundson, on behalf of David Edmundson.
Committed on 09/06/2024 at 08:25.
Pushed by davidedmundson into branch 'Plasma/6.0'.

Fix writing ICEAuthority file

Commit 9398f6cf8933055b31506ba155aef2fc2b3561d7 "Remove iceauth
dependency" introduced two bugs:

1) "fp" is never closed, so the generated auth data stays buffered in
   memory for some indeterminate time and the file stays empty on disk.
   This completely breaks authentication and thus also session restore.

2) Checking the return value of IceWriteAuthFileEntry() is inverted (the
   function returns non-zero on success), so warnings are printed iff
   everything goes well.


(cherry picked from commit 0dcf34458d99b07a3d9054ae0c86c656e0dfa7aa)

Co-authored-by: Tomáš Trnka <tomastrnka@gmx.com>

M  +7    -2    ksmserver/server.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/918cb38c3522ffcc241ac6a22b6741e41cdd3c30
Comment 27 Vence 2024-06-10 21:17:11 UTC
*** Bug 488308 has been marked as a duplicate of this bug. ***
Comment 28 krovikan 2024-06-13 16:18:55 UTC
*** Bug 488442 has been marked as a duplicate of this bug. ***
Comment 29 Aleksey Kontsevich 2024-07-19 18:37:28 UTC
Tried to switch to Plasma (Wayland) in SDDM after nvidia driver update - this bug 1 happened again, session was not restored - and completely broken. After that switch to Wayland KDE stopped to save session completely! How to fix?!

https://forums.opensuse.org/t/re-kde-plasma6-does-not-restore-previous-session-on-start-any-more/176937
https://bugzilla.opensuse.org/show_bug.cgi?id=1226110

Operating System: openSUSE Tumbleweed 20240716
KDE Plasma Version: 6.1.2
KDE Frameworks Version: 6.4.0
Qt Version: 6.7.2
Kernel Version: 6.9.9-1-default (64-bit)
Graphics Platform: X11
Comment 30 Nate Graham 2024-07-19 18:44:23 UTC
This is an X11-specific bug; you're talking about the general issue that real session restore isn't implemented on Wayland yet. That's different; see https://community.kde.org/Plasma/Wayland_Known_Significant_Issues#Waiting_on_new_Wayland_protocol.
Comment 31 Aleksey Kontsevich 2024-08-11 09:41:15 UTC
It still happens again and again and again!!! Plasma 6.1.4. Please fix!
Comment 32 Aleksey Kontsevich 2024-08-11 09:42:22 UTC
(In reply to Nate Graham from comment #30)
> This is an X11-specific bug; you're talking about the general issue that
> real session restore isn't implemented on Wayland yet. That's different; see


No, not different!!! I'm on X11 - not Wayland!
Comment 33 zb4ng 2024-08-11 13:56:46 UTC
(In reply to Aleksey Kontsevich from comment #32)
> (In reply to Nate Graham from comment #30)
> > This is an X11-specific bug; you're talking about the general issue that
> > real session restore isn't implemented on Wayland yet. That's different; see
> 
> 
> No, not different!!! I'm on X11 - not Wayland!

I can confirm! This keeps happening to me on openSuSE Leap, but also on Tumbleweed which has the newest updates sporadically since about 2 months. The last time a couple of days ago.
And I don't have Wayland as well !
Comment 34 Aleksey Kontsevich 2024-08-11 16:30:19 UTC
(In reply to zb4ng from comment #33)
> (In reply to Aleksey Kontsevich from comment #32)
> > (In reply to Nate Graham from comment #30)
> > > This is an X11-specific bug; you're talking about the general issue that
> > > real session restore isn't implemented on Wayland yet. That's different; see
> > 
> > 
> > No, not different!!! I'm on X11 - not Wayland!
> 
> I can confirm! This keeps happening to me on openSuSE Leap, but also on
> Tumbleweed which has the newest updates sporadically since about 2 months.
> The last time a couple of days ago.
> And I don't have Wayland as well !

True! Happens for me on openSuSE Tumbleweed.
Comment 35 Aleksey Kontsevich 2024-08-19 11:11:07 UTC
Happened today again!
Comment 36 Aleksey Kontsevich 2024-08-29 23:41:51 UTC
Shit, happened today again twice with 2 subsequent reboots - completely lost! Please fix! This is boring!!!
Comment 37 Aleksey Kontsevich 2024-08-30 13:37:36 UTC
Happened today again! Rebooted X11 by Ctrl-Alt-Backspace - session restored again. Is it possible some config left after Wayland and if to delete it then session restoration will work again?
Comment 38 Kishore Gopalakrishnan 2024-08-30 20:10:09 UTC
(In reply to Aleksey Kontsevich from comment #37)
> Happened today again! Rebooted X11 by Ctrl-Alt-Backspace - session restored
> again. Is it possible some config left after Wayland and if to delete it
> then session restoration will work again?

The bug in this report is fixed (the symptoms are described in comment 5 ).

To check if it is some config issue, try creating a fresh user account (see if session restore works, say, 30 times in a row in that account).

Your bug may be one of the following bugs. If not, file a new report with more information.
https://bugs.kde.org/show_bug.cgi?id=491130
https://bugs.kde.org/show_bug.cgi?id=491421
Comment 39 Andreas Sturmlechner 2024-09-05 11:36:34 UTC
(In reply to S. Umar from comment #25)
> Fedora 40 included these patches in a new version. However, it seems to
> break the logout from KDE plasma. When I select logout (on multiple
> computers) I get a black screen with the mouse cursor showing only.
Same behaviour confirmed by a Gentoo user of Plasma 6.1.4 with X11 session.

Fixed after reverting 0dcf34458d99b07a3d9054ae0c86c656e0dfa7aa

So this continues to be problematic.
Comment 40 Andreas Sturmlechner 2024-09-09 14:23:06 UTC
(In reply to S. Umar from comment #25)
> Fedora 40 included these patches in a new version. However, it seems to
> break the logout from KDE plasma. When I select logout (on multiple
> computers) I get a black screen with the mouse cursor showing only.

To anyone else with this problem, please try to reproduce the problem with a newly created testuser profile.
Comment 41 zb4ng 2024-09-12 06:04:24 UTC
(In reply to Andreas Sturmlechner from comment #40)
> To anyone else with this problem, please try to reproduce the problem with a
> newly created testuser profile.

This is related to openSUSE LEAP.
Around 10 days ago , I switched to a complete new user account that I have used since then. It worked just fine until now, when it all happened again (a couple of dolphin windows showing home folder instead of the folders before the last shutdown, no okular windows etc).
Comment 42 Aleksey Kontsevich 2024-09-12 11:05:58 UTC
(In reply to zb4ng from comment #41)

> This is related to openSUSE LEAP.
> Around 10 days ago , I switched to a complete new user account that I have
> used since then. It worked just fine until now, when it all happened again
> (a couple of dolphin windows showing home folder instead of the folders
> before the last shutdown, no okular windows etc).

Periodically in openSUSE Tubleweed I have EXACTLY the same: a couple of dolphin windows showing home folder instead of the folders before the last shutdown, no okular windows etc.
Comment 43 imaginator 2024-09-19 09:03:50 UTC
@ those affected by "partial" restores (programs only restored in their default state): If it happens again: could check whether there's a file in  ~/.config/session/  whose id matches that of the "restartCommand*" line in  ~/.config/ksmserverrc ?  Like
session-file: dolphin_104c55580000172605190600000090300033_1726072968_326808
ksmserverrc:  restartCommand11=/opt/kf5/bin/dolphin,-session,104c55580000172605190600000090300033_1726072968_326808

I suspect that in case of partial restores the program specific session-files are missing.   The outcome of a little experiment seems to corroborate this: I logged out of Plasma, found a new pair of matching ids for Dolphin and intentionally deleted the newly created session-file for Dolphin which had many open tabs at logout.  After login in Plasma Dolphin was restored but only with one window, showing the home directory.  The other KDE-programs were restored fine.

In case of complete session-restore failure  ~/.config/ksmserverrc  may be incomplete (no "restartCommand*" lines), see: https://bugs.kde.org/show_bug.cgi?id=488520.
Comment 44 zb4ng 2024-10-04 09:23:13 UTC
Some things I tried to avoid this mess and/or find out why this happens:
Every login, I create a log: 
journalctl /usr/bin/plasmashell

Whenever the bug happens, then this is in the log:
plasmashell[2581]: Qt: Session management error: Authentication Rejected, reason : MIT-MAGIC-COOKIE-1 authentication rejected
plasmashell[2581]: Aborting shell load: The activity manager daemon (kactivitymanagerd) is not running.
plasmashell[2581]: If this Plasma has been installed into a custom prefix, verify that its D-Bus services dir is known to the system for the daemon to be activatable.
see also here: https://bugs.kde.org/show_bug.cgi?id=491130#c1

Now the "magic cookie" is managed by the X-Server for authentication purposes (I don't really know what's going on there and I couldn't find very detailed info about this).
What I presume now is that there are at least two possible things that could be the cause:
Either: Sometimes, "activity manager daemon" doesn't start in time for the Xauthority/magic cookie stuff.
Or: The activity manager daemon doesn't start because the authentication got rejected.

In the light of this, I tried the following workarounds, but wo success:
1. add xhost +local: to ~/.profile in the hope that the X-Server authentication gets skipped.
2. boot and then wait two minutes before logging into the X-Server
Comment 45 Ondrej Mosnáček 2024-10-04 10:23:44 UTC
(In reply to zb4ng from comment #44)
> Whenever the bug happens, then this is in the log:
> plasmashell[2581]: Qt: Session management error: Authentication Rejected,
> reason : MIT-MAGIC-COOKIE-1 authentication rejected
> plasmashell[2581]: Aborting shell load: The activity manager daemon
> (kactivitymanagerd) is not running.
> plasmashell[2581]: If this Plasma has been installed into a custom prefix,
> verify that its D-Bus services dir is known to the system for the daemon to
> be activatable.
> see also here: https://bugs.kde.org/show_bug.cgi?id=491130#c1
> 
> Now the "magic cookie" is managed by the X-Server for authentication
> purposes (I don't really know what's going on there and I couldn't find very
> detailed info about this).
> What I presume now is that there are at least two possible things that could
> be the cause:
> Either: Sometimes, "activity manager daemon" doesn't start in time for the
> Xauthority/magic cookie stuff.
> Or: The activity manager daemon doesn't start because the authentication got
> rejected.

Maybe plasma-plasmashell.service just needs to depend on plasma-kactivitymanagerd.service? I just tried to add the following via `systemctl --user edit plasma-plasmashell.service`:
[Unit]
After=plasma-kactivitymanagerd.service

Will see if it helps during the next reboot(s).