fix(cron): propagate sessionKey to prevent duplicate tool responses

This commit is contained in:
afjcjsbx 2026-04-27 13:17:25 +02:00
parent f90e756e21
commit 0bb0fc429a
2 changed files with 6 additions and 1 deletions

View file

@ -357,7 +357,7 @@ func (t *CronTool) ExecuteJob(ctx context.Context, job *cron.CronJob) string {
} }
if response != "" { if response != "" {
t.executor.PublishResponseIfNeeded(ctx, channel, chatID, "", response) t.executor.PublishResponseIfNeeded(ctx, channel, chatID, sessionKey, response)
} }
return "ok" return "ok"
} }

View file

@ -24,6 +24,7 @@ type stubJobExecutor struct {
publishedResp string publishedResp string
publishedChan string publishedChan string
publishedChatID string publishedChatID string
publishedKey string
} }
func (s *stubJobExecutor) ProcessDirectWithChannel( func (s *stubJobExecutor) ProcessDirectWithChannel(
@ -47,6 +48,7 @@ func (s *stubJobExecutor) PublishResponseIfNeeded(
s.publishedResp = response s.publishedResp = response
s.publishedChan = channel s.publishedChan = channel
s.publishedChatID = chatID s.publishedChatID = chatID
s.publishedKey = sessionKey
} }
func newTestCronToolWithExecutorAndConfig(t *testing.T, executor JobExecutor, cfg *config.Config) *CronTool { func newTestCronToolWithExecutorAndConfig(t *testing.T, executor JobExecutor, cfg *config.Config) *CronTool {
@ -283,6 +285,9 @@ func TestCronTool_ExecuteJobPublishesAgentResponse(t *testing.T) {
if executor.publishedResp != "generated reply" { if executor.publishedResp != "generated reply" {
t.Fatalf("published response = %q, want generated reply", executor.publishedResp) t.Fatalf("published response = %q, want generated reply", executor.publishedResp)
} }
if executor.publishedKey != executor.lastKey {
t.Fatalf("published sessionKey = %q, want %q", executor.publishedKey, executor.lastKey)
}
if executor.publishedChan != "telegram" || executor.publishedChatID != "chat-1" { if executor.publishedChan != "telegram" || executor.publishedChatID != "chat-1" {
t.Fatalf("published target = %s/%s, want telegram/chat-1", executor.publishedChan, executor.publishedChatID) t.Fatalf("published target = %s/%s, want telegram/chat-1", executor.publishedChan, executor.publishedChatID)
} }