Skip to content

fix(desktop): converge profile deletion — stop respawn + refresh rail (supersedes #52301, #49335) - #57329

Merged
OutThisLife merged 2 commits into
mainfrom
bb/desktop-profile-delete-lifecycle
Jul 2, 2026
Merged

fix(desktop): converge profile deletion — stop respawn + refresh rail (supersedes #52301, #49335)#57329
OutThisLife merged 2 commits into
mainfrom
bb/desktop-profile-delete-lifecycle

Conversation

@OutThisLife

Copy link
Copy Markdown
Collaborator

Summary

Consolidates the two Desktop-side halves of the profile-deletion bug (#47368) into one review unit, since they compose into a single behavior — "when a profile is deleted, it actually goes away and stays gone in the UI":

Both commits are cherry-picked with original authorship intact.

Why one PR

These are the same language (desktop TS/Electron), the same CI lane, and the same user-visible outcome; they don't overlap in code but they finish each other's job. The CLI root-cause fix (#49435, recreation guard) lands separately — with it, a backend spawned into a deleted profile now exits on FileNotFoundError instead of resurrecting the tree, and these two changes make the Desktop stop spawning it and reflect the deletion immediately.

Supersedes

Part of #47368.

Validation

Check Result
tsc -p . --noEmit (apps/desktop) clean
node --test electron/profile-delete-respawn.test.cjs 2/2
vitest run src/store/profile.test.ts 7/7
eslint (all touched files) clean

#49335 was stale against main (import drift around $profileColors / getProfileSetupCommand and the starmap-cache test block); reconciled during the cherry-pick.

Co-authored-by: liuhao1024 sunsky.lau@gmail.com
Co-authored-by: Tranquil-Flow 66773372+Tranquil-Flow@users.noreply.github.com

liuhao1024 and others added 2 commits July 2, 2026 15:14
…vent respawn loop

When the renderer sends a DELETE /api/profiles/{name} request, the IPC
handler tears down the profile's pool backend (or primary backend) via
prepareProfileDeleteRequest.  However, the very next line calls
ensureBackend(profile), which spawns a fresh pool backend for the just-
deleted profile.  The new backend's startup path calls ensure_hermes_home(),
which recreates the profile directory — defeating the deletion and leaving
the process as a zombie.

On the next Desktop restart the cycle repeats: the profile directory exists,
the Desktop spawns a backend, the backend recreates the directory after
deletion, and PIDs accumulate indefinitely.

Fix: make prepareProfileDeleteRequest return the torn-down profile name.
The IPC handler uses this to route the DELETE to the primary backend
instead of spawning a new pool backend for the deleted profile.

Fixes #52279
@OutThisLife
OutThisLife enabled auto-merge (rebase) July 2, 2026 20:17
@OutThisLife
OutThisLife merged commit c3f06a8 into main Jul 2, 2026
20 checks passed
@OutThisLife
OutThisLife deleted the bb/desktop-profile-delete-lifecycle branch July 2, 2026 20:18
@alt-glitch alt-glitch added type/bug Something isn't working comp/desktop Electron desktop app (apps/desktop/*) P2 Medium — degraded but workaround exists labels Jul 2, 2026
teknium1 pushed a commit that referenced this pull request Aug 17, 2026
Two independent bugs let a deleted profile reappear / leave orphaned
resources on next launch:

1. hermes_cli/profiles.py's backend-process scanner required argv[0] to
   resolve to an executable literally named "hermes". Electron's
   pool-backend spawn resolves the hermes console-script shim's path and
   execs it via the interpreter directly (python3 /path/to/hermes ...), so
   argv[0] reports as "python3" and the scanner never matched the running
   backend -- delete removed the profile's files but left its live backend
   process running (still bound to a port via uvicorn), which
   accumulates across repeated delete/recreate cycles.
2. The desktop sidebar's ProfileRail only refreshed its cached profile
   list once, on mount, so a delete/create/rename from another surface
   (another window, or the CLI) left a stale ghost entry until something
   unrelated triggered a refetch. Note: a delete via this window's own
   Manage-Profiles view already refreshes the shared $profiles atom
   ProfileRail subscribes to (confirmed by reading refreshProfiles() and
   handleConfirmDelete()) -- this fix only covers the cross-window/cross-
   process staleness gap, not a duplicate of the already-merged
   #57329's Manage-Profiles rail-refresh work.

Fix 1: recognize a python-interpreter argv[0] exec'ing a hermes-named
console-script shim via argv[1]. Fix 2: refresh the profile list on window
focus/visibilitychange, matching the existing pattern used elsewhere in
the sidebar (sidebar/index.tsx, use-background-sync.ts, star-map.tsx,
use-gateway-boot.ts all use the same focus+visibilitychange pattern).

## Related work already on main

PR #57329 (merged) fixed the *headline* symptom from issue #52279
(deleted profile respawns) via a different, non-overlapping mechanism:
routing profile-delete through the primary backend instead of spawning a
fresh pool backend, plus a separate recreation guard in
ensure_hermes_home() (#49435, merged) that makes a backend spawned into a
deleted profile's directory raise FileNotFoundError instead of silently
recreating it.

This PR is NOT a duplicate of that fix. Verified: even with both of those
merged, a backend process that survives because of gap #1 above still
holds a bound port via uvicorn -- it just can no longer resurrect the
profile directory. That's real resource-hygiene, not a symptom already
covered. Gap #2 touches a different file/component (ProfileRail /
profile-switcher.tsx) than #57329's rail-refresh half (which touched the
Manage-Profiles view's own $profiles.ts / index.tsx) and covers a
distinct staleness path (cross-window/cross-process, not same-window
delete-then-refresh).

Tests: tests/hermes_cli/test_profiles.py -- 156 passed (existing +
regression coverage for the argv[0] python-interpreter detection case).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/desktop Electron desktop app (apps/desktop/*) P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants