The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): boot waits only on the homes that actually conflict
Teknium19023e3558e7
diff --git a/gateway/run_bootstrap.py b/gateway/run_bootstrap.pyindex 53413907080..a4a880ca223 100644--- a/gateway/run_bootstrap.py+++ b/gateway/run_bootstrap.py@@ -555,6 +555,23 @@ def _browse_reconcile_reserve_wait_s() -> float:return BROWSE_RECONCILE_BUDGET_S + 2.0+def _conflicting_homes(homes):+ """The homes whose gateway.lock another holder has right now: each probed alone with its own open+ file description and released at once (the all-or-nothing reserve does not say which failed).+ A home freed meanwhile is simply not listed; the next reserve attempt takes it."""+ from gateway.runtime_ownership import OwnershipConflict, ProfileOwnership+ conflicting = []+ for home in homes:+ probe = ProfileOwnership()+ try:+ probe.reserve([home])+ except OwnershipConflict:+ conflicting.append(home)+ finally:+ probe.close()+ return conflicting++def _reserve_waiting_out_browse_reconcile(ownership, homes, *, wait_s: float | None = None):"""Reserve *homes*, waiting (bounded) while a contender is a browse reconcile or has not yetpublished its lock record (flock taken, record unwritten). Only a positively identified holder@@ -569,9 +586,12 @@ def _reserve_waiting_out_browse_reconcile(ownership, homes, *, wait_s: float | Ntry:return ownership.reserve(homes)except OwnershipConflict:- holders = [h for h in homes+ # Only the homes that actually conflict decide: a real owner on any of them refuses at+ # once, even while another home is mid-browse (multiplexer boot, all-or-nothing).+ conflicting = _conflicting_homes(homes)+ holders = [h for h in conflictingif maintenance_holder(h, BROWSE_RECONCILE_PURPOSE) or lock_record_unpublished(h)]- if not holders or time.monotonic() >= deadline:+ if not holders or len(holders) < len(conflicting) or time.monotonic() >= deadline:raiseif not logged:logger.info("Profile %s is held by a short session-store schema catch-up; waiting up to %.0fs",diff --git a/tests/hermes_cli/test_browse_schema_drift.py b/tests/hermes_cli/test_browse_schema_drift.pyindex af93176a6e2..779c59651b4 100644--- a/tests/hermes_cli/test_browse_schema_drift.py+++ b/tests/hermes_cli/test_browse_schema_drift.py@@ -825,3 +825,33 @@ def test_unopenable_lock_on_lagging_store_is_a_named_503(tmp_path):detail = str(caught.value.detail)assert "foreign_stale_lock" in detail and "nothing was changed" in detailassert _file_state(path) == before++[email protected]("linux", "macos")+def test_boot_refuses_at_once_when_another_home_has_a_real_owner(tmp_path):+ """pastels m2: a multiplexer boot reserving profile A (owned by a standalone gateway) and profile B+ (mid-browse) must refuse at once on A, not wait out B's browse first. Homes the boot did take+ while deciding are released again (all-or-nothing)."""+ import time++ from gateway.run_bootstrap import _reserve_waiting_out_browse_reconcile+ from gateway.runtime_ownership import OwnershipConflict, ProfileOwnership+ from hermes_state_reconcile import BROWSE_RECONCILE_PURPOSE++ owned_home = _profile_home(tmp_path, "alpha")+ browsed_home = _profile_home(tmp_path, "beta")+ free_home = _profile_home(tmp_path, "gamma")+ gateway = _hold(owned_home, 30)+ browse = _hold(browsed_home, 30, BROWSE_RECONCILE_PURPOSE)+ booting = ProfileOwnership()+ try:+ started = time.monotonic()+ with pytest.raises(OwnershipConflict):+ _reserve_waiting_out_browse_reconcile(booting, [free_home, owned_home, browsed_home], wait_s=10)+ assert time.monotonic() - started < 2, "refusal waited for an unrelated browse holder"+ assert booting.homes == [] or not any(booting.owns(h) for h in (free_home, owned_home, browsed_home))+ finally:+ booting.close()+ for proc in (gateway, browse):+ proc.kill()+ proc.wait()