The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(cron): rename the worker boot marker and correct the pin's docs
kshitijk4pooreb65fff28562
diff --git a/cron/AGENTS.md b/cron/AGENTS.mdindex 05c2b3aaed8..dc62aff75cb 100644--- a/cron/AGENTS.md+++ b/cron/AGENTS.md@@ -72,12 +72,13 @@ Hardening invariants — each guards a real failure; don't weaken without answerin `served_profiles`, so a bare liveness answer would stand cron down host-wide.- **The restart-safe external worker boots itself.** `_launch_external_cron_worker` pins thecheckout — and, on a PM install, the committed generation's `site-packages` — on the child's- `PYTHONPATH` and marks it `HERMES_CRON_EXTERNAL_WORKER`; the child's own entry- (`cron/__init__.py` → `cron/worker_bootstrap.py`, ahead of the `cron.jobs` import) then runs PM's `activate_dependencies`,- which leases that generation for the worker's lifetime and activates it before the first- application import. Neither half is redundant (the pin is what the child can import through,- the boot is what keeps the generation alive and its `.pth` files executed) and the gateway- never re-runs the boot — `hermes_bootstrap` already did at its own launch (#122222).+ `PYTHONPATH` and marks it `_HERMES_CRON_WORKER_BOOT`; the child's package entry+ (`cron/__init__.py` → `cron/worker_bootstrap.py`, ahead of the `cron.jobs` import — `-m+ cron.scheduler` runs the package first) then runs PM's `activate_dependencies`, which+ leases the committed generation for the worker's lifetime, runs its `.pth` files and+ activates it before the first third-party import. The pin is the fallback the worker still+ imports through if that boot fails; the gateway never re-runs the boot — `hermes_bootstrap`+ already did at its own launch (#122222).- Cron sessions pass `skip_memory=True`; memory providers intentionally do not run during cron.- Cron execution has its own session. Eligible continuable deliveries may mirror or seed thereply-facing conversation: origin, origin-less home fallback, user-written bare-platform home,diff --git a/cron/scheduler_worker_env.py b/cron/scheduler_worker_env.pyindex d74327b1a7c..5f470df367e 100644--- a/cron/scheduler_worker_env.py+++ b/cron/scheduler_worker_env.py@@ -71,7 +71,9 @@ def pin_hermes_tree_on_pythonpath(worker_env: dict, repo_root: Path) -> dict:and pinning it would move site-packages ahead of the stdlib on ``sys.path``.Order (checkout, generation, sanitizer-kept) mirrors ``activate_dependencies``' own- ``sys.path``, so the worker resolves every module exactly as the gateway did.+ ``sys.path``. The worker's boot (``cron/worker_bootstrap.py``) re-selects and leases the+ committed generation before any third-party import; this pin is what the worker still+ imports through if that boot fails."""root = str(repo_root)if _installed_purelib() == Path(root).resolve():diff --git a/cron/worker_bootstrap.py b/cron/worker_bootstrap.pyindex 9ef63a9b535..0a74ece6c9e 100644--- a/cron/worker_bootstrap.py+++ b/cron/worker_bootstrap.py@@ -32,9 +32,8 @@ logger = logging.getLogger(__name__)# Set by ``_launch_external_cron_worker`` in the child's env and consumed here, so it never# reaches the worker's own children -- they inherit the activated PYTHONPATH instead.-WORKER_MARKER = "HERMES_CRON_EXTERNAL_WORKER"--_root = Path(__file__).resolve().parent.parent+# Distinct from ``_HERMES_CRON_EXTERNAL_WORKER`` (the owning execution id) in scheduler.py.+WORKER_MARKER = "_HERMES_CRON_WORKER_BOOT"def worker_bootstrap() -> None:@@ -44,6 +43,6 @@ def worker_bootstrap() -> None:try:from pm.environments import activate_dependencies- activate_dependencies(_root)+ activate_dependencies(Path(__file__).resolve().parent.parent)except Exception as exc:logger.warning("cron external worker dependency activation failed: %s", exc)diff --git a/tests/cron/test_restart_safe_worker.py b/tests/cron/test_restart_safe_worker.pyindex 1fb04780ed9..d150a418d38 100644--- a/tests/cron/test_restart_safe_worker.py+++ b/tests/cron/test_restart_safe_worker.py@@ -648,7 +648,6 @@ def test_launch_external_worker_pin_extends_the_sanitized_env_not_os_environ(assert "PYTHONPATH" not in worker_env_mod.pin_hermes_tree_on_pythonpath({}, repo_root)-def test_pin_restores_the_committed_generation_site_packages(tmp_path):"""#122222: the sanitizer drops the generation ``activate_dependencies`` put on our``sys.path``, and the worker inherits the store Python, which owns no dependencies. The@@ -691,7 +690,7 @@ import pm.environmentsboots = []pm.environments.activate_dependencies = lambda root: boots.append("cron.jobs" in sys.modules)import cron-print(json.dumps({"boots": boots, "marker": os.environ.get("HERMES_CRON_EXTERNAL_WORKER")}))+print(json.dumps({"boots": boots, "marker": os.environ.get(sys.argv[1])}))"""@@ -710,7 +709,7 @@ def test_marked_worker_boots_dependencies_before_cron_jobs(marked):if marked:env[worker_bootstrap.WORKER_MARKER] = "1"child = subprocess.run(- [sys.executable, "-c", _BOOT_ORDER_PROBE],+ [sys.executable, "-c", _BOOT_ORDER_PROBE, worker_bootstrap.WORKER_MARKER],cwd=repo_root, env=env, capture_output=True, text=True, timeout=60,)assert child.returncode == 0, child.stderr