Skip to content

The agent that grows with you

fix(gateway): keep pending-tail status diagnostic fast

KoNit-K3ff9596ef56b
diff --git a/apps/desktop/electron/local-gateway.test.ts b/apps/desktop/electron/local-gateway.test.ts
index 26cdec84c7f..78377681967 100644
--- a/apps/desktop/electron/local-gateway.test.ts
+++ b/apps/desktop/electron/local-gateway.test.ts
@@ -532,3 +532,9 @@ test('an ensure refusal names its remedy instead of only a status pointer', asyn
code: 3, stdout: JSON.stringify({ state: 'incompatible', reason_code: 'runtime_protocol', detail, endpoint: null })
}))).rejects.toThrow(`Gateway incompatible (runtime_protocol). ${detail}. Use hermes gateway status for recovery.`)
})
+
+test('an update-paused ensure refusal points to the restart that completes its tail', async () => {
+ await expect(ensureLocalGateway(async () => ({
+ code: 6, stdout: JSON.stringify({ state: 'draining', reason_code: 'update_paused', endpoint: null })
+ }))).rejects.toThrow('Gateway draining (update_paused). Use hermes gateway restart for recovery.')
+})
diff --git a/apps/desktop/electron/local-gateway.ts b/apps/desktop/electron/local-gateway.ts
index 0d69d183153..cf3eb963e1a 100644
--- a/apps/desktop/electron/local-gateway.ts
+++ b/apps/desktop/electron/local-gateway.ts
@@ -217,8 +217,9 @@ export async function ensureLocalGateway(
// A refused replacement (another install's or a newer Hermes's gateway) names its remedy in
// `detail`; a start that died carries its own output there. Either beats a pointer elsewhere.
const detail = typeof payload.detail === 'string' && payload.detail.trim() ? ` ${payload.detail.trim().split(/\r?\n/)[0]}.` : ''
+ const recovery = payload.reason_code === 'update_paused' ? 'restart' : 'status'
- throw new Error(`Gateway ${payload.state || 'inaccessible'} (${payload.reason_code || 'ensure_failed'}).${detail} Use hermes gateway status for recovery.`)
+ throw new Error(`Gateway ${payload.state || 'inaccessible'} (${payload.reason_code || 'ensure_failed'}).${detail} Use hermes gateway ${recovery} for recovery.`)
}
const endpoint: GatewayEndpoint = payload.endpoint
diff --git a/hermes_cli/venv_sync.py b/hermes_cli/venv_sync.py
index d962badd1f9..6ae56627e90 100644
--- a/hermes_cli/venv_sync.py
+++ b/hermes_cli/venv_sync.py
@@ -156,6 +156,11 @@ def collect_superseded_generations(project_root: Path) -> None:
_METADATA_FLAGS = frozenset({"-h", "--help", "-V", "--version"})
+def _is_read_only_gateway_status(command: list[str]) -> bool:
+ """Whether *command* is the recovery diagnostic that must not run an update tail."""
+ return command[:2] == ["gateway", "status"]
+
+
def completion_pending_path(project_root: Path) -> Path:
"""Marker for a source update whose dependency sync committed but whose tail
(launchers, products, maintenance) has not finished.
@@ -359,8 +364,13 @@ def prepare_launch(project_root: Path, argv: list[str]) -> Path | None:
from hermes_cli._parser import command_argv
from hermes_cli.steward import read_install_stamp
- if (command_argv(argv)[:1] == ["pm"]
+ command = command_argv(argv)
+ if (command[:1] == ["pm"]
or _METADATA_FLAGS & set(argv)
+ # This is the recovery path shown by the Desktop when a pending update has
+ # fenced the gateway. Completing that same tail first can take minutes and
+ # leaves the user without the fence diagnosis or a usable restart remedy.
+ or _is_read_only_gateway_status(command)
or os.environ.get("HERMES_DISABLE_LAZY_INSTALLS", "").lower() in ("1", "true", "yes")
or not (root / ".git").exists()
or not (root / "pyproject.toml").is_file()):
diff --git a/tests/hermes_cli/test_update_launch_completion.py b/tests/hermes_cli/test_update_launch_completion.py
index 9ef11faa8c3..80a96c3a4f2 100644
--- a/tests/hermes_cli/test_update_launch_completion.py
+++ b/tests/hermes_cli/test_update_launch_completion.py
@@ -425,6 +425,19 @@ def test_launch_under_the_owning_update_does_not_run_the_tail_again(tmp_path, mo
assert pending.is_file(), "the owning update's obligation was discharged by its own tail"
+def test_gateway_status_skips_pending_source_update_completion(tmp_path, monkeypatch, completion_tail):
+ """`gateway status` remains a read-only recovery diagnostic while a tail is owed (#139133)."""
+ import pm
+
+ root = _self_checkout(tmp_path, monkeypatch)
+ pending = venv_sync.arm_completion(root)
+ monkeypatch.setattr(pm, "venv_is_current", lambda **_kw: pytest.fail("status started a dependency sync"))
+
+ assert venv_sync.prepare_launch(root, ["gateway", "status"]) is None
+ assert completion_tail == []
+ assert pending.is_file(), "a status query must leave the update tail for `hermes gateway restart`"
+
+
@pytest.mark.parametrize("marker,value,owed_by_cli", [
("HERMES_SUPERVISED_CHILD", "1", True),
("HERMES_S6_SUPERVISED_CHILD", "true", True),