Skip to content

refactor: pass full documents in event emissions#453

Merged
larryro merged 3 commits into
mainfrom
refactor/emit-full-documents-in-events
Feb 13, 2026
Merged

refactor: pass full documents in event emissions#453
larryro merged 3 commits into
mainfrom
refactor/emit-full-documents-in-events

Conversation

@larryro
Copy link
Copy Markdown
Collaborator

@larryro larryro commented Feb 13, 2026

Summary

  • Emit complete document objects (conversation, message, customer, execution) in event data instead of cherry-picking individual fields, making event payloads richer and more consistent
  • Add getNestedValue helper with dot-notation support for event filter matching (e.g., execution.rootWfDefinitionId)
  • Remove unused workflow.failed event type and its redundant emissions from failed/canceled workflow paths

Test plan

  • Verify workflow triggers still fire correctly for conversation.created, conversation.closed, conversation.message_received, customer.created, customer.updated, customer.deleted, and workflow.completed events
  • Verify event filters with nested dot-notation keys (e.g., execution.rootWfDefinitionId) match correctly
  • Confirm self-trigger prevention still works for workflow.completed events
  • Verify no existing triggers reference the removed workflow.failed event type

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved event system reliability by emitting events only when data is successfully retrieved.
  • Refactor

    • Event payloads for messages, conversations, and customers now include complete objects instead of individual fields.
    • Updated workflow event handling and removed certain workflow failure event emissions.
    • Modified event filtering structure for workflow triggers.

…cked fields

Emit complete document objects (conversation, message, customer, execution)
in event data instead of individual fields. Add nested property access for
event filter matching to support dot-notation keys. Remove unused
workflow.failed event type.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

The pull request refactors event emission patterns across multiple services to restructure how event data is transmitted. Instead of emitting individual fields (e.g., conversationId, messageId, customerId), the code now conditionally emits full object payloads (conversation, message, customer, execution) after retrieving them from the database. This applies to events in conversations, customers, and workflow completion flows. Concurrently, the event processing system is enhanced with a new getNestedValue helper function to support nested property access in event filtering, and the workflow.failed event type is removed from emission paths while corresponding filter field configurations are updated to reference nested properties.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
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.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: pass full documents in event emissions' directly and clearly summarizes the main objective of the changeset—converting event payloads from individual fields to complete document objects.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ 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 refactor/emit-full-documents-in-events

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

Copy link
Copy Markdown

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
services/platform/convex/workflows/triggers/process_event.ts (1)

27-36: 🧹 Nitpick | 🔵 Trivial

Clarify stringification behavior for undefined values.

When eventVal is undefined, JSON.stringify(undefined) returns undefined (not a string), so the ?? '' fallback converts it to an empty string. This means an undefined nested field will match a filter value of ''.

If this is intentional (to allow filtering for "field not set"), consider adding a brief comment. If not, an explicit check for undefined may be clearer:

💡 Optional: explicit undefined handling
   for (const [key, value] of Object.entries(eventFilter)) {
     const eventVal = getNestedValue(eventData, key);
+    // undefined fields match empty string filter value (for "not set" checks)
     if (
       (typeof eventVal === 'string'
         ? eventVal
         : JSON.stringify(eventVal ?? '')) !== value
     )
       return false;
   }
🤖 Fix all issues with AI agents
In `@services/platform/convex/conversations/add_message_to_conversation.ts`:
- Around line 118-125: The emitted event currently uses parentConversation
(fetched before updating lastMessageAt and metadata.unread_count), so emitEvent
will contain stale conversation state; after you apply the conversation
patch/update (the operation that updates lastMessageAt/unread_count in this
file), re-fetch the up-to-date conversation (e.g., call ctx.db.get with the
conversation id or use the patched return value) and pass that fresh object into
emitEvent's eventData.conversation, or if the pre-update snapshot was
intentional, add a clear comment next to the emitEvent call explaining that
choice.

In
`@services/platform/convex/workflow_engine/helpers/engine/on_workflow_complete.ts`:
- Around line 51-55: The event is being emitted with an outdated exec object
(fetched before completeExecution), so update the code to emit the final
completed state by retrieving the post-completion execution and passing that to
emitEvent; specifically, call completeExecution(...) first, then either use the
updated execution object returned by completeExecution or re-fetch the execution
(same identifier used to create exec) and pass that updated object to emitEvent
(function names: completeExecution, emitEvent, and the local exec variable) so
eventData.execution reflects the completed state.

Comment thread services/platform/convex/workflow_engine/helpers/engine/on_workflow_complete.ts Outdated
@larryro larryro merged commit 553bcf5 into main Feb 13, 2026
15 checks passed
@larryro larryro deleted the refactor/emit-full-documents-in-events branch February 13, 2026 13:45
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