Files
PaperClipAI/server
Dotta 4ba596d268 fix(slack): recognize pre-pool Cloud stacks in managed Slack setup (#23783)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The Slack chat connector supports managed one-click setup on
Paperclip Cloud instances when
`PAPERCLIP_SLACK_MANAGED_SETUP_ENABLED=true` is set.
> - `createSlackManagerGrants` checked only `getCloudRuntimeIdentity()`
to detect a Cloud instance.
> - Pre-pool Cloud stacks have `isCloudManagedInstance() === true` (the
canonical Cloud predicate used by `/api/health`) but do not have a
persisted warm-pool runtime identity, so `getCloudRuntimeIdentity()`
returns `null`.
> - As a result, `/api/companies/:companyId/chat-slack/setup-options`
returned `defaultMethod: "automatic"` and `managedAvailable: false` on
those stacks, hiding managed Slack setup.
> - This pull request checks `Boolean(getCloudRuntimeIdentity()) ||
isCloudManagedInstance()` in `manager-grants.ts` and adds unit tests for
pre-pool Cloud stacks, self-hosted instances, and disabled flags.
> - The benefit is that managed Slack setup works consistently across
all Paperclip Cloud stacks while self-hosted instances remain completely
excluded.

## Linked Issues or Issue Description

**What happened?**

On a Paperclip Cloud stack without a warm-pool runtime identity record,
`GET /api/companies/:companyId/chat-slack/setup-options` returns
`{"defaultMethod":"automatic","managedAvailable":false,"workspaces":[]}`
even when `enableChatConnectors` is enabled,
`PAPERCLIP_SLACK_MANAGED_SETUP_ENABLED=true` is set, and the Cloud
Connector Broker advertises `slack.manager`.

**Expected behavior**

Any Paperclip Cloud stack where `isCloudManagedInstance()` is `true`,
`PAPERCLIP_SLACK_MANAGED_SETUP_ENABLED=true`, and Cloud Connector Broker
credentials are present should select `defaultMethod: "managed"` and
query the broker for `slack.manager` availability. Self-hosted instances
must continue to stay on `defaultMethod: "automatic"`.

**Steps to reproduce**

1. Run a Paperclip Cloud stack that sets
`PAPERCLIP_CLOUD_TENANT_SERVER_TOKEN` (or `PAPERCLIP_MANAGED_CONFIG`)
without a persisted warm-pool `cloud-runtime-identity/v1` row.
2. Enable `enableChatConnectors` and set
`PAPERCLIP_SLACK_MANAGED_SETUP_ENABLED=true` with valid
`PAPERCLIP_CLOUD_CONNECTOR_*` credentials.
3. Call `GET /api/companies/:companyId/chat-slack/setup-options`.
Observe `defaultMethod: "automatic"` and `managedAvailable: false`.

**Paperclip version or commit**

`306437a2a5` (and `7e025ae65f`)

## What Changed

- Updated `server/src/services/connectors/slack/setup/manager-grants.ts`
to compute `const isCloud = Boolean(getCloudRuntimeIdentity()) ||
isCloudManagedInstance();` instead of relying only on
`getCloudRuntimeIdentity()`.
- Added
`server/src/services/connectors/slack/setup/manager-grants.test.ts`
verifying that:
- Pre-pool Cloud stacks (`isCloudManagedInstance()` true, no runtime
identity) select `defaultMethod() === "managed"` when
`PAPERCLIP_SLACK_MANAGED_SETUP_ENABLED=true`.
- Self-hosted instances stay on `"automatic"` even if
`PAPERCLIP_SLACK_MANAGED_SETUP_ENABLED=true` is set.
- Cloud stacks stay on `"automatic"` when
`PAPERCLIP_SLACK_MANAGED_SETUP_ENABLED` is not `"true"`.

## Verification

- `pnpm --filter @paperclipai/server exec vitest run
src/services/connectors/slack/setup/manager-grants.test.ts
src/__tests__/slack-development-manager.test.ts` — 11/11 passed.
- `pnpm --filter @paperclipai/server typecheck` — passed with 0 errors.

## Risks

- Low risk: `isCloudManagedInstance()` is already the canonical Cloud
predicate across the server (including `/api/health`). Self-hosted
instances never set `PAPERCLIP_CLOUD_TENANT_SERVER_TOKEN` or
`PAPERCLIP_MANAGED_CONFIG`, and managed Slack setup still requires
`PAPERCLIP_SLACK_MANAGED_SETUP_ENABLED=true` plus valid
`PAPERCLIP_CLOUD_CONNECTOR_*` credentials and an active broker
`slack.manager` profile.

## Model Used

- Google Gemini (Antigravity agent with tool use and code execution)

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-12-04 17:25:17 -06:00
..