From 40492aca4e5f034e7ec58ea7610d0013639f1309 Mon Sep 17 00:00:00 2001 From: alt-glitch Date: Sun, 15 Nov 2026 18:37:30 +0530 Subject: [PATCH] refactor(environments-terminal): delete unreached vercel helpers, CredentialRef, failed_start and exit-137 hint Removed. A search for callers by name, attribute and string (Python, TypeScript, docs, the plugin API list and the frozen old-updater list) finds no supported path that reaches any of them: - tools/environments/vercel_sandbox.py: _exception_chain, _extract_status_code, _RETRY_BACKOFF_STEP, _MIN_SANDBOX_TIMEOUT, _MIN_RUNNING_WAIT, _RUNNING_WAIT_POLL_INTERVAL, _STOP_TIMEOUT, _STOP_POLL_INTERVAL, _SNAPSHOT_STORE_NAME - tools/environments/sandbox_scope.py: CredentialRef (docstring in agent/terminal_env_provider.py and the terminal-environment-plugin guide no longer name it) - tools/environments/streams.py: supports_streams() (the provider attribute of the same name stays) - completion_reason "failed_start": its producer left in cd818a4d054; drop the lookups in process_registry_notifications._REASON_STATUS (and its "Failed to Start" branch), cli_process_dock._STATUS_BY_REASON, ui-tui processRoster REASON_STATUS, and the field comments - tools/terminal_hints.py: _EXIT_CODE_HINTS[137] (exit 137 always carries a SIGKILL exit note, which gates annotate_failure off) - ProcessRegistry._config_value: unread `fallback` parameter --- agent/terminal_env_provider.py | 4 +-- hermes_cli/cli_process_dock.py | 2 +- tests/tools/test_terminal_hints.py | 1 - tools/environments/sandbox_scope.py | 8 ------ tools/environments/streams.py | 4 --- tools/environments/vercel_sandbox.py | 27 ++----------------- tools/process_registry.py | 10 +++---- tools/process_registry_notifications.py | 4 +-- tools/terminal_hints.py | 1 - ui-tui/src/app/processRoster.ts | 2 +- .../terminal-environment-plugin.md | 5 ++-- 11 files changed, 15 insertions(+), 53 deletions(-) diff --git a/agent/terminal_env_provider.py b/agent/terminal_env_provider.py index cf97d316c9..a832606631 100644 --- a/agent/terminal_env_provider.py +++ b/agent/terminal_env_provider.py @@ -78,8 +78,8 @@ class TerminalEnvironmentProvider(ProviderBase): sandbox. Suspending the sandbox once such a process is idle-stopped, and network isolation between sandboxes, are the backend's. - Credentials reach a hosted sandbox as broker references (``CredentialRef``), never values from - the secret store; no broker exists yet, so core passes none. + Credentials never reach a hosted sandbox as values from the secret store; no credential broker + exists yet, so core passes none. """ is_remote: bool = True diff --git a/hermes_cli/cli_process_dock.py b/hermes_cli/cli_process_dock.py index 3336cceee2..fbaccdd254 100644 --- a/hermes_cli/cli_process_dock.py +++ b/hermes_cli/cli_process_dock.py @@ -16,7 +16,7 @@ from agent.i18n import t RETAIN_SECONDS = 60 # Reader-thread exits report "exited"; `kill_process` / `kill_all` stamp "killed". -_STATUS_BY_REASON = {"killed": "killed", "lost": "lost", "failed_start": "failed"} +_STATUS_BY_REASON = {"killed": "killed", "lost": "lost"} def _last_output_line(buffer: str) -> str: diff --git a/tests/tools/test_terminal_hints.py b/tests/tools/test_terminal_hints.py index 6135821207..cf781a4042 100644 --- a/tests/tools/test_terminal_hints.py +++ b/tests/tools/test_terminal_hints.py @@ -16,7 +16,6 @@ class TestAnnotateFailureBasics: def test_empty_output_falls_to_exit_code_tier(self): assert "126" in annotate_failure("./run.sh", 126, "") - assert "SIGKILL" in annotate_failure("big_job", 137, "") assert "timeout" in annotate_failure("sleep 999", 124, "") def test_unknown_failure_returns_none(self): diff --git a/tools/environments/sandbox_scope.py b/tools/environments/sandbox_scope.py index 036f275d6e..96d299f782 100644 --- a/tools/environments/sandbox_scope.py +++ b/tools/environments/sandbox_scope.py @@ -71,14 +71,6 @@ class ProcessStream: poll: Callable[[], Optional[int]] = field(compare=False) -@dataclass(frozen=True) -class CredentialRef: - """A credential the sandbox resolves through a broker, by name. Hosted backends receive these, - never secret values from the secret store; no broker exists yet, so core passes none.""" - - name: str - - def hosted_scope() -> Optional[Scope]: """The bound scope when it is hosted, else ``None`` (no scope, or a local install).""" scope = current_scope() diff --git a/tools/environments/streams.py b/tools/environments/streams.py index bf37d77201..47240e5f1b 100644 --- a/tools/environments/streams.py +++ b/tools/environments/streams.py @@ -76,10 +76,6 @@ def sandbox_temp_dir(env: BaseEnvironment) -> str: return str(get_temp_dir()) if callable(get_temp_dir) else "/tmp" # no-tmp: ok — sandbox-side temp dir -def supports_streams(env: BaseEnvironment) -> bool: - return exec_prefix(env, interactive=True) is not None - - def remote_argv(prefix: Sequence[str], argv: Sequence[str], *, env: Optional[dict] = None, shell_joined: bool = False) -> list[str]: """``prefix`` + a ``bash -c`` that exports ``env`` and execs ``argv``. diff --git a/tools/environments/vercel_sandbox.py b/tools/environments/vercel_sandbox.py index 7fd77df052..35e59b2066 100644 --- a/tools/environments/vercel_sandbox.py +++ b/tools/environments/vercel_sandbox.py @@ -53,34 +53,11 @@ def _ensure_vercel_sdk() -> None: _lazy_ensure("vercel") except Exception as e: raise ImportError(str(e)) + + _WRITE_RETRY_ATTEMPTS = 3 -_RETRY_BACKOFF_STEP = timedelta(milliseconds=100) -_MIN_SANDBOX_TIMEOUT = timedelta(minutes=5) -_MIN_RUNNING_WAIT = timedelta(seconds=1) -_RUNNING_WAIT_POLL_INTERVAL = timedelta(milliseconds=250) -_STOP_TIMEOUT = timedelta(seconds=15) -_STOP_POLL_INTERVAL = timedelta(milliseconds=500) -_SNAPSHOT_STORE_NAME = "vercel_sandbox_snapshots.json" -def _exception_chain(exc: BaseException) -> list[BaseException]: - chain: list[BaseException] = [] - current: BaseException | None = exc - seen: set[int] = set() - while current is not None and id(current) not in seen: - chain.append(current) - seen.add(id(current)) - current = current.__cause__ or current.__context__ - return chain - - -def _extract_status_code(exc: BaseException) -> int | None: - response = getattr(exc, "response", None) - for value in (getattr(exc, "status_code", None), getattr(response, "status_code", None)): - if isinstance(value, int): - return value - return None - @cache def _transport_error_types() -> tuple[type[BaseException], ...]: """Network exceptions of every HTTP stack the SDK may raise from. diff --git a/tools/process_registry.py b/tools/process_registry.py index c8da9ecf01..cf167468ed 100644 --- a/tools/process_registry.py +++ b/tools/process_registry.py @@ -563,8 +563,8 @@ class ProcessSession: exited: bool = False exited_at: float = 0.0 # time.time() of the FIRST move to finished (0 = unknown) exit_code: Optional[int] = None # None while running - completion_reason: str = "exited" # exited|killed|lost|failed_start|already_exited - termination_source: str = "" # process.kill|kill_all|backend_lost|env_closed|failed_start + completion_reason: str = "exited" # exited|killed|lost|already_exited + termination_source: str = "" # process.kill|kill_all|backend_lost|env_closed output_buffer: str = "" # Rolling tail (last max_output_chars) max_output_chars: int = MAX_OUTPUT_CHARS detached: bool = False # Recovered from checkpoint (no pipe) @@ -1066,7 +1066,7 @@ class ProcessRegistry(ProcessTerminationMixin, ProcessCheckpointMixin, ProcessOu and not self._is_host_pid_alive(session.pid)) @staticmethod - def _config_value(section: str, key: str, fallback): + def _config_value(section: str, key: str): """``config.yaml`` value for ``section.key``, else the DEFAULT_CONFIG value. Raises if config is unreadable; callers wrap with their own hard fallback so registry code paths never crash on a broken config file.""" @@ -1079,7 +1079,7 @@ class ProcessRegistry(ProcessTerminationMixin, ProcessCheckpointMixin, ProcessOu def _config_seconds(key: str, fallback: float) -> float: """``terminal.`` as a non-negative float (0 disables); *fallback* if unreadable.""" try: - return max(float(ProcessRegistry._config_value("terminal", key, fallback)), 0.0) + return max(float(ProcessRegistry._config_value("terminal", key)), 0.0) except Exception: return fallback @@ -1775,7 +1775,7 @@ class ProcessRegistry(ProcessTerminationMixin, ProcessCheckpointMixin, ProcessOu """``delegation.surface_child_process_notifications``; False on any config error — never crash the drain loop.""" try: - return bool(ProcessRegistry._config_value("delegation", "surface_child_process_notifications", False)) + return bool(ProcessRegistry._config_value("delegation", "surface_child_process_notifications")) except Exception: return False diff --git a/tools/process_registry_notifications.py b/tools/process_registry_notifications.py index 604548e950..ba3ecdb8bc 100644 --- a/tools/process_registry_notifications.py +++ b/tools/process_registry_notifications.py @@ -8,7 +8,7 @@ from dataclasses import dataclass from contextlib import suppress _DONE = ("completed", "success") -_REASON_STATUS = {"lost": "marked lost because the process backend disappeared", "failed_start": "failed to start"} +_REASON_STATUS = {"lost": "marked lost because the process backend disappeared"} @dataclass(frozen=True, slots=True) @@ -444,7 +444,7 @@ def process_completion_display_text(events: list) -> str: if reason == "killed": outcome = "Terminated" elif reason in _REASON_STATUS: - outcome = "Lost" if reason == "lost" else "Failed to Start" + outcome = "Lost" else: outcome = "Finished" if exit_code == 0 else "Failed" cmd = _short_command(evt.get("command")) diff --git a/tools/terminal_hints.py b/tools/terminal_hints.py index 77b27581c6..d3d9bc0c34 100644 --- a/tools/terminal_hints.py +++ b/tools/terminal_hints.py @@ -76,7 +76,6 @@ _OUTPUT_HINTS: list[Callable[[str, str], Optional[str]]] = [ # cover per-command. Checked after output patterns. _EXIT_CODE_HINTS: dict[int, str] = { 126: "Exit 126: the file was found but is not executable — `chmod +x` it or invoke it via its interpreter (e.g. `bash script.sh`).", - 137: "Exit 137: the process was SIGKILLed — usually out-of-memory or an external kill. Reduce memory use or check `dmesg | tail` before retrying.", 124: "Exit 124: the command hit its timeout. Raise timeout= (foreground max 600s) or run it with background=true and notify_on_complete=true.", } diff --git a/ui-tui/src/app/processRoster.ts b/ui-tui/src/app/processRoster.ts index 930d06b1b8..f14cbfe1e7 100644 --- a/ui-tui/src/app/processRoster.ts +++ b/ui-tui/src/app/processRoster.ts @@ -43,7 +43,7 @@ export function applyProcessSnapshot(sid: string | null, processes: ProcessEntry } } -const REASON_STATUS: Record = { failed_start: 'failed', killed: 'killed', lost: 'lost' } +const REASON_STATUS: Record = { killed: 'killed', lost: 'lost' } export const processStatus = (entry: ProcessEntry): ProcessRow['status'] => { if (entry.status !== 'exited') { diff --git a/website/docs/developer-guide/terminal-environment-plugin.md b/website/docs/developer-guide/terminal-environment-plugin.md index d1af14b594..27696709dc 100644 --- a/website/docs/developer-guide/terminal-environment-plugin.md +++ b/website/docs/developer-guide/terminal-environment-plugin.md @@ -351,9 +351,8 @@ local backend on this host, docker/ssh and `supports_streams` plugins through their exec prefix). Suspending a sandbox once its processes are idle-stopped, and network isolation between sandboxes, are yours. -**Credentials** reach a hosted sandbox as broker references -(`sandbox_scope.CredentialRef`), never as values from the secret store. No -broker exists yet, so Hermes passes none. +**Credentials** never reach a hosted sandbox as values from the secret store. +No credential broker exists yet, so Hermes passes none. **Conformance.** `tools/environments/sandbox_conformance.py` holds the isolation checks Hermes runs against its recording stub backend