Skip to content

The agent that grows with you

docs+test: pin lease worst-case trade-off and cover all arm sites (OOF-298 review follow-ups)

Shannon Sands5a264f9a58c3
diff --git a/hermes_state.py b/hermes_state.py
index 80896812e3c..c3dea52e278 100644
--- a/hermes_state.py
+++ b/hermes_state.py
@@ -3505,6 +3505,9 @@ def repair_state_db_schema(db_path: Path, *, backup: bool = True) -> Dict[str, A
# Startup-watchdog progress lease: repair (raw backup copy + surgery +
# VACUUM) is I/O-bound — near-zero CPU on a multi-GB file — which the
# watchdog's CPU fallback would misread as a parked deadlock (OOF-298).
+ # Single lease is deliberate (clamped to _MAX_LEASE_S=900): honest worst
+ # case is up to the lease duration of zombie time on a wedged repair,
+ # accepted over per-chunk renewal complexity in the repair loop.
report_startup_progress(900.0, phase="state_db_repair")
db_path = Path(db_path)
diff --git a/hermes_state_schema.py b/hermes_state_schema.py
index c6252fe33b8..9813b12785d 100644
--- a/hermes_state_schema.py
+++ b/hermes_state_schema.py
@@ -977,6 +977,12 @@ class SessionSchemaMixin:
# version-gated data migrations below are legitimately slow and can
# be I/O-bound (near-zero CPU), which the watchdog's CPU fallback
# would misread as a parked deadlock (OOF-298 / PR #89750).
+ # Single lease is deliberate: this is the one pre-loop phase that can
+ # legitimately exceed the 300s default deadline (multi-GB DBs), and
+ # the lease is clamped to _MAX_LEASE_S=900. Honest worst case: a
+ # genuinely wedged DB init delays supervisor respawn by up to the
+ # lease duration. Per-chunk renewal would shrink that, but adds
+ # complexity to the migration loops for a rare failure mode.
report_startup_progress(600.0, phase="state_db_init_schema")
cursor = self._conn.cursor()
@@ -1078,6 +1084,9 @@ class SessionSchemaMixin:
current_version = row["version"] if isinstance(row, sqlite3.Row) else row[0]
# Renew the progress lease: the version-gated chain below can
# rewrite whole tables (PK rebuilds, backfills) on large DBs.
+ # Same deliberate single-lease trade-off as _init_schema: honest
+ # worst case is up to the lease duration of zombie time on a
+ # wedged migration, accepted over per-chunk renewal complexity.
report_startup_progress(600.0, phase="state_db_data_migrations")
# Data migrations that can't be expressed declaratively (row
# backfills, index changes tied to a specific version step) stay
diff --git a/tests/gateway/test_startup_watchdog.py b/tests/gateway/test_startup_watchdog.py
index 2d09adc1529..0b7296976d3 100644
--- a/tests/gateway/test_startup_watchdog.py
+++ b/tests/gateway/test_startup_watchdog.py
@@ -125,6 +125,53 @@ class TestContracts:
offenders.append(name)
assert offenders == []
+ def test_all_documented_entry_points_arm_the_watchdog(self):
+ """Every documented arm site must actually call arm_startup_watchdog,
+ so a future entry point can't silently ship unwatched. This is a
+ structural contract: the arm sites are the whole point of the
+ pre-loop coverage, and they're spread across four files."""
+ import ast
+ import inspect
+ from pathlib import Path
+
+ repo_root = Path(__file__).resolve().parents[2]
+ arm_sites = {
+ # (file, reason) — each must contain an arm_startup_watchdog call
+ "hermes_cli/main.py": "argv fast-path (standard `hermes gateway run`)",
+ "hermes_cli/gateway.py": "run_gateway() config-bridge re-arm",
+ "gateway/run.py": "gateway.run.main() backstop arm",
+ "cli.py": "legacy `--gateway` entry point",
+ }
+ for rel, reason in arm_sites.items():
+ path = repo_root / rel
+ assert path.exists(), f"arm site file missing: {rel} ({reason})"
+ source = path.read_text()
+ tree = ast.parse(source)
+ # Collect both direct calls and aliased imports (main.py uses
+ # `from hermes_startup_watchdog import arm_startup_watchdog as _arm_sw`
+ # then calls `_arm_sw()` to keep the fast-path import-light).
+ aliases = set()
+ for node in ast.walk(tree):
+ if isinstance(node, ast.ImportFrom) and node.module == "hermes_startup_watchdog":
+ for alias in node.names:
+ if alias.name == "arm_startup_watchdog":
+ aliases.add(alias.asname or "arm_startup_watchdog")
+ calls = []
+ for node in ast.walk(tree):
+ if isinstance(node, ast.Call):
+ fn = node.func
+ name = (
+ fn.id
+ if isinstance(fn, ast.Name)
+ else fn.attr
+ if isinstance(fn, ast.Attribute)
+ else None
+ )
+ if name in aliases or name == "arm_startup_watchdog":
+ calls.append(node.lineno)
+ assert calls, f"{rel} has no arm_startup_watchdog call ({reason})"
+
+
class TestConfigResolution:
def test_default_timeout(self):