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 <noreply@anthropic.com>
This commit is contained in:
1 parent
7934221403
commit
3c75c2296e
2 files changed
+7
-6
No files matched your search
@@ -73,7 +73,7 @@ class AsyncElydoraClient:
|
|||||||
self.token = token
|
self.token = token
|
||||||
|
|
||||||
self._prev_chain_hash = GENESIS_CHAIN_HASH
|
self._prev_chain_hash = GENESIS_CHAIN_HASH
|
||||||
self._kid = ""
|
self._kid = agent_id + '-key-1'
|
||||||
self._session: Optional[aiohttp.ClientSession] = None
|
self._session: Optional[aiohttp.ClientSession] = None
|
||||||
|
|
||||||
def set_kid(self, kid: str) -> None:
|
def set_kid(self, kid: str) -> None:
|
||||||
@@ -118,7 +118,7 @@ class AsyncElydoraClient:
|
|||||||
session = await self._get_session()
|
session = await self._get_session()
|
||||||
|
|
||||||
last_exc: Optional[Exception] = None
|
last_exc: Optional[Exception] = None
|
||||||
for attempt in range(self.max_retries):
|
for attempt in range(0, self.max_retries + 1):
|
||||||
try:
|
try:
|
||||||
async with session.request(
|
async with session.request(
|
||||||
method, url, json=json_body, params=params, headers=hdrs, timeout=aiohttp.ClientTimeout(total=30)
|
method, url, json=json_body, params=params, headers=hdrs, timeout=aiohttp.ClientTimeout(total=30)
|
||||||
@@ -128,7 +128,7 @@ class AsyncElydoraClient:
|
|||||||
raise
|
raise
|
||||||
except (aiohttp.ClientConnectionError, asyncio.TimeoutError) as exc:
|
except (aiohttp.ClientConnectionError, asyncio.TimeoutError) as exc:
|
||||||
last_exc = exc
|
last_exc = exc
|
||||||
if attempt < self.max_retries - 1:
|
if attempt < self.max_retries:
|
||||||
await asyncio.sleep(min(2 ** attempt, 8))
|
await asyncio.sleep(min(2 ** attempt, 8))
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -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
|
from __future__ import annotations
|
||||||
|
|
||||||
@@ -80,8 +80,10 @@ class OpenCodePlugin(AgentPlugin):
|
|||||||
|
|
||||||
def uninstall(self, agent_id: str = "") -> None:
|
def uninstall(self, agent_id: str = "") -> None:
|
||||||
plugin_path = self._plugin_path()
|
plugin_path = self._plugin_path()
|
||||||
if os.path.exists(plugin_path):
|
try:
|
||||||
os.remove(plugin_path)
|
os.remove(plugin_path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
# Hook script removal is handled by cli.py cmd_uninstall (rmtree of agent dir)
|
# Hook script removal is handled by cli.py cmd_uninstall (rmtree of agent dir)
|
||||||
print("Elydora hook uninstalled from OpenCode.")
|
print("Elydora hook uninstalled from OpenCode.")
|
||||||
|
|
||||||
@@ -298,5 +300,4 @@ module.exports = {{
|
|||||||
|
|
||||||
def _js_str(s: str) -> str:
|
def _js_str(s: str) -> str:
|
||||||
"""Escape a Python string for embedding as a JS string literal."""
|
"""Escape a Python string for embedding as a JS string literal."""
|
||||||
import json
|
|
||||||
return json.dumps(s)
|
return json.dumps(s)
|
||||||
Reference in new issue
Block a user