refactor: pass full documents in event emissions#453
Conversation
…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.
📝 WalkthroughWalkthroughThe 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)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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 | 🔵 TrivialClarify stringification behavior for undefined values.
When
eventValisundefined,JSON.stringify(undefined)returnsundefined(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
undefinedmay 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.
Summary
getNestedValuehelper with dot-notation support for event filter matching (e.g.,execution.rootWfDefinitionId)workflow.failedevent type and its redundant emissions from failed/canceled workflow pathsTest plan
conversation.created,conversation.closed,conversation.message_received,customer.created,customer.updated,customer.deleted, andworkflow.completedeventsexecution.rootWfDefinitionId) match correctlyworkflow.completedeventsworkflow.failedevent type🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Refactor