Merge pull request #2474 from srcrs/fix-cron-independent-sessions

fix(cron): make each job execution use an independent session
This commit is contained in:
daming大铭
2026-04-16 23:52:29 +08:00
committed by GitHub
2 changed files with 5 additions and 3 deletions
+3 -1
View File
@@ -6,6 +6,8 @@ import (
"strings"
"time"
"github.com/google/uuid"
"github.com/sipeed/picoclaw/pkg/bus"
"github.com/sipeed/picoclaw/pkg/config"
"github.com/sipeed/picoclaw/pkg/constants"
@@ -340,7 +342,7 @@ func (t *CronTool) ExecuteJob(ctx context.Context, job *cron.CronJob) string {
return "ok"
}
sessionKey := fmt.Sprintf("cron-%s", job.ID)
sessionKey := fmt.Sprintf("agent:cron-%s-%s", job.ID, uuid.New().String())
// Call agent with the job message
response, err := t.executor.ProcessDirectWithChannel(
+2 -2
View File
@@ -271,8 +271,8 @@ func TestCronTool_ExecuteJobPublishesAgentResponse(t *testing.T) {
t.Fatalf("ExecuteJob() = %q, want ok", got)
}
if executor.lastKey != "cron-job-1" {
t.Fatalf("sessionKey = %q, want cron-job-1", executor.lastKey)
if !strings.HasPrefix(executor.lastKey, "agent:cron-job-1-") {
t.Fatalf("sessionKey = %q, want agent:cron-job-1-{uuid}", executor.lastKey)
}
if executor.lastChan != "telegram" || executor.lastChatID != "chat-1" {
t.Fatalf("executor target = %s/%s, want telegram/chat-1", executor.lastChan, executor.lastChatID)