@devries-cameron20 / composio-1 / commits / ed3bb936d
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(connected-accounts-py): address review feedback on #3412

Six code-review nits from the multi-agent review on PR #3412: P1.1 — python/setup.py was still pinning composio-client==1.36.0 while pyproject.toml is on 1.39.0. The Experimental TypedDict that the new link() docstring imports only exists in 1.39+, so anyone installing via the legacy setup.py path would crash at import. Bumped to 1.39.0. P1.2 — exceptions.py ComposioSharedAccessDeniedError and ComposioSharedConnectionNotAccessibleError docstrings told users to call composio.connected_accounts.update_acl(), which no longer exists. Rewrote both to composio.experimental.update_acl(). P2.5 — ExperimentalAPI.update_acl returned t.Any; restored the typed ConnectedAccountPatchResponse return so callers reading .id / .status / .success keep type-safety at the API boundary. P2.6 — ExperimentalAPI.__init__(client: Optional[Any]) tightened to Optional[HttpClient]. The None branch stays for the one test that exercises it; production code in sdk.py always passes a real client. P2.7 — Dropped redundant alias=omit / connection=omit on the patch() call. Verified against the composio-client==1.39.0 wheel: both default to omit. Sibling ConnectedAccounts.update() already follows the cleaner pattern. Test assertions updated to match. P2.10 — Extracted the substring "acl_config_for_shared is only valid on SHARED" into ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT in experimental.py, and reused it from connected_accounts.py + tool_router_session.py. Single source of truth so a server-side message tweak doesn't silently downgrade three call sites to generic BadRequestError. Tests: 201/201 pass. mypy on composio/ clean. Pushed back on the remaining P2 (TS divergence) in the review — the companion TS PR #3424 ships the exact same restructure, so parity is preserved once both land together. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

