Skip to content

fix(cron): handle sessions list cron model override#21279

Merged
Takhoffman merged 7 commits intoopenclaw:mainfrom
altaywtf:fix/sessions-list-cron-model-override
Mar 1, 2026
Merged

fix(cron): handle sessions list cron model override#21279
Takhoffman merged 7 commits intoopenclaw:mainfrom
altaywtf:fix/sessions-list-cron-model-override

Conversation

@altaywtf
Copy link
Copy Markdown
Member

@altaywtf altaywtf commented Feb 19, 2026

Summary

  • Problem: sessions_list shows the agent default model (e.g. Opus) instead of the actual cron payload model override (e.g. Sonnet), making cost tracking unreliable
  • Why it matters: Users running cron jobs on cheaper models see inflated cost estimates because the wrong model is reported
  • What changed: Set model/modelProvider on the session entry before the agent run (not only after), wrapped in best-effort try-catch
  • What did NOT change (scope boundary): Post-run model persistence is untouched — it still overwrites with the actual model used (e.g. if fallback kicked in)

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

sessions_list now correctly reflects the cron payload model override for failed and in-progress runs, instead of falling back to the agent default model.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Any
  • Runtime/container: Node.js
  • Model/provider: Any agent with a cron job that overrides payload.model
  • Integration/channel (if any): Cron / isolated agent
  • Relevant config (redacted): Agent defaulting to Opus with cron job specifying model: "anthropic/claude-sonnet-4-6"

Steps

  1. Configure an agent with default model claude-opus-4-6
  2. Add a cron job with payload.model: "anthropic/claude-sonnet-4-6"
  3. Trigger the cron job and call sessions.list while it runs or after it fails

Expected

  • sessions_list shows claude-sonnet-4-6 for the cron session

Actual

  • sessions_list shows claude-opus-4-6 (the agent default)

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

6 test cases covering: error path, race condition (point-in-time persist snapshots), disallowed model rejection, session-level /model override, persist failure resilience, and default model (no override).

Human Verification (required)

  • Verified scenarios: All 28 src/cron/isolated-agent/ tests pass; new tests confirmed failing before fix and passing after
  • Edge cases checked: Filesystem error on persist (best-effort), disallowed payload model early-return, session-level /model override, no payload override
  • What you did not verify: End-to-end with a live cron job and real sessions.list call

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Revert the 2-line addition in src/cron/isolated-agent/run.ts (lines 433-434)
  • Files/config to restore: src/cron/isolated-agent/run.ts
  • Known bad symptoms reviewers should watch for: Model field on cron sessions showing unexpected values in sessions_list

Risks and Mitigations

  • Risk: Pre-run persist writes a model that differs from the actual model used (e.g. if fallback triggers)
    • Mitigation: The post-run persist at line 523-524 overwrites with the actual model from agentMeta on success; the pre-run value is only visible during the run or after a failure

Greptile Summary

Fixed race condition where sessions_list showed incorrect model for cron jobs when the run failed or was still in progress. The model override is now persisted to the session entry before the agent run executes, ensuring it reflects the intended cron model rather than falling back to the agent default.

  • Moved model and provider persistence from post-run telemetry block to pre-run, immediately after model resolution
  • Added try-catch wrapper around pre-run persist to make it best-effort (filesystem errors shouldn't block the agent run)
  • Added comprehensive test coverage for edge cases: run failures, race conditions during mid-run reads, disallowed models, session-level overrides, and persist failures

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is well-isolated to cron model persistence logic with comprehensive test coverage. The best-effort error handling ensures the change cannot break existing functionality. All 6 test cases pass and cover critical scenarios including failures, race conditions, and edge cases.
  • No files require special attention

Last reviewed commit: 8eb6b13

@altaywtf altaywtf force-pushed the fix/sessions-list-cron-model-override branch from 7214674 to 56c83f9 Compare February 23, 2026 08:51
@altaywtf altaywtf changed the title Fix/sessions list cron model override fix(cron): handle sessions list cron model override Feb 23, 2026
@altaywtf altaywtf force-pushed the fix/sessions-list-cron-model-override branch 4 times, most recently from bedd794 to c344bd4 Compare February 28, 2026 19:03
altaywtf and others added 7 commits March 1, 2026 07:07
…run (#21057)

Add failing test that proves the cron payload model override is not
persisted on the session entry when the agent run throws, causing
sessions_list to fall back to the agent default model.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…1057)

Set the cron payload model on the session entry before the pre-run
persist so that sessions_list shows the correct model even when the
run fails or is still in progress.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…21057)

