The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): name the remedy for a terminal bootstrap failure
Teknium4f33e9cd7466
diff --git a/tests/tui_gateway/test_ink_helper_dependencies.py b/tests/tui_gateway/test_ink_helper_dependencies.pyindex d4dd33e86bd..a9912ce9acc 100644--- a/tests/tui_gateway/test_ink_helper_dependencies.py+++ b/tests/tui_gateway/test_ink_helper_dependencies.py@@ -82,6 +82,26 @@ def test_packaged_gateway_bootstrap_boots_the_root_it_is_given_or_names_why_it_cassert "unavailable" not in booted.stderr+def _store_python_child(script: str, *args: str) -> subprocess.CompletedProcess:+ """The helper on PM's store Python: a non-venv interpreter living under the runtime dir."""+ child_env = {k: v for k, v in os.environ.items() if k != "VIRTUAL_ENV"}+ child_env.update(PYTHONPATH=str(_ROOT), HERMES_PYTHON_SRC_ROOT=str(_ROOT),+ HERMES_RUNTIME_DIR=str(Path(sys.base_prefix).resolve().parent))+ python = getattr(sys, "_base_executable", sys.executable)+ return subprocess.run([python, "-S", str(_SCRIPTS / script), *args], cwd=_ROOT, env=child_env,+ capture_output=True, text=True, timeout=60, check=False)+++def test_store_python_without_a_generation_names_the_remedy():+ """No committed generation is the one state no retry fixes: the client stops retrying and+ shows the verdict once, so it must end with the user's next step, not leave a dead TUI."""+ bootstrap = _store_python_child("gateway_bootstrap.py", "--start")+ lines = bootstrap.stderr.strip().splitlines()+ assert bootstrap.returncode == 1+ assert lines[0] == "gateway unavailable: bootstrap_dependencies", bootstrap.stderr+ assert lines[-1] == "gateway unavailable: run `hermes pm repair`, then restart the TUI", bootstrap.stderr++def test_unreadable_install_state_is_retried_not_terminal():"""An I/O error on the install state can be one-off: it takes the ordinary failure path theclient retries, never the terminal verdict that ends the TUI's gateway for its lifetime."""diff --git a/ui-tui/scripts/gateway_bootstrap.py b/ui-tui/scripts/gateway_bootstrap.pyindex 6e26c5c51af..e8bf030dd8f 100644--- a/ui-tui/scripts/gateway_bootstrap.py+++ b/ui-tui/scripts/gateway_bootstrap.py@@ -21,6 +21,9 @@ def python_root() -> Path:sys.path.insert(0, str(python_root()))+# The terminal verdict's next step: the client stops retrying on it, so the user needs one. A+# verdict line like the rest, so the TUI echoes it inline (userMessages.ts STDERR_PROBLEM_RE).+BOOTSTRAP_REMEDY = "gateway unavailable: run `hermes pm repair`, then restart the TUI"def failure_message(receipt) -> str:@@ -111,7 +114,7 @@ if __name__ == "__main__":except ImportError as exc:# This interpreter cannot load Hermes at all: no reconnect fixes that, so name it# (gatewayClient.ts stops retrying on this verdict).- print(f"gateway unavailable: bootstrap_dependencies\n{exc}", file=sys.stderr)+ print(f"gateway unavailable: bootstrap_dependencies\n{exc}\n{BOOTSTRAP_REMEDY}", file=sys.stderr)raise SystemExit(1)except (OSError, RuntimeError, ValueError, LookupError, AttributeError, TypeError) as exc:print(str(exc), file=sys.stderr)diff --git a/ui-tui/src/__tests__/gatewayStartTimeout.test.ts b/ui-tui/src/__tests__/gatewayStartTimeout.test.tsnew file mode 100644index 00000000000..281317fa29f--- /dev/null+++ b/ui-tui/src/__tests__/gatewayStartTimeout.test.ts@@ -0,0 +1,23 @@+import { beforeEach, expect, it } from 'vitest'++import { reportGatewayStartTimeout } from '../app/gatewayStartTimeout.js'+import { getTurnState, resetTurnState } from '../app/turnStore.js'++beforeEach(() => resetTurnState())++// The client never retries gateway_bootstrap.py's terminal verdict, so the user sees it once: it+// must carry the next step and must not claim Hermes is still starting.+it('shows a terminal bootstrap verdict and its remedy, never "still waiting"', () => {+ const statuses: string[] = []++ reportGatewayStartTimeout('Command failed: python3 gateway_bootstrap.py --start\n' ++ 'gateway unavailable: bootstrap_dependencies\n' ++ 'dependency environment unavailable: no dependency environment is committed for this install\n' ++ 'gateway unavailable: run `hermes pm repair`, then restart the TUI\n', s => statuses.push(s))++ const messages = getTurnState().activity.map(a => a.text)++ expect(messages).toContain('gateway unavailable: run `hermes pm repair`, then restart the TUI')+ expect(messages.some(m => m.includes('Still waiting'))).toBe(false)+ expect(statuses.some(s => s.includes('still starting'))).toBe(false)+})diff --git a/ui-tui/src/app/createGatewayEventHandler.ts b/ui-tui/src/app/createGatewayEventHandler.tsindex adc1a666226..c4eab443162 100644--- a/ui-tui/src/app/createGatewayEventHandler.ts+++ b/ui-tui/src/app/createGatewayEventHandler.ts@@ -39,6 +39,7 @@ import {openCanonicalClarify,settleSharedPrompt} from './gatewayCanonicalEvents.js'+import { reportGatewayStartTimeout } from './gatewayStartTimeout.js'import type { GatewayEventHandlerContext, NoticeLevel } from './interfaces.js'import { applyControlSnapshot } from './loopStatus.js'import { getOverlayState, patchOverlayState, SENSITIVE_PROMPTS } from './overlayStore.js'@@ -55,8 +56,6 @@ import { getTurnState } from './turnStore.js'import { getUiState, patchUiState } from './uiStore.js'import {backendReconnecting,- backendSlowStart,- backendSlowStartStatus,describeRpcError,describeTurnFailure,isBareErrorText,@@ -1284,31 +1283,10 @@ export function createGatewayEventHandler(ctx: GatewayEventHandlerContext): (ev:return}- case 'gateway.start_timeout': {- // Still waiting (the ready timer does not give up) — say so, and point- // at /logs for the interpreter/cwd/stderr detail instead of printing- // paths here. Only failure-looking stderr lines are echoed inline so- // "wrong python" / "missing dep" stay diagnosable at a glance.- const { stderr_tail: stderrTail } = ev.payload ?? {}-- setStatus(backendSlowStartStatus())- turnController.pushActivity(backendSlowStart(), 'warn')-- const STDERR_LINE_CAP = 120- const STDERR_LINES_MAX = 4-- const tailLines = (stderrTail ?? '')- .split('\n')- .map(l => l.trim())- .filter(l => l && stderrLooksLikeProblem(l))- .slice(-STDERR_LINES_MAX)-- for (const line of tailLines) {- turnController.pushActivity(line.slice(0, STDERR_LINE_CAP), 'error')- }+ case 'gateway.start_timeout':+ reportGatewayStartTimeout(ev.payload?.stderr_tail, setStatus)return- }case 'gateway.protocol_error':setStatus(t('gatewayMsg.status.protocolWarning'))diff --git a/ui-tui/src/app/gatewayStartTimeout.ts b/ui-tui/src/app/gatewayStartTimeout.tsnew file mode 100644index 00000000000..7b98e27dd9e--- /dev/null+++ b/ui-tui/src/app/gatewayStartTimeout.ts@@ -0,0 +1,39 @@+/** `gateway.start_timeout`: the backend has not attached yet, or its bootstrap gave up for good. */+import { isTerminalBootstrapFailure } from '../localGatewayBootstrap.js'++import { turnController } from './turnController.js'+import {+ backendGaveUpActivity,+ backendSlowStart,+ backendSlowStartStatus,+ stderrLooksLikeProblem+} from './userMessages.js'++const STDERR_LINE_CAP = 120+const STDERR_LINES_MAX = 4++/** Still waiting (the ready timer does not give up): say so, and point at /logs for the+ * interpreter/cwd/stderr detail instead of printing paths here. Only failure-looking stderr lines+ * are echoed inline so "wrong python" / "missing dep" stay diagnosable at a glance.+ *+ * gateway_bootstrap.py's terminal verdict is different: the client stops retrying, so "still+ * waiting" would be false. Its own verdict lines (the cause, then the remedy) are the message. */+export function reportGatewayStartTimeout(stderrTail: string | undefined, setStatus: (status: string) => void) {+ const terminal = isTerminalBootstrapFailure(stderrTail ?? '')++ setStatus(terminal ? backendGaveUpActivity() : backendSlowStartStatus())++ if (!terminal) {+ turnController.pushActivity(backendSlowStart(), 'warn')+ }++ const tailLines = (stderrTail ?? '')+ .split('\n')+ .map(l => l.trim())+ .filter(l => l && stderrLooksLikeProblem(l))+ .slice(-STDERR_LINES_MAX)++ for (const line of tailLines) {+ turnController.pushActivity(line.slice(0, STDERR_LINE_CAP), 'error')+ }+}