fix(gateway,web): address PR #160225 review feedback on switching copy, comments, and tests
Address all six review items from @BearHuddleston on https://github.com/NousResearch/hermes-agent/pull/160225: - web/src/components/BackendMigrationCard.tsx: drop "for a few seconds" from the switching state and show the profile-qualified `--status` command immediately while keeping the 1830 s poll cutoff, with a regression test. - web/src/lib/backend-migration.ts: clarify that UNREACHABLE_AFTER_SECONDS is an estimate of the migration's own caps rather than a launchd/unit bound. - hermes_cli/gateway_migrate_backends_host.py: clarify in _gateway_verb_timeout that these are the migration's caps, not systemd unit TimeoutStopSec limits. - tests/hermes_cli/gateway_migrate_backends_apply/test_engine.py: use the home fixture's 0 s handoff budget in the never-lands test to stop busy-spinning for 5 real seconds. - tests/hermes_cli/gateway_migrate_backends_apply/test_restart_handoff.py: add _RequestedRestartHost test verifying handoff starts after gateway_verb("restart") and outlasts a missed (None) PID lookup. - tests/hermes_cli/gateway_migrate_backends_host/test_gateway_verb_timeout.py, tests/hermes_cli/gateway_migrate_backends_apply/test_restart_handoff.py, tests/hermes_cli/test_gateway_migrate_backends_docs.py: assert relations against shared timeout constants rather than redundant hardcoded literals. Co-authored-by: BearHuddleston <bear@bearhuddleston.dev>
This commit is contained in:
committed by
Mark S.
parent
c30b7f31dd
commit
13e5c82616
@@ -58,6 +58,8 @@ def _gateway_verb_timeout(verb: str) -> int:
|
||||
|
||||
``restart`` can block across both the old gateway's in-band drain (``RESTART_HANDOFF_SECONDS``) and a
|
||||
``Type=notify`` startup (``VERIFY_SECONDS``); ``start`` can block on startup; ``stop`` can block on drain.
|
||||
These are the migration's caps, not the unit's: a raised ``agent.cron_drain_timeout`` or
|
||||
``agent.restart_drain_timeout`` gives the unit a ``TimeoutStopSec`` longer than they wait.
|
||||
"""
|
||||
if verb == "restart":
|
||||
return max(90, int(_timeouts.RESTART_HANDOFF_SECONDS + _timeouts.VERIFY_SECONDS))
|
||||
|
||||
@@ -1905,9 +1905,8 @@ def test_verify_waits_for_the_replacement_process_instead_of_the_draining_old_on
|
||||
assert engine.status_payload(host)["state"] == "done"
|
||||
|
||||
|
||||
def test_a_hand_off_that_never_lands_still_verifies_and_says_so(home, monkeypatch, capsys):
|
||||
monkeypatch.setattr(engine, "RESTART_HANDOFF_SECONDS", 5.0)
|
||||
host = _RestartHost(home, handover_after=10 ** 9, answer_while_old=True)
|
||||
def test_a_hand_off_that_never_lands_still_verifies_and_says_so(home, capsys):
|
||||
host = _RestartHost(home, handover_after=10 ** 9, answer_while_old=True) # the fixture's 0 s handoff budget
|
||||
|
||||
assert engine.cmd_apply(host, _args()) == engine.EXIT_OK
|
||||
|
||||
|
||||
@@ -99,6 +99,52 @@ def test_missing_before_pid_proceeds_once_live_pid_appears(home, monkeypatch):
|
||||
assert engine.status_payload(host)["state"] == "done"
|
||||
|
||||
|
||||
class _RequestedRestartHost(FakeHost):
|
||||
"""The old PID keeps draining until ``gateway_verb("restart")`` is requested; after it, the PID lookup
|
||||
reads the old PID, misses once (the old process gone, the new one not published yet), reads the old
|
||||
PID again, and only then the replacement."""
|
||||
|
||||
def __init__(self, home):
|
||||
super().__init__(home, gateway_installed=True, gateway_active=True)
|
||||
self.order: list[str] = []
|
||||
self.after_request = [_GATEWAY_PID, None, _GATEWAY_PID]
|
||||
self.replaced = False
|
||||
|
||||
def gateway_verb(self, verb):
|
||||
super().gateway_verb(verb)
|
||||
self.order.append(verb)
|
||||
|
||||
def gateway_pid(self):
|
||||
self.order.append("pid")
|
||||
if "restart" in self.order and not self.after_request:
|
||||
self.replaced = True
|
||||
if self.replaced:
|
||||
return _NEW_GATEWAY_PID
|
||||
return self.after_request.pop(0) if "restart" in self.order else _GATEWAY_PID
|
||||
|
||||
def sleep(self, seconds):
|
||||
assert "restart" in self.order, "waited for a replacement before the restart was requested"
|
||||
|
||||
def gateway_status(self, host, port):
|
||||
self.order.append("status")
|
||||
if not self.replaced:
|
||||
return None
|
||||
return {"gateway_state": "running", "auth_required": True, "auth_providers": ["basic"]}
|
||||
|
||||
def pid_listens_on(self, pid, port):
|
||||
return pid == _NEW_GATEWAY_PID and self._webapp_on_9119()
|
||||
|
||||
|
||||
def test_handoff_starts_after_the_restart_request_and_outlasts_a_missed_pid_lookup(home, monkeypatch):
|
||||
monkeypatch.setattr(engine, "RESTART_HANDOFF_SECONDS", 5.0)
|
||||
host = _RequestedRestartHost(home)
|
||||
|
||||
assert engine.cmd_apply(host, _args()) == engine.EXIT_OK
|
||||
|
||||
between = host.order[host.order.index("restart") + 1:host.order.index("status")]
|
||||
assert between == ["pid"] * 4 # old, missed (None), old, replacement: then verify
|
||||
|
||||
|
||||
@pytest.mark.parametrize("bad_state", ["draining", "starting", "startup_failed", None])
|
||||
def test_non_serving_gateway_states_fail_verify_and_roll_back(home, monkeypatch, bad_state):
|
||||
monkeypatch.setattr(engine, "RESTART_HANDOFF_SECONDS", 5.0, raising=False)
|
||||
@@ -127,8 +173,6 @@ def test_plan_verify_step_title_uses_verify_seconds(monkeypatch, tmp_path):
|
||||
plan = BackendPlan(home=str(tmp_path), new_host="0.0.0.0", new_port=9119)
|
||||
verify_step = next(step for step in plan.step_titles() if step["name"] == "verify")
|
||||
assert f"within {int(timeouts.VERIFY_SECONDS)} s" in verify_step["title"]
|
||||
assert "within 300 s" in verify_step["title"]
|
||||
assert "within 90 s" not in verify_step["title"]
|
||||
|
||||
monkeypatch.setattr(timeouts, "VERIFY_SECONDS", 420.0)
|
||||
updated = next(step for step in plan.step_titles() if step["name"] == "verify")
|
||||
|
||||
@@ -56,8 +56,7 @@ def test_gateway_verb_restart_timeout_covers_handoff_and_verify_budget(tmp_path,
|
||||
scope, args, timeout = calls[0]
|
||||
assert scope == "user"
|
||||
assert args == ["restart", "hermes-gateway"]
|
||||
assert timeout == 540
|
||||
assert timeout >= int(getattr(engine, "RESTART_HANDOFF_SECONDS", 240.0) + engine.VERIFY_SECONDS)
|
||||
assert timeout >= timeouts.RESTART_HANDOFF_SECONDS + timeouts.VERIFY_SECONDS
|
||||
|
||||
|
||||
def test_gateway_verb_start_timeout_covers_verify_budget(tmp_path, monkeypatch):
|
||||
@@ -65,7 +64,8 @@ def test_gateway_verb_start_timeout_covers_verify_budget(tmp_path, monkeypatch):
|
||||
|
||||
host.gateway_verb("start")
|
||||
|
||||
assert calls == [("user", ["start", "hermes-gateway"], 300)]
|
||||
[(scope, args, timeout)] = calls
|
||||
assert (scope, args) == ("user", ["start", "hermes-gateway"]) and timeout >= timeouts.VERIFY_SECONDS
|
||||
|
||||
|
||||
def test_gateway_verb_stop_marks_planned_stop_and_covers_handoff_budget(tmp_path, monkeypatch):
|
||||
@@ -74,7 +74,8 @@ def test_gateway_verb_stop_marks_planned_stop_and_covers_handoff_budget(tmp_path
|
||||
host.gateway_verb("stop")
|
||||
|
||||
assert planned_stops == [True]
|
||||
assert calls == [("user", ["stop", "hermes-gateway"], 240)]
|
||||
[(scope, args, timeout)] = calls
|
||||
assert (scope, args) == ("user", ["stop", "hermes-gateway"]) and timeout >= timeouts.RESTART_HANDOFF_SECONDS
|
||||
|
||||
|
||||
@pytest.mark.parametrize("verb", ["enable", "disable"])
|
||||
@@ -126,11 +127,9 @@ def test_plan_and_host_do_not_import_apply_engine(tmp_path):
|
||||
"from hermes_cli.gateway_migrate_backends_plan import BackendPlan\n"
|
||||
"from hermes_cli.gateway_migrate_backends_host import _gateway_verb_timeout\n"
|
||||
f"plan = BackendPlan(home={str(tmp_path)!r}, new_host='0.0.0.0', new_port=9119)\n"
|
||||
"steps = plan.step_titles()\n"
|
||||
"assert any('within 300 s' in s['title'] for s in steps)\n"
|
||||
"assert _gateway_verb_timeout('restart') == 540\n"
|
||||
"assert _gateway_verb_timeout('start') == 300\n"
|
||||
"assert _gateway_verb_timeout('stop') == 240\n"
|
||||
"plan.step_titles()\n"
|
||||
"for verb in ('restart', 'start', 'stop'):\n"
|
||||
" _gateway_verb_timeout(verb)\n"
|
||||
"assert 'hermes_cli.gateway_migrate_backends_apply' not in sys.modules\n"
|
||||
)
|
||||
res = subprocess.run(
|
||||
|
||||
@@ -4,6 +4,8 @@ from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from hermes_cli.gateway_migrate_backends_timeouts import VERIFY_SECONDS
|
||||
|
||||
_GUIDE = Path(__file__).resolve().parents[2] / "website" / "docs" / "user-guide" / "features" / "web-dashboard.md"
|
||||
|
||||
|
||||
@@ -12,5 +14,4 @@ def test_the_dry_run_section_no_longer_says_apply_is_unavailable():
|
||||
assert "not available in this version" not in text
|
||||
assert "without `--dry-run` exits 2" not in text
|
||||
assert "{#moving-a-dashboard-backend-to-the-gateway}" in text # the section the dry run points to
|
||||
assert "within 300 seconds" in text
|
||||
assert "within 90 seconds" not in text
|
||||
assert f"within {int(VERIFY_SECONDS)} seconds" in text # the verify budget the apply enforces
|
||||
|
||||
@@ -603,6 +603,24 @@ describe("BackendMigrationCard", () => {
|
||||
expect(shown).toContain("Reason: verify failed: verification failed after 300s: no HTTP 200");
|
||||
expect(button("Try again")).toBeDefined();
|
||||
});
|
||||
|
||||
it("names the status command while the address stays dark past the old 150 s cutoff", async () => {
|
||||
vi.stubGlobal("fetch", vi.fn<typeof fetch>(async (input) => {
|
||||
if (String(input).includes("/apply")) {
|
||||
return json(200, { ok: true, confirmed: true, requested_at: 100, old_address: "0.0.0.0:9119", new_address: "0.0.0.0:9119" });
|
||||
}
|
||||
return Promise.reject(new TypeError("Failed to fetch"));
|
||||
}));
|
||||
|
||||
await render(planWith({}));
|
||||
await confirmMove();
|
||||
await wait(200_000);
|
||||
|
||||
const progress = container.querySelector('[data-slot="backend-migration-progress"]')?.textContent ?? "";
|
||||
expect(progress).toContain("Switching over");
|
||||
expect(progress).not.toContain("for a few seconds");
|
||||
expect(container.textContent).toContain("hermes -p work gateway migrate --backends --status");
|
||||
});
|
||||
});
|
||||
|
||||
describe("readPoll", () => {
|
||||
|
||||
@@ -335,7 +335,15 @@ function Progress({ view, profile, commands, onCheckAgain, onTryAgain }: {
|
||||
case "running":
|
||||
return <Line spin>{stepWords(view.step)}…</Line>;
|
||||
case "switching":
|
||||
return <Line spin>Switching over: this address is unavailable for a few seconds…</Line>;
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<Line spin>Switching over: this address is unavailable until Hermes answers on it again…</Line>
|
||||
<span className="text-muted-foreground">
|
||||
A move that waits for running work, or puts everything back, can take several minutes. On this computer,
|
||||
see where it stands with <Cmd>{status}</Cmd>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
case "signInAgain":
|
||||
return (
|
||||
<div className="flex flex-col gap-2" data-slot="backend-migration-signin">
|
||||
|
||||
@@ -355,11 +355,13 @@ export function viewOf(st: BackendMigrationStatus): PollView {
|
||||
|
||||
/** Seconds after the request with no record of the new run before its outcome counts as unknown. */
|
||||
export const NOT_STARTED_AFTER_SECONDS = 60;
|
||||
/** Seconds without an answer about the followed run before a poll stops calling it the restart:
|
||||
* covers the worst-case sequential backend timeout budget from stopping the old backend through a
|
||||
* failed verify and rollback (port-free 30 s + gateway restart 540 s + handoff 240 s + verify 300 s
|
||||
* + rollback stop 240 s + rollback gateway start 300 s + listener-gone 30 s + old backend start 90 s
|
||||
* + rollback verify 60 s = 1830 s). */
|
||||
/** Seconds without an answer about the followed run before a poll stops calling it the restart: the
|
||||
* sum of the migration's own caps from stopping the old backend through a failed verify and rollback
|
||||
* (port-free 30 s + gateway restart 540 s + handoff 240 s + verify 300 s + rollback stop 240 s
|
||||
* + rollback gateway start 300 s + listener-gone 30 s + old backend start 90 s + rollback verify 60 s
|
||||
* = 1830 s). An estimate, not a bound: a launchd restart waits for the gateway to go idle for up to
|
||||
* the CLI's restart exit-wait budget (`agent.restart_after_turn_timeout` plus the stop envelope), and
|
||||
* a raised drain setting outlasts the systemctl caps. */
|
||||
export const UNREACHABLE_AFTER_SECONDS = 1830;
|
||||
|
||||
/** Which run a poll follows. `requestedAt`: the server time the apply answer named, or `null` when that
|
||||
|
||||
Reference in New Issue
Block a user