Workflow abort — 通过 event + GuardProjection 终止在跑的 workflow #10

Closed
opened 2026-04-18 13:38:41 +00:00 by xiaoju · 0 comments
Owner

背景

当前没有办法 kill 一个在跑的 workflow。一旦提交了错误的任务(如 #68 event 给 meta workflow 改核心包),只能等它 maxRounds 耗尽。

设计

有了 GuardProjection (#9),abort 变得自然:

1. workflow-lifecycle GuardProjection

{
  "name": "workflow-lifecycle",
  "initial_value": { "status": "unknown" },
  "sources": [
    { "kind": "*.__start__", "check": "state.status = 'unknown'", "transition": "{'status':'active'}" },
    { "kind": "*.__abort__", "check": "state.status = 'active'", "transition": "{'status':'aborted'}" },
    { "kind": "*.__end__", "check": "state.status = 'active'", "transition": "{'status':'ended'}" }
  ]
}

2. Adapter 改造

Adapter 在 tick 开始时读 workflow-lifecycle guard state:

  • status === 'aborted' → 跳过,不执行任何 role
  • status === 'ended' → 跳过
  • status === 'active' → 正常 tick

3. CLI

upulse workflow abort <key> [--reason "任务超出范围"]

写一个 meta.__abort__ event,GuardProjection 校验通过后状态变为 aborted

好处

  • 杀 workflow = push 一个 event,一切在 event sourcing 体系内
  • abort 状态可通过 projection 查询,有完整审计轨迹
  • GuardProjection 保证不会对已 abort/ended 的 workflow 重复操作
  • 不需要新的控制面机制

依赖

  • #9 GuardProjection(已完成)

— 小橘 🍊(NEKO Team)

## 背景 当前没有办法 kill 一个在跑的 workflow。一旦提交了错误的任务(如 #68 event 给 meta workflow 改核心包),只能等它 maxRounds 耗尽。 ## 设计 有了 GuardProjection (#9),abort 变得自然: ### 1. workflow-lifecycle GuardProjection ```json { "name": "workflow-lifecycle", "initial_value": { "status": "unknown" }, "sources": [ { "kind": "*.__start__", "check": "state.status = 'unknown'", "transition": "{'status':'active'}" }, { "kind": "*.__abort__", "check": "state.status = 'active'", "transition": "{'status':'aborted'}" }, { "kind": "*.__end__", "check": "state.status = 'active'", "transition": "{'status':'ended'}" } ] } ``` ### 2. Adapter 改造 Adapter 在 tick 开始时读 workflow-lifecycle guard state: - `status === 'aborted'` → 跳过,不执行任何 role - `status === 'ended'` → 跳过 - `status === 'active'` → 正常 tick ### 3. CLI ```bash upulse workflow abort <key> [--reason "任务超出范围"] ``` 写一个 `meta.__abort__` event,GuardProjection 校验通过后状态变为 `aborted`。 ### 好处 - 杀 workflow = push 一个 event,一切在 event sourcing 体系内 - abort 状态可通过 projection 查询,有完整审计轨迹 - GuardProjection 保证不会对已 abort/ended 的 workflow 重复操作 - 不需要新的控制面机制 ### 依赖 - #9 GuardProjection(已完成) — 小橘 🍊(NEKO Team)
This repo is archived. You cannot comment on issues.
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/pulse#10