openclaw - ✅(Solved) Fix Model state bleeds from cron sessions to parent session [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#62344Fetched 2026-04-08 03:05:41
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1referenced ×1

When a cron job is configured with a model override (e.g., model: "ollama/kimi-k2.5:cloud"), the model state bleeds into the parent session's persistent state in sessions.json, causing the main session to unexpectedly switch models.

Root Cause

Root Cause Hypothesis

The session state management appears to share state between sessions with nested keys (agent:main:cron:... inherits from agent:main:...). When a model_change event is written, it's persisting to the parent session's state in sessions.json despite sessionTarget: "isolated".

Fix Action

Workaround

  • Disable cron jobs that use model overrides, OR
  • Use the default model for all cron jobs (no model override)

PR fix notes

PR #62365: fix(cron): guard agentSessionKey write in createPersistCronSessionEntry

Description (problem / solution / changelog)

Summary

Closes #62344

Root cause: src/cron/isolated-agent/run-session-state.ts line 33 — createPersistCronSessionEntry() unconditionally writes the cron-mutated sessionEntry (carrying model override) to agentSessionKey = "agent:main:main" even when sessionTarget: "isolated" produces a distinct runSessionKey. Introduced in commit 870cc22.

Call path: runCronIsolatedAgentTurnprepareCronRunContext (run.ts:294) → createPersistCronSessionEntry → unconditional store write to agentSessionKey.

Runtime proof: When sessionTarget: "isolated", runSessionKey = "${agentSessionKey}:run:${runSessionId}" differs from agentSessionKey, so the unconditional write mutates the parent session with cron's model override.

Fix: Guard both store writes in createPersistCronSessionEntry behind runSessionKey === agentSessionKey.

G8: Single callsite — run.ts:294. No other files affected.

Test plan

  • New test: does not bleed cron model override into parent session when sessionTarget is isolated
  • New test: still writes to agentSessionKey when keys are equal (non-isolated path)
  • 8/8 tests pass in run.cron-model-override.test.ts
  • 75/75 test files pass in cron vitest project

🤖 Generated with Claude Code

Changed files

  • src/cron/isolated-agent/run-session-state.ts (modified, +11/-2)
  • src/cron/isolated-agent/run.cron-model-override.test.ts (modified, +45/-0)

Code Example

{
  "payload": {
    "kind": "agentTurn",
    "model": "ollama/kimi-k2.5:cloud",
    ...
  },
  "sessionTarget": "isolated"
}

---

{
  "agent:main:main": {
    "model": "kimi-k2.5:cloud",  // Wrong! Should be the default model
    ...
  },
  "agent:main:cron:<job-id>": {
    "model": "kimi-k2.5:cloud",  // Correct
    ...
  }
}

---

{"type":"model_change","id":"...","timestamp":"2026-04-07T06:47:33.548Z","provider":"ollama","modelId":"kimi-k2.5:cloud"}
{"type":"custom","customType":"model-snapshot","data":{"modelId":"kimi-k2.5:cloud",...}}

---

"agent:main:main": {"model": "kimi-k2.5:cloud"}

---

"agent:main:cron:105b2013-...": {"model": "kimi-k2.5:cloud"}
RAW_BUFFERClick to expand / collapse

Bug: Model Override in Cron Jobs Corrupts Parent Session State

Summary

When a cron job is configured with a model override (e.g., model: "ollama/kimi-k2.5:cloud"), the model state bleeds into the parent session's persistent state in sessions.json, causing the main session to unexpectedly switch models.

Steps to Reproduce

  1. Configure a cron job with sessionTarget: "isolated" and a model override:
{
  "payload": {
    "kind": "agentTurn",
    "model": "ollama/kimi-k2.5:cloud",
    ...
  },
  "sessionTarget": "isolated"
}
  1. Wait for the cron to run
  2. Check the main session (agent:main:main) in sessions.json
  3. Observe that model field is now set to the cron job's model

Expected Behavior

  • Cron sessions with sessionTarget: "isolated" should have completely isolated state
  • Model overrides in cron jobs should NOT affect the parent session's persistent model state
  • Main session should retain its configured default model

Actual Behavior

  • After cron runs, sessions.json contains:
{
  "agent:main:main": {
    "model": "kimi-k2.5:cloud",  // Wrong! Should be the default model
    ...
  },
  "agent:main:cron:<job-id>": {
    "model": "kimi-k2.5:cloud",  // Correct
    ...
  }
}
  • The session JSONL shows a model_change event being written:
{"type":"model_change","id":"...","timestamp":"2026-04-07T06:47:33.548Z","provider":"ollama","modelId":"kimi-k2.5:cloud"}
{"type":"custom","customType":"model-snapshot","data":{"modelId":"kimi-k2.5:cloud",...}}

Evidence

From debugging session:

  1. sessions.json shows corrupted state:
"agent:main:main": {"model": "kimi-k2.5:cloud"}
  1. All cron sessions correctly have their own model:
"agent:main:cron:105b2013-...": {"model": "kimi-k2.5:cloud"}
  1. Session key hierarchy appears to cause the bleed:
  • Main session: agent:main:main
  • Cron session: agent:main:cron:<job-id>
  • The nested key structure under agent:main may be causing state inheritance issues
  1. JSONL shows model_change events being written to main session file

Workaround

  • Disable cron jobs that use model overrides, OR
  • Use the default model for all cron jobs (no model override)

Root Cause Hypothesis

The session state management appears to share state between sessions with nested keys (agent:main:cron:... inherits from agent:main:...). When a model_change event is written, it's persisting to the parent session's state in sessions.json despite sessionTarget: "isolated".

The isolation should prevent:

  1. model_change events from being written to parent session JSONL
  2. Model state from persisting in parent session's sessions.json entry

Environment

  • OpenClaw version: 2026.4.5 (3e72c03)
  • Node: v22.22.2
  • OS: Linux 6.17.0-20-generic (x64)

Impact

This breaks user experience when:

  • Running multiple cron jobs with different model requirements
  • Using specialized models for specific background tasks (e.g., dreaming, analysis)
  • Expecting the main session to maintain its configured default model

Users may not notice until their main session unexpectedly starts using a different model, potentially affecting response quality, cost, or functionality.

extent analysis

TL;DR

Isolate cron job sessions by ensuring that model_change events are not written to the parent session's JSONL file and that model state is not persisted in the parent session's sessions.json entry.

Guidance

  • Verify that the sessionTarget: "isolated" configuration is correctly applied to all cron jobs with model overrides.
  • Check the session key hierarchy to ensure that cron sessions are not inheriting state from the main session.
  • Review the JSONL files to confirm that model_change events are not being written to the main session file when a cron job runs.
  • Consider implementing a more robust session state management system to prevent state sharing between sessions with nested keys.

Example

No code snippet is provided as the issue is related to configuration and session state management.

Notes

The root cause of the issue appears to be related to the session state management and the sharing of state between sessions with nested keys. The provided workaround of disabling cron jobs with model overrides or using the default model for all cron jobs may not be suitable for all users.

Recommendation

Apply the workaround of using the default model for all cron jobs (no model override) until a more permanent fix can be implemented to prevent state sharing between sessions. This will prevent the main session from unexpectedly switching models.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING