remove check task

This commit is contained in:
lpf
2026-02-19 09:40:19 +08:00
parent e2a6193376
commit 27c718def9
2 changed files with 7 additions and 63 deletions

View File

@@ -858,7 +858,7 @@ func gatewayCmd() {
}
go agentLoop.Run(ctx)
go runGatewayStartupSelfCheck(ctx, agentLoop, cfg.WorkspacePath())
go runGatewayStartupCompactionCheck(ctx, agentLoop)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
@@ -967,7 +967,7 @@ func gatewayCmd() {
}
}
func runGatewayStartupSelfCheck(parent context.Context, agentLoop *agent.AgentLoop, workspace string) {
func runGatewayStartupCompactionCheck(parent context.Context, agentLoop *agent.AgentLoop) {
if agentLoop == nil {
return
}
@@ -975,42 +975,13 @@ func runGatewayStartupSelfCheck(parent context.Context, agentLoop *agent.AgentLo
checkCtx, cancel := context.WithTimeout(parent, 10*time.Minute)
defer cancel()
prompt := buildGatewayStartupSelfCheckPrompt(workspace)
report := agentLoop.RunStartupSelfCheckAllSessions(checkCtx, prompt, "gateway:startup-self-check")
logger.InfoCF("gateway", "Startup self-check completed", map[string]interface{}{
report := agentLoop.RunStartupSelfCheckAllSessions(checkCtx)
logger.InfoCF("gateway", "Startup compaction check completed", map[string]interface{}{
"sessions_total": report.TotalSessions,
"sessions_compacted": report.CompactedSessions,
"sessions_checked": report.CheckedSessions,
"sessions_failed": report.FailedSessions,
})
}
func buildGatewayStartupSelfCheckPrompt(workspace string) string {
now := time.Now().Format(time.RFC3339)
notesPath := filepath.Join(workspace, "memory", "HEARTBEAT.md")
notes := ""
if data, err := os.ReadFile(notesPath); err == nil {
notes = strings.TrimSpace(string(data))
}
var sb strings.Builder
sb.WriteString("网关刚刚启动,请立即执行一次自检。\n")
sb.WriteString("目标:基于你自己的历史记录与记忆,判断是否有未完成任务需要继续执行,或是否需要立即采取其他行动。\n")
sb.WriteString("要求:\n")
sb.WriteString("1) 先给出结论(继续执行 / 暂无待续任务 / 其他行动)。\n")
sb.WriteString("2) 如果需要继续,请直接开始推进,并在关键节点自然汇报。\n")
sb.WriteString("3) 如果无需继续,也请给出下一步建议。\n")
sb.WriteString("4) 将本次结论简要写入 memory/MEMORY.md 便于下次启动继承。\n")
sb.WriteString("\n")
sb.WriteString("当前时间: ")
sb.WriteString(now)
if notes != "" {
sb.WriteString("\n\n参考 HEARTBEAT.md:\n")
sb.WriteString(notes)
}
return sb.String()
}
func maybePromptAndEscalateRoot(command string) {
if os.Getenv(envRootPrompted) == "1" {
return

View File

@@ -134,8 +134,6 @@ type stageReporter struct {
type StartupSelfCheckReport struct {
TotalSessions int
CompactedSessions int
CheckedSessions int
FailedSessions int
}
func (sr *stageReporter) Publish(stage int, total int, status string, detail string) {
@@ -1576,17 +1574,12 @@ func (al *AgentLoop) GetStartupInfo() map[string]interface{} {
return info
}
func (al *AgentLoop) RunStartupSelfCheckAllSessions(ctx context.Context, prompt, fallbackSessionKey string) StartupSelfCheckReport {
func (al *AgentLoop) RunStartupSelfCheckAllSessions(ctx context.Context) StartupSelfCheckReport {
report := StartupSelfCheckReport{}
if al == nil || al.sessions == nil {
return report
}
fallbackSessionKey = strings.TrimSpace(fallbackSessionKey)
if fallbackSessionKey == "" {
fallbackSessionKey = "gateway:startup-self-check"
}
keys := al.sessions.ListSessionKeys()
seen := make(map[string]struct{}, len(keys))
sessions := make([]string, 0, len(keys))
@@ -1603,7 +1596,7 @@ func (al *AgentLoop) RunStartupSelfCheckAllSessions(ctx context.Context, prompt,
}
report.TotalSessions = len(sessions)
// 仅对历史会话压缩,避免启动时在每个历史会话重复执行自检任务。
// 启动阶段只做历史会话压缩检测,避免额外触发自检任务。
for _, sessionKey := range sessions {
select {
case <-ctx.Done():
@@ -1613,7 +1606,7 @@ func (al *AgentLoop) RunStartupSelfCheckAllSessions(ctx context.Context, prompt,
before := al.sessions.MessageCount(sessionKey)
if err := al.persistSessionWithCompaction(ctx, sessionKey); err != nil {
logger.WarnCF("agent", "Startup self-check pre-compaction failed", map[string]interface{}{
logger.WarnCF("agent", "Startup compaction check failed", map[string]interface{}{
"session_key": sessionKey,
logger.FieldError: err.Error(),
})
@@ -1624,26 +1617,6 @@ func (al *AgentLoop) RunStartupSelfCheckAllSessions(ctx context.Context, prompt,
}
}
select {
case <-ctx.Done():
return report
default:
}
// 自检任务始终只执行一次,默认写入 gateway 启动专用会话。
runCtx, cancel := context.WithTimeout(ctx, 90*time.Second)
_, err := al.ProcessDirect(runCtx, prompt, fallbackSessionKey)
cancel()
if err != nil {
report.FailedSessions++
logger.WarnCF("agent", "Startup self-check task failed", map[string]interface{}{
"session_key": fallbackSessionKey,
logger.FieldError: err.Error(),
})
return report
}
report.CheckedSessions = 1
return report
}