Ten triggers for five refund cases: random workflow IDs refunded 4 times too often. Case IDs, conflict and reuse policies and signal-with-start fix it.
Ten triggers, five cases, four extra refunds
The help desk at Belgavi's Book Store runs each refund case as a durable workflow: gather evidence, ask the agent for a recommendation, issue the refund, notify the customer. Workflows are started by whatever notices the case first: a payment webhook, an incoming email, a chat message, or the agent itself calling a tool that opens the refund process.
The first version gave every start a random workflow ID. On a test day with ten triggers for five cases it started ten executions. Four of them issued a refund that had already been issued: a webhook that the payment provider resent after a timeout, an agent tool call repeated after the agent re-planned, Geetha's follow-up chat message with a photo of the damaged spine, and Tanishka's question a week later about when the refund would arrive. Each looked like a new case to the system because nothing tied the trigger to the case it belonged to.
Durable execution engines give you exactly one lever for this: the workflow ID. This guide uses Temporal's documented rules, but the reasoning carries to any engine that guarantees one running execution per ID.
What the workflow ID guarantees
Temporal documents that at most one execution with a given workflow ID can be open at a time in a namespace. Two policies decide what happens around that guarantee.
- The ID-conflict policy applies when an execution with the ID is still running.
FAILis the default: the start call returns a workflow-already-started error.USE_EXISTINGreturns a handle to the running execution instead.TERMINATE_EXISTINGterminates the running one and starts a new one. - The ID-reuse policy applies when the previous execution with that ID has closed and is still within the namespace retention period.
ALLOW_DUPLICATEis the default and lets a new execution start.ALLOW_DUPLICATE_FAILED_ONLYallows it only if the previous one failed, was cancelled, was terminated or timed out.REJECT_DUPLICATEnever allows it.
Signal-with-start combines the two cases: if an execution with the ID is running, it receives the signal; otherwise a new execution starts and receives the signal as its first input.
The ID is a business decision. If it is derived from the case, every trigger about that case meets the same execution. That is the whole idea, and the policies decide what meeting means.
Six strategies replayed on the same triggers
The companion model replays the ten triggers against those rules. A run issues its refund three minutes after it starts and completes three minutes later; the run for CASE-5103 fails after two minutes, before refunding. It is a rule model, not a Temporal server, and every trigger is synthetic.
| Strategy | Executions | Extra refunds | Triggers whose content was lost | Errors to the caller |
|---|---|---|---|---|
| Random ID per trigger | 10 | 4 | none | 0 |
| Case ID, default policies | 7 | 1 | T04 | 3 |
Case ID, USE_EXISTING | 7 | 1 | T04 | 0 |
Case ID, TERMINATE_EXISTING | 10 | 2 | none | 0 |
| Case ID, signal-with-start | 7 | 1 | none | 0 |
Signal-with-start, ALLOW_DUPLICATE_FAILED_ONLY | 6 | 0 | T08 | 1 |
Reading the rows in order:
Case ID with default policies stops the resent webhook and the repeated tool call. They get the already-started error, which is the right answer for a duplicate delivery. But Geetha's photo also gets that error. It is new information, and if the caller treats the error as success, the running workflow never sees it. Meanwhile Tanishka's follow-up arrives after the case completed, and ALLOW_DUPLICATE starts a second execution that refunds Tanishka again.
USE_EXISTING removes the errors but not the loss. The caller gets a handle to the running execution and the photo still goes nowhere, because starting a workflow does not deliver anything to an execution that is already running.
TERMINATE_EXISTING sounds like it would keep only the latest run, but it restarts work that may have side effects. Geetha's photo arrived after the refund was issued, so the restart issued it again. It also terminated three runs mid-flight.
Signal-with-start delivers every trigger to the running execution, so the photo reaches the workflow and the duplicates become duplicate signals the workflow can ignore. The remaining extra refund is Tanishka's follow-up after completion.
Signal-with-start with ALLOW_DUPLICATE_FAILED_ONLY refuses to reopen a completed case while still allowing the failed CASE-5103 run to be retried by Jenya's next email. Tanishka's question now gets an error. That is correct: it is a question about a finished refund, and it needs its own path, such as a status lookup or a new linked case, not another refund.
The start call
With the Temporal Python SDK the whole decision fits in one call:
handle = await client.start_workflow(
RefundCase.run,
case,
id=f"refund-case-{case.case_id}",
task_queue="help-desk",
id_conflict_policy=WorkflowIDConflictPolicy.USE_EXISTING,
id_reuse_policy=WorkflowIDReusePolicy.ALLOW_DUPLICATE_FAILED_ONLY,
start_signal="add_evidence",
start_signal_args=[trigger.to_evidence()],
)Passing start_signal turns the start into signal-with-start. Inside the workflow, the signal handler appends evidence keyed by the trigger's own delivery ID, so a resent webhook adds nothing new.
@workflow.signal
def add_evidence(self, item: Evidence) -> None:
if item.delivery_id in self.seen_deliveries:
return
self.seen_deliveries.add(item.delivery_id)
self.evidence.append(item)When the caller is an agent tool, return the outcome in words the agent can use: started, added to a running case, or refused because the case is closed. A refusal should name the next action, such as looking up the refund status, so the agent does not simply retry.
Choosing the ID
- Derive it from the business key the workflow is responsible for, with a type prefix:
refund-case-CASE-5101, not justCASE-5101, so a review workflow for the same case can exist alongside it. - Never include a timestamp, a trigger ID or a random suffix. Each makes every trigger unique and brings back the first row of the table.
- Decide what a second piece of work on the same key means. A refund case that may legitimately run twice, such as a partial refund followed by another, needs a sequence in the key that comes from the domain, such as
refund-case-CASE-5101-2, issued by whatever owns that decision. - Keep side effects idempotent anyway. The workflow ID protects the start, not every activity; the refund activity should carry its own idempotency key for the payment provider.
Tradeoffs
Signal-with-start ties the start path to a signal name, and the workflow must handle a signal arriving before, during or after its main logic. Long-lived cases accumulate history; an engine-specific mechanism such as continue-as-new keeps it bounded. REJECT_DUPLICATE is the strictest option, but it also blocks retries of failed runs, which usually is not what a help desk wants. Retention matters: once a closed execution is past the retention period the reuse policy has nothing to check, so a follow-up months later starts fresh. If that is not acceptable, record case closure in your own database and check it before starting.
Failure modes to test
- A duplicate delivery arriving before the first start call returns. Both calls race for the ID; one starts, the other gets the conflict outcome.
- A follow-up arriving between the refund activity and workflow completion. With signal-with-start it reaches the running execution; make sure the workflow reads signals after the refund step too.
- A follow-up after completion. Expect the refusal and route it.
- A failed run. Expect the next trigger to start a new execution under
ALLOW_DUPLICATE_FAILED_ONLY.
Verification
python example.py in the companion prints the per-trigger outcome for each strategy, and the tests assert every row of the table above. Against a real Temporal development server, send the same ten triggers through your start code and compare the number of executions and refund activity completions with the model. Then search your code for every start_workflow call: each should derive its ID from a business key and state both policies explicitly, rather than relying on defaults.