重构 worker 对话:复用 resume 机制,改专属 goroutine 运行

把「给运行中 Worker 发消息调方向」从自建的介入持久化协议,改为复用
已有的暂停/恢复 + transcript resume 能力,实现与主 Agent chat 一致。

- 拆 runWorkerStep:抽出 runIntent(执行+善后),池子与消息路径共用一份
  善后逻辑;新增 runDetachedIntent,把意图 paused→running(不经 frontier)
  并在专属 goroutine 里直接跑,用户消息不受 3 槽池限制、随发随跑。
- 精简 sendWorkerMessage handler:校验 + emit 用户活动 + 专属运行;消息经
  ExecuteWithMessage 作为下一轮输入注入,request_id 仅做 transcript 去重。
- 删除介入 DB 协议与 15 处 activity 查询过滤(回退 exploration.go)、
  directedClaims 调度屏障、RecoverWorkerMessages 恢复、workerWake/waitWorker、
  AbortWorkIntervenedByUser。无 DB schema 改动。
- 前端:保留消息框,恢复「直接继续」(resume)按钮;发送改由 SSE 承载,
  去掉乐观插入。
- 取舍(低频可接受):消息仅存内存,不做崩溃恢复;发消息时该任务可能瞬时
  超并发 1 个 worker。

净改动 9 文件 +583/-46(原 PR 15 文件 +1940/-72)。
This commit is contained in:
Autumn-27 committed 2026-08-31 09:00:21 -04:00
1 parent ff493ae42b
commit c9bf534818
14 files changed
+237 -1568

No files matched your search

+1 -16
View File
@@ -63,7 +63,6 @@ type Task struct {
Store *pgdb.ExplorationStore `json:"-"`
Guard *guard.Guard `json:"-"`
notify chan struct{}
workerWake chan struct{}
lifecycleMu sync.RWMutex
llmMu sync.RWMutex
@@ -738,7 +737,7 @@ func taskFromPG(pt *pgdb.Task, store *pgdb.ExplorationStore, ic *intercept.Inter
TimeoutSeconds: pt.TimeoutSeconds, PlanHeartbeatSeconds: pt.PlanHeartbeatSeconds,
CoverageEnabled: pt.CoverageEnabled,
FirstRunAt: unixOrZero(pt.FirstRunAt), DeadlineAt: unixOrZero(pt.DeadlineAt),
Store: store, Guard: guard.NewWithInterceptor(ic), notify: make(chan struct{}, 1), workerWake: make(chan struct{}, 64),
Store: store, Guard: guard.NewWithInterceptor(ic), notify: make(chan struct{}, 1),
}
}
@@ -1639,20 +1638,6 @@ func (t *Task) Notify() {
}
}
// NotifyWorker wakes one idle execution slot without also scheduling a Planner
// round. The channel is separate from notify because human intervention needs
// the reopened intent reclaimed immediately, while graph-change notifications
// are Planner-facing and debounced. A nil channel is tolerated by test fixtures.
func (t *Task) NotifyWorker() {
if t == nil || t.workerWake == nil {
return
}
select {
case t.workerWake <- struct{}{}:
default:
}
}
// NotifyDone is Notify plus a hint: a worker just finished intentID and that is
// what triggered this wake-up. The planner reads the accumulated triggers next
// round so it can spell out which intent finished (+ its output). Events pile up