venkat82 committed May 13, 2026 at 18:22 UTC ed3bb936d26acceb2ee4e82f63d923fc2e60d5e7
6 files changed +29 -18
python/composio/core/models/connected_accounts.py
+2 -1
@@ -21,6 +21,7 @@ from composio.client.types import (
21 )
22
23 from .base import Resource
24 +from .experimental import ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT
25
26 logger = logging.getLogger(__name__)
27
@@ -647,7 +648,7 @@ class ConnectedAccounts:
648 # as a typed error so callers can ``except`` instead of grepping
649 # messages.
650 message = str(error)
650 - if "acl_config_for_shared is only valid on SHARED" in message:
651 + if ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT in message:
652 raise exceptions.ComposioAclOnlyForSharedError(message) from error
653 raise
654
python/composio/core/models/experimental.py
+22 -7
@@ -20,6 +20,12 @@ import typing as t
20
21 from pydantic import BaseModel
22
23 +from composio.client import HttpClient
24 +from composio.client.types import (
25 + connected_account_patch_params,
26 + connected_account_patch_response,
27 +)
28 +
29 from .custom_tool import (
30 CustomTool,
31 ExperimentalToolkit,
@@ -27,6 +33,12 @@ from .custom_tool import (
33 _infer_tool_from_function,
34 )
35
36 +# Server-side 400 message the API uses to reject ACL writes against a
37 +# PRIVATE connection. Substring-matched in `update_acl` here and in the
38 +# sibling `link()` / `authorize()` call sites — kept as a single constant
39 +# so a server-side message tweak only requires one edit.
40 +ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT = "acl_config_for_shared is only valid on SHARED"
41 +
42
43 class ExperimentalAPI:
44 """Experimental APIs accessed via ``composio.experimental``.
@@ -38,7 +50,7 @@ class ExperimentalAPI:
50
51 Toolkit = ExperimentalToolkit
52
41 - def __init__(self, client: t.Optional[t.Any] = None) -> None:
53 + def __init__(self, client: t.Optional[HttpClient] = None) -> None:
54 self._client = client
55
56 def update_acl(
@@ -48,7 +60,7 @@ class ExperimentalAPI:
60 allow_all_users: t.Optional[bool] = None,
61 allowed_user_ids: t.Optional[t.List[str]] = None,
62 not_allowed_user_ids: t.Optional[t.List[str]] = None,
51 - ) -> t.Any:
63 + ) -> connected_account_patch_response.ConnectedAccountPatchResponse:
64 """
65 Update the per-user ACL on a SHARED connected account. Experimental —
66 shape may change in future releases.
@@ -75,7 +87,7 @@ class ExperimentalAPI:
87 not_allowed_user_ids=['user_bob'],
88 )
89 """
78 - from composio_client import BadRequestError, omit
90 + from composio_client import BadRequestError
91
92 from composio import exceptions
93
@@ -105,13 +117,16 @@ class ExperimentalAPI:
117 try:
118 return self._client.connected_accounts.patch(
119 nanoid,
108 - experimental={"acl_config_for_shared": acl},
109 - alias=omit,
110 - connection=omit,
120 + experimental={
121 + "acl_config_for_shared": t.cast(
122 + connected_account_patch_params.ExperimentalACLConfigForShared,
123 + acl,
124 + ),
125 + },
126 )
127 except BadRequestError as error:
128 message = str(error)
114 - if "acl_config_for_shared is only valid on SHARED" in message:
129 + if ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT in message:
130 raise exceptions.ComposioAclOnlyForSharedError(message) from error
131 raise
132
python/composio/core/models/tool_router_session.py
+2 -1
@@ -36,6 +36,7 @@ from composio.client.types import Tool
36 from composio.core.models._modifiers import Modifiers, apply_modifier_by_type
37 from composio.core.models.connected_accounts import ConnectionRequest
38 from composio.core.models.custom_tool import find_custom_tool_map_entry_by_final_slug
39 +from composio.core.models.experimental import ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT
40 from composio.core.models.custom_tool_execution import (
41 execute_custom_tool,
42 find_custom_tool,
@@ -565,7 +566,7 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
566 # The server rejects ACL on PRIVATE connections — surface that
567 # as a typed error mirroring ``composio.connected_accounts.link()``.
568 message = str(error)
568 - if "acl_config_for_shared is only valid on SHARED" in message:
569 + if ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT in message:
570 raise exceptions.ComposioAclOnlyForSharedError(message) from error
571 raise
572
python/composio/exceptions.py
+2 -2
@@ -353,7 +353,7 @@ class ComposioSharedAccessDeniedError(ConnectedAccountError):
353 going through a tool-router session.
354
355 Fix: ask the connection's creator to grant access via
356 - ``composio.connected_accounts.update_acl()`` — set ``allow_all_users``,
356 + ``composio.experimental.update_acl()`` — set ``allow_all_users``,
357 add the ``user_id`` to ``allowed_user_ids``, or remove it from
358 ``not_allowed_user_ids``.
359 """
@@ -368,7 +368,7 @@ class ComposioSharedConnectionNotAccessibleError(ConnectedAccountError):
368 that fails mid-execution.
369
370 Fix: grant the session user access via
371 - ``composio.connected_accounts.update_acl()`` on the pinned connection,
371 + ``composio.experimental.update_acl()`` on the pinned connection,
372 or pin a different connection the user can use.
373 """
374
python/setup.py
+1 -1
@@ -25,7 +25,7 @@ setup(
25 install_requires=[
26 "pysher>=1.0.8",
27 "pydantic>=2.6.4",
28 - "composio-client==1.36.0",
28 + "composio-client==1.39.0",
29 "typing-extensions>=4.0.0",
30 "openai",
31 "json-schema-to-pydantic>=0.4.8",
python/tests/test_connected_accounts.py
-6
@@ -687,8 +687,6 @@ class TestConnectedAccountsAcl:
687 "not_allowed_user_ids": ["user_bob"],
688 }
689 },
690 - alias=omit,
691 - connection=omit,
690 )
691 assert result is response
692
@@ -700,8 +698,6 @@ class TestConnectedAccountsAcl:
698 experimental={
699 "acl_config_for_shared": {"allowed_user_ids": ["user_alice"]}
700 },
703 - alias=omit,
704 - connection=omit,
701 )
702
703 def test_update_acl_preserves_empty_array(self, experimental, mock_client):
@@ -710,8 +706,6 @@ class TestConnectedAccountsAcl:
706 mock_client.connected_accounts.patch.assert_called_once_with(
707 "ca_abc",
708 experimental={"acl_config_for_shared": {"allowed_user_ids": []}},
713 - alias=omit,
714 - connection=omit,
709 )
710
711 def test_update_acl_rejects_all_none(self, experimental, mock_client):