The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: require an unambiguous baseline for successor-credited gateway restarts
DavidMetcalfef42fd748c809
diff --git a/hermes_cli/update_inventory.py b/hermes_cli/update_inventory.pyindex c5c17adea65..10a5474e9bf 100644--- a/hermes_cli/update_inventory.py+++ b/hermes_cli/update_inventory.py@@ -419,6 +419,12 @@ def match_runtime_outcomes(answers for the same profile counts as ``restarted``. A missing successor, or the planned PIDstill answering, stays ``unaccounted`` — the tripwire keeps its teeth.+ That credit needs an unambiguous baseline: a profile with SEVERAL planned gateway runtimes cannot+ be attributed to one successor (the fleet probe publishes at most one row per profile), so one+ replacement cannot have replaced two planned processes. Such a profile keeps the name-path+ verdict instead of letting an untouched sibling vanish behind a successor that can only have+ replaced one of them.+See #91277.They never borrow the gateway's outcome: ``relaunched_profiles`` and ``hermes-gateway*`` name adifferent process that shares the profile, nothing more. See #100479.@@ -442,6 +448,12 @@ def match_runtime_outcomes(if live_gateway_pids is not Noneelse None)+ # Baseline identity: the fleet probe publishes at most one row per profile, so successor+ # evidence is only attributable when the plan holds ONE gateway runtime for that profile.+ planned_gateways: dict[str, int] = {}+ for _planned in plan.runtimes:+ if isinstance(_planned, RuntimeRecord) and _planned.kind not in _SERVE_KINDS:+ planned_gateways[_planned.profile] = planned_gateways.get(_planned.profile, 0) + 1def _outcome(r: RuntimeRecord) -> str:killed_here = r.pid is not None and r.pid in killed@@ -477,9 +489,16 @@ def match_runtime_outcomes(# label/unit may encode the install root (or a hashed home) instead of the served# profile, which the profile-scoped name matcher above can never credit.live = successors.get(r.profile)- if live and r.pid not in live:+ ambiguous = planned_gateways.get(r.profile, 0) > 1+ if live and r.pid not in live and not ambiguous:return "restarted"- if not live:+ if ambiguous:+ logger.debug(+ "%s planned gateway runtimes for profile %r — one successor cannot attribute "+ "the restart, leaving pid %s on the name path",+ planned_gateways[r.profile], r.profile, r.pid,+ )+ elif not live:# No row for this profile: the fallback has nothing to work with and reconciliation# stays on the service-name path. Logged because the tripwire below reads identically# whether the evidence was missing or the restart was actually missed.diff --git a/tests/hermes_cli/test_restart_plan_reconciliation.py b/tests/hermes_cli/test_restart_plan_reconciliation.pyindex 457b4d858cc..c2b0f83dd1b 100644--- a/tests/hermes_cli/test_restart_plan_reconciliation.py+++ b/tests/hermes_cli/test_restart_plan_reconciliation.py@@ -508,6 +508,32 @@ def test_live_gateway_pids_from_fleet_skips_down_and_unusable_rows():assert _live_gateway_pids_from_fleet([]) == {}+def test_one_successor_cannot_credit_two_planned_runtimes_same_profile():+ """The fleet probe publishes at most one row per profile, so one successor cannot+ say which of two planned same-profile gateways it replaced. Neither may be+ credited — otherwise an untouched sibling disappears behind a replacement that+ can only have replaced one of them, and the tripwire is suppressed."""+ outcomes = match_runtime_outcomes(+ _plan(_rt("coder", 76508, supervisor="launchd"), _rt("coder", 76795, supervisor="launchd")),+ restarted_services=[], relaunched_profiles=[], externally_supervised_profiles=[],+ killed_pids=set(), failed_units=[], live_gateway_pids={"coder": {76796}},+ )+ assert [o["outcome"] for o in outcomes] == ["unaccounted", "unaccounted"]+ assert report_unaccounted_runtimes(outcomes) is True+++def test_successor_credit_stays_per_profile_with_several_planned_runtimes():+ """The ambiguity guard is per profile: two profiles with one planned runtime each+ are both credited from their own successor."""+ outcomes = match_runtime_outcomes(+ _plan(_rt("coder", 76508, supervisor="launchd"), _rt("work", 401, supervisor="launchd")),+ restarted_services=[], relaunched_profiles=[], externally_supervised_profiles=[],+ killed_pids=set(), failed_units=[],+ live_gateway_pids={"coder": {76796}, "work": {402}},+ )+ assert [o["outcome"] for o in outcomes] == ["restarted", "restarted"]++def test_successor_evidence_is_gateway_only_and_stays_optional():"""Serve/dashboard rows reconcile in their own vocabulary, and callers thatpass no ``live_gateway_pids`` keep the bookkeeping-only verdict."""