taskflow: run extensions through one dispatcher and tell them which phase they run in

Open
#396 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@mushrafmim is already working on this.

Since Nov 9, 2026.

  • #397 by @mushrafmim — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
22/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Stale
Tech stack
go
Domain
backend

Research direction

Start with the two call sites that run extensions, CompleteTaskStep and SaveDraft, and the stopOnError and go func() logic they each duplicate. The issue asks for an extensions.Invocation context value, an orchestrator.Dispatcher with WithDispatcher, and an internal fire that handles guard and notify phases. Work is already under way in open PR #397, so coordinate there before starting. Done means both existing phases behave as before and POST_RESUME goes through the dispatcher.

Written by the indexing model from the issue text.

Description

Type/Improvement
Current Limitation

The orchestrator runs extensions from two call sites, CompleteTaskStep and SaveDraft. Each call site deep-copies the record and payload itself, and each decides for itself whether the run blocks or is asynchronous, using a stopOnError bool and a hand-written go func(). Adding the lifecycle phases in #395 this way would copy that logic into every new call site.

It also leaves two gaps:

  • An extension can't tell which phase it is running in, or recognise a repeat of an event it already handled.
  • POST_RESUME always runs in a bare goroutine. A host can't bound its concurrency, recover its panics, or run it inline in tests, which currently need a WaitGroup to wait for it.
Suggested Improvement

Route every extension run through one dispatcher, with no behaviour change for the two existing phases:

  • extensions.Invocation{Phase, IdempotencyKey} on the context passed to Execute, read with extensions.InvocationFrom(ctx). The key is <task id>/<step id>/<seq>/<phase> and names the run of the step, whatever seq the row has moved on to. TaskExtension is unchanged.
  • orchestrator.Dispatcher (with a DispatcherFunc adapter) runs notify phases, set with WithDispatcher. The default is one goroutine per dispatch, as today.
  • An internal fire(phase, …) looks up the phase's policy. A guard (PRE_RESUME) runs inline and returns the first error. A notify (POST_RESUME) is handed to the dispatcher with a context that is never cancelled. Deep copies are made in one place.
Version

53b0bd3

Additional Context

This is PR 1 of the rollout in #395. Telling a draft save apart from a submission (#327) stays separate.

Dominant language
Go
Stars
6
Forks
8
Avg merge
21h 36m
Merged PRs (30d)
42

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenNSW/core

All issues in OpenNSW/core

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.