The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(auth): keep agent_key-only nous pool rows when stripping/healing forks
kshitijk4poore61c45bc2d6b
diff --git a/hermes_cli/auth_oauth_grants.py b/hermes_cli/auth_oauth_grants.pyindex 1ccfd5b5db4..96fb6ac0bf2 100644--- a/hermes_cli/auth_oauth_grants.py+++ b/hermes_cli/auth_oauth_grants.py@@ -41,6 +41,15 @@ def _block_tokens(block: Dict[str, Any]) -> Dict[str, Any]:return tokens if isinstance(tokens, dict) else block+def _is_forkable_pool_row(provider_id: str, entry: Any) -> bool:+ # An agent_key-only nous row carries no single-use refresh token: it is not a fork, and+ # stripping it while its providers block survives lets the profile's next load_pool('nous')+ # 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"))++def _is_oauth_pool_payload(entry: Any) -> bool:if not isinstance(entry, dict):return False@@ -106,7 +115,7 @@ def strip_cloned_single_use_oauth_grants(profile_dir: Path) -> Dict[str, Any]:if (provider_id not in SINGLE_USE_REFRESH_POOL_PROVIDERSor not isinstance(entries, list)):continue- kept = [e for e in entries if not _is_oauth_pool_payload(e)]+ kept = [e for e in entries if not _is_forkable_pool_row(provider_id, e)]if len(kept) != len(entries):changed = Truestripped["pool"].append(provider_id)@@ -449,8 +458,9 @@ class _HealPass:def heal_pool_rows(self) -> None:kept_rows: List[Any] = []for row in self.p_rows:- if not _is_oauth_pool_payload(row):- kept_rows.append(row) # API keys are safe to duplicate+ if not _is_forkable_pool_row(self.provider_id, row):+ # API keys (and agent_key-only nous rows) are safe to duplicate+ kept_rows.append(row)continuematch_idx = _find_root_counterpart(row, self.r_rows)if match_idx is not None:diff --git a/tests/agent/test_credential_pool_profile_oauth_fork.py b/tests/agent/test_credential_pool_profile_oauth_fork.pyindex 3797c5a15f2..c88cc061bea 100644--- a/tests/agent/test_credential_pool_profile_oauth_fork.py+++ b/tests/agent/test_credential_pool_profile_oauth_fork.py@@ -155,21 +155,33 @@ def test_strip_helper_drops_device_code_blocks_and_reports(tmp_path):assert "openai-codex" not in store["providers"] and "nous" in store["providers"]-def test_strip_helper_drops_cloned_nous_refresh_grant(tmp_path):- """Nous refresh tokens rotate on use: a cloned pool row or providers block is a fork (#121649)."""- from hermes_cli.auth import strip_cloned_single_use_oauth_grants+def test_strip_helper_drops_cloned_nous_refresh_grant(tmp_path, fleet):+ """Nous refresh tokens rotate on use: a cloned pool row or providers block is a fork (#121649).++ agent_key-only nous rows carry no single-use grant and must survive both strip and heal.+ """+ from hermes_cli.auth import heal_forked_single_use_oauth_grants, strip_cloned_single_use_oauth_grantspdir = tmp_path / "p"pdir.mkdir()grant = {"access_token": "AT1", "refresh_token": "RT1", "agent_key": "AK"}+ ak_row = {"id": "ak", "source": "device_code", "auth_type": "oauth", "agent_key": "PAK"}(pdir / "auth.json").write_text(json.dumps({"version": 1,"providers": {"nous": dict(grant)},- "credential_pool": {"nous": [dict(grant, id="n", source="device_code", auth_type="oauth")]},+ "credential_pool": {"nous": [dict(grant, id="n", source="device_code", auth_type="oauth"), ak_row]},}))summary = strip_cloned_single_use_oauth_grants(pdir)store = json.loads((pdir / "auth.json").read_text())assert (summary["pool"], summary["providers"]) == (["nous"], ["nous"])- assert "nous" not in store["credential_pool"] and "nous" not in store["providers"]+ assert store["credential_pool"]["nous"] == [ak_row] and "nous" not in store["providers"]++ # Heal: a fork living only in the providers block (flat nous tokens, shared RT) is dropped.+ (fleet["root"] / "auth.json").write_text(json.dumps({"version": 1, "providers": {"nous": dict(grant)}}))+ kid = _profile(fleet, "nousfork")+ (kid / "auth.json").write_text(json.dumps({"version": 1, "providers": {"nous": dict(grant)}}))+ fleet["use"](kid)+ assert heal_forked_single_use_oauth_grants("nous")["providers_block"] is True+ assert "nous" not in json.loads((kid / "auth.json").read_text())["providers"]def test_strip_helper_is_a_noop_without_credentials(tmp_path):