feat(cli): thread step --background + thread running #457
Reference in New Issue
Block a user
Delete Branch "fix/456-thread-step-background"
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?
What
This PR implements issue #456, adding two related capabilities to the
uwfCLI:Background execution mode for
uwf thread step(via--backgroundflag)--countoption to run multiple steps in backgroundRunning threads query command (
uwf thread running)Why
Enable long-running workflow executions without blocking the CLI. Users can:
Changes
Core Implementation
workflow-protocol: Added
RunningThreadItem,RunningThreadsOutputtypes; updatedStepOutputto includebackground: boolean | nullfieldcli-workflow/background: New module for process management
cli-workflow/commands/thread:
cmdThreadStepto support--backgroundand--_background-workerflagscmdThreadStepBackgroundfor spawning detached processescmdThreadRunningto list running threadscmdThreadKillto terminate background processescli-workflow/cli: Added CLI routing for new commands and flags
Integration
uwf thread killnow terminates background processes before archiving~/.uncaged/workflow/running/*.jsonTesting
parseClaudeCodeStreamOutputedge cases from issue #439Ref
Fixes #456
整体实现方向正确,代码结构清晰。几个问题需要修:
必须修
1.
createMarker的"原子写入"并不原子写了 tempPath 但没用
rename,最终还是直接writeFile到 markerPath。这不是原子操作。应该用rename(tempPath, markerPath)—rename在同一文件系统上是原子的。注意
tmpdir()可能跟storageRoot不在同一文件系统(比如 /tmp 是 tmpfs),rename会 cross-device 失败。tempPath 应该放在runningDir下:2. background worker 的 marker role 信息不准确
当前通过
UWF_BACKGROUND_ROLE环境变量传初始 role,但-c > 1时后续 step 的 role 会变,marker 里的 role 不会更新。建议:要么每次 step 后更新 marker(在
cmdThreadStepOnce里),要么 marker 里不存 role(用currentRole: string | null,初始为 null,查询时从 thread head 动态读取)。3.
cmdThreadStepBackground里做了一次完整的 moderator evaluate只是为了拿 role 名写 marker,但这引入了额外的 CAS 读取和 evaluate 开销。而且 background worker 启动后会再 evaluate 一次(重复)。结合上面第 2 点,建议 marker 不存 role,省掉这次 evaluate。
建议
4.
RunningThreadItem.workflow是CasRef(bundle hash)对用户来说 hash 不直观。issue spec 里写的是
workflowName。建议加一个name字段(从 registry 反查),或者至少在 marker 里记上 workflow name。5. 测试
parseClaudeCodeStreamOutput的测试跟 #456 无关(是 #439 的),放在这个 PR 里有点混。不阻塞合并,但建议以后分开。40b6abb4c3to521d908719LGTM 🍊 三个问题全部修干净了。