Skip to content

preferredWorkflowId changes lose a race with the scheduler's select-then-attach window #4574

Description

@lsm

maybeAttachStandaloneTasks in space-runtime.ts re-reads the task before attaching and re-checks workflowRunId and status, but not preferredWorkflowId:

const selected = await this.selectWorkflowForStandaloneTask(fresh, workflows);
if (!selected) continue;

const current = this.config.taskRepo.getTask(fresh.id);
if (!current || current.workflowRunId) continue;
if (current.status !== 'open') continue;
...
await this.startWorkflowRun(space.id, selected.id, ...)

A preference change committing between selectWorkflowForStandaloneTask and startWorkflowRun is therefore ignored: the scheduler starts workflow A while the write that chose B has already succeeded. The task runs a workflow the user did not pick, with no error anywhere.

Pre-existing — the loop dates to the #1991/#2004 era and the same window is reachable today through spaceTask.update. It is not introduced by task.setPreferredWorkflow (#4573), whose own guard covers a different window: a write landing after the task has already started.

Fixing it means including the selected preference in the attachment CAS, so a winning preference update forces the scheduler to reselect.

Found by Codex review on #4573.

Part of #4164.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions