fix(evolution): skip cold path for heartbeat turns

This commit is contained in:
Alix-007 2026-06-24 23:29:46 +08:00
parent 540f81ff9e
commit 288013ca0f
2 changed files with 32 additions and 0 deletions

View file

@ -202,6 +202,9 @@ func (b *evolutionBridge) handleTurnEndAsync(meta EventMeta, payload TurnEndPayl
FinalSuccessfulPath: append([]string(nil), payload.FinalSuccessfulPath...),
SkillContextSnapshots: toEvolutionSkillContextSnapshots(payload.SkillContextSnapshots),
}
if isEvolutionHeartbeatInput(input) {
return false
}
b.rememberScheduledColdPathWorkspace(input.Workspace)
b.closeMu.Lock()
@ -228,6 +231,10 @@ func (b *evolutionBridge) handleTurnEndAsync(meta EventMeta, payload TurnEndPayl
return true
}
func isEvolutionHeartbeatInput(input evolution.TurnCaseInput) bool {
return strings.EqualFold(strings.TrimSpace(input.SessionKey), "heartbeat")
}
func (b *evolutionBridge) subscribeRuntimeEvents(ch runtimeevents.EventChannel) error {
if b == nil || ch == nil {
return nil

View file

@ -513,6 +513,31 @@ func TestEvolutionBridge_DraftModeAutomaticallyRunsColdPathAndCreatesDraftFile(t
waitForDrafts(t, filepath.Join(tmpDir, "state", "evolution", "skill-drafts.json"), 1)
}
func TestEvolutionBridge_DraftModeDoesNotRunColdPathForHeartbeat(t *testing.T) {
tmpDir := t.TempDir()
seedReadyRule(t, tmpDir)
al := newEvolutionTestLoop(t, tmpDir, config.EvolutionConfig{
Enabled: true,
Mode: "draft",
}, &simpleMockProvider{
response: `{"target_skill_name":"weather","draft_type":"shortcut","change_kind":"append","human_summary":"unexpected heartbeat draft","body_or_patch":"## Unexpected"}`,
})
defer al.Close()
resp, err := al.ProcessHeartbeat(context.Background(), "check heartbeat tasks", "telegram", "chat-1")
if err != nil {
t.Fatalf("ProcessHeartbeat failed: %v", err)
}
if resp == "" {
t.Fatal("expected non-empty heartbeat response")
}
time.Sleep(150 * time.Millisecond)
assertNotExists(t, filepath.Join(tmpDir, "state", "evolution", "task-records.jsonl"))
assertNotExists(t, filepath.Join(tmpDir, "state", "evolution", "skill-drafts.json"))
}
func TestEvolutionBridge_ScheduledModeDoesNotRunColdPathAfterTurn(t *testing.T) {
tmpDir := t.TempDir()
seedReadyRule(t, tmpDir)