Skip to content

fix #75452: Heartbeat per-turn model override persists after turn completes (2026.4.29)#75557

Merged
BunsDev merged 4 commits intoopenclaw:mainfrom
zhangguiping-xydt:feat/issue-75452
May 2, 2026
Merged

fix #75452: Heartbeat per-turn model override persists after turn completes (2026.4.29)#75557
BunsDev merged 4 commits intoopenclaw:mainfrom
zhangguiping-xydt:feat/issue-75452

Conversation

@zhangguiping-xydt
Copy link
Copy Markdown
Contributor

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels May 1, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 1, 2026

Codex review: needs changes before merge.

Summary
The PR adds a heartbeat-only runtime-model preservation flag, wires it from agent runs, adds session-store regression tests, updates heartbeat docs, and records the fix in the changelog.

Reproducibility: yes. Configure a heartbeat model that differs from the primary model, run a heartbeat on a shared session, and inspect session_status or the session row; current main writes the heartbeat provider/model/context window into shared runtime fields.

Next step before merge
A narrow automated repair can address the remaining status/listing fallback bug on this PR or a replacement branch.

Security
Cleared: The diff changes TypeScript session persistence, focused tests, docs, and changelog text only; it adds no dependency, workflow, secret, download, or publishing surface.

Review findings

  • [P2] Preserve context identity when contextTokens are missing — src/agents/command/session-store.ts:124
Review details

Best possible solution:

Preserve heartbeat model selection as run-scoped while ensuring session status/listing derives any missing context window from the preserved runtime model rather than from the latest heartbeat transcript.

Do we have a high-confidence way to reproduce the issue?

Yes. Configure a heartbeat model that differs from the primary model, run a heartbeat on a shared session, and inspect session_status or the session row; current main writes the heartbeat provider/model/context window into shared runtime fields.

Is this the best way to solve the issue?

No. The preservation flag is the right boundary, but the missing-context branch should also cover the status/listing transcript fallback path or add status-level regression coverage before merge.

Full review comments:

  • [P2] Preserve context identity when contextTokens are missing — src/agents/command/session-store.ts:124
    When a preserved entry has a model but no cached contextTokens, this branch intentionally leaves contextTokens unset. Session rows then treat runtime fields with missing context as needing transcript fallback, and readRecentSessionUsageFromTranscript can replace the displayed model/provider with the latest heartbeat transcript, so the bleed can still show up in session_status for older entries.
    Confidence: 0.86

Overall correctness: patch is incorrect
Overall confidence: 0.86

Acceptance criteria:

  • pnpm test src/agents/command/session-store.test.ts
  • pnpm test src/agents/openclaw-tools.session-status.test.ts
  • pnpm test src/gateway/session-utils.fs.test.ts
  • pnpm exec oxfmt --check --threads=1 src/agents/agent-command.ts src/agents/command/session-store.ts src/agents/command/session-store.test.ts src/agents/openclaw-tools.session-status.test.ts src/gateway/session-utils.ts docs/gateway/heartbeat.md CHANGELOG.md

What I checked:

Likely related people:

  • steipete: Recent blame and commit history show repeated maintenance of the central session-store, agent-command, heartbeat docs, and session status/listing paths involved in this behavior. (role: recent maintainer; confidence: high; commits: d678bcfcc7d0, f7ed29e11812, 59fb9e5ca7fe; files: src/agents/command/session-store.ts, src/agents/agent-command.ts, src/gateway/session-utils.ts)
  • bittoby: Recent merged work touched current-session resolution and session-status tests, which are the user-visible status surfaces affected by the remaining edge case. (role: adjacent session/status maintainer; confidence: medium; commits: d5ad90f7ec7c; files: src/agents/openclaw-tools.session-status.test.ts, src/agents/tools/session-status-tool.ts)

Remaining risk / open question:

  • The PR has a concrete correctness gap for sessions that have a preserved runtime model but no cached contextTokens; status/listing can still display the heartbeat model from transcript fallback.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 2244ba87b362.

…ion state

- Skip setting runtime model when preserveRuntimeModel is true and no prior model exists
- Preserve model-only entries without borrowing heartbeat provider to avoid invalid cross-provider pairs
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime labels May 2, 2026
Copy link
Copy Markdown
Member

@BunsDev BunsDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the updated head 42a00dcf38.

This is merge-ready from the maintainer review side:

  • fixes the heartbeat runtime-model bleed at the session-store persistence boundary
  • preserves existing runtime model/provider/context metadata for heartbeat turns without creating invalid model/provider pairs
  • keeps normal non-heartbeat runtime persistence unchanged
  • covers the prior blockers with focused regression tests, including model-only entries and empty prior runtime state
  • refreshes the heartbeat docs and changelog attribution

Validation:

  • pnpm test src/agents/command/session-store.test.ts src/agents/openclaw-tools.session-status.test.ts passed locally (67 tests)
  • pnpm exec oxfmt --check --threads=1 src/agents/agent-command.ts src/agents/command/session-store.ts src/agents/command/session-store.test.ts CHANGELOG.md docs/gateway/heartbeat.md passed locally
  • git diff --check passed locally
  • GitHub checks on 42a00dcf38 are clean: no active checks, no relevant failures.

@BunsDev BunsDev merged commit 2c272e2 into openclaw:main May 2, 2026
106 of 107 checks passed
lxe pushed a commit to lxe/openclaw that referenced this pull request May 6, 2026
Fixes openclaw#75452.

Heartbeat runs can use a per-turn model override via agents.defaults.heartbeat.model. Before this change, the run metadata was written back to the shared session store, so the next normal turn could inherit the heartbeat provider/model and a smaller context window.

This lands the contributor fix plus maintainer polish:
- preserve existing session runtime model/provider/context metadata when persisting heartbeat turns
- avoid creating invalid provider/model pairs for legacy model-only session entries
- leave empty prior runtime state unset for heartbeat-only turns
- keep normal non-heartbeat runtime persistence unchanged
- add focused regression coverage for the session-store edge cases
- refresh heartbeat docs and changelog attribution

Validation:
- pnpm test src/agents/command/session-store.test.ts src/agents/openclaw-tools.session-status.test.ts
- pnpm exec oxfmt --check --threads=1 src/agents/agent-command.ts src/agents/command/session-store.ts src/agents/command/session-store.test.ts CHANGELOG.md docs/gateway/heartbeat.md
- git diff --check
- GitHub checks on 42a00dc: clean; no active checks and no relevant failures

Duplicate PR openclaw#75567 was already closed; openclaw#75557 is the canonical fix.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
Fixes openclaw#75452.

Heartbeat runs can use a per-turn model override via agents.defaults.heartbeat.model. Before this change, the run metadata was written back to the shared session store, so the next normal turn could inherit the heartbeat provider/model and a smaller context window.

This lands the contributor fix plus maintainer polish:
- preserve existing session runtime model/provider/context metadata when persisting heartbeat turns
- avoid creating invalid provider/model pairs for legacy model-only session entries
- leave empty prior runtime state unset for heartbeat-only turns
- keep normal non-heartbeat runtime persistence unchanged
- add focused regression coverage for the session-store edge cases
- refresh heartbeat docs and changelog attribution

Validation:
- pnpm test src/agents/command/session-store.test.ts src/agents/openclaw-tools.session-status.test.ts
- pnpm exec oxfmt --check --threads=1 src/agents/agent-command.ts src/agents/command/session-store.ts src/agents/command/session-store.test.ts CHANGELOG.md docs/gateway/heartbeat.md
- git diff --check
- GitHub checks on 42a00dc: clean; no active checks and no relevant failures

Duplicate PR openclaw#75567 was already closed; openclaw#75557 is the canonical fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Heartbeat per-turn model override persists after turn completes (2026.4.29)

2 participants