Skip to content

Comments

Threads context#300

Merged
Selinali01 merged 1 commit intomainfrom
threads_context
Feb 10, 2026
Merged

Threads context#300
Selinali01 merged 1 commit intomainfrom
threads_context

Conversation

@Selinali01
Copy link
Contributor

@Selinali01 Selinali01 commented Feb 10, 2026

Summary

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • New Bubble Integration
  • Other (please describe):

Checklist

  • My code follows the code style of this project
  • I have added appropriate tests for my changes
  • I have run pnpm check and all tests pass
  • I have tested my changes locally
  • I have linked relevant issues

Screenshots (Required)

For New Bubble Integrations

📋 Integration Flow Tests: When creating a new bubble, you must write an integration flow test that exercises all operations end-to-end in realistic scenarios—including edge cases. This flow should be runnable in bubble studio and return structured results tracking each operation's success/failure with details. See packages/bubble-core/src/bubbles/service-bubble/google-sheets/google-sheets.integration.flow.ts for a complete reference implementation.

⚠️ If your integration requires API credits for testing, please reach out to the team for test credentials.

  • Integration flow test (.integration.flow.ts) covers all operations
  • Screenshots showing full test results in Bubble Studio attached above

Additional Context

Summary by CodeRabbit

  • New Features

    • AI agents now automatically capture and utilize conversation history from Slack threads, enabling improved multi-turn context awareness without requiring explicit input.
  • Chores

    • Updated package versions across the platform (0.1.138 → 0.1.139).

@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

Version 0.1.139 introduces conversation history propagation. A new optional property stores thread history on BubbleFlow instances. The runtime extracts thread histories from webhook payloads, formats them as conversation objects, and attaches them to flow contexts. AI agent bubbles auto-inject this history into their parameters.

Changes

Cohort / File(s) Summary
Package Version Bumps
packages/bubble-core/package.json, packages/bubble-runtime/package.json, packages/bubble-scope-manager/package.json, packages/bubble-shared-schemas/package.json, packages/create-bubblelab-app/package.json
Version bumped from 0.1.138 to 0.1.139 across all packages.
BubbleFlow Enhancement
packages/bubble-core/src/bubble-flow/bubble-flow-class.ts
Added optional public property __triggerConversationHistory__ as an array of role/content message objects for storing conversation context.
Runtime History Extraction
packages/bubble-runtime/src/runtime/BubbleRunner.ts
Extracts thread_histories from webhook payloads, formats them into conversation history objects (excluding current message), and assigns to flow's __triggerConversationHistory__ property.
Parameter Propagation
packages/bubble-runtime/src/utils/parameter-formatter.ts
Appends triggerConversationHistory from the bubble flow instance to generated parameter objects for execution.
AI Agent Auto-Injection
packages/bubble-core/src/bubbles/service-bubble/ai-agent.ts
Auto-injects triggerConversationHistory into agent parameters during beforeAction if not explicitly provided, enabling multi-turn conversational context.

Sequence Diagram

