Skip to content

fix(cron): always reset session before cron runs — stateless flag inverted#1032

Open
kamushadenes wants to merge 1 commit into
nextlevelbuilder:devfrom
kamushadenes:fix/cron-stateless-session-reset
Open

fix(cron): always reset session before cron runs — stateless flag inverted#1032
kamushadenes wants to merge 1 commit into
nextlevelbuilder:devfrom
kamushadenes:fix/cron-stateless-session-reset

Conversation

@kamushadenes
Copy link
Copy Markdown

Summary

Cron jobs with stateless=true accumulate unbounded session history because the reset logic is inverted.

Current code (cmd/gateway_cron.go:92):

if !job.Stateless {
    sessionMgr.Reset(cronCtx, sessionKey)
    sessionMgr.Save(cronCtx, sessionKey)
}

This resets non-stateless jobs but skips stateless ones. The agent loop always persists messages to the session key regardless of the stateless flag, so stateless cron sessions grow indefinitely.

Observed in production: A stateless cron job accumulated 230KB of messages over ~10 runs. The model saw stale context from previous runs, causing it to skip data collection ("already done").

Fix: Remove the condition — always reset before cron execution. This is consistent with the intent of #294 (which added the reset to prevent error accumulation) and ensures stateless jobs actually start fresh.

Test plan

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 nextlevelbuilder#294 (which added the reset for non-stateless
jobs) and ensures stateless jobs actually start fresh each run.

Fixes nextlevelbuilder#1029-related session accumulation observed in production.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
kamushadenes added a commit to kamushadenes/goclaw that referenced this pull request Apr 24, 2026
@kamushadenes kamushadenes changed the base branch from main to dev April 24, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant