Skip to content

fix(platform): start one agency flow per task and workflow - #466

Merged
sthanikan2000 merged 6 commits into
OpenNSW:mainfrom
sandunip-govtech:fix/1316-agency-flow-id-per-workflow
Dec 4, 2026
Merged

sthanikan2000 merged 6 commits into
OpenNSW:mainfrom
sandunip-govtech:fix/1316-agency-flow-id-per-workflow

Conversation

@sandunip-govtech

@sandunip-govtech sandunip-govtech commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An EXTERNAL_REVIEW step 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 answered 409. 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. caseflow is unchanged: it recognises a repeat by the flow ID alone and doesn't parse it.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Other (please describe):

Changes Made

  • platform/tasktypes/external_review.go
    • New dispatchFlowID(taskID, workflowID) builds the flow ID <taskId>-<workflowId>.
    • startFlowBody sends that ID as flowId, 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.go

    • TestDispatchFlowID: checks the flow ID format.
    • TestExternalReview_FlowIDPerWorkflow: one task dispatches payment_confirm and then officer_review and gets two separate flow IDs.
    • TestExternalReview_RetryKeepsFlowID: a retried dispatch sends the same flowId.
    • TestExternalReview_DispatchesWithoutReplyToken expects the new ID.

go test ./... and go vet pass in platform.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have checked that there are no merge conflicts

The documentation changes are in OpenNSW/nsw-srilanka#1323.

Related Issues

Related to OpenNSW/nsw-srilanka#1316

Screenshots/Demo

N/A

Additional Notes

  • A step that runs again in a loop must reply, not dispatch. It has a new 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 get 409 and the step would never complete. A loop step replies on the other side's replyToken, as the artifacts do.
  • No backward compatibility for the old flow ID. A dispatch the other side recorded under the bare task ID, and that TNSW sends again after the upgrade, starts a second flow there. The main example is an admin retrying a parked EXTERNAL_REVIEW step. 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).

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.
@CLAassistant

CLAassistant commented Dec 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 53856f5a-38c7-416c-8f57-5512b9bfafd6
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@sandunip-govtech

Copy link
Copy Markdown
Contributor Author

I've moved the EXTERNAL_REVIEW and caseflow changes into core. @lokewate @chathura-de-silva

@chathura-de-silva chathura-de-silva left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread platform/caseflow/client_handler.go Resolved
@Aravinda-HWK

Copy link
Copy Markdown
Contributor

Other than that, LGTM

@sthanikan2000 sthanikan2000 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Loading
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.
Loading

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:

  1. Drop c91216b and 20c5a39 and ship the plugin change alone, with a deployment note: agencies before or with TNSW, and let retrying EXTERNAL_REVIEW steps settle before upgrading TNSW. This is the option I'd prefer.
  2. 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, and caseflow reads 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.
@sandunip-govtech

Copy link
Copy Markdown
Contributor Author

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.
Removed the / check from dispatchRequest. The agency's 400 already parks the step.
Fixed the description.
The nsw-srilanka PR will land together with the core bump.

@chathura-de-silva chathura-de-silva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

TNSW no longer sends priorFlowId; the replay mock trims the
workflow off flowId again.

@chathura-de-silva chathura-de-silva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sthanikan2000 sthanikan2000 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@sthanikan2000
sthanikan2000 merged commit 68efa35 into OpenNSW:main Dec 4, 2026
33 checks passed
sthanikan2000 pushed a commit to OpenNSW/one-trade-artifacts that referenced this pull request Dec 4, 2026
TNSW names an agency flow <taskId>-<workflowId> (OpenNSW/core#466), so
the taskId variable holds that ID, not TNSW's task ID.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants