From 3c75c2296ed4111b59d058242077ff0d5ff00726 Mon Sep 17 00:00:00 2001 From: Zachary Date: Mon, 2 Mar 2026 20:23:44 -0500 Subject: [PATCH] Simplify review: fix async retry off-by-one, TOCTOU, and stale docstring - Mirror client.py retry fix in async_client.py (range + boundary alignment) - Sync _kid default to agent_id + '-key-1' in async client - Fix TOCTOU in opencode.py uninstall (try/except vs exists+remove) - Update docstring to reflect new plugin path and filename - Remove redundant deferred json import in _js_str Co-Authored-By: Claude Opus 4.6 --- elydora/async_client.py | 6 +++--- elydora/plugins/opencode.py | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/elydora/async_client.py b/elydora/async_client.py index ff741b4..cae1d40 100644 --- a/elydora/async_client.py +++ b/elydora/async_client.py @@ -73,7 +73,7 @@ class AsyncElydoraClient: self.token = token self._prev_chain_hash = GENESIS_CHAIN_HASH - self._kid = "" + self._kid = agent_id + '-key-1' self._session: Optional[aiohttp.ClientSession] = None def set_kid(self, kid: str) -> None: @@ -118,7 +118,7 @@ class AsyncElydoraClient: session = await self._get_session() last_exc: Optional[Exception] = None - for attempt in range(self.max_retries): + for attempt in range(0, self.max_retries + 1): try: async with session.request( method, url, json=json_body, params=params, headers=hdrs, timeout=aiohttp.ClientTimeout(total=30) @@ -128,7 +128,7 @@ class AsyncElydoraClient: raise except (aiohttp.ClientConnectionError, asyncio.TimeoutError) as exc: last_exc = exc - if attempt < self.max_retries - 1: + if attempt < self.max_retries: await asyncio.sleep(min(2 ** attempt, 8)) continue raise diff --git a/elydora/plugins/opencode.py b/elydora/plugins/opencode.py index b3f4a10..df4334e 100644 --- a/elydora/plugins/opencode.py +++ b/elydora/plugins/opencode.py @@ -1,4 +1,4 @@ -"""OpenCode plugin — writes .opencode/plugins/elydora-audit.js (JS plugin).""" +"""OpenCode plugin — writes ~/.config/opencode/plugins/elydora-audit.mjs (JS plugin).""" from __future__ import annotations @@ -80,8 +80,10 @@ class OpenCodePlugin(AgentPlugin): def uninstall(self, agent_id: str = "") -> None: plugin_path = self._plugin_path() - if os.path.exists(plugin_path): + try: os.remove(plugin_path) + except FileNotFoundError: + pass # Hook script removal is handled by cli.py cmd_uninstall (rmtree of agent dir) print("Elydora hook uninstalled from OpenCode.") @@ -298,5 +300,4 @@ module.exports = {{ def _js_str(s: str) -> str: """Escape a Python string for embedding as a JS string literal.""" - import json return json.dumps(s)