fix(auth): route the borrowed-root add_entry write through the token-base boundary

The profile-claims-its-own-credential branch of add_entry wrote the
profile store directly, so the newly owned rows had no recorded token
base until the next pre-refresh sync, and a stale peer could not be told
apart from an unknown one on the first later flush. Pass the current bases
and reseed from the written rows, mirroring _persist().
This commit is contained in:
kshitijk4poor
2026-09-24 14:26:27 +05:30
committed by kshitij
parent 9e66e405cf
commit 80d8d28392

View File

@@ -109,6 +109,7 @@ class CredentialPoolAdminMixin:
def add_entry(self, entry: PooledCredential) -> PooledCredential:
from agent.credential_pool import _next_priority, write_credential_pool
from hermes_cli import auth as auth_mod
with self._lock:
entry = replace(entry, priority=_next_priority(self._entries))
@@ -121,7 +122,11 @@ class CredentialPoolAdminMixin:
# its single-use refresh token (#100339). Once the profile owns
# rows, the root fallback for this provider is shadowed.
self._entries = [e for e in self._entries if e.id not in borrowed_ids]
write_credential_pool(self.provider, [e.to_dict() for e in self._entries])
written = write_credential_pool(
self.provider, [e.to_dict() for e in self._entries],
token_bases=self._persisted_token_pairs,
)
self._persisted_token_pairs = auth_mod._token_pairs_by_id(written)
self._borrowed_root_ids = set()
else:
self._persist()