Skip to content

feat(chat): channel-bound chat triggers; share a Slack workspace or Teams tenant among companies - #537

Merged
artempartos merged 10 commits into
developfrom
artempartos/triggers-without-channels-audit
Oct 22, 2026
Merged

artempartos merged 10 commits into
developfrom
artempartos/triggers-without-channels-audit

Conversation

@artempartos

@artempartos artempartos commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Implements docs/design/shared-chat-workspaces.md (board task #199), both phases:

  1. Channel-bound chat triggers. Every chat trigger listens in exactly one channel, and a channel reaches a company only when someone in it posts a one-time code there.
  2. Shared workspaces. Several companies can connect one Slack workspace or Microsoft 365 organization as peers, and each reaches only its own connected channels.

Why

A Slack or Teams chat trigger took any channel id in its conditions, or none, and the chat_* tools posted to any channel id the bot could reach. Channel ids are not secret: public channel ids are visible to every workspace member, and ids travel in links and mentions. So neither was a boundary. A workspace also belonged to exactly one company, so tenants could not share one.

Phase 1 — a channel per trigger, connected by code

  • Connecting a channel. Flow issues a code (aixle-XXXXXXXX: single use, 10 minutes, at most 10 open per company). It can be asked for from the trigger form, the Slack/Teams row on Integrations, the API or MCP.
    • Someone in the channel posts @<bot> connect <code>. The bot connects that channel and answers publicly in the thread; the Channels list links to that answer.
    • Every refusal gets the same reply in the channel; the reason is shown on the code in Flow.
    • Connections are company-wide. Removing one is announced in the channel.
  • One channel per chat trigger. trigger_bindings.chat_conversation_id, validated in the model: an enabled chat trigger needs a channel of its own messenger connected to its company. Conditions may not name a place (channel, conversation.*, workspace.*, …).
  • Agent tools reach only connected channels and the thread the run came from.
  • Write paths that bypassed the checks now follow the rule:
    • template export drops the channel, and install strips it from older templates;
    • archive restore and template activation leave a trigger without a usable channel off;
    • a project move, and removing an install, switch chat triggers off and clear their channel.
  • API / MCP. chat_channel_id on triggers; GET/DELETE /api/v1/projects/:id/chat_channels, POST/GET /api/v1/projects/:id/chat_connect_codes; MCP list_chat_channels, create_chat_connect_code, get_chat_connect_code.
  • UI.
    • A Channel select with "Connect a new channel…" in the trigger form.
    • A connect dialog showing the bot's real name.
    • "Needs a channel" in trigger lists.
    • A Channels section on the Slack and Teams rows.
  • Slack. The bot's name comes from auth.test. channels:read / groups:read are requested for channel names, and channel_rename / group_rename keep them current.
  • Behaviour change. A Teams 1:1 chat no longer starts triggers (it is not a channel); /run, /status and help still answer there.

Phase 2 — one workspace, many companies

  • chat_workspaces. Each company's install links to it, and the channel registry lives under it. One company's disconnect leaves the others' channels, triggers and endpoint alone. Uninstalling the app in Slack stops it for every company; reinstalling from any of them restores it for all.
  • The bot token. Each install keeps its copy, synced to the latest on every install. Existing token readers are unchanged, and it does not matter whether Slack hands a reinstall the same token (spike S1).
  • Chat::WorkspaceRouter.
    • Connect codes, help, commands and private messages are answered once.
    • Then each company with a matching trigger on that channel gets an event of its own, with a per-company dedup key. The old global slack:<event_id> key would have dropped the second company's copy.
    • A message no company matched is stored nowhere.
  • Self-service. /run, the shortcut and /status span the person's companies on the workspace. Account linking accepts a member of any of them, and the link page names only the person's own companies.
  • chat_messages. In a channel two companies share, an agent edits or deletes only the bot messages posted for its company.
  • Rate limits. Slack::Client::RateLimited reaches agents as rate_limited with retry_after.
  • Smaller fixes.
    • The trigger form keeps sender conditions it does not show.
    • The builder's Triggers tab shows a refused switch.
    • Teams channel messages use the registry's channel key (spike S2).

Migrations and rollout

  • 20261022100000 / 20261022120000 add the tables and columns.
  • 20261022100100 connects the channels each company already uses and gives every chat trigger exactly one channel.
    • Sources: trigger conditions, chat events, run origins, step instructions, the Teams registry.
    • A channel-less trigger that fired from several channels is split into one per channel.
    • One that never fired, or listened to Slack DMs (which could not fire), is switched off.
  • 20261022120100 links every Slack/Teams install, its channels and its endpoint to a workspace.
  • The data migrations read everything from the database and log counts only.
  • A copy of the channel id stays in filter_predicate["channel"], so the previous release keeps matching correctly during the rolling deploy. API and MCP never show it. Removing it is a later contract step.
  • Operators:
    • add channels:read,groups:read to the Slack app and to an explicit SLACK_SCOPES;
    • subscribe the app to channel_rename and group_rename;
    • have each workspace reinstall the app once. This can ride along with the reinstall already needed for commands. Until then channels show their id instead of their name; nothing else depends on it.

Verification

  • Backend, locally against a private Postgres: the full bin/rails test passed (8727 runs, 0 failures). rubocop and brakeman are clean.
  • Frontend, locally: tsc, eslint and steiger are clean. vitest passed for the triggers, integrations, chat-channels, workflows and integrations-pages folders.
  • CI is the verification of record.
  • Still to check live on staging: spikes S3 (mentions in private and Slack Connect channels) and S4 (a pasted @bot mention in Slack). The connect dialog already tells people to pick the bot from the list.

Notes for review:

  • app/frontend/shared/routes.ts was regenerated with RAILS_ENV=test. Besides the four new helpers it picks up existing drift (adminCompanyInvitations*, gitlabOauth*, …) from routes added earlier without regenerating.

🤖 Generated with Claude Code

artempartos and others added 4 commits October 22, 2026 02:29
One Slack workspace or Microsoft 365 tenant serving several companies as
peers, with no company owning it. A chat trigger listens in exactly one
channel, and a channel reaches a company only when someone in it posts a
one-time code there — a typed channel id is never trusted, because channel
ids are not secret. Records the agreed decisions, the gaps the review found
and the phasing (#199).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
A chat trigger used to take any channel id, or none, in its conditions, and
agent tools posted to any channel id the bot could reach. Channel ids are not
secret, so neither boundary held.

Now a channel is connected to a company only by redeeming a one-time code
inside it (`@<bot> connect <code>`), answered publicly by the bot. An enabled
chat trigger must listen in exactly one connected channel; routing keys in its
conditions are refused; chat_* tools reach only connected channels and the
thread a run came from. Template export/install, archive restore, project move
and removing an install no longer carry or keep a channel the company has not
connected.

The migration connects the channels each company already uses and splits a
channel-less trigger that fired from several channels into one per channel,
reading everything from the database. A copy of the channel stays in
filter_predicate so the previous release keeps matching during the rolling
deploy.

Phase 1 of docs/design/shared-chat-workspaces.md (#199).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
A workspace used to belong to exactly one company, so a second company
connecting the same Slack workspace or Microsoft 365 organization was refused.
Now companies connect it as peers: chat_workspaces is the shared thing, each
company's install links to it, and the channel registry lives under it, so one
company's disconnect leaves the others' channels and triggers alone.

A message is routed by Chat::WorkspaceRouter: connect codes, help, commands
and private messages are answered once, then each company with a matching
trigger on that channel gets an event of its own (dedup per company), so a
message is stored only in the companies it reached. Self-service /run spans
the person's companies on the workspace, agents change only the bot messages
posted for their company in a shared channel (chat_messages), and Slack's
rate limit reaches agents as rate_limited with retry_after.

Also: a link to the bot's confirmation on the Channels list, the trigger form
keeps sender conditions it does not show, the builder's Triggers tab shows a
refused switch, and Teams channel messages use the registry's channel key.

Phase 2 of docs/design/shared-chat-workspaces.md (#199).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…rs-without-channels-audit

* origin/develop:
  feat(feature-flags): admin pages, writes and audit (3/7) (#536)

# Conflicts:
#	CHANGELOG.md
@artempartos artempartos changed the title feat(chat): connect chat channels by code; a chat trigger listens in one feat(chat): channel-bound chat triggers; share a Slack workspace or Teams tenant among companies Oct 22, 2026
artempartos and others added 6 commits October 22, 2026 22:15
From the design review (decisions 21-23 in
docs/design/shared-chat-workspaces.md):

- A code is issued for one named channel (Slack "#deploys"; Teams
  "Team / Channel" or a group chat's name). Posted in any other channel it
  connects nothing and stays good for its own, so a code left in a channel the
  bot is not in cannot be carried elsewhere.
- The bot's public confirmation and help name the company and the command,
  never the person who asked or the project: a channel may hold guests and
  other organizations.
- A refused code is answered only to whoever posted it (Slack ephemeral; Teams
  at most once a minute per person), and codes are stored as an HMAC keyed with
  a server secret instead of a plain SHA-256.

The connect dialog now asks for the channel before it asks for a code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…rs-without-channels-audit

* origin/develop:
  fix(deps): weekly dependency batch — inertia_rails 3.23, mcp 1.8, Sentry 11.8, Mantine 9.7.3, prosemirror-view advisory (#543)
  fix(sessions): preload session_admission in session_list MCP tool (#542)
…rs-without-channels-audit

#544 took migration version 20261022120000, so the chat workspace migrations
move to 20261022121000/121100 (order unchanged, nothing has run them outside
dev). The fully wired user scenario gains rows behind the two new
requested_by foreign keys, which already nullify.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…s Slack does

The channels list sat inside the integrations table as an extra row; it
now opens from a Channels button on the messenger's row.

Slack completes a mention only from the bot's display name, while
auth.test returns the username, so the connect instructions named a bot
nobody could mention. users:read lets users.info give the display name,
and the name of whoever posted a connect code, which replaces the raw
Slack user id shown as "posted by".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…rs-without-channels-audit

* origin/develop:
  fix(sessions): commit as the deployment's bot in every agent session (#545)
  fix(pull-requests): return the GitLab head pipeline from pull_request_checks (#546)
The channels list no longer loads on the page; it waits for its dialog.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos marked this pull request as ready for review October 22, 2026 17:22
@artempartos
artempartos merged commit 9ab303d into develop Oct 22, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant