Skip to content

An open-source, faster Devin alternative

TypeScript

Slack: blocked manual completion points at the automated setup

Igor Zalutskiee9b2a5bad81
diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.ts
index bad21c8b..2466ab08 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts
@@ -1578,6 +1578,7 @@ describe("managed agents proxy", () => {
"slack_setup_connected",
"slack_setup_busy",
"slack_setup_cancelled",
+ "slack_manual_completion_blocked",
];
const GENERIC_MESSAGES = [
"The agent request could not be completed.",
@@ -1901,6 +1902,50 @@ describe("managed agents proxy", () => {
});
});
+ it("curates a blocked manual completion on the connection route", async () => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async () =>
+ Response.json(
+ {
+ error: {
+ code: "slack_manual_completion_blocked",
+ message: "backend text with setup_private",
+ },
+ },
+ { status: 409 },
+ ),
+ ),
+ );
+
+ const response = await proxyManagedAgents(
+ new Request(
+ "https://app.opencomputer.dev/api/managed-agents/channels/slack/connections/channel_slack",
+ {
+ method: "PUT",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ appId: "A1",
+ signingSecret: "s",
+ botToken: "xoxb-1",
+ }),
+ },
+ ),
+ env,
+ caller,
+ "/api/managed-agents",
+ );
+
+ expect(response.status).toBe(409);
+ expect(await response.json()).toEqual({
+ error: {
+ code: "slack_manual_completion_blocked",
+ message:
+ "Manual completion is blocked: cancel the automated setup for this connection, then generate a new manifest (Reconnect) before entering credentials.",
+ },
+ });
+ });
+
it("curates a busy cancel and a cancelled record", async () => {
vi.stubGlobal(
"fetch",
diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.ts
index 1264ae4d..50331ecc 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.ts
@@ -161,6 +161,8 @@ const SLACK_SETUP_ERROR_MESSAGES: Record<string, string> = {
"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_manual_completion_blocked:
+ "Manual completion is blocked: cancel the automated setup for this connection, then generate a new manifest (Reconnect) before entering credentials.",
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 c03c147c..5bfdf2b7 100644
--- a/docs/agents/api.mdx
+++ b/docs/agents/api.mdx
@@ -548,6 +548,7 @@ Error codes, as HTTP errors or as `error.code` on the setup:
| `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_manual_completion_blocked` | `409` on the manual credential save (`PUT /channels/slack/connections/<id>`): an automated setup owns the connection, or the pasted manifest is no longer current; cancel the setup, generate a new manifest, then enter credentials |
| `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. Not recoverable in place: fix the declaration, redeploy, cancel the setup and start again |
| `slack_app_limit_reached` | The workspace cannot hold another app |
diff --git a/web/src/managed-agents/Detail.tsx b/web/src/managed-agents/Detail.tsx
index 01199319..edd7c0c2 100644
--- a/web/src/managed-agents/Detail.tsx
+++ b/web/src/managed-agents/Detail.tsx
@@ -665,6 +665,11 @@ export default function ManagedAgentDetail({
const activeAliasChannel = activeAliasChannels[0]
const declaredChannels =
activeDeployment.data?.projectDeployment?.resources.channels ?? []
+ // Slack apps are set up on Connections; the wizard points there when a
+ // manual completion is blocked by an automated setup.
+ const connectionsHref = project
+ ? `/projects/${encodeURIComponent(project.project.id)}/connections?environment=${environment}`
+ : undefined
const sessionColumns: Column<ManagedAgentSessionSummary>[] = [
{
@@ -1190,6 +1195,7 @@ export default function ManagedAgentDetail({
)}
channelId={declaredChannel.id}
destinations={Object.keys(declaredChannel.destinations)}
+ connectionsHref={connectionsHref}
/>
),
)
@@ -1199,6 +1205,7 @@ export default function ManagedAgentDetail({
alias={activeDeployment.data.alias}
agentName={displayManagedAgentName(agent)}
connection={activeAliasChannel}
+ connectionsHref={connectionsHref}
/>
)
) : (
diff --git a/web/src/managed-agents/Slack.tsx b/web/src/managed-agents/Slack.tsx
index a11900d3..ac6ae79b 100644
--- a/web/src/managed-agents/Slack.tsx
+++ b/web/src/managed-agents/Slack.tsx
@@ -59,6 +59,7 @@ import {
describeSlackVerification,
newSlackSetupRequestKey,
slackAuthorizationHref,
+ slackSetupAnchorId,
slackReturnFromSearch,
slackSlotsForEnvironment,
withoutSlackReturn,
@@ -495,6 +496,7 @@ function SlackAutomaticSetup({
return (
<div
+ id={slackSetupAnchorId(target)}
className={cn(
'space-y-3 border-t px-5 py-4',
highlighted && view.tone === 'error' && 'bg-status-error-bg/20',
diff --git a/web/src/managed-agents/SlackWizard.test.tsx b/web/src/managed-agents/SlackWizard.test.tsx
new file mode 100644
index 00000000..a8d45424
--- /dev/null
+++ b/web/src/managed-agents/SlackWizard.test.tsx
@@ -0,0 +1,194 @@
+// @vitest-environment happy-dom
+
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { MemoryRouter } from 'react-router-dom'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { ApiError } from '@/api/client'
+import type { ManagedAgentChannel } from './api'
+import { slackSetupAnchorId } from './slack-setup'
+
+const api = vi.hoisted(() => ({
+ startManagedAgentSlack: vi.fn(),
+ completeManagedAgentSlack: vi.fn(),
+ bindManagedAgentSlackDestination: vi.fn(),
+ disconnectManagedAgentSlack: vi.fn(),
+}))
+vi.mock('./api', () => api)
+
+// Imported after the mock so the component sees the fakes.
+const { ManagedSlackWizard } = await import('./SlackWizard')
+
+const BLOCKED =
+ 'Manual completion is blocked: cancel the automated setup for this connection, then generate a new manifest (Reconnect) before entering credentials.'
+
+// A connection whose events are rejected: the wizard offers Edit credentials,
+// which starts at the details step without a manifest round trip.
+const connection: ManagedAgentChannel = {
+ id: 'channel_1',
+ channel: 'slack',
+ channelId: 'slack',
+ agentId: 'coder',
+ alias: 'development',
+ appId: 'A1',
+ appName: 'Patch',
+ verificationError: 'signing_secret_mismatch',
+ status: 'pending',
+ createdAt: '2026-09-18T00:00:00.000Z',
+ updatedAt: '2026-09-18T00:00:00.000Z',
+ destinations: [],
+ agents: ['coder'],
+}
+
+function button(scope: ParentNode, label: string): HTMLButtonElement {
+ const match = [...scope.querySelectorAll('button')].find(
+ (element) => element.textContent?.trim() === label,
+ )
+ if (!(match instanceof HTMLButtonElement))
+ throw new Error(`Button not found: ${label}`)
+ return match
+}
+
+async function settle(until: () => boolean, label: string) {
+ for (let attempt = 0; attempt < 50; attempt += 1) {
+ if (until()) return
+ await act(async () => {
+ await new Promise((resolve) => setTimeout(resolve, 0))
+ })
+ }
+ throw new Error(`Timed out waiting for ${label}`)
+}
+
+function typeInto(input: HTMLInputElement, value: string) {
+ Object.getOwnPropertyDescriptor(
+ HTMLInputElement.prototype,
+ 'value',
+ )!.set!.call(input, value)
+ input.dispatchEvent(new Event('input', { bubbles: true }))
+}
+
+describe('ManagedSlackWizard blocked manual completion', () => {
+ let container: HTMLDivElement
+ let root: Root
+ let client: QueryClient
+
+ beforeEach(() => {
+ ;(
+ globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }
+ ).IS_REACT_ACT_ENVIRONMENT = true
+ container = document.createElement('div')
+ document.body.append(container)
+ root = createRoot(container)
+ client = new QueryClient({
+ defaultOptions: {
+ queries: { retry: false },
+ mutations: { retry: false },
+ },
+ })
+ api.completeManagedAgentSlack.mockReset()
+ api.completeManagedAgentSlack.mockRejectedValue(
+ new ApiError(BLOCKED, 409, 'slack_manual_completion_blocked'),
+ )
+ })
+
+ afterEach(() => {
+ act(() => root.unmount())
+ client.clear()
+ container.remove()
+ document.body.replaceChildren()
+ })
+
+ function render(connectionsHref?: string) {
+ act(() => {
+ root.render(
+ <QueryClientProvider client={client}>
+ <MemoryRouter>
+ <ManagedSlackWizard
+ agentId="coder"
+ alias="development"
+ agentName="Coder"
+ connection={connection}
+ connectionsHref={connectionsHref}
+ />
+ </MemoryRouter>
+ </QueryClientProvider>,
+ )
+ })
+ }
+
+ async function saveCredentials() {
+ act(() => button(container, 'Edit credentials').click())
+ await settle(
+ () => document.body.querySelector('#managed-slack-secret') !== null,
+ 'the details step',
+ )
+ act(() =>
+ typeInto(
+ document.body.querySelector(
+ '#managed-slack-secret',
+ ) as HTMLInputElement,
+ 'signing-secret',
+ ),
+ )
+ act(() => button(document.body, 'Next: install').click())
+ await settle(
+ () => document.body.querySelector('#managed-slack-token') !== null,
+ 'the install step',
+ )
+ act(() =>
+ typeInto(
+ document.body.querySelector('#managed-slack-token') as HTMLInputElement,
+ 'xoxb-token',
+ ),
+ )
+ act(() => button(document.body, 'Save credentials').click())
+ await settle(
+ () => document.body.querySelector('[role="alert"]') !== null,
+ 'the blocked state',
+ )
+ }
+
+ it('shows the blocked message and scrolls to the automated setup on the page', async () => {
+ const anchor = document.createElement('div')
+ anchor.id = slackSetupAnchorId({
+ agentId: 'coder',
+ alias: 'development',
+ channelId: undefined,
+ })
+ const scrollIntoView = vi.fn()
+ anchor.scrollIntoView = scrollIntoView
+ document.body.append(anchor)
+ render()
+
+ await saveCredentials()
+ expect(api.completeManagedAgentSlack).toHaveBeenCalledTimes(1)
+ const alert = document.body.querySelector('[role="alert"]') as HTMLElement
+ expect(alert.textContent).toContain(BLOCKED)
+
+ act(() => button(alert, 'Show the automated setup').click())
+ await settle(
+ () => document.body.querySelector('#managed-slack-token') === null,
+ 'the dialog to close',
+ )
+ expect(scrollIntoView).toHaveBeenCalledTimes(1)
+ })
+
+ it('links to Connections when the automated setup is on another tab', async () => {
+ render('/projects/prj_1/connections?environment=development')
+
+ await saveCredentials()
+ const alert = document.body.querySelector('[role="alert"]') as HTMLElement
+ expect(alert.textContent).toContain(BLOCKED)
+ const link = alert.querySelector('a') as HTMLAnchorElement
+ expect(link.textContent?.trim()).toBe('Open Connections')
+ expect(link.getAttribute('href')).toBe(
+ '/projects/prj_1/connections?environment=development',
+ )
+ expect(
+ [...alert.querySelectorAll('button')].some(
+ (element) => element.textContent?.trim() === 'Show the automated setup',
+ ),
+ ).toBe(false)
+ })
+})
diff --git a/web/src/managed-agents/SlackWizard.tsx b/web/src/managed-agents/SlackWizard.tsx
index 363bd9cb..f9fbbdad 100644
--- a/web/src/managed-agents/SlackWizard.tsx
+++ b/web/src/managed-agents/SlackWizard.tsx
@@ -1,5 +1,7 @@
import { useEffect, useState, type ReactNode } from 'react'
import { useMutation, useQueryClient } from '@tanstack/react-query'
+import { Link } from 'react-router-dom'
+import { ApiError } from '@/api/client'
import {
Check,
Copy,
@@ -31,6 +33,7 @@ import {
type ManagedAgentChannel,
type ManagedSlackManifest,
} from './api'
+import { slackSetupAnchorId } from './slack-setup'
type Step = 'create' | 'details' | 'install' | 'done'
const CREATE_STEPS = ['Create app', 'Details', 'Install', 'Verify']
@@ -141,6 +144,7 @@ export function ManagedSlackWizard({
destinations = [],
consumers,
setup,
+ connectionsHref,
}: {
agentId: string
alias: string
@@ -156,6 +160,11 @@ export function ManagedSlackWizard({
* present this wizard is the "Set up manually" fallback.
*/
setup?: ReactNode
+ /**
+ * Where the automated setup lives when it is not on this page (the
+ * project's Connections tab), for a blocked manual completion.
+ */
+ connectionsHref?: string
}) {
const queryClient = useQueryClient()
const [open, setOpen] = useState(false)
@@ -169,6 +178,11 @@ export function ManagedSlackWizard({
const [verificationBaseline, setVerificationBaseline] = useState<string>()
const [confirmDisconnect, setConfirmDisconnect] = useState(false)
const [copied, markCopied] = useTransientFlag(1500)
+ // The platform's reason a manual save is refused while an automated setup
+ // owns this connection or the pasted manifest is stale.
+ const [blocked, setBlocked] = useState<string>()
+ const setupAnchor = slackSetupAnchorId({ agentId, alias, channelId })
+ const setupOnPage = Boolean(blocked && document.getElementById(setupAnchor))
const invalidate = () =>
queryClient.invalidateQueries({ queryKey: ['managed-agent-channels'] })
@@ -204,8 +218,16 @@ export function ManagedSlackWizard({
setBotToken('')
void invalidate()
},
- onError: (error) =>
- notifyError('Slack rejected those values. Double-check them.', error),
+ onError: (error) => {
+ if (
+ error instanceof ApiError &&
+ error.type === 'slack_manual_completion_blocked'
+ ) {
+ setBlocked(error.message)
+ return
+ }
+ notifyError('Slack rejected those values. Double-check them.', error)
+ },
})
const disconnect = useMutation({
mutationFn: () => disconnectManagedAgentSlack(connection!.id),
@@ -217,6 +239,7 @@ export function ManagedSlackWizard({
})
const reset = () => {
+ setBlocked(undefined)
setStep('create')
setEditing(false)
setManifest(undefined)
@@ -229,6 +252,13 @@ export function ManagedSlackWizard({
reset()
setOpen(true)
}
+ const showAutomatedSetup = () => {
+ setOpen(false)
+ reset()
+ document
+ .getElementById(setupAnchor)
+ ?.scrollIntoView({ behavior: 'smooth', block: 'center' })
+ }
const beginEdit = () => {
reset()
setEditing(true)
@@ -512,6 +542,34 @@ export function ManagedSlackWizard({
placeholder="xoxb-…"
/>
</Field>
+ {blocked ? (
+ <div
+ role="alert"
+ className="bg-status-error-bg/30 space-y-2 rounded-md px-3 py-2"
+ >
+ <div className="flex items-start gap-2">
+ <TriangleAlert
+ className="text-status-error mt-0.5 size-4 shrink-0"
+ aria-hidden
+ />
+ <p className="text-sm">{blocked}</p>
+ </div>
+ {setupOnPage ? (
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={showAutomatedSetup}
+ >
+ Show the automated setup
+ </Button>
+ ) : connectionsHref ? (
+ <Button asChild variant="outline" size="sm">
+ <Link to={connectionsHref}>Open Connections</Link>
+ </Button>
+ ) : null}
+ </div>
+ ) : null}
<DialogFooter>
<Button
type="button"
diff --git a/web/src/managed-agents/slack-setup.ts b/web/src/managed-agents/slack-setup.ts
index 73bee6cb..03942a07 100644
--- a/web/src/managed-agents/slack-setup.ts
+++ b/web/src/managed-agents/slack-setup.ts
@@ -438,6 +438,18 @@ export type SlackSlot = {
export const DEDICATED_SLACK_CHANNEL_ID = 'slack'
+/**
+ * The automated setup card's element id for a target, so the manual wizard
+ * can point at it when a manual completion is blocked by that setup.
+ */
+export function slackSetupAnchorId(target: {
+ agentId: string
+ alias: string
+ channelId?: string
+}): string {
+ return `slack-setup-${target.agentId}-${target.alias}-${target.channelId ?? DEDICATED_SLACK_CHANNEL_ID}`
+}
+
export function slackSlotsForEnvironment(input: {
project: ManagedProjectOverview['project']
deployments: ManagedAgentDeployment[]