sequenceDiagram
    actor Webhook
    participant BubbleRunner
    participant BubbleFlow
    participant ParameterFormatter
    participant AIAgentBubble
    
    Webhook->>BubbleRunner: Receive payload with thread_histories
    BubbleRunner->>BubbleRunner: Extract & format thread_histories
    BubbleRunner->>BubbleFlow: Attach __triggerConversationHistory__
    BubbleRunner->>ParameterFormatter: Prepare execution parameters
    ParameterFormatter->>ParameterFormatter: Append triggerConversationHistory
    ParameterFormatter->>AIAgentBubble: Pass params with history
    AIAgentBubble->>AIAgentBubble: beforeAction: auto-inject if missing
    AIAgentBubble->>AIAgentBubble: Execute with conversation context
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A thread of tales through time does flow,
From webhook's ping to agent's glow,
With history's whisper, context clear,
The bubbles chat without a fear,
Past words awakened, future bright! 🌟

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Threads context' is vague and generic, using non-descriptive terms that don't clearly convey what the changeset actually accomplishes. Improve the title to be more specific and descriptive, such as 'Add conversation history from Slack threads to bubble flow context' or 'Support thread context injection into AI agent bubbles'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch threads_context

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/bubble-runtime/src/runtime/BubbleRunner.ts`:
- Around line 493-516: The code maps webhookPayload.thread_histories into
__triggerConversationHistory__ without validating each entry, so malformed items
produce entries like "[undefined]: undefined"; update the logic around
webhookPayload/thread_histories and historyWithoutCurrent to filter out entries
missing name or message (and skip non-objects), then map only valid items to {
role: 'user', content: `[${name}]: ${message}` } before assigning to
(flowInstance as any).__triggerConversationHistory__.
🧹 Nitpick comments (3)
packages/bubble-core/src/bubbles/service-bubble/ai-agent.ts (1)

590-602: The type assertion on triggerConversationHistory bypasses validation.

The source type (context.triggerConversationHistory) has role: string, but the target type requires role: 'user' | 'assistant'. If upstream data ever includes unexpected roles (e.g., 'system', 'tool'), they'd pass through unchecked and could cause subtle issues downstream (e.g., when converting to LangChain messages in executeAgent at lines 1929-1949, unrecognized roles are silently dropped).

Consider filtering to known roles instead of casting:

Suggested safer approach
     if (
       !this.params.conversationHistory?.length &&
       this.context?.triggerConversationHistory
     ) {
-      this.params.conversationHistory = this.context
-        .triggerConversationHistory as Array<{
-        role: 'user' | 'assistant';
-        content: string;
-      }>;
+      this.params.conversationHistory = this.context.triggerConversationHistory
+        .filter(
+          (msg): msg is { role: 'user' | 'assistant'; content: string } =>
+            msg.role === 'user' || msg.role === 'assistant'
+        );
     }
packages/bubble-runtime/src/runtime/BubbleRunner.ts (2)

497-502: user_id is declared in the type assertion but never read.

The local type includes user_id: string but it is unused in the mapping logic. If it's not needed, removing it keeps the type honest; if it will be needed later (e.g., for distinguishing bot vs. user messages), consider adding a TODO.


504-506: All history entries are hardcoded to role: 'user'.

If thread histories could include bot/assistant responses in the future, this will produce incorrect conversation context for the AI agent. Worth noting as a known limitation or adding a comment about the assumption.

Comment on lines +493 to +516
if (
webhookPayload &&
Array.isArray((webhookPayload as any).thread_histories)
) {
const threadHistories = (webhookPayload as any)
.thread_histories as Array<{
user_id: string;
name: string;
message: string;
}>;
if (threadHistories.length > 0) {
// Convert to {role, content} format — all thread messages are "user" role
// The last entry is the current message that triggered the flow (already in `message` param),
// so we only include history up to but NOT including it to avoid duplication
const historyWithoutCurrent = threadHistories.slice(0, -1);
if (historyWithoutCurrent.length > 0) {
(flowInstance as any).__triggerConversationHistory__ =
historyWithoutCurrent.map((h) => ({
role: 'user' as const,
content: `[${h.name}]: ${h.message}`,
}));
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing validation on individual thread history items.

If any entry in thread_histories has a missing or undefined name or message, the content will be [undefined]: undefined, which would produce confusing conversation history for the AI agent.

Consider adding a guard to filter out malformed entries:

🛡️ Proposed defensive filter
          const historyWithoutCurrent = threadHistories.slice(0, -1);
          if (historyWithoutCurrent.length > 0) {
            (flowInstance as any).__triggerConversationHistory__ =
-              historyWithoutCurrent.map((h) => ({
+              historyWithoutCurrent.filter((h) => h.message).map((h) => ({
                role: 'user' as const,
                content: `[${h.name}]: ${h.message}`,
              }));
          }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (
webhookPayload &&
Array.isArray((webhookPayload as any).thread_histories)
) {
const threadHistories = (webhookPayload as any)
.thread_histories as Array<{
user_id: string;
name: string;
message: string;
}>;
if (threadHistories.length > 0) {
// Convert to {role, content} format — all thread messages are "user" role
// The last entry is the current message that triggered the flow (already in `message` param),
// so we only include history up to but NOT including it to avoid duplication
const historyWithoutCurrent = threadHistories.slice(0, -1);
if (historyWithoutCurrent.length > 0) {
(flowInstance as any).__triggerConversationHistory__ =
historyWithoutCurrent.map((h) => ({
role: 'user' as const,
content: `[${h.name}]: ${h.message}`,
}));
}
}
}
if (
webhookPayload &&
Array.isArray((webhookPayload as any).thread_histories)
) {
const threadHistories = (webhookPayload as any)
.thread_histories as Array<{
user_id: string;
name: string;
message: string;
}>;
if (threadHistories.length > 0) {
// Convert to {role, content} format — all thread messages are "user" role
// The last entry is the current message that triggered the flow (already in `message` param),
// so we only include history up to but NOT including it to avoid duplication
const historyWithoutCurrent = threadHistories.slice(0, -1);
if (historyWithoutCurrent.length > 0) {
(flowInstance as any).__triggerConversationHistory__ =
historyWithoutCurrent.filter((h) => h.message).map((h) => ({
role: 'user' as const,
content: `[${h.name}]: ${h.message}`,
}));
}
}
}
🤖 Prompt for AI Agents
In `@packages/bubble-runtime/src/runtime/BubbleRunner.ts` around lines 493 - 516,
The code maps webhookPayload.thread_histories into
__triggerConversationHistory__ without validating each entry, so malformed items
produce entries like "[undefined]: undefined"; update the logic around
webhookPayload/thread_histories and historyWithoutCurrent to filter out entries
missing name or message (and skip non-objects), then map only valid items to {
role: 'user', content: `[${name}]: ${message}` } before assigning to
(flowInstance as any).__triggerConversationHistory__.

@Selinali01 Selinali01 merged commit 88acb33 into main Feb 10, 2026
8 checks passed
@Selinali01 Selinali01 deleted the threads_context branch February 11, 2026 07:05
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