Skip to content

feat: tell OpenBot who a turn is from when paired (OPENBOT_PAIRING) - #92

Draft
mxmzb wants to merge 1 commit into
mainfrom
openbot-pairing
Draft

mxmzb wants to merge 1 commit into
mainfrom
openbot-pairing

Conversation

@mxmzb

@mxmzb mxmzb commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Why

OpenBot already implements the server side of the OpenTag pairing. It exposes POST /api/delivery/webhooks/opentag/agent, links identities with link <code>, maps approvals onto confirm_write, and sends proactive messages to /openbot/deliver. OpenTag never implemented its own half. OpenBot refuses every turn that doesn't carry exactly one structured openbot.sender context entry. OpenTag only sends a human-readable label, so pointing AGENT_URL at OpenBot today gets "OpenTag did not say who sent this message" on every turn.

This is the first of the four pieces OpenTag is missing, and the one that makes reactive DMs work.

What

  • OPENBOT_PAIRING=true (off by default) adds an openbot.sender entry to every run, placed beside the existing label:
    { "user": "slack:<team>:<user>", "event": "<event id>", "mentioned": true,
      "conversation": { "id": "D0…", "kind": "im" } }
    user is the Channel's own provider:tenant:actor id, which is what OpenBot's identity links are keyed on.
  • Conversation. OpenBot needs the conversation to tell a DM from a shared channel: link codes are only redeemed in a DM, and private-context answers are only posted there. The managed handler's message doesn't carry it, but identifyUser receives it. When paired, the Channel uses an identifyUser callback that returns the same user as the "platform" strategy (pinned by tests) and records the turn's conversation under its event id for the handler to take. Entries are bounded, so turns the handler drops can't accumulate.
  • Unpaired runs are unchanged. The Channel keeps "platform", and the existing context tests still pass as they are.
  • Docs: setup.md gains a "Pairing with OpenBot" section and an env-table row; .env.example gains the variable.

Not in this PR

  1. POST /openbot/deliver (proactive sends) and POST /openbot/membership (channel-membership check for Slack triggers). These are blocked on a design question. In @copilotkit/channels 0.9.2 every post on the managed path is tied to a live delivery, and this repository holds no Slack token by design (pinned in env.test.ts/server.test.ts). Both routes need either an out-of-turn send and membership API on Intelligence, or a token held here. Until then, OpenBot replies that it routes outside the live turn (for example, answers to a mention in a shared channel), and Slack triggers, won't arrive.
  2. Forwarding observed events (observe) for OpenBot's Slack triggers. That goes in a follow-up PR.

Verification

  • pnpm check-types passes.
  • pnpm test: 518 passed.
  • (cd agent && uv run pytest): 853 passed.
  • node node_modules/railway/dist/iac/bin.js: no diagnostics.
  • Against a real OpenBot (main @ f1961c35, local), posting OpenTag-shaped run input to the webhook:
    • Without the secret, the webhook returns 401.
    • Without the entry, OpenBot replies "OpenTag did not say who sent this message".
    • With the entry and the sender unlinked, OpenBot replies with its link instructions.
    • link <code> in a DM links the sender.
    • The next DM ran the General Assistant Bot, which answered.
  • A real Slack round trip has not been run yet. The runtime came up on the Channel, but the round trip needs a person to DM the app.

🤖 Generated with Claude Code

OpenBot can be the agent at AGENT_URL, but it refuses every turn that
lacks one structured `openbot.sender` context entry naming the sender,
the event, whether the app was mentioned, and the conversation. OpenTag
only ever sent a human-readable label, so the pairing could not work.

With OPENBOT_PAIRING=true the Channel resolves identity through a
callback equivalent to the "platform" strategy, which also notes the
turn's conversation (the managed handler's message does not carry it),
and each run carries the `openbot.sender` entry beside the existing
label. Off by default; unpaired runs are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@calebjoshuapaul

Copy link
Copy Markdown

We ran this branch through a real Slack round trip, against a local OpenBot (main) and a managed Intelligence Channel. Reactive turns now reach OpenBot, but OpenBot never treats a direct message as a DM, so a link <code> is always cancelled.

What the managed adapter reports for a Slack DM

We added temporary logging in identifyUser and sent @openbot hi in a DM with the app:

{
  "trigger": "message",
  "tenant": { "id": "unknown" },
  "conversation": { "id": "<uuid>", "kind": "thread" },
  "raw": { "kind": "text" }
}
  • conversation.kind is "thread", not "im".
  • conversation.id is an Intelligence UUID, not the Slack D… id.
  • raw holds no Slack event fields, so channel_type is not available anywhere.
  • tenant.id is "unknown", so the sender is slack:unknown:<user>.

As a result, the openbot.sender entry carries "kind": "thread", and OpenBot replies: "That code was posted where others could see it, so I cancelled it."

Two smaller things we hit

  • A plain DM (with no mention) in a conversation the Channel is not following is dropped silently by onMessage, because readSubscription returns "not-following". So a first link <code> sent as a normal DM never reaches OpenBot. It works only as an @mention.
  • The test plan says link codes were verified by posting OpenTag-shaped input to the webhook. That path sets the conversation by hand, so it does not show this problem.

Workaround we used for local testing only

We patched conversationOf to always return kind: "im". After that, linking worked and the General Assistant Bot answered from a Slack DM. This is not safe as a fix, because a mention in a shared channel is then treated as private too.

What would fix it

The managed adapter needs to expose the Slack conversation type, or the Slack channel id, in ChannelIdentityContext.conversation (or raw), so that this branch can send kind: "im" only for real DMs. A real tenant id would also give OpenBot a stable slack:<team>:<user>.

Versions: @copilotkit/channels 0.9.2, this branch at decca44.

This branch has not been deployed

No deployments
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.

2 participants