The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(connectors): Try again on a named account repairs the account it minted
Siddharth Balyan6569c1bdde06
diff --git a/tests/tools/test_connector_accounts.py b/tests/tools/test_connector_accounts.pyindex 454b7e49f9a..880422d7ed2 100644--- a/tests/tools/test_connector_accounts.py+++ b/tests/tools/test_connector_accounts.py@@ -128,6 +128,20 @@ def test_reconnect_of_a_name_no_account_has_yet_sends_the_alias():assert gateway.mints == [{"connectors": ("gmail",), "reinitiate": True, "alias": "work"}]+def test_try_again_on_a_named_account_repairs_the_account_it_minted_not_the_name(monkeypatch):+ from tools.connectors import run+ from tools.connectors.contract import Actor, TargetState++ gateway = _Gateway()+ monkeypatch.setattr("tools.connectors.managed.managed_client", lambda: gateway)+ operation = op.ConnectionOperation([op.Target("gmail", "connector", "reconnect", alias="work")], session_key="s1")+ operation.transition("gmail", TargetState.initiated, Actor.backend_watcher, connection_id="ca_work")+ operation.transition("gmail", TargetState.failed, Actor.backend_watcher, detail="expired")+ with patch("tools.connectors.gateway.client.session_platform", return_value="desktop"):+ assert run.reissue(operation, ["gmail"]) is None+ assert gateway.mints == [{"connectors": ("gmail",), "reinitiate": True, "alias": None, "connection_id": "ca_work"}]++def test_reconnect_with_an_alias_mints_nothing_when_the_account_list_cannot_be_read():from tools.connectors.gateway.errors import ToolGatewayErrordiff --git a/tools/connectors/managed.py b/tools/connectors/managed.pyindex 359debfa60a..83b2117dfaa 100644--- a/tools/connectors/managed.py+++ b/tools/connectors/managed.py@@ -64,13 +64,18 @@ def mint(client: Any, operation: ConnectionOperation, names: list[str], *, reini"""Mint links for ``names`` and apply the gateway's per-app answer to the operation. ``actor`` isthe watcher on the first mint and the user on Try again. The operation id rides along so thevendor's done page can name it on the way back to the desktop. ``connection_id`` names the one- existing account a repair restarts; the gateway then needs no alias to find it."""+ existing account a repair restarts; the gateway then needs no alias to find it. A repair without+ one (Try again) reuses the account the named target already minted, so a rename in between+ cannot point the retry at another login."""from tools.connectors.gateway.client import return_to_argsif not names:return- # One aliased target per call, so the alias of the first named target is the request's.- alias = None if connection_id else next((t.alias for t in operation.targets if t.name in names and t.alias), None)+ # One aliased target per call, so the first named target is the request's.+ named = next((t for t in operation.targets if t.name in names and t.alias), None)+ if reinitiate and connection_id is None and named is not None:+ connection_id = named.connection_id+ alias = None if connection_id or named is None else named.aliasresponse = client.connections(names, reinitiate=reinitiate, alias=alias, connection_id=connection_id,**return_to_args(op=operation.op_id))for entry in response.get("results", []):