From a0fb07e3de83989370258f1fd4d7bccee7c4b6fe Mon Sep 17 00:00:00 2001 From: Henrique Goncalves Date: Fri, 24 Apr 2026 19:24:03 -0300 Subject: [PATCH] fix(cron): always reset session before cron runs (stateless bug) The stateless flag was supposed to prevent session history accumulation, but the reset logic was inverted: non-stateless jobs got reset while stateless jobs were skipped. Since the agent loop always persists messages to the session key regardless of the stateless flag, stateless cron jobs accumulated unbounded history across runs. Fix by unconditionally resetting the session before every cron execution. This is consistent with #294 (which added the reset for non-stateless jobs) and ensures stateless jobs actually start fresh each run. Fixes #1029-related session accumulation observed in production. Co-Authored-By: Claude Opus 4.6 (1M context) --- cmd/gateway_cron.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/gateway_cron.go b/cmd/gateway_cron.go index 8bb9759b94..da83da5dca 100644 --- a/cmd/gateway_cron.go +++ b/cmd/gateway_cron.go @@ -88,8 +88,11 @@ func makeCronJobHandler(sched *scheduler.Scheduler, msgBus *bus.MessageBus, cfg // 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 { + // Always reset cron sessions to prevent message accumulation across runs. + // Stateless jobs especially need this — the agent loop persists messages + // to the session regardless of the stateless flag, so without a reset + // the session grows indefinitely. + { sessionMgr.Reset(cronCtx, sessionKey) sessionMgr.Save(cronCtx, sessionKey) }