fix(dispatcher): honor caller-supplied :causation_id on persisted events - #103
Conversation
The execution context dropped pipeline.causation_id and used command_uuid, breaking chain-of-causation reconstruction from events alone for any multi-event flow where a process manager or event handler dispatches follow-up commands. Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
PR SummaryMedium Risk Overview Tests are updated/expanded to cover both fallback and explicit Reviewed by Cursor Bugbot for commit efb195f. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis PR enhances command dispatch to support explicit causation_id propagation. The dispatcher's execution context construction now examines the command payload for an optional causation_id and applies it, defaulting to the command_uuid when absent. Tests verify both behaviors and confirm causation_id chains through event handler dispatch. ChangesCausation ID Propagation
Sequence DiagramsequenceDiagram
participant Client
participant Dispatcher
participant ExecutionContext
participant EventHandler
participant Event
Client->>Dispatcher: dispatch(command with optional causation_id)
Dispatcher->>Dispatcher: extract command from Pipeline
Dispatcher->>ExecutionContext: build with causation_id from payload || command_uuid
ExecutionContext->>EventHandler: pass causation_id in context
EventHandler->>Event: create with causation_id from context
Event-->>Client: event persisted with causation_id
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
The org policy blocks the conventional-commits action and any tag-pinned reference, so CI has been failing at startup on every PR since the policy landed. Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
test/commands/correlation_causation_test.exs (1)
1-1:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winFix typo in module name.
The module name has a typo:
CorrelationCasuationTestshould beCorrelationCausationTest(missing 'a' in "Causation").📝 Proposed fix
-defmodule Commanded.Commands.CorrelationCasuationTest do +defmodule Commanded.Commands.CorrelationCausationTest do🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/commands/correlation_causation_test.exs` at line 1, Rename the misspelled module identifier Commanded.Commands.CorrelationCasuationTest to Commanded.Commands.CorrelationCausationTest in the test file so the module name matches the intended spelling; update the module declaration (defmodule Commanded.Commands.CorrelationCasuationTest -> defmodule Commanded.Commands.CorrelationCausationTest) and any references to that module in the file or tests to use the corrected name.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@test/commands/correlation_causation_test.exs`:
- Line 1: Rename the misspelled module identifier
Commanded.Commands.CorrelationCasuationTest to
Commanded.Commands.CorrelationCausationTest in the test file so the module name
matches the intended spelling; update the module declaration (defmodule
Commanded.Commands.CorrelationCasuationTest -> defmodule
Commanded.Commands.CorrelationCausationTest) and any references to that module
in the file or tests to use the corrected name.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 370b76ab-6dda-4b57-b8f9-00cd173dbc25
📒 Files selected for processing (2)
lib/commanded/commands/dispatcher.extest/commands/correlation_causation_test.exs
…sted Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Pre-existing drift surfaced by the first CI run since the action allowlist was unblocked; unrelated to the dispatcher fix on this branch. Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
causation_idalways points at the dispatched command'scommand_uuid, which is not stored in the event store — so a chain of causation cannot be reconstructed from events alone for any flow where a process manager or event handler dispatches follow-up commands.