28
# 2026-05-08 / 2026-07-03 retirement when the auth config is Composio-managed.
29
_LEGACY_RETIRING_OAUTH_SCHEMES = frozenset({"OAUTH1", "OAUTH2", "DCR_OAUTH"})
30
31
+# Mirrors the TS contract (`ConnectionRequest.ts` `terminalErrorStates`):
32
+# FAILED / EXPIRED / REVOKED are credentials-gone states and should raise
33
+# immediately rather than poll until timeout. INACTIVE is intentionally
34
+# excluded — it means "user disabled, can be reactivated", and a connection
35
+# can briefly transit through it before settling on ACTIVE.
36
+_TERMINAL_CONNECTION_STATES: t.FrozenSet[str] = frozenset(
37
+ {"FAILED", "EXPIRED", "REVOKED"}
38
+)
39
+
40
# One-time-per-process guard so long-running services don't spam the deprecation
41
# warning on every initiate() call.
42
_legacy_initiate_warning_emitted = False
83
"""
84
timeout = self.DEFAULT_WAIT_TIMEOUT if timeout is None else timeout
85
deadline = time.time() + timeout
77
- # Mirror the TS contract (`ConnectionRequest.ts` `terminalErrorStates`):
78
- # FAILED / EXPIRED / REVOKED are terminal — credentials are gone and
79
- # cannot transition back to ACTIVE without a fresh auth flow, so
80
- # polling until timeout is wasted wall-clock time.
81
- # INACTIVE is intentionally NOT terminal: it means "user disabled, can
82
- # be reactivated", and a connection can briefly transit through it
83
- # before settling on ACTIVE — failing fast there would regress callers.
84
- terminal_states = ("FAILED", "EXPIRED", "REVOKED")
86
while deadline > time.time():
87
connection = self._client.connected_accounts.retrieve(nanoid=self.id)
88
self.status = connection.status
89
if self.status == "ACTIVE":
90
return connection
90
- if self.status in terminal_states:
91
+ if self.status in _TERMINAL_CONNECTION_STATES:
92
raise exceptions.SDKError(
93
message=(
94
f"Connection {self.id} entered terminal state "