@devries-cameron20 / composio-1 / commits / 0b1b33d24
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(cli): use 'UNKNOWN' sentinel for unrecognized connection statuses

`normalizeConnectedAccountStatus` was coercing any value outside the known status set to `'INACTIVE'`. That misled selection helpers like `resolveDefaultConnectedAccountsByToolkit`, since `'INACTIVE'` carries a specific meaning ("user-disabled"). When Apollo introduces a new status (REVOKED was added in PR #9550; S2S_OAUTH2 revocation is queued), every account with that status would silently be tagged as user-disabled rather than honestly labeled as unrecognized. Introduce a `'UNKNOWN'` sentinel exposed via a new `SelectableConnectedAccount` type (a CLI-internal widening of `ConnectedAccountItem` that the selection helpers accept). Selection still picks only `'ACTIVE'` accounts, so any other label is filtered out; `'UNKNOWN'` rows are not selectable, but the original server value is logged via `Effect.logWarning` so users notice and can upgrade. Addresses PR #3344 review comment P2#8.

jkomyno committed May 7, 2026 at 10:24 UTC 0b1b33d24a6c9843d9d137a26b3bcfc0737f06b6
2 files changed +83 -53
ts/packages/cli/src/services/connected-account-selection.ts
+19 -7
@@ -1,5 +1,17 @@
1 import type { ConnectedAccountItem } from 'src/models/connected-accounts';
2
3 +/**
4 + * `ConnectedAccountItem` widened to allow an `'UNKNOWN'` status sentinel
5 + * used by the CLI when the server returns a status the schema does not
6 + * recognize (e.g. a newly-added Apollo enum value). Selection helpers only
7 + * pick `'ACTIVE'` accounts, so any other label — including `'UNKNOWN'` —
8 + * is filtered out, but storing the honest sentinel avoids falsely tagging
9 + * the row as `'INACTIVE'` (which means "user-disabled" specifically).
10 + */
11 +export type SelectableConnectedAccount = Omit<ConnectedAccountItem, 'status'> & {
12 + readonly status: ConnectedAccountItem['status'] | 'UNKNOWN';
13 +};
14 +
15 export type CachedConnectedAccountSummary = {
16 readonly id: string;
17 readonly alias: string | null;
@@ -31,7 +43,7 @@ const compareSummaryNewestFirst = (
43 Math.max(parseTimestamp(left.updatedAt), parseTimestamp(left.createdAt));
44
45 export const isUsableConnectedAccount = (
34 - item: Pick<ConnectedAccountItem, 'status' | 'is_disabled'>
46 + item: Pick<SelectableConnectedAccount, 'status' | 'is_disabled'>
47 ): boolean => item.status === 'ACTIVE' && !item.is_disabled;
48
49 export const toCachedConnectedAccountSummary = (
@@ -45,7 +57,7 @@ export const toCachedConnectedAccountSummary = (
57 });
58
59 export const groupCachedConnectedAccountsByToolkit = (
48 - items: ReadonlyArray<ConnectedAccountItem>
60 + items: ReadonlyArray<SelectableConnectedAccount>
61 ): Record<string, ReadonlyArray<CachedConnectedAccountSummary>> => {
62 const grouped = new Map<string, CachedConnectedAccountSummary[]>();
63
@@ -68,9 +80,9 @@ export const groupCachedConnectedAccountsByToolkit = (
80 };
81
82 export const resolveDefaultConnectedAccountsByToolkit = (
71 - items: ReadonlyArray<ConnectedAccountItem>
83 + items: ReadonlyArray<SelectableConnectedAccount>
84 ): Record<string, string> => {
73 - const grouped = new Map<string, ConnectedAccountItem[]>();
85 + const grouped = new Map<string, SelectableConnectedAccount[]>();
86
87 for (const item of items) {
88 if (!isUsableConnectedAccount(item)) continue;
@@ -92,10 +104,10 @@ export const resolveDefaultConnectedAccountsByToolkit = (
104 );
105 };
106
95 -export const resolveConnectedAccountSelection = (
96 - items: ReadonlyArray<ConnectedAccountItem>,
107 +export const resolveConnectedAccountSelection = <T extends SelectableConnectedAccount>(
108 + items: ReadonlyArray<T>,
109 selector?: string
98 -): ConnectedAccountItem | undefined => {
110 +): T | undefined => {
111 const usable = items.filter(isUsableConnectedAccount).sort(compareNewestFirst);
112 if (usable.length === 0) return undefined;
113
ts/packages/cli/src/services/tool-router-session-connections.ts
+64 -46
@@ -3,8 +3,8 @@ import type { Composio } from '@composio/client';
3 import {
4 groupCachedConnectedAccountsByToolkit,
5 resolveDefaultConnectedAccountsByToolkit,
6 + type SelectableConnectedAccount,
7 } from 'src/services/connected-account-selection';
7 -import type { ConnectedAccountItem } from 'src/models/connected-accounts';
8
9 type RawConnectedAccount = {
10 readonly id: string;
@@ -48,7 +48,7 @@ const parseTimestamp = (value?: string | null): number => {
48
49 const normalizeConnectedAccountStatus = (
50 status?: string | null
51 -): ConnectedAccountItem['status'] => {
51 +): SelectableConnectedAccount['status'] => {
52 switch (status) {
53 case 'INITIALIZING':
54 case 'INITIATED':
@@ -59,7 +59,10 @@ const normalizeConnectedAccountStatus = (
59 case 'REVOKED':
60 return status;
61 default:
62 - return 'INACTIVE';
62 + // Apollo can introduce new statuses at any time. Use a sentinel
63 + // (`'UNKNOWN'`) instead of coercing to `'INACTIVE'`, which would
64 + // falsely tag the account as user-disabled in selection logic.
65 + return 'UNKNOWN';
66 }
67 };
68
@@ -91,15 +94,20 @@ export const resolveToolRouterSessionConnections = (
94 limit: 1000,
95 })
96 ).pipe(
94 - Effect.map(response => {
95 - const items = (response.items ?? []) as ReadonlyArray<RawConnectedAccount>;
96 - const normalizedItems: ConnectedAccountItem[] = items.map(
97 - item =>
98 - ({
97 + Effect.flatMap(response =>
98 + Effect.gen(function* () {
99 + const items = (response.items ?? []) as ReadonlyArray<RawConnectedAccount>;
100 + const unknownStatuses = new Set<string>();
101 + const normalizedItems: SelectableConnectedAccount[] = items.map(item => {
102 + const normalizedStatus = normalizeConnectedAccountStatus(item.status);
103 + if (normalizedStatus === 'UNKNOWN' && item.status) {
104 + unknownStatuses.add(item.status);
105 + }
106 + return {
107 id: item.id,
108 alias: item.alias ?? null,
109 word_id: item.word_id ?? null,
102 - status: normalizeConnectedAccountStatus(item.status),
110 + status: normalizedStatus,
111 status_reason: null,
112 is_disabled: item.is_disabled ?? false,
113 user_id: item.user_id ?? '',
@@ -115,50 +123,60 @@ export const resolveToolRouterSessionConnections = (
123 created_at: item.created_at ?? '',
124 updated_at: item.updated_at ?? '',
125 test_request_endpoint: '',
118 - }) satisfies ConnectedAccountItem
119 - );
120 - const connectedToolkits = new Set<string>();
121 - const explicitAccountsByToolkit = new Map<string, RawConnectedAccount>();
126 + } satisfies SelectableConnectedAccount;
127 + });
128
123 - for (const item of items) {
124 - const toolkit = item.toolkit?.slug?.toLowerCase().trim();
125 - if (!toolkit || item.is_disabled) continue;
129 + if (unknownStatuses.size > 0) {
130 + yield* Effect.logWarning(
131 + `[ToolRouterSession] received unrecognized connected_account.status ` +
132 + `value(s): ${[...unknownStatuses].join(', ')}. Treating as 'UNKNOWN' ` +
133 + `(not selectable). Run "composio upgrade" to pick up the latest schema.`
134 + );
135 + }
136
127 - connectedToolkits.add(toolkit);
137 + const connectedToolkits = new Set<string>();
138 + const explicitAccountsByToolkit = new Map<string, RawConnectedAccount>();
139
129 - // Tool Router already handles Composio-managed auth well.
130 - // Explicitly pin non-managed auth configs/accounts so consumer sessions
131 - // can execute against custom-auth toolkits like PostHog.
132 - if (item.auth_config?.is_composio_managed !== false) {
133 - continue;
134 - }
140 + for (const item of items) {
141 + const toolkit = item.toolkit?.slug?.toLowerCase().trim();
142 + if (!toolkit || item.is_disabled) continue;
143 +
144 + connectedToolkits.add(toolkit);
145
136 - const current = explicitAccountsByToolkit.get(toolkit);
137 - if (!current || isNewerAccount(item, current)) {
138 - explicitAccountsByToolkit.set(toolkit, item);
146 + // Tool Router already handles Composio-managed auth well.
147 + // Explicitly pin non-managed auth configs/accounts so consumer sessions
148 + // can execute against custom-auth toolkits like PostHog.
149 + if (item.auth_config?.is_composio_managed !== false) {
150 + continue;
151 + }
152 +
153 + const current = explicitAccountsByToolkit.get(toolkit);
154 + if (!current || isNewerAccount(item, current)) {
155 + explicitAccountsByToolkit.set(toolkit, item);
156 + }
157 }
140 - }
158
142 - const authConfigs: Record<string, string> = {};
143 - for (const [toolkit, item] of explicitAccountsByToolkit) {
144 - const authConfigId = item.auth_config?.id?.trim();
145 - if (!authConfigId) continue;
146 - authConfigs[toolkit] = authConfigId;
147 - }
159 + const authConfigs: Record<string, string> = {};
160 + for (const [toolkit, item] of explicitAccountsByToolkit) {
161 + const authConfigId = item.auth_config?.id?.trim();
162 + if (!authConfigId) continue;
163 + authConfigs[toolkit] = authConfigId;
164 + }
165
149 - return {
150 - connectedToolkits: [...connectedToolkits],
151 - authConfigs: Object.keys(authConfigs).length > 0 ? authConfigs : undefined,
152 - connectedAccounts: (() => {
153 - const selected = resolveDefaultConnectedAccountsByToolkit(normalizedItems);
154 - return Object.keys(selected).length > 0 ? selected : undefined;
155 - })(),
156 - availableConnectedAccounts: (() => {
157 - const grouped = groupCachedConnectedAccountsByToolkit(normalizedItems);
158 - return Object.keys(grouped).length > 0 ? grouped : undefined;
159 - })(),
160 - } satisfies ToolRouterSessionConnectionContext;
161 - }),
166 + return {
167 + connectedToolkits: [...connectedToolkits],
168 + authConfigs: Object.keys(authConfigs).length > 0 ? authConfigs : undefined,
169 + connectedAccounts: (() => {
170 + const selected = resolveDefaultConnectedAccountsByToolkit(normalizedItems);
171 + return Object.keys(selected).length > 0 ? selected : undefined;
172 + })(),
173 + availableConnectedAccounts: (() => {
174 + const grouped = groupCachedConnectedAccountsByToolkit(normalizedItems);
175 + return Object.keys(grouped).length > 0 ? grouped : undefined;
176 + })(),
177 + } satisfies ToolRouterSessionConnectionContext;
178 + })
179 + ),
180 Effect.catchAll(() =>
181 Effect.succeed({
182 connectedToolkits: [],