Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/connections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"dependencies": {
"@corbits/credential-providers": "workspace:*",
"@corbits/error-sink": "workspace:*",
"@corbits/inference-settings": "workspace:*",
"@corbits/mcp-tools": "workspace:*",
"@intx/crypto": "0.3.0",
Expand Down
66 changes: 66 additions & 0 deletions packages/connections/src/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,72 @@ describe("disconnectConnector", () => {
expect(result.disconnected).toBe(false);
expect(calls.some((call) => call.method === "DELETE")).toBe(false);
});

test("a concurrent disconnect (catalog provider DELETE 404s because a first call already removed it) resolves instead of throwing", async () => {
const { api } = fakeDisconnectAPI(({ method, path }) => {
if (
method === "GET" &&
path === `/api/tenants/${TENANT_ID}/catalog/providers`
) {
return page([catalogProviderRow("mprv_1", "anthropic")]);
}
if (
method === "DELETE" &&
path === `/api/tenants/${TENANT_ID}/catalog/providers/mprv_1`
) {
return { status: 404, data: { error: { code: "not_found" } } };
}
if (
method === "GET" &&
path === `/api/tenants/${TENANT_ID}/providers?inherited=false`
) {
return page([]);
}
return undefined;
});

const result = await disconnectConnector(
api,
[],
{ tenantId: TENANT_ID, connectorId: "anthropic" },
() => {},
);

expect(result.disconnected).toBe(false);
});

test("a concurrent disconnect (provider DELETE 404s because a first call already removed it) resolves instead of throwing", async () => {
const { api } = fakeDisconnectAPI(({ method, path }) => {
if (
method === "GET" &&
path === `/api/tenants/${TENANT_ID}/catalog/providers`
) {
return page([]);
}
if (
method === "GET" &&
path === `/api/tenants/${TENANT_ID}/providers?inherited=false`
) {
return page([providerRow("prv_1", "anthropic")]);
}
if (
method === "DELETE" &&
path === `/api/tenants/${TENANT_ID}/providers/prv_1`
) {
return { status: 404, data: { error: { code: "not_found" } } };
}
return undefined;
});

const result = await disconnectConnector(
api,
[],
{ tenantId: TENANT_ID, connectorId: "anthropic" },
() => {},
);

expect(result.disconnected).toBe(false);
});
});

describe("DELETE /:connectorId/disconnect", () => {
Expand Down
28 changes: 23 additions & 5 deletions packages/connections/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from "@intx/types";
import type { RequireGrant, TenantEnv } from "@intx/hub-api";
import { hasUsableModel } from "@corbits/inference-settings";
import { reportError } from "@corbits/error-sink";
import {
cookiesFromHeader,
createHubAPI,
Expand Down Expand Up @@ -114,11 +115,17 @@ export async function disconnectConnector(
cookies,
);
if (deletedCatalogProvider.status !== 204) {
throw new Error(
`couldn't remove the catalog provider for ${args.connectorId} (status ${String(deletedCatalogProvider.status)})`,
if (deletedCatalogProvider.status !== 404) {
throw new Error(
`couldn't remove the catalog provider for ${args.connectorId} (status ${String(deletedCatalogProvider.status)})`,
);
}
log(
`catalog provider ${args.connectorId} was already removed (concurrent disconnect)`,
);
} else {
log(`removed catalog provider ${args.connectorId} and its offerings`);
}
log(`removed catalog provider ${args.connectorId} and its offerings`);
}

const providers = await api(
Expand All @@ -144,9 +151,15 @@ export async function disconnectConnector(
cookies,
);
if (deletedProvider.status !== 204) {
throw new Error(
`couldn't remove the provider row for ${args.connectorId} (status ${String(deletedProvider.status)})`,
if (deletedProvider.status !== 404) {
throw new Error(
`couldn't remove the provider row for ${args.connectorId} (status ${String(deletedProvider.status)})`,
);
}
log(
`provider ${args.connectorId} was already removed (concurrent disconnect)`,
);
return { disconnected: false };
}
log(`removed provider ${args.connectorId} and its credentials`);
return { disconnected: true };
Expand Down Expand Up @@ -581,6 +594,11 @@ export function createConnectionRoutes(
deps.log(
`disconnect failed for connector ${connectorId} on tenant ${tenant.id}: ${message}`,
);
reportError(cause, {
operation: "disconnect_connector",
tenantId: tenant.id,
extra: { connectorId },
});
return c.json(
ErrorEnvelope(
"disconnect_failed",
Expand Down
Loading