Skip to content

#164.4 — Dispatcher: cancel workflow logic #180

Description

@zeroklaw

Parent Epic

#164 — Cancel workflow on unassignment

Description

Add cancellation logic to the dispatcher so an unassignment event can cancel an in-flight workflow when cancel_on_unassign is enabled.

Tasks

  • Add a cancel_workflow method to Dispatcher that:
    1. Looks up the event's dedup key in the in_flight set
    2. If found, signals the running task to cancel (via a CancellationToken or similar mechanism added per spawned task)
    3. On cancellation:
      • Removes the dedup key from in_flight and does NOT add it to completed or permanently_failed
      • Moves the workspace directory from <workdir>/<owner>/<repo>/<event_id>/ to <workdir>/<owner>/<repo>/<event_id>/cancelled/
      • Logs cancellation
    4. If the event is not in-flight (already completed or not found), do nothing — log and return
  • Update the dispatch loop to handle the new unassign trigger type:
    • When a GithubIssueUnassigned or GitlabIssueUnassigned trigger event arrives, check whether the matching workflow has cancel_on_unassign = true
    • If yes, call cancel_workflow instead of handle_dispatch
    • If no, ignore the unassign event (log and return)
  • Wire a CancellationToken (from tokio_util or a custom AtomicBool) into each spawned workflow task so cancellation can be signaled
  • When the cancellation token is set, the runner stops between steps (not mid-step) and does not mark the workflow as completed/failed

Exit Criteria

  • An in-flight workflow for an assigned issue can be cancelled via an unassign event
  • The workspace is moved to cancelled/
  • The dedup key is cleared so re-assignment triggers a fresh run

Dependencies

  • Tasks 1, 2, 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions