The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): an unusable token-lock dir keeps the adapter retryable, so a token-only gateway stays up
Tekniume541f21ed811
diff --git a/gateway/platforms/base.py b/gateway/platforms/base.pyindex 8fb0c9aaed4..e185a78e799 100644--- a/gateway/platforms/base.py+++ b/gateway/platforms/base.py@@ -2198,16 +2198,18 @@ class BasePlatformAdapter(ABC):try:acquired, existing = acquire_scoped_lock(scope, identity, metadata=lock_meta)except ScopedLockDirUnusable as exc:- # An ACL no retry can change (an elevated install created the lock dir, #134889 W2):- # stay down with the repair named instead of a reconnect loop that fails identically.- # The status module already logged the WARNING (once per dir).+ # An ACL an elevated install left on the lock dir (#134889 W2): name the repair. Stay+ # RETRYABLE: the dir is shared by every token-locked adapter, so a non-retryable park+ # on a gateway that runs only those exits 78 and takes cron and the Desktop attach+ # endpoint down with it. The status module logs the WARNING once per dir (DEBUG after),+ # so the watcher's backoff retries quietly and picks the repair up without a restart.self._platform_lock_identity = Noneself._set_fatal_error("lock_dir_unusable",f"{resource_desc} lock cannot be taken: the gateway lock directory {exc.filename} is not "f"usable by this user (likely created by an elevated Hermes). To repair, "- f"{unusable_dir_remedy(exc.filename)}, then restart the gateway.",- retryable=False)+ f"{unusable_dir_remedy(exc.filename)}; the gateway retries on its own.",+ retryable=True)return Falseif acquired:return Truediff --git a/tests/gateway/test_scoped_lock_dir_unusable.py b/tests/gateway/test_scoped_lock_dir_unusable.pyindex 222f7cb5b96..247f86e91b5 100644--- a/tests/gateway/test_scoped_lock_dir_unusable.py+++ b/tests/gateway/test_scoped_lock_dir_unusable.py@@ -5,6 +5,7 @@ leading cause is a ``gateway-locks`` dir created by an elevated install. The POShere is real, not patched: a lock dir without write permission for this uid. The Windows ACL shapeitself is proved by ``test_scoped_lock_dir_windows_acl.py`` on Windows CI."""+import asyncioimport loggingimport osimport stat@@ -16,6 +17,7 @@ import pytestfrom gateway import statusfrom gateway.platforms.base import BasePlatformAdapterfrom gateway.restart import is_global_startup_conflict+from gateway.run_startup import GatewayStartupMixinpytestmark = pytest.mark.skipif(os.name == "nt" or os.geteuid() == 0, # windows-footgun: ok — skipped on ntreason="POSIX mode bits; root ignores them")@@ -68,7 +70,9 @@ def test_unusable_lock_dir_parks_the_adapter_with_the_repair(locked_out_dir, capassert _adapter()._acquire_platform_lock("telegram-bot-token", "tok", "Telegram bot token") is Falseassert adapter._fatal_error_code == "lock_dir_unusable"- assert adapter._fatal_error_retryable is False+ # Retryable: the shared lock dir parks EVERY token-locked adapter at once, and a non-retryable+ # park on a Telegram-only gateway exits 78 (taking cron and the Desktop attach endpoint down).+ assert adapter._fatal_error_retryable is Trueassert not is_global_startup_conflict(adapter._fatal_error_code)assert str(locked_out_dir) in adapter._fatal_error_messageassert "chown" in adapter._fatal_error_message@@ -101,3 +105,46 @@ def test_unreadable_stale_token_lock_is_named_not_reported_as_a_holderless_conflfinally:lock_dir.chmod(stat.S_IRWXU)stale.chmod(stat.S_IRUSR | stat.S_IWUSR)+++class _StartupProbe:+ """Only the state the two real startup decisions read; their bodies run unchanged."""++ _startup_queue_transient_failure = GatewayStartupMixin._startup_queue_transient_failure+ _start_aggregate_connect_results = GatewayStartupMixin._start_aggregate_connect_results+ _start_handle_no_connections = GatewayStartupMixin._start_handle_no_connections+ _startup_retry_entry = GatewayStartupMixin._startup_retry_entry++ def __init__(self):+ self._failed_platforms, self.status_updates, self.fatal = {}, [], []+ self._startup_parked_platforms = False++ async def _safe_adapter_disconnect(self, adapter, platform):+ pass++ def _update_platform_runtime_status(self, name, **kw):+ self.status_updates.append((name, kw))++ def _reconnect_queue_entry(self, platform, adapter, platform_config, **kw):+ return {"adapter": adapter, **kw}++ def _startup_fail_fatal_config(self, reason):+ self.fatal.append(reason)+++def test_a_sole_token_locked_platform_on_an_unusable_lock_dir_keeps_the_gateway_up(locked_out_dir, monkeypatch):+ """Review 2.1 on #140490: a Telegram-only gateway must not exit 78 over the lock dir."""+ import gateway.run as run_mod+ monkeypatch.setattr(run_mod, "_write_runtime_status_quiet", lambda **k: None, raising=False)+ adapter = _adapter()+ assert adapter._acquire_platform_lock("telegram-bot-token", "tok", "Telegram bot token") is False+ platform = MagicMock(value="telegram")+ runner = _StartupProbe()+ retryable, nonretryable = [], []+ connected = asyncio.run(runner._start_aggregate_connect_results(+ [(platform, adapter, MagicMock(), "failed", None)], retryable, nonretryable))+ must_exit = runner._start_handle_no_connections(connected, 1, retryable, nonretryable)++ assert (connected, must_exit, nonretryable, runner.fatal) == (0, False, [], [])+ assert platform in runner._failed_platforms # the reconnect watcher picks the repair up+ assert retryable and "not usable" in retryable[0]diff --git a/tests/test_hermes_dir_acl_windows.py b/tests/test_hermes_dir_acl_windows.pyindex 765c2b8779e..5223150727c 100644--- a/tests/test_hermes_dir_acl_windows.py+++ b/tests/test_hermes_dir_acl_windows.py@@ -234,7 +234,7 @@ def _w2(lock_dir):if lvl == "WARNING" and "not usable" in m]}))""", str(lock_dir), prelude=_DROP_PRIVILEGES)for ok, code, retryable, message in result["codes"]:- assert (ok, code, retryable) == (False, "lock_dir_unusable", False)+ assert (ok, code, retryable) == (False, "lock_dir_unusable", True)assert "icacls" in message and "/reset" in message and str(lock_dir) in messageassert len(result["warnings"]) == 1, result