Replace the weak pre-run persist test with one that captures deep
snapshots at each updateSessionStore call, proving the model override
is on the session entry before the agent run starts.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…21057)

Wrap the pre-run persistSessionEntry in try-catch with logWarn so a
filesystem error does not abort the entire cron run for a cosmetic
persist.

Add tests for: disallowed payload model early-return, session-level
/model override, pre-run persist failure resilience, and default model
(no override) pre-run persistence. Fix stale line-number references in
test comments and strengthen persist-count assertion.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@Takhoffman Takhoffman force-pushed the fix/sessions-list-cron-model-override branch from c344bd4 to cad3fa1 Compare March 1, 2026 13:32
@Takhoffman Takhoffman merged commit 98e30dc into openclaw:main Mar 1, 2026
9 checks passed
@Takhoffman
Copy link
Copy Markdown
Contributor

PR #21279 - fix(cron): handle sessions list cron model override (#21279)

Merged via squash.

  • Merge commit: 98e30dc
  • Verified: pnpm install --frozen-lockfile, pnpm build, pnpm check, pnpm test:macmini
  • Changes made:
    M CHANGELOG.md
    M src/cron/isolated-agent/run.cron-model-override.test.ts
  • Why these changes were made:
    Keep changelog policy intact and align the PR's new tests with current run.ts behavior () after rebase on latest main.
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

Thanks @altaywtf!

@Takhoffman
Copy link
Copy Markdown
Contributor

PLACEHOLDER

@Takhoffman
Copy link
Copy Markdown
Contributor

PR #21279 - fix(cron): handle sessions list cron model override (#21279)

Merged via squash.

  • Merge commit: 98e30dc
  • Verified: pnpm install --frozen-lockfile, pnpm build, pnpm check, pnpm test:macmini
  • Changes made:
    M CHANGELOG.md
    M src/cron/isolated-agent/run.cron-model-override.test.ts
  • Why these changes were made:
    Keep changelog policy intact and align the PR's new tests with current run.ts behavior (setSessionRuntimeModel) after rebase on latest main.
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

Thanks @altaywtf!

github-actions bot pushed a commit to tankerwng2/openclaw that referenced this pull request Mar 1, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
@altaywtf altaywtf deleted the fix/sessions-list-cron-model-override branch March 1, 2026 15:57
@altaywtf
Copy link
Copy Markdown
Member Author

altaywtf commented Mar 1, 2026

zooqueen added a commit to hanzoai/bot that referenced this pull request Mar 1, 2026
ansh pushed a commit to vibecode/openclaw that referenced this pull request Mar 2, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
safzanpirani pushed a commit to safzanpirani/clawdbot that referenced this pull request Mar 2, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
robertchang-ga pushed a commit to robertchang-ga/openclaw that referenced this pull request Mar 2, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
hanqizheng pushed a commit to hanqizheng/openclaw that referenced this pull request Mar 2, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
execute008 pushed a commit to execute008/openclaw that referenced this pull request Mar 2, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
dorgonman pushed a commit to kanohorizonia/openclaw that referenced this pull request Mar 3, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
sachinkundu pushed a commit to sachinkundu/openclaw that referenced this pull request Mar 6, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
zooqueen added a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
Mateljan1 pushed a commit to Mateljan1/openclaw that referenced this pull request Mar 7, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 16, 2026
…thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
(cherry picked from commit 98e30dc)
alexey-pelykh added a commit to remoteclaw/remoteclaw that referenced this pull request Mar 16, 2026
* fix(cron): handle sessions list cron model override (openclaw#21279) thanks @altaywtf

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
(cherry picked from commit 98e30dc)

* fix: adapt cron model override test imports for fork

model-fallback.js and model-selection.js paths differ in fork.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Altay <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sessions_list shows agent default model instead of actual cron model override

2 participants