fix(cron): reset session for stateless cron jobs, not stateful ones#1262
Merged
mrgoonie merged 1 commit intoJun 23, 2026
Merged
Conversation
The per-run session reset was gated on `!job.Stateless`, inverting the flag: stateless jobs (the token-saving default) skipped the reset and accumulated unbounded history, while stateful jobs were wiped every run. Reset for `job.Stateless` instead, and clear BOTH session layers — the goclaw session store AND the Claude CLI on-disk .jsonl. claude-cli resumes its own session by a deterministic per-key UUID, so without clearing the .jsonl a "stateless" run still replayed the entire accumulated history (and silently grew it run after run).
mrgoonie
approved these changes
Jun 23, 2026
mrgoonie
left a comment
Contributor
There was a problem hiding this comment.
Summary: This is a focused cron-session fix. It corrects the stateless gate so stateless cron runs reset both the GoClaw session store and the Claude CLI on-disk session, while preserving stateful cron history.
Risk level: Medium
Mandatory gates:
- Duplicate/prior implementation: overlap found with older open PR #1032, but this PR is the stronger successor because it preserves stateful jobs and also clears the Claude CLI session layer.
- Project standards: passed; the change is localized to cmd/gateway_cron.go with targeted tests in cmd/gateway_cron_test.go.
- Strategic necessity: clear value; prevents stateless cron token/history accumulation and fixes the inverted stateful/stateless behavior.
- CI/checks: green.
Findings:
- Critical: none.
- Important: none.
- Suggestion: after merge, #1032 should be closed as superseded by this implementation.
Verdict: APPROVE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Cron runs reset the session before each run (so a previous run's tool errors can't pollute the next — #294). That reset was gated on
if !job.Stateless, which inverts the flag:stateless = true(the default, documented as "saves tokens" / fresh each run) → reset skipped → session accumulates unbounded history across runs.stateless = false(stateful, wants memory) → reset runs every time → session wiped each run.Observed in production: a frequently-firing
stateless=truecron grew its Claude CLI session.jsonlto ~30 MB, replaying the whole history on every run (large token cost) until the model started emitting malformed tool calls.There's a second layer: the cron reset only cleared the goclaw session store, never the Claude CLI on-disk session. claude-cli resumes its own
.jsonlby a deterministic per-key UUID (--resume), so even when the reset fired the model still saw the full accumulated history — i.e.statelesshad no effect on the actual model context for claude-cli agents.Fix
if job.Stateless(correct direction).ResetCLISession(indirected through an overridable package var for testing), so a stateless run truly starts fresh on both layers.sessionMgr != nil(it is nil in some unit-test setups).Stateful jobs (
stateless=false) now correctly keep their session across runs. Non-claude-cli providers are unaffected —ResetCLISessionis a no-op when no CLI session file exists.Test
cmd/gateway_cron_test.go: newTestCronJobHandler_StatelessResetsSessionasserts a stateless run clears both the session store and the CLI session, and a stateful run clears neither (via a fakeSessionStore+ an overriddencronCLISessionReset).No migration / schema / i18n change.
Note for operators
Behavior change: any cron currently set
stateless=falsethat was relying on the (buggy) per-run wipe will now retain its session. Re-check the flag on existing crons — setstateless=truefor jobs that should start fresh each run.