refactor(gateway): reuse utils.file_signature for the pairing cache key

Also collapse the artifact-store lock lookup to a single setdefault.
This commit is contained in:
kshitijk4poor
2026-09-23 19:11:23 +05:30
committed by kshitij
parent 709aaf9764
commit b3a1900e72
2 changed files with 3 additions and 5 deletions

View File

@@ -20,7 +20,7 @@ from typing import Optional
from gateway.whatsapp_identity import expand_whatsapp_aliases, normalize_whatsapp_identifier
from hermes_constants import get_default_hermes_root, get_hermes_dir, get_hermes_home
from utils import atomic_json_write
from utils import atomic_json_write, file_signature
logger = logging.getLogger(__name__)
@@ -379,7 +379,7 @@ class PairingStore:
# fstat identifies the actual opened file even during atomic replacement.
with path.open("rb") as stream:
st = os.fstat(stream.fileno())
key = (st.st_dev, st.st_ino, st.st_mtime_ns, st.st_ctime_ns, st.st_size)
key = (st.st_dev, *file_signature(st))
cached = self._approved_cache.get(platform)
if cached is not None and cached[0] == key:
return cached[1]

View File

@@ -2646,9 +2646,7 @@ class APIServerAdapter(OpenAICompatRoutesMixin, BasePlatformAdapter):
store = self._browser_control_artifacts.get(profile_key)
if store is not None:
return store
lock = self._browser_control_artifact_locks.get(profile_key)
if lock is None:
lock = self._browser_control_artifact_locks.setdefault(profile_key, asyncio.Lock())
lock = self._browser_control_artifact_locks.setdefault(profile_key, asyncio.Lock())
async with lock:
store = self._browser_control_artifacts.get(profile_key)
if store is not None: