Skip to content

The agent that grows with you

fix(auth): read flat refresh_token for forkable pool rows; reuse pool ownership in load_pool

kshitijk4poor3dac1b3ae1f4
diff --git a/agent/credential_pool.py b/agent/credential_pool.py
index 74d6e63d69d..ee05500299e 100644
--- a/agent/credential_pool.py
+++ b/agent/credential_pool.py
@@ -3038,6 +3038,8 @@ def load_pool(provider: str) -> CredentialPool:
auth_mod.heal_forked_single_use_oauth_grants(provider)
raw_entries = read_credential_pool(provider)
disk_ids = {e.get("id") for e in raw_entries if isinstance(e, dict) and e.get("id")}
+ # Computed once (auth.json read) after the heal above; see reuse below.
+ owns_provider: Optional[bool] = None
changed = any(
isinstance(payload, dict) and sanitize_borrowed_credential_payload(payload, provider) != payload
for payload in raw_entries
@@ -3068,10 +3070,12 @@ def load_pool(provider: str) -> CredentialPool:
changed |= singleton_changed or env_changed
# ``load_pool()`` is a non-destructive read for env-seeded entries
# (#9331); file-backed singletons still prune when their file is gone.
+ if provider in SINGLE_USE_REFRESH_POOL_PROVIDERS and disk_ids:
+ owns_provider = _profile_owns_pool_provider(provider)
borrowing_root_grant = (
provider in SINGLE_USE_REFRESH_POOL_PROVIDERS
and bool(disk_ids)
- and not _profile_owns_pool_provider(provider)
+ and not owns_provider
)
if borrowing_root_grant:
# Rows read through the global-root fallback are seeded from the
@@ -3096,6 +3100,12 @@ def load_pool(provider: str) -> CredentialPool:
pool._persist(removed_ids=sorted(disk_ids - {entry.id for entry in entries}))
# Remember the root's borrowed rows so a later ``add_entry`` in this
# profile leaves them out of the profile's own store (#100339).
- if provider in SINGLE_USE_REFRESH_POOL_PROVIDERS and not _profile_owns_pool_provider(provider):
- pool._borrowed_root_ids = set(disk_ids)
+ if provider in SINGLE_USE_REFRESH_POOL_PROVIDERS:
+ # Reuse the pre-persist ownership answer unless _persist() just rewrote
+ # the store (it can give the profile its own rows); nothing else between
+ # the two checks touches auth.json.
+ if changed or owns_provider is None:
+ owns_provider = _profile_owns_pool_provider(provider)
+ if not owns_provider:
+ pool._borrowed_root_ids = set(disk_ids)
return pool
diff --git a/hermes_cli/auth_oauth_grants.py b/hermes_cli/auth_oauth_grants.py
index 96fb6ac0bf2..99be906b285 100644
--- a/hermes_cli/auth_oauth_grants.py
+++ b/hermes_cli/auth_oauth_grants.py
@@ -47,7 +47,8 @@ def _is_forkable_pool_row(provider_id: str, entry: Any) -> bool:
# write that block over root's shared row. Same refresh_token gate the block strip uses.
if not _is_oauth_pool_payload(entry):
return False
- return provider_id != "nous" or bool(_block_tokens(entry).get("refresh_token"))
+ # Pool rows are flat (no ``tokens`` nesting), so read refresh_token directly.
+ return provider_id != "nous" or bool(str(entry.get("refresh_token") or "").strip())
def _is_oauth_pool_payload(entry: Any) -> bool: