Skip to content

P1: Guard cancellation state transitions and racing completion #9

@vamgan

Description

@vamgan

Problem

cancelTask() can mutate terminal tasks, and runTask() can still mark a task succeeded while cancellation is in progress.

Relevant code:

  • src/runtime.ts:133-150
  • src/runtime.ts:196-205

Issues:

  • A completed or failed task can be moved to cancelling, then cancelled/failed.
  • runTask() only treats cancelled/failed as terminal before marking success; cancelling can still become succeeded.

Impact

Final task state is nondeterministic and can regress from terminal states.

Suggested fix

  • Make cancelTask() no-op or throw for succeeded, failed, and cancelled.
  • Treat cancelling as a finalization blocker in runTask().
  • Consider atomic/compare-and-set style state transitions in the store contract.

Acceptance criteria

  • Cancelling a terminal task cannot change its terminal status.
  • Race tests cover cancellation while runTask() is near success finalization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions