fix(cron): invert stateless gate to match UI label (#1139)

The cron job handler reset the session when stateless=false and skipped
reset when stateless=true — the opposite of what every UI locale labels
the field (en/ko/zh/vi all describe stateless as "each run starts fresh
without loading previous messages").

The buggy gate caused stateless=true crons to silently accumulate session
history across every execution, leading to context bloat and increasing
the chance of LLMs short-circuiting tool calls in favor of replaying
prior assistant turns. One affected daily ETL cron grew to 38 messages
over 18 days before the regression was noticed.

Fix: gate the Reset on `if job.Stateless` so the runtime matches the UI
contract. No DB migration is required — existing values were set by users
based on the UI label, so they already encode the intended behavior.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
codebit0andClaude Opus 4.7 authored and GitHub committed 2026-06-21 07:36:28 +07:00
1 parent d5033b4aaf
commit fabe86b3de
1 file changed
+8 -5
+8 -5
View File
@@ -88,11 +88,14 @@ func makeCronJobHandler(sched *scheduler.Scheduler, msgBus *bus.MessageBus, cfg
cronCtx = store.WithCredentialUserID(cronCtx, job.Payload.CredentialUserID)
}
// Reset session before each cron run to prevent tool errors from previous
// runs from polluting the context and blocking future executions (#294).
// Save() persists the empty session to DB so stale data won't reload after restart.
// Stateless jobs skip this — they intentionally carry no session history.
if !job.Stateless {
// Stateless jobs explicitly reset their session before each run — they
// carry no history between executions, matching the "Stateless" UI label
// and statelessHelp ("each run starts fresh without loading previous
// messages"). Stateful (non-stateless) jobs keep prior turns to enable
// multi-run dialog.
// Save() persists the empty session to DB so stale data won't reload
// after restart (#294).
if job.Stateless {
sessionMgr.Reset(cronCtx, sessionKey)
sessionMgr.Save(cronCtx, sessionKey)
}