RFC: resume completed threads + unify thread storage #39
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?
动机
已完成的 thread 无法 resume。用户在 thread 结束后收到新信息(PR 反馈、需求变更),只能新开 thread,丢失原有上下文。
现有 suspend → resume 已经证明了 resume 的价值。Completed → resume 是自然延伸:end → start,衔尾蛇——上下文全在 CAS chain 里,只需要重新进入 graph。
现状
@uwf/thread/<id>(tag: suspendedRole, suspendMessage)@uwf/thread/<id>删除,搬到@uwf/history/<id>(tag: completedAt, reason)uwf thread resume只认 suspended 状态,completed 直接报错方案
1. 统一 thread storage(取消 history prefix)
所有 thread 统一存
@uwf/thread/<id>,用 tag 表达状态:statusidle | running | suspended | completed | cancelledsuspendedRolesuspendMessagecompletedAtreasoncompleted | cancelled查询方式:
statustag 不是completed也不是cancelledstatustag 是completed或cancelled@uwf/history/*prefix2. Resume completed thread
uwf thread resume <id>扩展支持 completed 状态:$START重新进入 graph(衔尾蛇:end → start)--supplement,传递新信息(PR 反馈等)completedAt/reasontag,将status改回idle,然后正常走 step行为对比:
3. 迁移
@uwf/history/<id>数据需一次性迁移到@uwf/thread/<id>(加 status tag)HISTORY_VAR_PREFIX和相关函数标记 deprecated,迁移完成后删除分步实施
Phase 1: 统一 thread storage
@uwf/thread/<id>+ status tag@uwf/history/*→@uwf/thread/*(加 status=completed/cancelled tag)HISTORY_VAR_PREFIX及相关代码Phase 2: Resume completed thread
uwf thread resume支持 completed 状态$START进入 graph--supplement传递用户输入不做
uwf thread resumeRFC 整体思路清晰,两个问题值得讨论:
1. tag 和 tag 冗余
已经区分了 , 完全重复。建议二选一:
2. 状态的崩溃恢复
新增 的区分意味着需要有人负责 running → idle/completed 的状态转移。如果 agent 进程崩溃(OOM、kill),status 会卡在 再也回不来。
建议:
其他部分 LGTM:
RFC 整体思路清晰,两个问题值得讨论:
1.
reasontag 和statustag 冗余status已经区分了completed | cancelled,reason: completed | cancelled完全重复。建议二选一:reason,靠status本身区分reason承载不同语义(比如 human-readable 的结束原因:"all roles passed"、"user cancelled"、"timeout"),这样才有存在价值2.
running状态的崩溃恢复新增
idle | running的区分意味着需要有人负责 running → idle/completed 的状态转移。如果 agent 进程崩溃(OOM、kill),status 会卡在running再也回不来。建议:
running,Phase 1 先只用idle | suspended | completed | cancelled(和现状行为一致,只是换了存储方式)running的同时加 stale detection(比如记录startedAttimestamp,超时自动视为 idle)其他部分 LGTM:
补充:关于
running状态崩溃恢复的问题,重新想了一下——exec是单步执行,崩溃只是当前步没完成、-c计数中断,不会死循环。下次exec/resume时只要允许从running状态重新进入即可,running本质是信息标记不是排他锁。所以
running状态可以直接引入,不需要 stale detection。之前的顾虑撤回。小墨的两点都同意,更新方案:
1. 去掉
reasontagstatus=completed|cancelled已经足够区分,reason纯冗余。去掉。如果以后需要 human-readable 结束原因(timeout、user cancel 等),再加endReasontag。2.
running状态 Phase 1 不引入Phase 1 只用
idle | suspended | completed | cancelled四个状态,和现状行为一致。running 检测继续用现有的 background marker 文件机制,不往 tag 里加。更新后的 tag 模型:
statusidle | suspended | completed | cancelledsuspendedRolesuspendMessagecompletedAt开始做了。