openclaw - ✅(Solved) Fix [Bug]: 2026.4.11: embedded heartbeat precheck ignores configured compaction reserve and uses reserveTokens=16384 [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#65218Fetched 2026-04-12 13:25:03
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×2cross-referenced ×1referenced ×1

On 2026.4.11, a stripped-down embedded heartbeat using ollama/qwen2.5:3b-instruct-q4_K_M still fails in precheck with context overflow, even though:

Ollama is actually loading the model at CONTEXT 16384 config sets: agents.defaults.compaction.reserveTokens: 1000 agents.defaults.compaction.reserveTokensFloor: 0

At runtime, heartbeat precheck still logs reserveTokens=16384, leaving promptBudgetBeforeReserve=1 for an estimatedPromptTokens=35 heartbeat.

Error Message

06:41:41+00:00 warn agent/embedded ... low context window: ollama/qwen2.5:3b-instruct-q4_K_M ctx=16384 (warn<32000) source=modelsConfig 06:41:46+00:00 warn agent/embedded ... [context-overflow-precheck] ... estimatedPromptTokens=35 promptBudgetBeforeReserve=1 overflowTokens=34 ... reserveTokens=16384 ... 06:41:46+00:00 warn agent/embedded ... [context-overflow-diag] ... error=Context overflow: prompt too large for the model (precheck). 06:41:46+00:00 warn agent/embedded ... context overflow detected (attempt 1/3); attempting auto-compaction ... 06:41:51+00:00 warn agent/embedded ... auto-compaction failed ... no real conversation messages 06:41:51+00:00 error Auto-compaction failed (Context overflow: prompt too large for the model (precheck).). Restarting session ...

Root Cause

  • context-overflow-precheck
  • promptBudgetBeforeReserve=1
  • reserveTokens=16384
  • auto-compaction skipped because there are no real conversation messages
  • session restarted and retried

Fix Action

Fixed

PR fix notes

PR #65263: fix(compaction): clamp reserveTokens to at most 90% of context window in precheck

Description (problem / solution / changelog)

Problem

When the Pi settings manager returns a compaction reserve value equal to (or exceeding) the full context token budget, the preemptive overflow precheck computes:

promptBudgetBeforeReserve = contextTokenBudget - reserveTokens
                         = 16384 - 16384 = 0 → clamped to 1

This guarantees context overflow for any prompt, even a minimal heartbeat. The logs show:

estimatedPromptTokens=35 promptBudgetBeforeReserve=1 reserveTokens=16384

This was observed on embedded heartbeat sessions using small local models (ollama/qwen2.5:3b, ctx=16384) where the user explicitly configured reserveTokens: 1000 and reserveTokensFloor: 0, but the Pi settings manager still returned 16384 at runtime.

Fix

Add a safety clamp in shouldPreemptivelyCompactBeforePrompt that caps reserveTokens to at most 90% of the context window. This ensures at least 10% of the context budget (1638 tokens for a 16K window) is always available for the system prompt + user prompt, preventing the degenerate zero-budget scenario regardless of how the upstream settings manager resolves the reserve.

The clamp is defense-in-depth — it does not address the root cause of the config override not propagating (which may be in the external Pi settings manager), but it prevents the catastrophic symptom.

Changes

  • preemptive-compaction.ts: Compute maxReserve = floor(contextTokenBudget × 0.9) and clamp reserveTokens before computing prompt budget.
  • preemptive-compaction.test.ts: Two new test cases:
    • reserveTokens == contextTokenBudget → prompt budget > 1 (was guaranteed overflow)
    • reserveTokens >> contextTokenBudget → correctly capped at 90%

Test Results

All 9 tests pass (7 existing + 2 new).

Closes #65218

Changed files

  • src/agents/pi-embedded-runner/run/preemptive-compaction.test.ts (modified, +33/-0)
  • src/agents/pi-embedded-runner/run/preemptive-compaction.ts (modified, +11/-1)

Code Example

Successful trigger:
PS C:\WINDOWS\system32> openclaw system event --text "heartbeat test" --mode now --timeout 180000
ok

Overflow sequence:
06:41:41+00:00 warn agent/embedded ... low context window: ollama/qwen2.5:3b-instruct-q4_K_M ctx=16384 (warn<32000) source=modelsConfig
06:41:46+00:00 warn agent/embedded ... [context-overflow-precheck] ... estimatedPromptTokens=35 promptBudgetBeforeReserve=1 overflowTokens=34 ... reserveTokens=16384 ...
06:41:46+00:00 warn agent/embedded ... [context-overflow-diag] ... error=Context overflow: prompt too large for the model (precheck).
06:41:46+00:00 warn agent/embedded ... context overflow detected (attempt 1/3); attempting auto-compaction ...
06:41:51+00:00 info agent/embedded ... [compaction] skipping — no real conversation messages ...
06:41:51+00:00 warn agent/embedded ... auto-compaction failed ... no real conversation messages
06:41:51+00:00 error Auto-compaction failed (Context overflow: prompt too large for the model (precheck).). Restarting session ...

Heartbeat last output:
{
  "status": "skipped",
  "reason": "target-none",
  "preview": "⚠️ Context limit exceeded. I've reset our conversation to start fresh - please try again.",
  "durationMs": 116644
}
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

On 2026.4.11, a stripped-down embedded heartbeat using ollama/qwen2.5:3b-instruct-q4_K_M still fails in precheck with context overflow, even though:

Ollama is actually loading the model at CONTEXT 16384 config sets: agents.defaults.compaction.reserveTokens: 1000 agents.defaults.compaction.reserveTokensFloor: 0

At runtime, heartbeat precheck still logs reserveTokens=16384, leaving promptBudgetBeforeReserve=1 for an estimatedPromptTokens=35 heartbeat.

Steps to reproduce

  1. Run OpenClaw 2026.4.11 on Windows with a local loopback gateway.
  2. Configure heartbeat to use:
    • ollama/qwen2.5:3b-instruct-q4_K_M
    • prompt: "Reply exactly HEARTBEAT_OK."
  • lightContext: true
    • isolatedSession: true
    • target: "none"
    • includeReasoning: false
  • Configure compaction defaults to:
    • reserveTokens: 1000
    • reserveTokensFloor: 0
  • Confirm ollama ps shows the model loaded at CONTEXT 16384.
  • Trigger a heartbeat test:
    • openclaw system event --text "heartbeat test" --mode now --timeout 180000
  • Inspect heartbeat logs / openclaw system heartbeat last.

Expected behavior

The heartbeat should fit comfortably inside a 16k context window and return HEARTBEAT_OK or otherwise complete without immediate precheck overflow.

At minimum, runtime should honor the configured compaction reserve and not use reserveTokens=16384.

Actual behavior

openclaw system event ... returns ok, but the embedded heartbeat immediately fails with:

  • context-overflow-precheck
  • promptBudgetBeforeReserve=1
  • reserveTokens=16384
  • auto-compaction skipped because there are no real conversation messages
  • session restarted and retried

openclaw system heartbeat last then shows a skipped heartbeat with preview text indicating context limit/reset behavior.

OpenClaw version

2026.4.11 (769908e)

Operating system

Windows (local loopback gateway on 127.0.0.1:18789)

Install method

Global install under the user Node/npm global path (example runtime path: C:\Users\prapunsak\AppData\Roaming\npm\node_modules\openclaw\dist\index.js)

Model

ollama/qwen2.5:3b-instruct-q4_K_M

Provider / routing chain

Local Ollama provider for embedded heartbeat: ollama/qwen2.5:3b-instruct-q4_K_M

Additional provider/model setup details

Relevant heartbeat config: "heartbeat": { "every": "55m", "model": "ollama/qwen2.5:3b-instruct-q4_K_M", "includeReasoning": false, "target": "none", "directPolicy": "block", "prompt": "Reply exactly HEARTBEAT_OK.", "lightContext": true, "isolatedSession": true }

Relevant compaction config: "compaction": { "mode": "safeguard", "reserveTokensFloor": 0, "reserveTokens": 1000 }

Ollama runtime evidence: qwen2.5:3b-instruct-q4_K_M ... CONTEXT 16384

Logs, screenshots, and evidence

Successful trigger:
PS C:\WINDOWS\system32> openclaw system event --text "heartbeat test" --mode now --timeout 180000
ok

Overflow sequence:
06:41:41+00:00 warn agent/embedded ... low context window: ollama/qwen2.5:3b-instruct-q4_K_M ctx=16384 (warn<32000) source=modelsConfig
06:41:46+00:00 warn agent/embedded ... [context-overflow-precheck] ... estimatedPromptTokens=35 promptBudgetBeforeReserve=1 overflowTokens=34 ... reserveTokens=16384 ...
06:41:46+00:00 warn agent/embedded ... [context-overflow-diag] ... error=Context overflow: prompt too large for the model (precheck).
06:41:46+00:00 warn agent/embedded ... context overflow detected (attempt 1/3); attempting auto-compaction ...
06:41:51+00:00 info agent/embedded ... [compaction] skipping — no real conversation messages ...
06:41:51+00:00 warn agent/embedded ... auto-compaction failed ... no real conversation messages
06:41:51+00:00 error Auto-compaction failed (Context overflow: prompt too large for the model (precheck).). Restarting session ...

Heartbeat last output:
{
  "status": "skipped",
  "reason": "target-none",
  "preview": "⚠️ Context limit exceeded. I've reset our conversation to start fresh - please try again.",
  "durationMs": 116644
}

Impact and severity

Medium to high.

This blocks use of a tiny local model for embedded heartbeat even with an intentionally minimal heartbeat prompt/config, and suggests runtime is not honoring configured compaction reserve values.

Additional information

This appears to be a separate issue from earlier 2026.4.9 gateway/connect problems. On 2026.4.11, the system event connect path improved, but the embedded heartbeat overflow remains reproducible.

The core discrepancy is:

config shows reserveTokens: 1000 runtime logs reserveTokens=16384

That mismatch seems to be the heart of the bug.

extent analysis

TL;DR

The most likely fix is to investigate and resolve the discrepancy between the configured reserveTokens value and the value used at runtime.

Guidance

  • Verify that the compaction configuration is being loaded correctly and that the reserveTokens value is being overridden somewhere in the code.
  • Check the Ollama model configuration and the OpenClaw heartbeat configuration to ensure that they are consistent and that the reserveTokens value is being set correctly.
  • Investigate the logging and debugging output to determine why the runtime is using a different reserveTokens value than the one configured.
  • Consider adding additional logging or debugging statements to help identify the source of the discrepancy.

Example

No code example is provided as the issue is related to configuration and runtime behavior rather than a specific code snippet.

Notes

The discrepancy between the configured reserveTokens value and the value used at runtime is the core issue. Resolving this discrepancy is likely to fix the problem. However, without more information about the code and configuration, it is difficult to provide a more specific solution.

Recommendation

Apply a workaround to manually set the reserveTokens value to the desired value, or investigate and fix the underlying issue that is causing the discrepancy between the configured and runtime values. The reason for this recommendation is that the discrepancy is the root cause of the problem, and resolving it is likely to fix the issue.

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…

FAQ

Expected behavior

The heartbeat should fit comfortably inside a 16k context window and return HEARTBEAT_OK or otherwise complete without immediate precheck overflow.

At minimum, runtime should honor the configured compaction reserve and not use reserveTokens=16384.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: 2026.4.11: embedded heartbeat precheck ignores configured compaction reserve and uses reserveTokens=16384 [1 pull requests, 1 participants]