fix(daemon): defer hot-reload drain until in-flight runs complete #135

Merged
xiaomo merged 1 commits from fix/134-hot-reload-in-flight into main 2026-04-25 05:38:53 +00:00
Owner

What

Defer file-watcher hot-reload drain+respawn until all in-flight workflow runs complete, instead of immediately killing active threads.

Why

When workflow-generator modifies another workflow's source while it's running, the daemon's file watcher immediately drains the worker, interrupting the active run (~50% failure rate). (#134)

Changes

  • workflow-manager.ts — add drainWhenIdle() with pendingDrains tracking; wire maybeDeferredHotReloadDrain into thread-event and workflow-error completion paths; clean up on crash and stop()
  • kernel-file-watch.ts — call drainWhenIdle instead of drainAndRespawn
  • hot-reload.test.ts — 6 new test cases covering deferred drain, concurrency, dedup, error path, and immediate drain
  • daemon-ipc.test.ts — add mock for new method

Ref

Fixes #134

## What Defer file-watcher hot-reload drain+respawn until all in-flight workflow runs complete, instead of immediately killing active threads. ## Why When workflow-generator modifies another workflow's source while it's running, the daemon's file watcher immediately drains the worker, interrupting the active run (~50% failure rate). (#134) ## Changes - **workflow-manager.ts** — add `drainWhenIdle()` with `pendingDrains` tracking; wire `maybeDeferredHotReloadDrain` into thread-event and workflow-error completion paths; clean up on crash and stop() - **kernel-file-watch.ts** — call `drainWhenIdle` instead of `drainAndRespawn` - **hot-reload.test.ts** — 6 new test cases covering deferred drain, concurrency, dedup, error path, and immediate drain - **daemon-ipc.test.ts** — add mock for new method ## Ref Fixes #134
xiaoju added 1 commit 2026-04-25 05:37:41 +00:00
When a workflow file changes while runs are active, defer the
drain+respawn until all active threads finish instead of immediately
killing them.

- Add drainWhenIdle() with pendingDrains tracking
- Wire maybeDeferredHotReloadDrain into thread-event and workflow-error paths
- Clean up pendingDrains on worker crash and stop()
- 6 new test cases in hot-reload.test.ts

Fixes #134
xiaomo approved these changes 2026-04-25 05:38:52 +00:00
xiaomo left a comment
Owner

LGTM 逻辑清晰,完成路径全覆盖,测试扎实。

LGTM ✅ 逻辑清晰,完成路径全覆盖,测试扎实。
xiaomo merged commit abe205f96c into main 2026-04-25 05:38:53 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#135