Keep auto-present reminders synchronous to avoid run races
ci / vet-and-test (pull_request) Successful in 56s
ci / vet-and-test (pull_request) Successful in 56s
Why: Async notice-run delivery raced with test teardown and in-flight conversation runs (database closed / material lifecycle flakes). Evidence: go test ./internal/runmgr/ -run Material Impact: Reminders append as system messages only; material path still inlines into startNoticeRun. Refs: Dev PR #425 CI test-pg failure Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,8 +12,9 @@ func genUIAutoReminderText() string {
|
||||
return "任务语义事件已发生(阶段或材料/工件完成)。若 generative-ui 已启用,请调用一次 generative-ui.present 生成或修订建议页,按当前任务阶段组织信息。不要点击页面 actions,不要改写 plan/todo/任务完成状态;任务事实只能来自真实任务记录。"
|
||||
}
|
||||
|
||||
// maybeGenUIAuto:语义事件钩子入口。会话忙碌时只追加 system 消息供下一轮消费;
|
||||
// 空闲时启动短 notice-run 让模型有机会立即 present。
|
||||
// maybeGenUIAuto:语义事件钩子入口。仅同步追加 system-reminder,供后续回合消费;
|
||||
// 不另起 notice-run(避免与在途 run / 测试拆卸竞态)。材料完成路径在
|
||||
// startNoticeRun 内联注入同一文案。
|
||||
func (m *Manager) maybeGenUIAuto(owner, convID, reason string) {
|
||||
if m == nil || m.genuiAuto == nil {
|
||||
return
|
||||
@@ -22,34 +23,12 @@ func (m *Manager) maybeGenUIAuto(owner, convID, reason string) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
go m.deliverGenUIAutoReminder(owner, convID, reason)
|
||||
}
|
||||
|
||||
func (m *Manager) deliverGenUIAutoReminder(owner, convID, reason string) {
|
||||
text := "<system-reminder>\n" + genUIAutoReminderText() + "\n(trigger=" + reason + ")\n</system-reminder>"
|
||||
msg := core.Message{
|
||||
ConversationID: convID, Role: core.RoleSystem,
|
||||
Parts: []core.Part{{Type: core.PartText, Text: text}},
|
||||
}
|
||||
if err := m.st.AppendMessage(&msg); err != nil {
|
||||
return
|
||||
}
|
||||
m.convMu.Lock()
|
||||
busy := m.convActive[convID]
|
||||
m.convMu.Unlock()
|
||||
if busy {
|
||||
return
|
||||
}
|
||||
conv, err := m.st.GetConversation(owner, convID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := m.claimConversation(convID); err != nil {
|
||||
return
|
||||
}
|
||||
if _, err := m.startClaimedRun(conv, msg, nil, nil, nil); err != nil {
|
||||
m.releaseConversation(convID)
|
||||
}
|
||||
_ = m.st.AppendMessage(&msg)
|
||||
}
|
||||
|
||||
func planStageChanged(prev, next core.PlanSnapshot) bool {
|
||||
|
||||
Reference in New Issue
Block a user