The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(profiles): refuse to replace a deleted profile's shell a live gateway still owns
Tekniumb88e2b8222cc
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.pyindex 05c3e36533d..d868b4fad53 100644--- a/hermes_cli/profiles.py+++ b/hermes_cli/profiles.py@@ -1431,7 +1431,10 @@ def create_profile(profile_dir = get_profile_dir(canon)if profile_dir.exists() and not named_profile_has_identity(profile_dir):if named_profile_is_deleted(profile_dir):- # Empty shell left by a post-delete mkdir: invisible to ``profile list``, safe to replace.+ # Empty shell left by a post-delete mkdir: invisible to ``profile list``, safe to replace+ # unless a gateway still tearing the deleted profile down holds its gateway.lock in it.+ if not wait_profile_unowned(profile_dir, timeout=0):+ raise FileExistsError(f"Cannot create profile '{canon}': a running gateway still owns {profile_dir}")shutil.rmtree(profile_dir)else:# A live marker-less dir is invisible to ``profile list`` but may still hold userdiff --git a/tests/hermes_cli/test_profile_delete_held_lock.py b/tests/hermes_cli/test_profile_delete_held_lock.pyindex 1bc164e9315..e119fea5625 100644--- a/tests/hermes_cli/test_profile_delete_held_lock.py+++ b/tests/hermes_cli/test_profile_delete_held_lock.py@@ -4,6 +4,7 @@ A multiplexer answers the delete's rescan ``pending`` after 5 s and keeps tearinit releases the profile's ``gateway.lock`` reservation last. The holder here is a real separateprocess reserving through the same primitive the multiplexer uses (``process_ownership.reserve``)."""+import shutilimport subprocessimport sysimport threading@@ -46,14 +47,18 @@ def _release(holder):# Every site that removes or moves a profile home after unrouting it from a live multiplexer.-CASES = [("delete", True), ("delete", False), ("rename", False)]+CASES = [("delete", True), ("delete", False), ("rename", False), ("recreate", False)]@pytest.mark.parametrize(("op", "released"), CASES, ids=["delete-owner-releases", "delete-owner-keeps-it",- "rename-owner-keeps-it"])+ "rename-owner-keeps-it", "recreate-over-owned-shell"])def test_profile_home_waits_for_the_live_owner_to_release_it(profile, monkeypatch, op, released):monkeypatch.setattr(profiles_remove, "OWNER_RELEASE_WAIT_SECONDS", 30.0 if released else 1.5)monkeypatch.setattr(profiles, "_live_default_multiplexer", lambda: op == "rename") # rename's unroute arm+ if op == "recreate":+ shutil.rmtree(profile)+ profile.mkdir()+ profiles.mark_named_profile_deleted(profile)holder = _hold(profile)outcome = {}@@ -61,10 +66,12 @@ def test_profile_home_waits_for_the_live_owner_to_release_it(profile, monkeypatctry:if op == "rename":profiles.rename_profile("owned-delete", "owned-renamed")+ elif op == "recreate": # the tombstoned, marker-less shell an owner's reserve() re-made+ profiles.create_profile("owned-delete", no_alias=True)else:profiles.delete_profile("owned-delete", yes=True)outcome["ok"] = True- except RuntimeError as exc:+ except (RuntimeError, FileExistsError) as exc:outcome["error"] = str(exc)worker = threading.Thread(target=delete)@@ -82,4 +89,4 @@ def test_profile_home_waits_for_the_live_owner_to_release_it(profile, monkeypatcif released:assert outcome == {"ok": True} and not profile.exists()else:- assert "still owns this profile" in outcome["error"] and profile.is_dir()+ assert "still owns" in outcome["error"] and (profile / "gateway.lock").is_file()