fix(desktop): coordinate orphan reaping across profile backends - #65059
fix(desktop): coordinate orphan reaping across profile backends#65059metamindedu wants to merge 2 commits into
Conversation
a82a711 to
1f8ded8
Compare
dfb39fd to
c6eaeb3
Compare
c6eaeb3 to
9389d65
Compare
|
Thanks for the focused cross-process ownership work. The premise remains present on current main: unlimited sessions retain only a no-op active-session lease ( The diff adds profile-local, fail-closed Desktop liveness leases and holds the registry lock through the automatic lifecycle decision. It also correctly preserves explicit-close behavior and keeps gateway-owned-session protections separate. The new process/lock-boundary and profile-identity coverage matches the affected paths. No substantive defect was identified in this review. This is an automated hermes-sweeper review. |
|
Superseded by #96511. That salvage keeps the Desktop liveness lease and lock-held sibling check, rebased onto current main, and:
You're credited via |
What does this PR do?
Prevents one Desktop profile backend from ending a durable session while another live Desktop backend process still owns and runs that same session.
The Desktop can temporarily serve one profile from two Python backends:
profile_home; andHERMES_HOME.Both can hold a runtime for the same durable session. Process-local orphan checks cannot see the sibling backend, so a WebSocket disconnect could previously mark the shared profile
state.dbrow ended and interrupt durable-key delegations even while the primary worker was still producing messages.This PR uses the profile-local active-session registry as a cross-process ownership signal. Desktop sessions retain liveness leases even when
max_concurrent_sessionsis disabled; other surfaces keep the existing unlimited/no-op behavior. Automatic Desktop finalization atomically releases the local lease and checks sibling ownership while holding the registry lock across the durable DB decision.The protected automatic reasons are:
ws_orphan_reapws_disconnectidle_timeoutlru_evicttui_shutdownIf another live lease exists—or registry/PID ownership cannot be inspected safely—the local runtime is cleaned up but the durable row and sibling delegation work are preserved. A sole owner still ends normally, and explicit user-close semantics are unchanged.
This is complementary to #44102 and #49900, which guard same-process
running/agent-build/pending-work state. It also differs from #60609 and #63207: those protect gateway-owned messaging sessions, while this bug involves separatesource=desktopbackend processes.Related Issue
Related to #60609 and #63207, but this is a distinct cross-process Desktop profile-backend ownership case.
Type of Change
Changes Made
hermes_cli/active_sessions.pytui_gateway/server.pyprofile_home, profile DB, and lease ownership through initial session publication.(profile_home, durable_key)so equal keys in different profiles remain isolated./undo, pending titles, and auto-title through the owning profile DB.runningwhen another consumer already owns delivery.Tests
How to Test
Run the ownership and related gateway regressions in a clean non-Desktop environment:
env -u PYTHONPATH -u HERMES_DESKTOP -u HERMES_DESKTOP_TERMINAL \ uv run pytest \ tests/hermes_cli/test_active_sessions.py \ tests/hermes_cli/test_cli_active_session_limit.py \ tests/tui_gateway/test_cross_process_orphan_ownership.py \ tests/tui_gateway/test_profile_session_ownership.py \ tests/tui_gateway/test_gateway_owned_session_reap.py \ tests/tui_gateway/test_delegation_session_lifecycle.py \ tests/tui_gateway/test_protocol.py \ -q -o addopts=Result on Windows 10 / CPython 3.11:
137 passed.Run the full TUI gateway server regression file:
Result:
325 passed.Run the separate compaction status regressions:
Result:
4 passed.Run static checks:
Results: Ruff, py_compile, diff check, and the focused ty check passed.
tui_gateway/server.pyretains existing repository ty diagnostics; none fall on this PR's changed lines.A total of 466 related tests passed locally. The repository-wide suite is deferred to CI.
Checklist
Code
pytest tests/ -qand all tests pass locally (466 related tests passed; full suite deferred to CI)Documentation & Housekeeping
msvcrtlocally; CI will exercise POSIXflockScreenshots / Logs
No UI changes. The spawned-process regression tests are the executable reproduction and verification evidence.