Skip to content

[Bug] Workflows can be constructed in which update handlers do not, but should, execute #1474

Closed
@dandavison

Description

@dandavison

If the workflow below is started, and then a signal and an update are sent in the 2nd Workflow task, the workflow exits without the update handler ever being executed. See @bergundy's original comment #1459 (review)

export async function workflow(): Promise<string> {
  var numFoos = 0;

  wf.setHandler(fooSignal, () => {
    numFoos++;
  });

  wf.setHandler(fooUpdate, () => {
    numFoos++;
  });

  await wf.condition(() => numFoos > 0);
  return `foos: ${numFoos}`;
}

The fix will be to group update activation jobs together with signals here:

const [patches, nonPatches] = partition(activation.jobs, ({ notifyHasPatch }) => notifyHasPatch != null);
const [signals, nonSignals] = partition(nonPatches, ({ signalWorkflow }) => signalWorkflow != null);
const [queries, rest] = partition(nonSignals, ({ queryWorkflow }) => queryWorkflow != null);
let batchIndex = 0;

Fixing this will be backwards incompatible w.r.t. replay of existing workflows, so will need to use an SDK flag.

We did not update that code when we implemented update because core orders the activation jobs and we were planning to eliminate this typescript code, but this decision overlooked the fact that update and signal activation jobs need to be placed into the same batch in order for them all to be executed before giving the chance for an awaitable such as the workflow.condition() above to be unblocked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions