RFC-006: WorkerRuntime — message-routed process management #279
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Extract a generic
WorkerRuntime<K>module from the daemon, replacing the current ad-hoc process management scattered acrossworker-pool.ts,workflow-manager.ts, andworker-fork-support.ts.The key insight: our worker processes are containers for user code. The process itself is an implementation detail — what matters is routing messages to the right handler with automatic lifecycle management.
Motivation
Current problems:
workflow-manager.ts(792 lines) mixes process management with thread tracking, concurrency control, and queue overflowDesign
Core Abstraction
Inspired by Cloudflare Workers — message-routed, auto-lifecycle:
Internal: ManagedWorker
Single-process lifecycle manager (not exposed to consumers):
State machine:
How It Replaces Current Code
worker-pool.ts(SenseWorkerPool)WorkerRuntime<GroupName>+ thin sense routing on topworkflow-manager.tsprocess partsWorkerRuntime<WorkflowName>+ thread/concurrency logic on topworker-fork-support.tsConsumers Become Thinner
Sense layer: only handles compute scheduling + signal routing. Process lifecycle delegated to runtime.
Workflow layer: only handles thread tracking, concurrency control, queue/drop overflow. Process lifecycle delegated to runtime.
Message Flow
What Does NOT Change
sense-worker.ts,workflow-worker.ts) — untouchedipc.ts) — untouchedWorkerRuntimeinstead of raw poolPhase Plan
Phase 1: Extract WorkerRuntime
packages/daemon/src/worker-runtime.tsManagedWorker+WorkerRuntime<K>with fork/crash/drain/shutdownworker-fork-support.tsinto itPhase 2: Migrate Sense Pool
worker-pool.ts(SenseWorkerPool) withWorkerRuntime<string>+ thin wrapperworker-pool.tsPhase 3: Migrate Workflow Manager
workflow-manager.tsintoWorkerRuntime<string>workflow-manager.tsshrinks to: thread tracking, concurrency, queue/overflow, drainWhenIdle coordinationPhase 4: Cleanup
worker-fork-support.tsPhase Tracking
Non-goals
RFC-006 全部 4 个 Phase 已完成并合并(#280 Phase 1, #292 Phase 2, #295 Phase 3, Phase 4 cleanup)。WorkerRuntime 已在 worker-pool.ts 和 workflow-manager.ts 中投入使用。
— 小橘 🍊(NEKO Team)