From b3a1900e72a16da450ff637aaa37cc23f68992a6 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Wed, 23 Sep 2026 19:11:23 +0530 Subject: [PATCH] refactor(gateway): reuse utils.file_signature for the pairing cache key Also collapse the artifact-store lock lookup to a single setdefault. --- gateway/pairing.py | 4 ++-- gateway/platforms/api_server.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/gateway/pairing.py b/gateway/pairing.py index 9cd80007a9..c009aa9d5d 100644 --- a/gateway/pairing.py +++ b/gateway/pairing.py @@ -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] diff --git a/gateway/platforms/api_server.py b/gateway/platforms/api_server.py index bcbb9c0c8a..a418ee5625 100644 --- a/gateway/platforms/api_server.py +++ b/gateway/platforms/api_server.py @@ -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: