Repository navigation
fix(platform): start one agency flow per task and workflow - #466
sthanikan2000 merged 6 commits into
Conversation
Send <taskId>-<service_workflow_id> as the flowId, so one task can start several of the other side's workflows.
A dispatch retried after the flowId gained the workflow resumes the flow it started.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
I've moved the |
There was a problem hiding this comment.
The logic looks sound to me with backwards compatiability.
However I feel like the ideal way is to have both legacy and new flowids being passed instead of trimming down for the second, legacy id check.
@lokewate Please provide your input.
|
Other than that, LGTM |
There was a problem hiding this comment.
The fix is right but the caseflow fallback should not ship as written.
The fix (b51455c) is correct. With flowId = <taskId>-<service_workflow_id>, one task can start several agency workflows and a retry still names the same flow. The lot adjustment case from OpenNSW/nsw-srilanka#1316, before and after:
sequenceDiagram
autonumber
participant T as TNSW lot adjustment task T
participant A as CDA caseflow
participant DB as case_flows
Note over T,DB: Before the fix: flowId = task ID, for every dispatch of the task
T->>A: POST /cases/C/flows {workflowId cda_payment_confirm, flowId T}
A->>DB: Record(T, C, cda_payment_confirm) and start
A-->>T: 200
Note over T: step parks in QUEUED_EXTERNALLY
Note over A: CDA officer confirms the payment
A->>T: callback on the step's token {payment_status success}
Note over T: step completes, workflow moves on to officer_review
T->>A: POST /cases/C/flows {workflowId cda_lot_adjustment_review, flowId T}
A->>DB: Get(T)
DB-->>A: row T is for template cda_payment_confirm
A-->>T: 409 flowId is already started with different details
Note over T: a 409 is permanent, so the step parks for an admin.<br/>Trader sees the application on hold. The officer never gets the review task.
sequenceDiagram
autonumber
participant T as TNSW lot adjustment task T
participant A as CDA caseflow
participant DB as case_flows
Note over T,DB: After the fix: flowId = task ID + "-" + service_workflow_id
T->>A: POST /cases/C/flows {workflowId cda_payment_confirm, flowId T-cda_payment_confirm}
A->>DB: Record(T-cda_payment_confirm, C, cda_payment_confirm) and start
A-->>T: 200
Note over A: CDA officer confirms the payment
A->>T: callback on the step's token {payment_status success}
T->>A: POST /cases/C/flows {workflowId cda_lot_adjustment_review, flowId T-cda_lot_adjustment_review}
A->>DB: Get(T-cda_lot_adjustment_review)
DB-->>A: not found
A->>DB: Record(T-cda_lot_adjustment_review, C, cda_lot_adjustment_review) and start
A-->>T: 200
Note over A: the officer gets the review task
Note over T,DB: A retry of either dispatch sends the same flowId again,<br/>so the agency returns the recorded flow instead of starting another, as before.
Blocking: the caseflow fallback (c91216b, 20c5a39) puts the - convention on both sides. tasktypes joins the ID and caseflow cuts it apart again with CutSuffix; the nsw-srilanka replay mock cuts it a third time. The client route in caseflow is generic and treats flowId as an opaque engine ID. With the fallback it has to know how one caller builds its IDs, and the TODO ties core to another repo's issue. What it buys is narrow: only a dispatch the agency recorded under the bare ID that TNSW is still retrying when TNSW upgrades, which needs the agency to have kept failing after committing the row (retries run about a day, then park). Nothing else depends on the format: running flows keep their engine ID, callbacks and replies route by token, the needs-more-info loop replies via replyToken, and the agency's taskId variable is only passed into task inputs.
Please do one of these:
- Drop c91216b and 20c5a39 and ship the plugin change alone, with a deployment note: agencies before or with TNSW, and let retrying
EXTERNAL_REVIEWsteps settle before upgrading TNSW. This is the option I'd prefer. - If the window has to be covered, send the old ID explicitly instead of deriving it: the dispatcher adds
priorFlowId: <taskId>to the body for one release, andcaseflowreads that field with the same case and template check. No parsing on either side, and removing it later is a dispatcher-only change, since the route already allows unknown fields.
Please also correct the description. "Instead of retrying into a 400" is not right: a 400 from the agency already parks the step, since any 4xx other than 408 and 429 is permanent. The / pre-check in dispatchRequest only changes the error type, and it teaches the plugin a caseflow rule. I'd drop it, but it is not blocking.
The nsw-srilanka PR must land together with the core bump either way, since the replay mock agency strips the suffix.
An EXTERNAL_REVIEW dispatch now sends the bare task ID as priorFlowId, and caseflow resumes the flow recorded under it, instead of cutting "-<workflowId>" off the flowId. VarNames.PriorFlowID, optional, saves it with the flow's variables. TODOs no longer name the host repo.
caseflow refuses a flow ID with "/" itself, and its 400 already parks the step, so the plugin need not repeat the rule.
|
I went with option 2: Dropped the CutSuffix fallback. The dispatcher now sends priorFlowId: , and caseflow resumes that flow only for the same case and template, so neither side parses the ID. |
TNSW no longer sends priorFlowId; the replay mock trims the workflow off flowId again.
chathura-de-silva
left a comment
There was a problem hiding this comment.
Has removed the backward compatibility considering how narrow the case where it could break anything and the fact that those cases could be handled gracefully, as discussed with @lokewate.
TNSW names an agency flow <taskId>-<workflowId> (OpenNSW/core#466), so the taskId variable holds that ID, not TNSW's task ID.
Summary
An
EXTERNAL_REVIEWstep named the flow it started on the other side by its task's ID alone. When one task starts two of the other side's workflows, the second start used the same flow ID. The other side then found a flow already recorded under that ID for a different template and answered409. The step parked for an admin. For example, a payment check (payment_confirm) and then the officer's review (officer_review) run from the same task.The flow ID is now
<taskId>-<service_workflow_id>. Each workflow a task starts gets its own flow, and a retried dispatch still sends the same ID, so the other side still recognises the retry.caseflowis unchanged: it recognises a repeat by the flow ID alone and doesn't parse it.Type of Change
Changes Made
platform/tasktypes/external_review.godispatchFlowID(taskID, workflowID)builds the flow ID<taskId>-<workflowId>.startFlowBodysends that ID asflowId, in place of the bare task ID.Testing
I have tested this change locally
I have added tests that prove my fix is effective or that my feature works
I have tested edge cases
All existing tests pass
platform/tasktypes/external_review_test.goTestDispatchFlowID: checks the flow ID format.TestExternalReview_FlowIDPerWorkflow: one task dispatchespayment_confirmand thenofficer_reviewand gets two separate flow IDs.TestExternalReview_RetryKeepsFlowID: a retried dispatch sends the sameflowId.TestExternalReview_DispatchesWithoutReplyTokenexpects the new ID.go test ./...andgo vetpass inplatform.Checklist
The documentation changes are in OpenNSW/nsw-srilanka#1323.
Related Issues
Related to OpenNSW/nsw-srilanka#1316
Screenshots/Demo
N/A
Additional Notes
callbackToken, but a second dispatch of the same workflow from the same task names the flow already started. The other side returns that flow as it is, still holding the first token, so its decision would get409and the step would never complete. A loop step replies on the other side'sreplyToken, as the artifacts do.EXTERNAL_REVIEWstep. Nothing fails, and an admin can close the duplicate review task. Deploying the agencies before TNSW, and letting dispatches that are still retrying finish, keeps this rare (see fix(tasks): start one agency flow per task and workflow nsw-srilanka#1323).