Repository navigation
Conversation
A start request with an idempotency key now gets a workflow id derived from the workflow name and the key (UUID v3 of "name:key"), unless the caller gives a workflow id. The start goes through startWorkflowIdempotent: a second start with the same name and key returns the id of the first workflow and creates nothing. With strategy FAIL, a second start is a 409 conflict. Before this change the engine ignored the key on startWorkflow. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
mp-orkes
left a comment
There was a problem hiding this comment.
Not ready to merge. The server ignored the idempotency key until now, and existing callers already send it. Two of the three strategies and the concurrent path do not do what the description states.
| # | Severity | Location | Issue |
|---|---|---|---|
| 1 | Blocking | WorkflowExecutorOps.java:2780 |
FAIL_ON_RUNNING has no handling |
| 2 | Blocking | SchedulerService.java:1032 |
A schedule with a key runs one time only |
| 3 | Blocking | WorkflowExecutorOps.java:2780 |
The FAIL check runs outside the lock |
| 4 | Major | WorkflowExecutorOps.java:2839 |
A duplicate create deletes or replaces the first workflow |
| 5 | Major | WorkflowExecutorOps.java:2792 |
A start with a key loses the synchronous first decide |
| 6 | Major | TestWorkflowExecutor.java:1071 |
The tests use mocks for the store and the lock |
| 7 | Minor | WorkflowExecutorOps.java:2804 |
A lock timeout gives a 500 |
| 8 | Minor | WorkflowExecutorOps.java:2776 |
name:key can collide; the key is not stored |
1. FAIL_ON_RUNNING. Only FAIL has a branch. FAIL_ON_RUNNING and a null strategy return the existing workflow in any status. A key stays bound to one execution, also after that execution is COMPLETED. Fix: give a 409 while the workflow runs, and define what a start does when the existing workflow is terminal. A derived id cannot hold a second execution.
2. Scheduler. swrFrom copies the key and the strategy of the schedule to each trigger. Before, the key had no effect. Now the first trigger starts a workflow, and each later trigger returns that same id and is recorded as EXECUTED. The schedule stops with no error. Fix: decide the scheduler contract (for example, add the scheduled time to the key) and add a scheduler test.
3. FAIL and the lock. The existence check is before the lock that startWorkflowIdempotent takes. Two concurrent FAIL starts can both get "not found". The second then finds the workflow in the locked section and returns it. No caller gets the 409. Fix: move the strategy decision into the locked section.
4. Duplicate create. The default lock is NoopLock, and the server default local_only is for one JVM. Two starts can both call createWorkflow. Postgres and MySQL: the second insert fails and the catch block removes the workflow of the first caller. Redis and Cassandra: the second create replaces the record. Fix: do not remove the workflow when the id exists; read it and return it. #1847 removes the delete, so this PR depends on it.
5. First decide. The path with no key calls decide in the request. The path with a key only pushes to the decider queue. A2AWorkflowAgent.sendMessage reads the workflow immediately after the start and gets a workflow with no tasks. Fix: run the first decide in the request for a new workflow.
6. Tests. startWithSameIdempotencyKeyReturnsExistingWorkflow makes one call against a stub. No test covers FAIL_ON_RUNNING, a terminal workflow, two concurrent starts, or a duplicate create. Fix: add one test for each strategy in the running and terminal states, and one test with a real DAO that starts two times with the same key.
7. Lock timeout. The lock wait is 500 ms by default. A retry that arrives during a slow first create gets a TransientException (500). Fix: on a lock timeout, read the workflow and return it.
8. Id and key. a:b + c gives the same id as a + b:c. WorkflowModel has no key field, so Workflow.idempotencyKey stays null. Fix: use an encoding with no ambiguity and store the key.
Not checked: the SQLite constraint on the workflow id, the lock implementations, and a run against a real server.
|
Closing this in favor of #1857. My strategy was to make these changes incrementally and discuss things like the scheduler: a schedule that sets an idempotency key now runs one time only, because every later trigger returns the first workflow. |
Split out of #1832.
Why
StartWorkflowRequesthas anidempotencyKeyand anidempotencyStrategy, butWorkflowExecutorOps.startWorkflowignores them. A caller that retries a start after a network error gets a second workflow. #1832 makes the start use the key. This change is independent of the other changes in that PR. This PR moves it out, so that it can be reviewed on its own.What changed
name:key).FAIL, the second start gets a 409.How to test
POST /api/workflowwith"name": "<workflow>"and"idempotencyKey": "k1". The response is a workflow id."idempotencyStrategy": "FAIL". The response is a 409.Notes
🤖 Generated with Claude Code