Skip to content

feat(slack): follow all replies in threads Cyrus is bound to (CYPACK-1267)#1273

Open
cyrusagent wants to merge 2 commits into
mainfrom
cypack-1267
Open

feat(slack): follow all replies in threads Cyrus is bound to (CYPACK-1267)#1273
cyrusagent wants to merge 2 commits into
mainfrom
cypack-1267

Conversation

@cyrusagent
Copy link
Copy Markdown
Contributor

@cyrusagent cyrusagent commented May 29, 2026

Summary

Makes Cyrus feel "present" in a Slack thread it's been pulled into. After an initial @mention binds a thread, every subsequent reply in that thread is fed into the same agent session — no need to re-mention Cyrus each time. (CYPACK-1267)

This is the cyrus (runtime) half of the change; the cyrus-hosted half (webhook forwarding gate + Slack manifest) is in a paired PR.

What changed

  • SlackEventTransport now accepts message events (not just app_mention). It applies cheap, conservative structural filters before doing any work:
    • drops the bot's own / other bots' messages (bot_id) — prevents reply loops
    • drops subtype events (edits, deletes, joins, bot_message, …)
    • drops non-threaded messages (only a threaded reply can belong to a bound thread)
    • de-dupes Slack's double-delivery — a message that mentions the bot arrives as both an app_mention and a message event; we collapse identical (channel, ts) pairs (10-min TTL) so the thread is prompted once.
  • ChatPlatformAdapter gains an optional isSessionInitiatingEvent(event). ChatSessionHandler refuses to start a new session from a non-initiating event, so a plain reply only ever continues an already-bound thread — it never spins one up. (Defaults to "initiating" when the adapter omits the method, so Linear/GitHub behaviour is unchanged.)
  • SlackChatAdapter marks app_mention as session-initiating and message as follow-up; SlackMessageTranslator now maps message → user prompt.
  • Slack setup manifest (cyrus-setup-slack) subscribes to message.channels / message.groups / message.mpim / message.im (the *:history scopes were already present).

Design notes (SOLID)

  • SRP — transport owns ingress + filtering + dedup; the adapter owns platform policy (isSessionInitiatingEvent); the handler owns session lifecycle.
  • OCP/LSP/ISP — the new adapter method is optional and defaults to true, so existing adapters (and the test adapter) need no change.
  • Works for both ingress paths: cyrus-hosted proxy forwarding and self-host direct Slack delivery (where cyrus is the only gate — hence the dedup + binding gate live here too).

Testing

  • pnpm test:packages:run — all green (slack-event-transport 70, edge-worker 673, etc.). New tests cover: threaded message emitted, non-threaded/bot/subtype dropped, app_mention+message dedup, and the session-initiation gate.
  • pnpm typecheck and pnpm lint clean.

Operational note

Existing Slack apps must add the four message.* bot events in Event Subscriptions for follow-ups to be delivered.

After an initial @mention binds a Slack thread, plain follow-up messages in
that thread are now fed into the same agent session — no re-mention needed.

- SlackEventTransport accepts "message" events, drops bot/own messages,
  subtype events, and non-threaded messages, and de-dupes the app_mention +
  message double-delivery on (channel, ts).
- ChatPlatformAdapter gains optional isSessionInitiatingEvent; ChatSessionHandler
  refuses to start a new session from a non-initiating event, so a plain reply
  only continues an already-bound thread.
- SlackChatAdapter marks app_mention as initiating, message as follow-up.
- Slack setup manifest subscribes to message.channels/groups/mpim/im.

CYPACK-1267
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