Skip to content

Backfill Slack thread history when bot is @-mentioned mid-thread #575

Description

@Aaronontheweb

Problem

When Netclaw is @-mentioned in an existing Slack thread that already has message history, the session starts with no awareness of prior messages in that thread. The bot only sees the mention message itself, which means it lacks context about what the conversation was about before it was pulled in.

This makes the interaction feel unnatural — users expect the bot to understand what was already discussed.

Proposed Behavior

When a new session is initialized from an AppMention in a thread with existing messages:

  1. Call Slack's conversations.replies API to fetch prior messages in the thread
  2. Inject those messages as context (observation/system context, not full conversation turns) into the session before the first LLM call
  3. Cap the backfill to a reasonable limit (message count or token budget) to handle very long threads
  4. Apply compaction if the backfilled history exceeds the token budget

Current Behavior

  • SlackThreadBindingActor.EnsureInitializedAsync() creates a session with only system prompts and the mention message
  • No calls to conversations.replies or any other Slack API for thread history
  • On daemon restart, recovery is from SQLite persistence only (the bot's own prior turns), not from Slack thread history

Scope

  • Only applies to threads where the bot is mentioned for the first time (new session)
  • Daemon-restart recovery already works via SQLite and is not affected
  • Need to consider Slack API rate limits and token budget for very long threads

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions