The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(connectors): a session retry with the open account's id is no longer refused
Siddharth Balyana1e78983d686
diff --git a/tests/tui_gateway/test_connector_accounts_rpc.py b/tests/tui_gateway/test_connector_accounts_rpc.pyindex 8e96d7209fc..4c332cb1ddf 100644--- a/tests/tui_gateway/test_connector_accounts_rpc.py+++ b/tests/tui_gateway/test_connector_accounts_rpc.py@@ -108,6 +108,36 @@ def test_a_session_retry_for_another_account_does_not_re_mint_the_open_one(monkeassert mints == []+def test_a_session_retry_with_the_open_accounts_id_reissues_it(monkeypatch):+ from tools.connectors.contract import Actor, TargetState+ from tools.connectors.operation import ConnectionOperation, Target++ transport = _Transport()+ session = dict(transport=transport, agent=None, session_key="retry-sid", history=[],+ history_lock=threading.Lock(), history_version=0, running=False, attached_images=[],+ source="desktop")+ monkeypatch.setitem(server._sessions, "retry-sid", session)+ monkeypatch.setattr("model_tools._select_tool_names", lambda *a, **k: {"manage_connections"})+ operation = ConnectionOperation([Target("gmail", "connector", "reconnect", alias="work")], session_key="retry-sid")+ live.open(operation)+ operation.transition("gmail", TargetState.initiated, Actor.backend_watcher, connect_url="https://l/1",+ connection_id="ca_work")+ operation.transition("gmail", TargetState.failed, Actor.backend_watcher, detail="expired")+ mints = []++ class Client:+ def connections(self, names, **kwargs):+ mints.append((tuple(names), kwargs.get("connection_id")))+ return {"results": [{"connector": n, "status": "initiated", "connect_url": "https://l/2",+ "connection_id": "ca_work2"} for n in names]}++ monkeypatch.setattr("tools.connectors.managed.managed_client", Client)+ reply = _rpc("connectors.connect", transport, owner={"type": "session", "session_id": "retry-sid"},+ connectors=["gmail"], reconnect=True, connection_id="ca_work")+ assert "result" in reply, reply+ assert mints == [(("gmail",), "ca_work")]++def test_rename_to_a_name_another_account_holds_is_alias_taken(monkeypatch):def taken(self, connection_id, alias):raise IdempotencyConflict("alias taken", code="alias_taken", status=409)diff --git a/tui_gateway/methods_connectors.py b/tui_gateway/methods_connectors.pyindex a2ae2d98636..54a21d0b8b2 100644--- a/tui_gateway/methods_connectors.py+++ b/tui_gateway/methods_connectors.py@@ -152,7 +152,7 @@ def _session_connector_rpc(rid, request, session, action):# A retry without an alias or id means the open target; one naming another account must not re-mint this one.if (request.alias is not None or request.connection_id is not None) and any((target := operation.target(name)) is not None- and (target.alias != request.alias+ and ((request.alias is not None and target.alias != request.alias)or request.connection_id not in (None, target.repair_id, target.connection_id))for name in request.connectors):return _connector_rpc_error(rid, 4004, ConnectorErrorReason.unknown_target, "No such target on the open operation.")