Skip to content

fix(gateway): reap orphaned gateways before spawning restart (#77276) - #77721

Closed
RelaxJonh wants to merge 1 commit into
NousResearch:mainfrom
RelaxJonh:fix/orphan-gateway-reap-on-restart
Closed

RelaxJonh wants to merge 1 commit into
NousResearch:mainfrom
RelaxJonh:fix/orphan-gateway-reap-on-restart

Conversation

@RelaxJonh

Copy link
Copy Markdown
Contributor

Problem

When the desktop app restarts, the old serve process exits but its gateway child gets reparented to launchd (PPID=1) and keeps its platform connection alive. The new serve spawns a fresh gateway, resulting in two live gateways racing the same connection — messages split across parallel session trees (#77276).

Root cause

_reap_unsupervised_gateway_orphans() was implemented for the CLI restart path (stop_profile_gateway()#75936) but the dashboard's _spawn_gateway_restart() path was not covered.

Fix

Call _reap_unsupervised_gateway_orphans() at the top of _spawn_gateway_restart() before spawning the new hermes gateway restart child. The reap is wrapped in a try/except so a failure never blocks the restart.

Testing

  • New unit tests verify the reap is called before spawn
  • Existing test_gateway.py orphan tests continue to pass
  • Lint clean

Fixes #77276

@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard comp/dashboard Web dashboard / control panel UI (dashboard/, landing) P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Aug 3, 2026
…earch#77276)

_spawn_gateway_restart() now calls _reap_unsupervised_gateway_orphans()
before spawning a new `hermes gateway restart` child.  On desktop-app
restart the old serve exits but its gateway child gets reparented to
launchd (PPID=1) and keeps its platform connection alive.  The new
serve then spawns a fresh gateway, resulting in two live gateways
racing the same connection.

The reap was already implemented for the CLI restart path (NousResearch#75936) but
the dashboard's _spawn_gateway_restart path was not covered.

Fixes NousResearch#77276
@teknium1

Copy link
Copy Markdown
Collaborator

Merged via PR #83542 — your commit(s) were cherry-picked onto current main with your authorship preserved in git log (rebase merge). Thank you for the contribution!

This follow-up PR completed the EMFILE hardening cluster after #83406: restart-path gateway orphan reap, Desktop-managed gateway termination on serve shutdown, SSH-spawn ulimit raise, and the dashboard iterdir→scandir fd-leak fixes. Everything was live-tested end-to-end on a real serve backend before merge, including a hostile unreadable-profile-dir fixture that surfaced (and fixed) a pre-existing /api/profiles 500 along the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/dashboard Web dashboard / control panel UI (dashboard/, landing) P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Desktop app restart leaves orphan gateway (app-managed spawn path not covered by #75936 fix)

3 participants