Skip to content

Multi-tier framework for evaluating AI agent skills and plugins with quality gates, security scanning, harness compatibility checks, semantic overlap detection, synthetic evaluation dataset generation, and live agent evaluation that measures how skills affect agent behavior. Ships reusable CI templates that bring every check to any repository.

fix(tier3): retry transient Claude Code and Codex install failures (#277)

Narendran Raghavana52c82bed081
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 37b9c362..b4b0002b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -336,6 +336,15 @@ All notable changes to SkillEvaluator are documented in this file.
listed. The JSON report still carries every error under
`tier3.provenance.source_validation`. Validation rules, gate decisions, and
the finding's suggestion text are unchanged.
+- Tier 3 Docker and Kata runs retry a Claude Code or Codex install that fails,
+ for example on a dropped download or a package mirror error, instead of
+ failing the trial on the first attempt. Up to three attempts run within
+ Harbor's agent setup timeout, so an install that keeps failing still fails
+ the trial. A slow failure that would leave no room for another attempt is
+ not retried, so the trial reports the install error rather than a setup
+ timeout, and each retry warning ends with the failed command's output.
+ Platform probe and transport errors are not retried, and local mode still
+ checks the installed CLI once.
- Tier 2 caps every intra-skill embedding chunk at 3,000 characters, preserves
meaningful short tails and actual Python docstring source ranges, and avoids
counting pieces of one original chunk as duplicates of each other. Oversized
diff --git a/docs/agents-and-sandboxes.mdx b/docs/agents-and-sandboxes.mdx
index 249c1869..c1035bee 100644
--- a/docs/agents-and-sandboxes.mdx
+++ b/docs/agents-and-sandboxes.mdx
@@ -30,6 +30,16 @@ The pinned CLI releases apply wherever Harbor installs the agent: Docker and
the remote environments. [Local mode](#local-mode) runs the CLI already on your
machine instead.
+In Docker and Kata, SkillEvaluator reruns a Claude Code or Codex install that
+fails, for example on a dropped download or a package mirror error. It makes up
+to three attempts, waiting 2 and then 4 seconds, all within Harbor's agent setup
+timeout, so an install that keeps failing still fails the trial. A slow failure
+is not retried when the attempt took over a third of that timeout, or when
+another attempt as long would not finish within it, so the trial reports the
+install error rather than a setup timeout. Each retry logs a warning that ends
+with the failed command's output. Claude Code on GKE, and Codex behind an
+OpenAI-compatible gateway, are retried the same way.
+
Claude Code runs with background tasks turned off. Every staged task sets
`CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1` in its environment, in every env mode,
so a shell command finishes in the agent's turn or is stopped at Claude Code's
diff --git a/src/skillevaluator/tier3/harbor/installed_agents.py b/src/skillevaluator/tier3/harbor/installed_agents.py
index b6e514f4..552ffc5d 100644
--- a/src/skillevaluator/tier3/harbor/installed_agents.py
+++ b/src/skillevaluator/tier3/harbor/installed_agents.py
@@ -1,22 +1,106 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
-"""Keep Harbor's bootstrap dependencies aligned with its installer branches."""
+"""Keep Harbor's bootstrap dependencies aligned with its installer branches.
+
+The wrappers also retry a failed agent CLI install, since a dropped download or
+a package mirror error otherwise fails the trial before the agent starts.
+"""
from __future__ import annotations
+import asyncio
+from collections.abc import Awaitable, Callable
+from time import monotonic
from typing import TYPE_CHECKING
+from harbor.agents.installed.base import NonZeroAgentExitCodeError
from harbor.agents.installed.claude_code import ClaudeCode
from harbor.agents.installed.codex import Codex
+from skillevaluator.utils.redaction import redact_sensitive_text
+
if TYPE_CHECKING:
+ from harbor.agents.installed.base import BaseInstalledAgent
from harbor.environments.base import BaseEnvironment
# Harbor's installers download over HTTPS but never request a CA bundle; apt
# images used to get one only as a dependency of the skipped npm package.
_CA_BUNDLE_PREDICATE = "[ -s /etc/ssl/certs/ca-certificates.crt ] || [ -s /etc/pki/tls/certs/ca-bundle.crt ]"
_INSTALLER_BRANCHES = frozenset({"system", "bundled", "bundled-without-ca"})
+# Harbor runs each installer once. Its install() skips a CLI that an earlier
+# attempt already installed, so rerunning it after a failure is safe.
+_INSTALL_ATTEMPTS = 3
+_INSTALL_RETRY_BASE_DELAY_SEC = 2.0
+# A slow failure (a connect that hangs, say) is not retried when it used more
+# than this share of the agent setup timeout, so the trial still ends with the
+# install error instead of Harbor's setup timeout.
+_INSTALL_RETRY_MAX_ATTEMPT_SHARE = 1 / 3
+# The retry warning keeps the end of Harbor's error, which holds the failed
+# command's stderr; Harbor logs the full output only at debug level.
+_INSTALL_FAILURE_DETAIL_CHARS = 200
+
+
+def _install_failure_detail(exc: BaseException) -> str:
+ # Redact before truncating so a credential cut at the boundary is still
+ # recognized, and fold Harbor's stdout/stderr lines into one log line.
+ detail = " ".join(redact_sensitive_text(str(exc)).split())
+ if len(detail) > _INSTALL_FAILURE_DETAIL_CHARS:
+ return "..." + detail[-_INSTALL_FAILURE_DETAIL_CHARS:]
+ return detail
+
+
+async def _install_with_retries(
+ agent: BaseInstalledAgent,
+ install: Callable[[BaseEnvironment], Awaitable[None]],
+ environment: BaseEnvironment,
+) -> None:
+ # Retry only a Harbor command that exited non-zero. Probe, transport and
+ # cancellation errors propagate, and all attempts share Harbor's agent
+ # setup timeout. The agent cannot see Harbor's timeout multiplier, so the
+ # budget is the agent's unscaled default; a larger multiplier only makes
+ # the guard skip a retry that would have fit.
+ budget_sec = agent.DEFAULT_SETUP_TIMEOUT_SEC
+ started = monotonic()
+ for attempt in range(1, _INSTALL_ATTEMPTS + 1):
+ attempt_started = monotonic()
+ try:
+ await install(environment)
+ return
+ except NonZeroAgentExitCodeError as exc:
+ if attempt == _INSTALL_ATTEMPTS:
+ raise
+ now = monotonic()
+ attempt_sec = now - attempt_started
+ delay = _INSTALL_RETRY_BASE_DELAY_SEC * attempt
+ detail = _install_failure_detail(exc)
+ # Assume another attempt takes as long as this one.
+ if (
+ attempt_sec > budget_sec * _INSTALL_RETRY_MAX_ATTEMPT_SHARE
+ or now - started + delay + attempt_sec > budget_sec
+ ):
+ agent.logger.warning(
+ "%s install attempt %d of %d failed with %s after %.0fs; not retrying, another "
+ "attempt would not fit the %.0fs agent setup timeout: %s",
+ agent.name(),
+ attempt,
+ _INSTALL_ATTEMPTS,
+ type(exc).__name__,
+ attempt_sec,
+ budget_sec,
+ detail,
+ )
+ raise
+ agent.logger.warning(
+ "%s install attempt %d of %d failed with %s; retrying in %.0fs: %s",
+ agent.name(),
+ attempt,
+ _INSTALL_ATTEMPTS,
+ type(exc).__name__,
+ delay,
+ detail,
+ )
+ await asyncio.sleep(delay)
async def _installer_dependencies(
@@ -53,6 +137,9 @@ async def _installer_dependencies(
class SkillEvaluatorCodex(Codex):
"""Avoid a redundant distribution Node/npm install before Harbor's NVM."""
+ async def install(self, environment: BaseEnvironment) -> None:
+ await _install_with_retries(self, super().install, environment)
+
async def ensure_system_dependencies(
self,
environment: BaseEnvironment,
@@ -69,6 +156,9 @@ class SkillEvaluatorCodex(Codex):
class SkillEvaluatorClaudeCode(ClaudeCode):
"""Avoid distribution Node/npm for Harbor's native Claude installer."""
+ async def install(self, environment: BaseEnvironment) -> None:
+ await _install_with_retries(self, super().install, environment)
+
async def ensure_system_dependencies(
self,
environment: BaseEnvironment,
diff --git a/tests/tier3/test_installed_agent_install_retry.py b/tests/tier3/test_installed_agent_install_retry.py
new file mode 100644
index 00000000..a2dc02bb
--- /dev/null
+++ b/tests/tier3/test_installed_agent_install_retry.py
@@ -0,0 +1,299 @@
+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+
+"""Retry a container agent CLI install that a transient failure stopped."""
+
+import asyncio
+import logging
+from pathlib import Path
+
+import pytest
+
+pytest.importorskip("harbor")
+
+from harbor.agents.installed.base import NetworkConnectionError, NonZeroAgentExitCodeError
+from harbor.agents.installed.claude_code import ClaudeCode
+from harbor.agents.installed.codex import Codex
+from harbor.environments.base import ExecResult
+
+from skillevaluator.tier3.harbor import installed_agents
+from skillevaluator.tier3.harbor.installed_agents import SkillEvaluatorClaudeCode, SkillEvaluatorCodex
+from skillevaluator.tier3.harbor.local_agents import SkillEvaluatorClaudeCode as ContainerClaudeCode
+from skillevaluator.tier3.harbor.local_agents import (
+ SkillEvaluatorGatewayCodex,
+ SkillEvaluatorLocalClaudeCode,
+ SkillEvaluatorLocalCodex,
+ SkillEvaluatorNvidiaBuildClaudeCode,
+ SkillEvaluatorNvidiaBuildCodex,
+)
+
+_INSTALLER_MARKERS = ("nvm install 22", "claude-code-releases/bootstrap.sh")
+_PACKAGE_INSTALL_MARKERS = ("apt-get install", "apk add")
+
+
+class _FakeClock:
+ def __init__(self) -> None:
+ self.now = 1000.0
+
+ def __call__(self) -> float:
+ return self.now
+
+
+class _FlakyEnvironment:
+ """Fail the vendor installer or the package install a set number of times."""
+
+ default_user = None
+
+ def __init__(
+ self,
+ *,
+ installer_failures: int = 0,
+ package_failures: int = 0,
+ system_npm: bool = False,
+ probe_result: ExecResult | None = None,
+ probe_error: Exception | None = None,
+ clock: _FakeClock | None = None,
+ installer_seconds: float = 0.0,
+ installer_stderr: str = "curl: (6) Could not resolve host: example.invalid",
+ ) -> None:
+ self.commands: list[str] = []
+ self.installer_failures = installer_failures
+ self.package_failures = package_failures
+ self.system_npm = system_npm
+ self.probe_result = probe_result
+ self.probe_error = probe_error
+ self.clock = clock
+ self.installer_seconds = installer_seconds
+ self.installer_stderr = installer_stderr
+ self.installed = False
+
+ def _count(self, markers: tuple[str, ...]) -> int:
+ return sum(any(marker in command for marker in markers) for command in self.commands)
+
+ @property
+ def installer_runs(self) -> int:
+ return self._count(_INSTALLER_MARKERS)
+
+ @property
+ def package_installs(self) -> int:
+ return self._count(_PACKAGE_INSTALL_MARKERS)
+
+ @property
+ def probes(self) -> int:
+ return sum(command.startswith("if ") and "printf" in command for command in self.commands)
+
+ async def exec(self, command: str, **_kwargs: object) -> ExecResult:
+ self.commands.append(command)
+ if command in (
+ Codex._INSTALL_CHECK_COMMAND,
+ ClaudeCode._INSTALL_CHECK_COMMAND,
+ Codex._INSTALL_VERSION_COMMAND,
+ ClaudeCode._INSTALL_VERSION_COMMAND,
+ ):
+ return ExecResult(return_code=0 if self.installed else 1, stdout="", stderr="")
+ if command.startswith("command -v ") and command.endswith(" >/dev/null 2>&1"):
+ missing = command.split()[2] in {"node", "npm"}
+ return ExecResult(return_code=1 if missing else 0, stdout="", stderr="")
+ if command.startswith("for manager in "):
+ return ExecResult(return_code=0, stdout="apk" if self.system_npm else "apt-get", stderr="")
+ if command.startswith("if ") and "printf" in command:
+ if self.probe_error is not None:
+ raise self.probe_error
+ if self.probe_result is not None:
+ return self.probe_result
+ return ExecResult(return_code=0, stdout="system" if self.system_npm else "bundled", stderr="")
+ if any(marker in command for marker in _PACKAGE_INSTALL_MARKERS):
+ if self.package_installs <= self.package_failures:
+ return ExecResult(
+ return_code=1,
+ stdout="",
+ stderr="WARNING: fetching https://dl-cdn.alpinelinux.org/alpine/APKINDEX.tar.gz: temporary error",
+ )
+ elif any(marker in command for marker in _INSTALLER_MARKERS):
+ if self.clock is not None:
+ self.clock.now += self.installer_seconds
+ if self.installer_runs <= self.installer_failures:
+ return ExecResult(return_code=6, stdout="", stderr=self.installer_stderr)
+ self.installed = True
+ return ExecResult(return_code=0, stdout="", stderr="")
+
+
+def clock(monkeypatch: pytest.MonkeyPatch) -> _FakeClock:
+ fake = _FakeClock()
+ monkeypatch.setattr(installed_agents, "monotonic", fake)
+ return fake
+
+
+def sleeps(monkeypatch: pytest.MonkeyPatch, clock: _FakeClock) -> list[float]:
+ delays: list[float] = []
+
+ async def record_sleep(delay: float) -> None:
+ delays.append(delay)
+ clock.now += delay
+
+ monkeypatch.setattr(installed_agents.asyncio, "sleep", record_sleep)
+ return delays
+
+
+_CONTAINER_AGENT_CLASSES = [
+ SkillEvaluatorCodex,
+ SkillEvaluatorClaudeCode,
+ SkillEvaluatorGatewayCodex,
+ SkillEvaluatorNvidiaBuildCodex,
+ SkillEvaluatorNvidiaBuildClaudeCode,
+ pytest.param(ContainerClaudeCode, id="ContainerClaudeCode"),
+]
+
+
[email protected]("agent_class", _CONTAINER_AGENT_CLASSES)
+def test_transient_installer_failure_is_retried(tmp_path: Path, agent_class: type, sleeps: list[float]) -> None:
+ environment = _FlakyEnvironment(installer_failures=1)
+ agent = agent_class(logs_dir=tmp_path, model_name="openai/test-model")
+
+ asyncio.run(agent.install(environment))
+
+ assert environment.installer_runs == 2
+ assert environment.installed
+ assert sleeps == [installed_agents._INSTALL_RETRY_BASE_DELAY_SEC]
+
+
[email protected]("agent_class", [SkillEvaluatorCodex, SkillEvaluatorClaudeCode])
+def test_persistent_installer_failure_stops_after_bounded_attempts(
+ tmp_path: Path, agent_class: type, sleeps: list[float]
+) -> None:
+ environment = _FlakyEnvironment(installer_failures=installed_agents._INSTALL_ATTEMPTS)
+ agent = agent_class(logs_dir=tmp_path, model_name="openai/test-model")
+
+ with pytest.raises(NetworkConnectionError, match="Could not resolve host"):
+ asyncio.run(agent.install(environment))
+
+ assert environment.installer_runs == installed_agents._INSTALL_ATTEMPTS
+ base_delay = installed_agents._INSTALL_RETRY_BASE_DELAY_SEC
+ assert sleeps == [base_delay, 2 * base_delay]
+
+
[email protected]("agent_class", [SkillEvaluatorCodex, SkillEvaluatorClaudeCode])
+def test_slow_installer_failure_is_not_retried(
+ tmp_path: Path, agent_class: type, clock: _FakeClock, sleeps: list[float]
+) -> None:
+ # A failure that used over a third of the setup timeout is raised as is,
+ # so Harbor does not replace it with its agent setup timeout.
+ agent = agent_class(logs_dir=tmp_path, model_name="openai/test-model")
+ budget = agent.DEFAULT_SETUP_TIMEOUT_SEC
+ environment = _FlakyEnvironment(
+ installer_failures=installed_agents._INSTALL_ATTEMPTS, clock=clock, installer_seconds=budget / 3 + 1
+ )
+
+ with pytest.raises(NetworkConnectionError, match="Could not resolve host"):
+ asyncio.run(agent.install(environment))
+
+ assert environment.installer_runs == 1
+ assert sleeps == []
+
+
[email protected]("agent_class", [SkillEvaluatorCodex, SkillEvaluatorClaudeCode])
+def test_retry_stops_when_another_attempt_would_exceed_setup_timeout(
+ tmp_path: Path, agent_class: type, clock: _FakeClock, sleeps: list[float]
+) -> None:
+ # Each attempt stays under a third of the budget, but a third attempt as
+ # long as the first two would end after the setup timeout.
+ agent = agent_class(logs_dir=tmp_path, model_name="openai/test-model")
+ budget = agent.DEFAULT_SETUP_TIMEOUT_SEC
+ environment = _FlakyEnvironment(
+ installer_failures=installed_agents._INSTALL_ATTEMPTS, clock=clock, installer_seconds=0.33 * budget
+ )
+
+ with pytest.raises(NetworkConnectionError, match="Could not resolve host"):
+ asyncio.run(agent.install(environment))
+
+ assert environment.installer_runs == 2
+ assert sleeps == [installed_agents._INSTALL_RETRY_BASE_DELAY_SEC]
+
+
+def test_retry_warning_keeps_the_end_of_the_failure_output(
+ tmp_path: Path, sleeps: list[float], caplog: pytest.LogCaptureFixture
+) -> None:
+ token = "abcd" * 6
+ stderr = "x" * 500 + f" Authorization: Bearer {token}\ncurl: (6) Could not resolve host: example.invalid"
+ environment = _FlakyEnvironment(installer_failures=1, installer_stderr=stderr)
+ agent = SkillEvaluatorCodex(logs_dir=tmp_path, model_name="openai/test-model")
+
+ with caplog.at_level(logging.WARNING):
+ asyncio.run(agent.install(environment))
+
+ warnings = [record.getMessage() for record in caplog.records if "install attempt" in record.getMessage()]
+ assert len(warnings) == 1
+ message = warnings[0]
+ assert "NetworkConnectionError" in message
+ assert "Could not resolve host" in message
+ assert token not in message
+ assert "\n" not in message
+ detail = message.split("retrying in 2s: ", 1)[1]
+ assert detail.startswith("...")
+ assert len(detail) == len("...") + installed_agents._INSTALL_FAILURE_DETAIL_CHARS
+
+
[email protected]("agent_class", [SkillEvaluatorCodex, SkillEvaluatorClaudeCode])
+def test_transient_system_package_failure_is_retried(tmp_path: Path, agent_class: type, sleeps: list[float]) -> None:
+ # The npm installer branch still needs distribution Node/npm from a mirror.
+ environment = _FlakyEnvironment(package_failures=1, system_npm=True)
+ agent = agent_class(logs_dir=tmp_path, model_name="openai/test-model")
+
+ asyncio.run(agent.install(environment))
+
+ assert environment.package_installs == 2
+ assert any("npm install -g" in command for command in environment.commands)
+ assert len(sleeps) == 1
+
+
[email protected]("agent_class", [SkillEvaluatorCodex, SkillEvaluatorClaudeCode])
+ ("probe_result", "probe_error", "expected"),
+ [
+ (ExecResult(return_code=0, stdout="unrecognized", stderr=""), None, RuntimeError),
+ (None, TimeoutError("probe transport timeout"), TimeoutError),
+ ],
+ ids=["unknown-platform", "probe-timeout"],
+)
+def test_platform_and_transport_errors_are_not_retried(
+ tmp_path: Path,
+ agent_class: type,
+ probe_result: ExecResult | None,
+ probe_error: Exception | None,
+ expected: type[Exception],
+ sleeps: list[float],
+) -> None:
+ environment = _FlakyEnvironment(probe_result=probe_result, probe_error=probe_error)
+ agent = agent_class(logs_dir=tmp_path, model_name="openai/test-model")
+
+ with pytest.raises(expected) as raised:
+ asyncio.run(agent.install(environment))
+
+ assert not isinstance(raised.value, NonZeroAgentExitCodeError)
+ assert environment.probes == 1
+ assert environment.installer_runs == 0
+ assert sleeps == []
+
+
[email protected]("agent_class", [SkillEvaluatorLocalCodex, SkillEvaluatorLocalClaudeCode])
+def test_local_agents_do_not_retry_a_missing_host_cli(tmp_path: Path, agent_class: type, sleeps: list[float]) -> None:
+ class _MissingCli:
+ default_user = None
+
+ def __init__(self) -> None:
+ self.commands: list[str] = []
+
+ async def exec(self, command: str, **_kwargs: object) -> ExecResult:
+ self.commands.append(command)
+ return ExecResult(return_code=127, stdout="", stderr="command not found")
+
+ environment = _MissingCli()
+ agent = agent_class(logs_dir=tmp_path, model_name="openai/test-model")
+
+ with pytest.raises(NonZeroAgentExitCodeError):
+ asyncio.run(agent.install(environment))
+
+ assert len(environment.commands) == 1
+ assert sleeps == []