fix(cron): add agent: prefix to session key so resolveScopeKey preserves it

Cron session keys "agent:cron-{id}-{uuid}" were being silently ignored by
resolveScopeKey, which only recognizes keys prefixed with "agent:". This
caused multiple executions of the same job to share a session. Also
switch from timestamp to UUID to avoid collisions in concurrent scenarios.
This commit is contained in:
srcrs
2026-04-11 23:16:12 +08:00
parent 36b9693d31
commit 2b73978c5f
2 changed files with 4 additions and 3 deletions
+2 -1
View File
@@ -6,6 +6,7 @@ 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"
@@ -342,7 +343,7 @@ func (t *CronTool) ExecuteJob(ctx context.Context, job *cron.CronJob) string {
return "ok"
}
sessionKey := fmt.Sprintf("cron-%s-%d", job.ID, time.Now().UnixMilli())
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)