fix(cron): make each job execution use an independent session#2474
fix(cron): make each job execution use an independent session#2474yinwm merged 3 commits intosipeed:mainfrom
Conversation
Previously all executions of the same cron job reused the session key
"cron-{jobID}", causing conversation history to accumulate across runs.
Now each run gets a unique key "cron-{jobID}-{timestamp}", preventing
cross-execution interference.
yinwm
left a comment
There was a problem hiding this comment.
Thanks for the fix! The core idea is correct — cron jobs should get independent sessions. However, there are two blocking issues:
1. Session key is silently ignored by resolveScopeKey
In pkg/agent/loop.go:1457-1462, resolveScopeKey only honors session keys prefixed with "agent:":
func resolveScopeKey(route routing.ResolvedRoute, msgSessionKey string) string {
if msgSessionKey != "" && strings.HasPrefix(msgSessionKey, sessionKeyAgentPrefix) {
return msgSessionKey
}
return route.SessionKey
}The cron key "cron-{jobID}-{timestamp}" doesn't match this prefix, so it falls back to route.SessionKey (derived from channel/chatID). This means the fix may have no effect — multiple executions of the same cron job could still share a session.
Could you verify this by checking the actual scope_key in logs when a cron job fires? If confirmed, consider either:
- Prefixing cron keys with
"agent:"(e.g.,"agent:cron-{jobID}-{timestamp}") - Or adding a special case in
processMessagefor cron-sourced messages
2. Test assertion is hardcoded to old format
pkg/tools/cron_test.go:274 still expects "cron-job-1" but the new format is "cron-job-1-{timestamp}". This will fail CI. Update to use a prefix match like strings.HasPrefix(executor.lastKey, "cron-job-1-").
Non-blocking suggestions:
- Add a TTL/cleanup strategy for cron sessions to prevent unbounded disk and memory growth
- Consider using UUID instead of
time.Now().UnixMilli()to avoid collision in concurrent scenarios
…ves 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.
fixed, testing is normal. |
|
could you fix lint please? 🙏 |
… gci gci linter requires a blank line separating import sections (default vs localmodule). Missing separator caused CI failure.
done |
yinwm
left a comment
There was a problem hiding this comment.
LGTM. All blocking issues from the previous review have been addressed — the agent: prefix ensures resolveScopeKey honors the session key, UUID avoids collision, and tests are updated. Clean fix.
📝 Description
Previously all executions of the same cron job reused the session key "cron-{jobID}", causing conversation history to accumulate across runs. Now each run gets a unique key "cron-{jobID}-{timestamp}", preventing cross-execution interference.
🗣️ Type of Change
🤖 AI Code Generation
📚 Technical Context (Skip for Docs)
☑️ Checklist