Skip to content

An open-source, faster Devin alternative

TypeScript

Slack setup: slack_setup_busy and slack_setup_cancelled

Igor Zalutskicc0cb12dc6eb
diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.ts
index 6c3ad9f7..bad21c8b 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts
@@ -1576,6 +1576,8 @@ describe("managed agents proxy", () => {
"slack_exchange_failed",
"slack_setup_not_authorizable",
"slack_setup_connected",
+ "slack_setup_busy",
+ "slack_setup_cancelled",
];
const GENERIC_MESSAGES = [
"The agent request could not be completed.",
@@ -1899,6 +1901,77 @@ describe("managed agents proxy", () => {
});
});
+ it("curates a busy cancel and a cancelled record", async () => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async () =>
+ Response.json(
+ { error: { code: "slack_setup_busy", message: "backend text" } },
+ { status: 409 },
+ ),
+ ),
+ );
+ const busy = await proxyManagedAgents(
+ new Request(
+ "https://app.opencomputer.dev/api/managed-agents/channels/slack/setups/setup_1/cancel",
+ { method: "POST" },
+ ),
+ env,
+ caller,
+ "/api/managed-agents",
+ );
+ expect(busy.status).toBe(409);
+ expect(await busy.json()).toEqual({
+ error: {
+ code: "slack_setup_busy",
+ message:
+ "This Slack setup is in progress. Wait for it to finish before cancelling.",
+ },
+ });
+
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async () =>
+ Response.json({
+ setup: {
+ ...backendSetup,
+ phase: "cancelled",
+ actions: [],
+ error: {
+ code: "slack_setup_cancelled",
+ message: "backend text",
+ recoverable: false,
+ at: "2026-09-18T08:00:00.000Z",
+ },
+ },
+ }),
+ ),
+ );
+ const cancelled = await proxyManagedAgents(
+ new Request(
+ "https://app.opencomputer.dev/api/managed-agents/channels/slack/setups/setup_1/cancel",
+ { method: "POST" },
+ ),
+ env,
+ caller,
+ "/api/managed-agents",
+ );
+ expect(await cancelled.json()).toEqual({
+ setup: {
+ ...publicSetup,
+ phase: "cancelled",
+ actions: [],
+ error: {
+ code: "slack_setup_cancelled",
+ message:
+ "This Slack setup was cancelled. The Slack app may still appear in your workspace's app list and can be removed there.",
+ recoverable: false,
+ at: "2026-09-18T08:00:00.000Z",
+ },
+ },
+ });
+ });
+
it("never lets a documented setup error fall to a generic message", async () => {
for (const code of SETUP_ERROR_CODES) {
for (const status of [400, 404, 409, 429, 503]) {
diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.ts
index 382c8432..2cdffa64 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.ts
@@ -157,6 +157,10 @@ const SLACK_SETUP_ERROR_MESSAGES: Record<string, string> = {
"This setup cannot be authorized in its current state. Reload to see its next step.",
slack_setup_connected:
"This setup is already connected and cannot be cancelled. Disconnect the Slack connection instead.",
+ slack_setup_busy:
+ "This Slack setup is in progress. Wait for it to finish before cancelling.",
+ slack_setup_cancelled:
+ "This Slack setup was cancelled. The Slack app may still appear in your workspace's app list and can be removed there.",
slack_authorization_denied:
"The Slack installation was declined. Authorize the app again when you are ready.",
slack_authorization_expired:
diff --git a/docs/agents/api.mdx b/docs/agents/api.mdx
index f6547c77..b003ffec 100644
--- a/docs/agents/api.mdx
+++ b/docs/agents/api.mdx
@@ -546,6 +546,8 @@ Error codes, as HTTP errors or as `error.code` on the setup:
| `slack_setup_not_found` | `404`: no setup with that id in this project |
| `slack_setup_not_authorizable` | `409` on authorize: the setup's phase does not allow it; read the setup for its next step |
| `slack_setup_connected` | `409` on cancel: the setup is connected; disconnect the connection instead |
+| `slack_setup_busy` | `409` on cancel: the setup is creating or exchanging; wait for it to finish |
+| `slack_setup_cancelled` | Recorded on a setup cancelled after the app was created or its creation was uncertain: the Slack app may still appear in the workspace's app list and can be removed there |
| `slack_configuration_token_invalid`, `slack_configuration_token_expired` | The token was rejected; generate a new one and submit it with the same key |
| `slack_manifest_rejected` | Slack rejected the generated app configuration; `pointer` names the field |
| `slack_app_limit_reached` | The workspace cannot hold another app |
diff --git a/web/src/managed-agents/Slack.test.tsx b/web/src/managed-agents/Slack.test.tsx
index eca167ce..8b78e750 100644
--- a/web/src/managed-agents/Slack.test.tsx
+++ b/web/src/managed-agents/Slack.test.tsx
@@ -829,4 +829,51 @@ describe('ManagedProjectSlack', () => {
.map((mutation) => JSON.stringify(mutation.state))
expect(states.join('\n')).not.toContain('xoxe.xoxp-secret-token')
})
+
+ it('shows the cancellation message on a cancelled setup and offers a fresh start', async () => {
+ api.findManagedSlackSetup.mockResolvedValue(
+ setup({
+ phase: 'app_created',
+ app: { id: 'A1', name: 'Patch' },
+ actions: ['authorize', 'cancel'],
+ }),
+ )
+ const message =
+ "This Slack setup was cancelled. The Slack app may still appear in your workspace's app list and can be removed there."
+ api.cancelManagedSlackSetup.mockResolvedValue(
+ setup({
+ phase: 'cancelled',
+ app: { id: 'A1', name: 'Patch' },
+ actions: [],
+ error: {
+ code: 'slack_setup_cancelled',
+ message,
+ recoverable: false,
+ at: '2026-09-18T08:00:00.000Z',
+ },
+ }),
+ )
+ render()
+ await settle(() => buttons(container).includes('Cancel setup'), 'resume')
+ act(() => button(container, 'Cancel setup').click())
+ await settle(
+ () => document.body.querySelector('[role="alertdialog"]') !== null,
+ 'the confirmation',
+ )
+ act(() =>
+ button(
+ document.body.querySelector('[role="alertdialog"]') as HTMLElement,
+ 'Cancel setup',
+ ).click(),
+ )
+ await settle(
+ () => text().includes('Setup cancelled'),
+ 'the cancelled state',
+ )
+ expect(api.cancelManagedSlackSetup).toHaveBeenCalledWith('setup_1')
+ expect(text()).toContain(message)
+ expect(buttons(container)).toContain('Create Slack bot')
+ expect(buttons(container)).not.toContain('Authorize in Slack')
+ expect(buttons(container)).not.toContain('Cancel setup')
+ })
})
diff --git a/web/src/managed-agents/Slack.tsx b/web/src/managed-agents/Slack.tsx
index dc4f980e..be44de69 100644
--- a/web/src/managed-agents/Slack.tsx
+++ b/web/src/managed-agents/Slack.tsx
@@ -392,17 +392,15 @@ function SlackAutomaticSetup({
}
const cancel = useMutation({
mutationFn: (setupId: string) => cancelManagedSlackSetup(setupId),
- onSuccess: () => {
+ onSuccess: (cancelled) => {
setConfirmCancel(false)
- queryClient.setQueryData(queryKey, null)
- void queryClient.invalidateQueries({ queryKey })
+ // The cancelled record stays on screen with the platform's message
+ // until the next lookup, which answers only non-cancelled setups.
+ queryClient.setQueryData(queryKey, cancelled)
void queryClient.invalidateQueries({
queryKey: ['managed-agent-channels'],
})
- notifySuccess(
- 'Slack setup cancelled.',
- 'If Slack already created the app, it is still in your Slack app list.',
- )
+ notifySuccess('Slack setup cancelled.', cancelled.error?.message)
},
onError: (error) => notifyError("Couldn't cancel the Slack setup.", error),
})
@@ -465,7 +463,10 @@ function SlackAutomaticSetup({
}
const view = describeSlackSetup(setup)
- const actions = setup?.actions ?? ['create']
+ // A cancelled record is shown for its message only; a new setup starts
+ // fresh, with its own request key.
+ const resumable = setup && setup.phase !== 'cancelled' ? setup : undefined
+ const actions = resumable?.actions ?? ['create']
const busy = view.tone === 'pending' || setupQuery.isLoading
const showCreate =
view.primary?.action === 'create' && actions.includes('create')
@@ -524,11 +525,11 @@ function SlackAutomaticSetup({
{view.primary!.label}
</Button>
) : null}
- {showAuthorize && setup ? (
+ {showAuthorize && resumable ? (
<Button
size="sm"
disabled={authorize.isPending}
- onClick={() => startAuthorization(setup.id)}
+ onClick={() => startAuthorization(resumable.id)}
>
{authorize.isPending ? (
<Loader2 className="animate-spin" />
@@ -543,7 +544,7 @@ function SlackAutomaticSetup({
</a>
</Button>
) : null}
- {setup && actions.includes('cancel') ? (
+ {resumable && actions.includes('cancel') ? (
<Button
size="sm"
variant="ghost"
@@ -558,8 +559,8 @@ function SlackAutomaticSetup({
{dialogOpen ? (
<SlackSetupDialog
target={target}
- setup={setup ?? undefined}
- defaultName={setup?.name ?? agentName}
+ setup={resumable}
+ defaultName={resumable?.name ?? agentName}
slotLabel={
slot.dedicated
? `${agentName} · ${environment}`
@@ -578,7 +579,7 @@ function SlackAutomaticSetup({
cancelLabel="Keep"
destructive
pending={cancel.isPending}
- onConfirm={() => setup && cancel.mutate(setup.id)}
+ onConfirm={() => resumable && cancel.mutate(resumable.id)}
/>
</div>
)
diff --git a/web/src/managed-agents/slack-setup.test.ts b/web/src/managed-agents/slack-setup.test.ts
index 75a12f61..0d7e6d7d 100644
--- a/web/src/managed-agents/slack-setup.test.ts
+++ b/web/src/managed-agents/slack-setup.test.ts
@@ -359,6 +359,29 @@ describe('setup copy', () => {
).toBeUndefined()
})
+ it('shows the platform message on a cancelled setup and offers a fresh start', () => {
+ const message =
+ "This Slack setup was cancelled. The Slack app may still appear in your workspace's app list and can be removed there."
+ expect(
+ describeSlackSetup(
+ setup({
+ phase: 'cancelled',
+ actions: [],
+ error: {
+ code: 'slack_setup_cancelled',
+ message,
+ recoverable: false,
+ at: '2026-09-18T08:00:00.000Z',
+ },
+ }),
+ ),
+ ).toMatchObject({
+ title: 'Setup cancelled',
+ description: message,
+ primary: { action: 'create', label: 'Create Slack bot' },
+ })
+ })
+
it('separates connected credentials from the first received message', () => {
expect(describeSlackVerification(connection(), 'Patch').state).toBe(
'waiting',
diff --git a/web/src/managed-agents/slack-setup.ts b/web/src/managed-agents/slack-setup.ts
index b8a11a7e..f6868702 100644
--- a/web/src/managed-agents/slack-setup.ts
+++ b/web/src/managed-agents/slack-setup.ts
@@ -161,7 +161,19 @@ function retryAfter(ms?: number) {
export function describeSlackSetup(
setup: ManagedSlackSetup | null | undefined,
): SlackSetupView {
- if (!setup || setup.phase === 'cancelled') {
+ if (setup?.phase === 'cancelled') {
+ // The record carries what a cancellation leaves behind: possibly an app
+ // in the workspace's app list, which the platform never deletes.
+ return {
+ title: 'Setup cancelled',
+ description:
+ setup.error?.message ??
+ "The Slack app may still appear in your workspace's app list and can be removed there.",
+ tone: 'idle',
+ primary: { action: 'create', label: 'Create Slack bot' },
+ }
+ }
+ if (!setup) {
return {
title: 'Not connected',
description: