/protean:add-saga-flowfrom protean
Builds a complete saga in Protean using a process manager to coordinate multi-step workflows across aggregates, with compensating actions for failures.
Ships in protean. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A saga coordinates a business process that spans several aggregates. Each step commits on its own, so there is no single transaction across the whole flow. A process manager runs the saga: it reacts to events, keeps its own state, issues the command for the next step, and closes when the flow reaches a terminal state.
This skill sequences the process-manager element skill into an end-to-end flow. Read that skill for the process manager itself. This one shows how to build the whole saga around it.
The saga coordinates four aggregates: Order, Inventory, Payment, and Shipping.
| Step | Event it reacts to | Command it issues | Handler kind |
|---|---|---|---|
| Start | OrderPlaced | CreateReservation | start |
| Reserve | StockReserved | RequestPayment | intermediate |
| Pay | PaymentConfirmed | CreateShipment | intermediate |
| Ship | ShipmentDispatched | (none) | end (success) |
| Fail | PaymentFailed | CancelReservation, CancelOrder | end (compensating) |
The full flow is in saga_after_closed.py. It has every piece the flow needs: a command handler for each command the saga issues, and an aggregate method that raises the event driving the next step. Payment is the branch point, confirming an amount up to a limit and failing anything above it, so the same flow reaches either terminal path.
The asset sets event_processing and command_processing to "sync", so
processing one PlaceOrder command runs the whole saga in-process, with no
broker and no server. A deployed domain leaves both asynchronous and lets the
server drive each step.
The saga reacts to one event per step and issues one
command to drive the next aggregate. Name events in the
past tense (OrderPlaced, StockReserved) and commands in the imperative
(CreateReservation, RequestPayment). Every event carries the correlation field,
here order_id, so the saga can route each event to the right instance.
Each command needs a command-handler, and each
step's aggregate method needs to raise the event for the next step. Without
them the saga stalls after the first command, and check reports
UNUSED_COMMAND and AGGREGATE_WITHOUT_COMMAND_HANDLER.
Every handler names the field that ties events to one running saga instance:
correlate="order_id". When a step's event names the field differently, map it
with a dict, for example correlate={"order_id": "ext_order_ref"}.
A start handler opens the saga. Mark it start=True. It stores the fields the
later steps need and issues the first command. A saga needs at least one; give it
one per event that can begin the flow.
# fragment
@handle(OrderPlaced, start=True, correlate="order_id")
def on_order_placed(self, event: OrderPlaced) -> None:
self.order_id = event.order_id
self.total = event.total
self.status = "reserving_stock"
current_domain.process(CreateReservation(order_id=event.order_id))
Each intermediate handler advances the saga's state and issues the next command.
It carries only correlate. The command it issues is processed by that
aggregate's command-handler, which does the actual
work.
# fragment
@handle(StockReserved, correlate="order_id")
def on_stock_reserved(self, event: StockReserved) -> None:
# Remember the reservation: the failure path needs it to compensate.
self.reservation_id = event.reservation_id
self.status = "awaiting_payment"
current_domain.process(RequestPayment(order_id=self.order_id, amount=self.total))
Mark a terminating handler end=True on every path that ends the flow. The
success path closes when the shipment goes out:
# fragment
@handle(ShipmentDispatched, correlate="order_id", end=True)
def on_shipment_dispatched(self, event: ShipmentDispatched) -> None:
self.status = "fulfilled"
The saga lifecycle reference covers the start, intermediate, and end handler kinds in full.
When a later step fails, the earlier steps have already committed. Undo them with compensating commands, then end the saga. Here, a failed payment releases the stock reservation and cancels the order:
# fragment
@handle(PaymentFailed, correlate="order_id", end=True)
def on_payment_failed(self, event: PaymentFailed) -> None:
self.status = "cancelled"
current_domain.process(CancelReservation(reservation_id=self.reservation_id))
current_domain.process(CancelOrder(order_id=self.order_id))
The saga stored reservation_id when the stock was reserved. That is how the
failure handler knows which reservation to release.
The compensation reference covers the pattern in full.
check reports PROCESS_MANAGER_UNCLOSED for a saga that has handlers but none
marked end=True. It reads handler metadata, not run-time behavior. When no
handler calls mark_as_complete() either, nothing retires an instance: its
instances stay open and the saga keeps matching later events for them.
saga_before_unclosed.py is
saga_after_closed.py with the two end=True
markers removed and nothing else changed, so a diff between them shows only what
this diagnostic is about. Both terminal handlers are still there and both still
run: the success path reaches fulfilled, the failure path compensates and
reaches cancelled. Neither closes the saga any more, so check flags it:
PROCESS_MANAGER_UNCLOSED Process manager `OrderFulfillmentPM` has no handler
marked `end=True` to close its instances
The fix is saga_after_closed.py: mark a
terminating handler end=True on the success path and on the failure path.
Once each terminal path has an end=True handler, check no longer reports the
code.
mark_as_complete() inside a handler also completes an instance at run time. The
PROCESS_MANAGER_UNCLOSED rule looks for end=True, so mark the terminating
handler end=True to clear the diagnostic.
check and
resolve what it reports, including any PROCESS_MANAGER_UNCLOSED.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub proteanhq/protean --plugin protean39 skills in this plugin
/add-commandAdd a complete command flow to an existing aggregate. It creates a command class, a FastAPI API endpoint, and a command handler with repository logic. This is the primary workflow for adding write operations to a Protean domain. Use when the user wants to "add a command", "add an action", "add an operation", "expose a write endpoint", "create a command flow", "wire up a POST endpoint", "add a new operation to an aggregate", or describes an action like "I want users to be able to [verb] a [thing]" (e.g., "place an order", "register a user", "cancel a reservation"). This workflow composes the command, command-handler, and api-endpoint element skills./add-domain-service-flowBuild a domain service flow in Protean for business logic that spans two or more aggregates. Domain services are stateless, encapsulate cross-aggregate business rules, and run pre/post invariants for validation. They are used when business logic doesn't naturally belong to a single aggregate. Wire them into command handlers or application services for persistence. Use when the user asks to "add a domain service", "implement cross-aggregate logic", "coordinate multiple aggregates", "add a business operation spanning aggregates", "validate across aggregates", or when they describe scenarios like "placing an order checks inventory and reserves stock", "transferring funds between accounts", "scheduling involves both resource and calendar"./add-eventAdd a complete event flow to an existing aggregate. It creates a domain event, adds or updates an aggregate method that raises the event via self.raise_(), and wires an event handler that processes the event and performs specified side effects (such as syncing state across aggregates, sending notifications, or triggering downstream processes). This is the primary workflow for adding reactive, event-driven behavior to a Protean domain. Use when the user wants to "add an event", "add a domain event", "add a reaction to a state change", "add a side effect", "create an event flow", "wire an event handler", "add event-driven behavior", "react to a state change", "sync aggregates on event", or describes something that happened or should happen (like "when an order is placed, reduce inventory", "after payment is confirmed, send a notification", "when a user registers, create a welcome email", "notify the warehouse when an order ships"). This workflow composes the event, aggregate, and event-handler element skills./add-fieldAdd fields to Protean domain elements (aggregates, entities, value objects). Guides you through selecting the right field type, configuring validations, and placing fields correctly. Use when the user asks to "add a field", "add an attribute", "add a property", "I need to store [data]", "add a new field to [aggregate/entity]", or describes data that needs to be tracked. Covers simple fields, association fields (HasOne, HasMany, ValueObject), field validation, custom validators, and choosing between field types for different use cases./add-read-modelBuild a complete read model in Protean, a projection populated by a projector that reacts to domain events. Covers single-aggregate projections (flattened view of one aggregate), cross-aggregate projections (combining data from multiple aggregates), and choosing between database-backed and cache-backed storage. Use when the user asks to "add a read model", "create a projection with projector", "build a query view", "add a CQRS read side", "create a denormalized view", "build a reporting view", "add a dashboard query model", or when they need to combine data from multiple aggregates into one queryable structure./add-subscriber-flowBuild a complete external integration flow in Protean using subscribers. Subscribers consume messages from external systems via broker streams and translate them into domain actions using the anti-corruption layer (ACL) pattern. Use when the user asks to "add an external integration", "consume external events", "handle webhook events", "integrate with an external system", "add a subscriber flow", "build an anti-corruption layer", "translate external messages", "process broker messages", or when they describe scenarios like "when the payment gateway confirms", "when the ERP syncs users", "react to external system notifications".Other plugins' skills for the same job