The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): a lost completion is owed without adopting a retired channel
Teknium8e9b1bcb583d
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex d9d4697f17e..cb817be5f38 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -776,6 +776,7 @@ def _complete_source_update(request: dict | None) -> None:_write_fleet_restart_pending_marker(expected_sha=request.get("expected_sha") or _current_checkout_sha() or "")# Pre-swap module (imported with run_completion above): never the replacement tree's.from hermes_cli.update_completion import settle_lost_completion+ lost = Falsetry:result = run_completion(request)except KeyboardInterrupt as interrupt:@@ -783,12 +784,14 @@ def _complete_source_update(request: dict | None) -> None:_completion_receipt.finalize_interrupted_update_receipt("KeyboardInterrupt: interrupted after the code was updated")raise SystemExit(130) from interruptexcept Exception as exc: # health: allow BLE001 -- after the commit point a lost completion is owed, never a failed update (C3)- result = settle_lost_completion(request, f"{type(exc).__name__}: {exc}")- if result.get("receipt") is None and result["exit_code"] == 130:+ result, lost = settle_lost_completion(request, f"{type(exc).__name__}: {exc}"), True+ if not lost and result.get("receipt") is None and result["exit_code"] == 130:_completion_receipt.finalize_interrupted_update_receipt("the completion was interrupted after the code was updated")- elif result.get("receipt") is None:- # The child crashed (OOM, SIGKILL) or never answered: the same owed tail (review P2).- result = settle_lost_completion(request, result.get("error") or f"the completion process exited {result['exit_code']}")+ elif not lost and result.get("receipt") is None and result["exit_code"]:+ # The child crashed (OOM, SIGKILL) or never answered (run_completion maps every answer+ # without a correlated terminal receipt to non-zero): the same owed tail (review P2).+ result, lost = settle_lost_completion(+ request, result.get("error") or f"the completion process exited {result['exit_code']}"), True_accept_completion_pm_receipt(result.get("pm_receipt"), request["receipt"]["update_id"])token = request["windows_resume"]if token is not None and result.get("windows_resume") is not None:@@ -813,6 +816,8 @@ def _complete_source_update(request: dict | None) -> None:_completion_receipt._current.reset(current.current_token)if result["exit_code"]:raise SystemExit(result["exit_code"])+ if lost:+ return # a retired channel is adopted after a verified completion only; the next update adopts ittry:if adopt_retired_channel(request):print(f"→ Source subscription moved to {request['channel_retirement']['destination']}")diff --git a/tests/hermes_cli/test_source_channel_integration.py b/tests/hermes_cli/test_source_channel_integration.pyindex 5695dc06c05..10d8704e1df 100644--- a/tests/hermes_cli/test_source_channel_integration.py+++ b/tests/hermes_cli/test_source_channel_integration.py@@ -125,11 +125,9 @@ def test_retirement_adopts_destination_only_after_success(source, monkeypatch, omonkeypatch.setattr(update_cmd, "_write_fleet_restart_pending_marker", lambda **kw: None)flags = ["--channel", name] if outcome == "transient" else []args = source.parser.parse_args(["update", "--yes", *flags])- if outcome == "failed":- with pytest.raises(SystemExit):- update_cmd._cmd_update_impl(args, False)- else:- update_cmd._cmd_update_impl(args, False)+ # A completion that answered no terminal receipt ("failed") was SystemExit: after the commit+ # point it is an owed completion, exit 0 (review P2) -- and still never adopts the destination.+ update_cmd._cmd_update_impl(args, False)expected = {"success": "stable", "already-current": "stable", "failed": name,"transient": name, "concurrent": "my-new-choice"}[outcome]assert saved(source)["channel"] == expected@@ -430,11 +428,13 @@ def test_retirement_waits_for_correlated_completion_process(source, monkeypatch,"receipt": deepcopy(update_receipt._current.get().data),"channel_retirement": {"original": original, "destination": "stable"}}monkeypatch.setattr(update_cmd, "_write_fleet_restart_pending_marker", lambda **kw: None)- if outcome == "success":- update_cmd._complete_source_update(request)- else:+ if outcome == "failure": # the child itself answered a correlated failurewith pytest.raises(SystemExit):update_cmd._complete_source_update(request)+ else:+ # An uncorrelated or missing answer was SystemExit: after the commit point it is an owed+ # completion, exit 0 (review P2). Adoption still waits for a verified completion.+ update_cmd._complete_source_update(request)assert saved(source)["channel"] == ("stable" if outcome == "success" else name)child_request = json.loads((source.home / "child-request.json").read_text())assert child_request["channel_retirement"]["original"] == original