RFC-006 Phase 1: Extract WorkerRuntime + ManagedWorker #280

Closed
opened 2026-04-30 12:53:02 +00:00 by xiaomo · 0 comments
Owner

目标

创建 packages/daemon/src/worker-runtime.ts,实现通用进程管理原语。

变更范围

  • 新增 worker-runtime.ts
  • 吸收 worker-fork-support.ts 的通用逻辑(stderr capture, exit summary)

具体任务

  1. 实现 ManagedWorker:fork → ready → draining → stopped 状态机
  2. 实现 WorkerRuntime<K>:按 key 管理多个 ManagedWorker
  3. 功能:cold start, send, crash respawn with backoff, drain+respawn, graceful shutdown
  4. 单元测试(不需要 sense/workflow 上下文):
    • cold start: send 时自动 fork
    • crash respawn: worker 挂了自动重启
    • crash limit: 连续崩溃超限停止重试
    • drain: shutdown + 自动 respawn
    • evict: shutdown 不 respawn
    • shutdown all: 全部关闭

验证步骤

  • WorkerRuntime 类型导出
  • 基本状态转换测试通过
  • crash backoff 测试通过
  • drain + respawn 测试通过
  • pnpm run build + pnpm test 通过
  • 不影响现有 sense/workflow 逻辑(纯新增文件)

Ref: #279

## 目标 创建 `packages/daemon/src/worker-runtime.ts`,实现通用进程管理原语。 ## 变更范围 - 新增 `worker-runtime.ts` - 吸收 `worker-fork-support.ts` 的通用逻辑(stderr capture, exit summary) ## 具体任务 1. 实现 `ManagedWorker`:fork → ready → draining → stopped 状态机 2. 实现 `WorkerRuntime<K>`:按 key 管理多个 ManagedWorker 3. 功能:cold start, send, crash respawn with backoff, drain+respawn, graceful shutdown 4. 单元测试(不需要 sense/workflow 上下文): - cold start: send 时自动 fork - crash respawn: worker 挂了自动重启 - crash limit: 连续崩溃超限停止重试 - drain: shutdown + 自动 respawn - evict: shutdown 不 respawn - shutdown all: 全部关闭 ## 验证步骤 - [ ] `WorkerRuntime` 类型导出 - [ ] 基本状态转换测试通过 - [ ] crash backoff 测试通过 - [ ] drain + respawn 测试通过 - [ ] `pnpm run build` + `pnpm test` 通过 - [ ] 不影响现有 sense/workflow 逻辑(纯新增文件) Ref: #279
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/nerve#280