Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(composio): handle missing window.composio in connect flow

Steven Enamakeld30d18ff2244
diff --git a/app/src/components/composio/useComposioConnectFlow.ts b/app/src/components/composio/useComposioConnectFlow.ts
index 229d645fef..51bf2ee91e 100644
--- a/app/src/components/composio/useComposioConnectFlow.ts
+++ b/app/src/components/composio/useComposioConnectFlow.ts
@@ -101,9 +101,6 @@ export function useComposioConnectFlow({
? 'waiting'
: 'idle'
);
- if (initialState === 'pending' && connection && pendingConnectionIdRef.current === null) {
- pendingConnectionIdRef.current = connection.id;
- }
const [error, setError] = useState<string | null>(null);
const [connectUrl, setConnectUrl] = useState<string | null>(null);
const [clearMemoryOnDisconnect, setClearMemoryOnDisconnect] = useState(false);
@@ -260,6 +257,9 @@ export function useComposioConnectFlow({
// the user to click Connect again.
useEffect(() => {
if (initialState === 'pending') {
+ // Remember which connection the handoff belongs to so "Cancel" can
+ // delete it even though this mount never ran `authorize` itself.
+ if (connection) pendingConnectionIdRef.current = connection.id;
startPolling();
}
// intentionally run once on mount — startPolling has stable deps and
@@ -454,6 +454,60 @@ export function useComposioConnectFlow({
[savingScope, scopes, t, toolkit.slug]
);
+ /**
+ * Abandon an OAuth handoff that is still `waiting`.
+ *
+ * Closing the modal was previously the only way out, and it left the
+ * Composio connection sitting in `INITIATED`/`PENDING`: the tile kept
+ * reading "Connecting", reopening the modal resumed the poll, and the only
+ * real escape was waiting out the five-minute poll deadline. Cancelling
+ * deletes the pending connection through the same
+ * `openhuman.composio_delete_connection` RPC that Disconnect uses, so the
+ * toolkit genuinely returns to disconnected on the Composio side rather
+ * than just in local state.
+ *
+ * When the user was adding a second account to an already-connected
+ * toolkit, cancelling drops back to the `connected` view instead of `idle`
+ * — the existing accounts are untouched.
+ */
+ const handleCancelConnect = useCallback(async () => {
+ if (cancelInFlightRef.current) return;
+ cancelInFlightRef.current = true;
+ setCancelInFlight(true);
+ stopPolling();
+ setPhase('cancelling');
+ setError(null);
+
+ const pendingId = pendingConnectionIdRef.current;
+ console.debug(
+ '[composio][cancel] → toolkit=%s connection_id=%s',
+ toolkit.slug,
+ pendingId ?? 'none'
+ );
+ try {
+ if (pendingId) await deleteConnection(pendingId);
+ pendingConnectionIdRef.current = null;
+ setConnectUrl(null);
+ if (activeConnections.length > 0) {
+ setActiveConnection(activeConnections[0]);
+ setPhase('connected');
+ } else {
+ setActiveConnection(undefined);
+ setPhase('idle');
+ }
+ console.debug('[composio][cancel] ← toolkit=%s cancelled', toolkit.slug);
+ onChanged?.();
+ } catch (err) {
+ const msg = err instanceof Error ? err.message : String(err);
+ console.error('[composio][cancel] failed toolkit=%s error=%o', toolkit.slug, err);
+ setPhase('error');
+ setError(t('composio.connect.cancelFailed').replace('{msg}', msg));
+ } finally {
+ cancelInFlightRef.current = false;
+ setCancelInFlight(false);
+ }
+ }, [activeConnections, onChanged, stopPolling, t, toolkit.slug]);
+
const handleDisconnect = useCallback(
async (targetConnection?: ComposioConnection) => {
const conn = targetConnection ?? activeConnection;
@@ -504,9 +558,11 @@ export function useComposioConnectFlow({
scopeError,
savingScope,
connectInFlight,
+ cancelInFlight,
initiallyConnected,
initiallyExpired,
handleConnect,
+ handleCancelConnect,
handleToggleScope,
handleDisconnect,
};