Skip to content

The agent that grows with you

fix(desktop): an exit without a window reveal no longer writes hermes.desktop

teknium149b9bbb6fc52
diff --git a/hermes_cli/linux_desktop_entry.py b/hermes_cli/linux_desktop_entry.py
index d866321f356..44d3c0ea29b 100644
--- a/hermes_cli/linux_desktop_entry.py
+++ b/hermes_cli/linux_desktop_entry.py
@@ -28,6 +28,7 @@ DESKTOP_ENTRY_NAME = "hermes.desktop"
SHELL_LAUNCH_ENV_VAR = "DESKTOP_STARTUP_ID"
# Write end of the reveal pipe handed to Electron; one byte means "main window is on screen".
READY_FD_ENV_VAR = "HERMES_DESKTOP_READY_FD"
+REVEAL_BYTE = b"r" # what linux-launcher-ready.ts writes; anything else is finish()'s wake-up
_SHELL_NAMES = ("bash", "sh", "dash", "zsh", "ksh")
@@ -647,9 +648,11 @@ class DeferredDesktopEntryInstall:
The launcher hands Electron the write end of a pipe (``HERMES_DESKTOP_READY_FD``); Electron
writes one byte when the main window is revealed and a worker thread then installs the entry.
- ``finish()`` runs after Electron exits and covers the app never revealing a window (a STOPPED
- app has no STARTING object, so writing there is safe). Terminal and detached launches never
- build one of these: they install immediately, as before.
+ An exit without a reveal (boot crash, early quit) does NOT heal: gnome-shell keeps the ShellApp
+ in STARTING until the startup-notification sequence completes or times out (mutter, ~15 s),
+ not until the process dies, so a write right after such an exit still lands in the arming
+ window. The next terminal/updater launch or revealed grid launch installs the entry instead.
+ Terminal and detached launches never build one of these: they install immediately, as before.
"""
def __init__(
@@ -665,8 +668,6 @@ class DeferredDesktopEntryInstall:
# after the condition, not a substitute for it.
self._settle_seconds = settle_seconds
self._read_fd, self.write_fd = os.pipe()
- self._lock = threading.Lock()
- self._done = False
self._thread = threading.Thread(target=self._wait_for_reveal, name="desktop-entry-install", daemon=True)
def child_env(self, env: dict) -> dict:
@@ -685,17 +686,10 @@ class DeferredDesktopEntryInstall:
data = os.read(self._read_fd, 1)
except OSError:
return
- if self._done: # woken by finish(): the app already exited, finish() owns the heal
+ if data != REVEAL_BYTE: # woken by finish(): the app exited without a reveal, skip the heal
return
- if data and self._settle_seconds:
+ if self._settle_seconds:
time.sleep(self._settle_seconds)
- self._heal()
-
- def _heal(self) -> None:
- with self._lock:
- if self._done:
- return
- self._done = True
try:
entry = self._install(self._project_root)
if entry:
@@ -704,10 +698,9 @@ class DeferredDesktopEntryInstall:
print(f"⚠ Could not install the desktop launcher entry: {exc}")
def finish(self) -> None:
- """Electron exited: heal now if the reveal never came, and let an in-flight heal complete."""
- self._heal()
+ """Electron exited: let a heal already triggered by the reveal complete, never start one."""
try:
- os.write(self.write_fd, b"x") # wake the reader so join() returns promptly
+ os.write(self.write_fd, b"x") # wake a still-waiting reader so join() returns promptly
except OSError:
pass
self._thread.join(timeout=15)
diff --git a/tests/hermes_cli/test_linux_desktop_entry.py b/tests/hermes_cli/test_linux_desktop_entry.py
index db72c991f3d..1a8551beddc 100644
--- a/tests/hermes_cli/test_linux_desktop_entry.py
+++ b/tests/hermes_cli/test_linux_desktop_entry.py
@@ -1150,10 +1150,11 @@ def test_install_resizes_decodable_png_to_panel_sizes(
assert struct.unpack(">II", dest_256.read_bytes()[16:24]) == (256, 256)
-def test_deferred_install_heals_exactly_once_after_exit_without_reveal():
- """Electron exiting without ever revealing a window (crash, --version, closed at the
- onboarding step) must still self-heal the entry — once, after the exit, when no
- STARTING app object exists (#111906)."""
+def test_deferred_install_skips_heal_after_exit_without_reveal():
+ """Electron exiting without ever revealing a window (boot crash, --version, early quit) must
+ NOT heal the entry: gnome-shell keeps the ShellApp in STARTING until the startup-notification
+ sequence completes or times out, not until the process dies, so a write right after the exit
+ is exactly the #111906 arming condition. The next terminal/updater or revealed launch heals."""
calls: list[Path] = []
deferred = lde.DeferredDesktopEntryInstall(
Path("/proj"), install=lambda root: calls.append(root) or Path("/entry"), settle_seconds=0
@@ -1163,5 +1164,5 @@ def test_deferred_install_heals_exactly_once_after_exit_without_reveal():
assert calls == [] # nothing is written while the app may still be STARTING
deferred.finish()
- assert calls == [Path("/proj")]
+ assert calls == []
assert not deferred._thread.is_alive()
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index ba24216dc09..a75728202c8 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -334,7 +334,7 @@ hermes config set desktop.manage_launcher_entry false
A missing entry is still created; the flag only stops `hermes desktop` from rewriting an entry that already exists.
-When you start Hermes from the application grid or menu (the launcher sets `DESKTOP_STARTUP_ID`), the entry is written only after the window is on screen, or after the app exits if no window ever appeared. Some GNOME Shell versions lose track of an app whose `.desktop` file changes while it is still starting, and that can crash the whole session later; waiting for the window avoids it. Terminal launches and the updater's relaunch still write the entry immediately.
+When you start Hermes from the application grid or menu (the launcher sets `DESKTOP_STARTUP_ID`), the entry is written only after the window is on screen. If the app exits before a window appears, nothing is written that time; the next terminal launch, updater relaunch, or grid launch that shows a window installs it. Some GNOME Shell versions lose track of an app whose `.desktop` file changes while it is still starting (they keep it in that state until the startup notification completes or times out, not until the process exits), and that can crash the whole session later; waiting for the window avoids it. Terminal launches and the updater's relaunch still write the entry immediately.
| Flag | Description |
| -------------------- | ----------------------------------------------------------------------------------------- |