openclaw - ✅(Solved) Fix [Bug]: Running Local Models Results in Complete Loss of Conversation Memory [2 pull requests, 3 comments, 3 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#50894Fetched 2026-04-08 01:06:50
View on GitHub
Comments
3
Participants
3
Timeline
18
Reactions
0
Author
Timeline (top)
referenced ×8commented ×3cross-referenced ×2labeled ×2

Environment Setup: Windows 11 + Ollama + QWEN3.5-9B (locally running model) + WSL 2 + Ubuntu 24.04 + OpenClaw 2026.3.13

Key Phenomenon: The model completely fails to retain the content of the previous conversation turn, and has no recollection at all when asked about it in the next turn. This is not an issue with local file-based memory, but a complete loss of the entire conversation session context history.

When I use Alibaba DashScope's QWEN3.5-PLUS large model for conversations with OpenClaw, the conversation memory (context retention) works perfectly fine. Additionally, when I converse with the local QWEN3.5-9B model directly via the Ollama window on Windows 11, the memory function (session context retention) also works as expected—the model can recall the content of previous turns without any issues.

I adjusted the configuration of the local QWEN3.5-9B model to match the JSON configuration of QWEN3.5-PLUS from the DashScope platform. However, the local model still suffers from complete loss of conversation session context: it cannot remember any content from prior turns. Except for basic settings (such as model invocation path, API key, etc.), all other parameters of the DashScope model and the local model are kept consistent.

I have tried adjusting numerous configurations in openclaw.json (e.g., session persistence, context inclusion, history forwarding), but none of them took effect whatsoever.

Does OpenClaw completely lack support for local lightweight models? Additionally, there are also adaptation issues with tool call functionality for local models.

Any guidance from experts would be greatly appreciated.

Root Cause

Environment Setup: Windows 11 + Ollama + QWEN3.5-9B (locally running model) + WSL 2 + Ubuntu 24.04 + OpenClaw 2026.3.13

Key Phenomenon: The model completely fails to retain the content of the previous conversation turn, and has no recollection at all when asked about it in the next turn. This is not an issue with local file-based memory, but a complete loss of the entire conversation session context history.

When I use Alibaba DashScope's QWEN3.5-PLUS large model for conversations with OpenClaw, the conversation memory (context retention) works perfectly fine. Additionally, when I converse with the local QWEN3.5-9B model directly via the Ollama window on Windows 11, the memory function (session context retention) also works as expected—the model can recall the content of previous turns without any issues.

I adjusted the configuration of the local QWEN3.5-9B model to match the JSON configuration of QWEN3.5-PLUS from the DashScope platform. However, the local model still suffers from complete loss of conversation session context: it cannot remember any content from prior turns. Except for basic settings (such as model invocation path, API key, etc.), all other parameters of the DashScope model and the local model are kept consistent.

I have tried adjusting numerous configurations in openclaw.json (e.g., session persistence, context inclusion, history forwarding), but none of them took effect whatsoever.

Does OpenClaw completely lack support for local lightweight models? Additionally, there are also adaptation issues with tool call functionality for local models.

Any guidance from experts would be greatly appreciated.

Fix Action

Fixed

PR fix notes

PR #51094: fix(agents): accept model options in config and recover Ollama tool calls from text (#50894)

Description (problem / solution / changelog)

Summary

  • Problem: Users configuring local Ollama models (e.g. Qwen3.5-9B) in openclaw.json hit two blockers: (1) adding "options": {"num_ctx": 8192} to a model definition is rejected with Unrecognized key: "options", and (2) smaller models that understand tools semantically but lack native tool_calls output silently fail to dispatch tool calls.
  • Why it matters: Without num_ctx passthrough, Ollama defaults to a tiny context window (2048–4096 tokens), silently truncating conversation history and appearing as complete memory loss. Without tool-call recovery, local models cannot interact with the filesystem or execute tools at all.
  • What changed:
    • ModelDefinitionSchema now accepts an optional options record for provider-specific passthrough settings.
    • options.num_ctx is used as a fallback for contextWindow in both the native Ollama stream path and the OpenAI-compat num_ctx injection path.
    • New recoverToolCallsFromText() parser in ollama-stream.ts extracts structured tool calls from <tool_call> XML tags and fenced JSON code blocks when the model response contains no tool_calls array.
  • What did NOT change (scope boundary): Cloud provider paths, existing contextWindow behavior when explicitly set, tool schema generation, and the OpenAI-completions/responses tool-call parsing remain untouched.

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

  • Closes #50894

User-visible / Behavior Changes

  1. Users can now add "options": {"num_ctx": 8192, ...} to model definitions in openclaw.json without config validation errors.
  2. When contextWindow is not set but options.num_ctx is, the value is used as context window size for Ollama requests — preventing silent conversation history truncation.
  3. Smaller local models that emit tool-call-like JSON in text output (e.g. <tool_call>{"name":"write_file",...}</tool_call>) now have those calls recovered and dispatched as real tool invocations.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No — tool calls recovered from text go through the same dispatch and policy pipeline as native tool calls.
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Windows 11 + WSL 2 + Ubuntu 24.04
  • Runtime/container: Ollama (local)
  • Model/provider: qwen3.5:9b via Ollama
  • Relevant config (redacted):
{
  "models": {
    "providers": {
      "my-ollama": {
        "baseUrl": "http://localhost:11434/v1",
        "models": [{
          "id": "qwen3.5:9b",
          "name": "Qwen3.5 9B",
          "api": "ollama",
          "options": { "num_ctx": 32768 }
        }]
      }
    }
  }
}

## Changed files

- `src/agents/ollama-stream.test.ts` (modified, +154/-0)
- `src/agents/ollama-stream.ts` (modified, +87/-5)
- `src/agents/pi-embedded-runner/run/attempt.ts` (modified, +20/-2)
- `src/config/types.models.ts` (modified, +1/-0)
- `src/config/zod-schema.core.ts` (modified, +1/-0)


---

# PR #51356: fix(agents): accept model `options` in config and safely recover Ollama tool calls (#50894)

- Repository: openclaw/openclaw
- Author: hhhhao28
- State: open | merged: False
- Link: https://github.com/openclaw/openclaw/pull/51356

## Description (problem / solution / changelog)

## Summary

- Problem: Users configuring local Ollama models (e.g. Qwen3.5-9B) in `openclaw.json` cannot pass provider-specific options like `num_ctx` — the config validator rejects the key, and even if the schema were relaxed, `applyConfiguredProviderOverrides` drops the field so it never reaches the runtime. Separately, smaller models that understand tools semantically but lack native `tool_calls` output silently fail to dispatch tool calls.
- Why it matters: Without `num_ctx` passthrough, Ollama defaults to a 20484096 token context window, silently truncating conversation history and appearing as complete memory loss. Without tool-call recovery, local models cannot execute tools at all.
- What changed:
  - `ModelDefinitionSchema` now accepts an optional `options` record for provider-specific passthrough settings.
  - `applyConfiguredProviderOverrides` in `model.ts` now propagates `options` so user config reaches the runtime.
  - `options.num_ctx` is used as a fallback for `contextWindow` in both the native Ollama stream path and the OpenAI-compat `num_ctx` injection path. The extraction is done once and reused in both places.
  - New `recoverToolCallsFromText()` parser in `ollama-stream.ts` extracts structured tool calls from `<tool_call>` XML tags only (fenced JSON code blocks are intentionally excluded per security review). Recovered markup is stripped from text content to prevent history pollution.
- What did NOT change (scope boundary): Cloud provider paths, existing `contextWindow` behavior when explicitly set, tool schema generation, the OpenAI-completions/responses tool-call parsing, and fenced JSON code blocks are never interpreted as tool calls.

## Change Type (select all)

- [x] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Docs
- [ ] Security hardening
- [ ] Chore/infra

## Scope (select all touched areas)

- [x] Gateway / orchestration
- [x] Skills / tool execution
- [ ] Auth / tokens
- [ ] Memory / storage
- [x] Integrations
- [x] API / contracts
- [ ] UI / DX
- [ ] CI/CD / infra

## Linked Issue/PR

- Closes #50894
- Supersedes #51094 (closed — addressed all bot review feedback from that PR)

## User-visible / Behavior Changes

1. Users can now add `"options": {"num_ctx": 8192, ...}` to model definitions in `openclaw.json` without config validation errors.
2. The `options` field is properly propagated through model resolution (previously dropped by `applyConfiguredProviderOverrides`).
3. When `contextWindow` is not set but `options.num_ctx` is, the value is used as context window size — preventing silent conversation history truncation.
4. Smaller local models that emit `<tool_call>{"name":"write_file",...}</tool_call>` in text output now have those calls recovered and dispatched. The raw markup is stripped from the visible text to keep conversation history clean.

## Security Impact (required)

- New permissions/capabilities? `No`
- Secrets/tokens handling changed? `No`
- New/changed network calls? `No`
- Command/tool execution surface changed? `No` — recovered tool calls go through the same dispatch and policy pipeline as native tool calls. Only explicit `<tool_call>` XML tags are matched; fenced JSON code blocks are intentionally excluded to prevent accidental execution of explanatory examples.
- Data access scope changed? `No`

## Repro + Verification

### Environment

- OS: Windows 11 + WSL 2 + Ubuntu 24.04
- Runtime/container: Ollama (local)
- Model/provider: qwen3.5:9b via Ollama
- Relevant config (redacted):

```json
{
  "models": {
    "providers": {
      "my-ollama": {
        "baseUrl": "http://localhost:11434",
        "api": "ollama",
        "models": [{
          "id": "qwen3.5:9b",
          "name": "Qwen3.5 9B",
          "options": { "num_ctx": 32768 }
        }]
      }
    }
  }
}

## Changed files

- `docs/.generated/config-baseline.json` (modified, +19/-0)
- `docs/.generated/config-baseline.jsonl` (modified, +3/-1)
- `docs/.generated/plugin-sdk-api-baseline.json` (modified, +4/-4)
- `docs/.generated/plugin-sdk-api-baseline.jsonl` (modified, +4/-4)
- `src/agents/context-window-guard.test.ts` (modified, +38/-0)
- `src/agents/context-window-guard.ts` (modified, +11/-4)
- `src/agents/ollama-stream.test.ts` (modified, +217/-0)
- `src/agents/ollama-stream.ts` (modified, +88/-2)
- `src/agents/pi-embedded-runner.e2e.test.ts` (modified, +1/-0)
- `src/agents/pi-embedded-runner.run-embedded-pi-agent.auth-profile-rotation.e2e.test.ts` (modified, +1/-0)
- `src/agents/pi-embedded-runner/compact.ts` (modified, +14/-3)
- `src/agents/pi-embedded-runner/extensions.ts` (modified, +8/-9)
- `src/agents/pi-embedded-runner/model.test.ts` (modified, +48/-0)
- `src/agents/pi-embedded-runner/model.ts` (modified, +6/-1)
- `src/agents/pi-embedded-runner/run.overflow-compaction.harness.ts` (modified, +1/-0)
- `src/agents/pi-embedded-runner/run.ts` (modified, +21/-2)
- `src/agents/pi-embedded-runner/run/attempt.ts` (modified, +17/-12)
- `src/config/defaults.ts` (modified, +69/-2)
- `src/config/model-alias-defaults.test.ts` (modified, +99/-0)
- `src/config/schema.base.generated.ts` (modified, +7/-0)
- `src/config/types.models.ts` (modified, +1/-0)
- `src/config/zod-schema.core.ts` (modified, +1/-0)
RAW_BUFFERClick to expand / collapse
<img width="936" height="1007" alt="Image" src="https://github.com/user-attachments/assets/6b7c23a1-886f-47de-91a3-6c32a0dd50db" />

Bug type

Behavior bug (incorrect output/state without crash)

Summary

Environment Setup: Windows 11 + Ollama + QWEN3.5-9B (locally running model) + WSL 2 + Ubuntu 24.04 + OpenClaw 2026.3.13

Key Phenomenon: The model completely fails to retain the content of the previous conversation turn, and has no recollection at all when asked about it in the next turn. This is not an issue with local file-based memory, but a complete loss of the entire conversation session context history.

When I use Alibaba DashScope's QWEN3.5-PLUS large model for conversations with OpenClaw, the conversation memory (context retention) works perfectly fine. Additionally, when I converse with the local QWEN3.5-9B model directly via the Ollama window on Windows 11, the memory function (session context retention) also works as expected—the model can recall the content of previous turns without any issues.

I adjusted the configuration of the local QWEN3.5-9B model to match the JSON configuration of QWEN3.5-PLUS from the DashScope platform. However, the local model still suffers from complete loss of conversation session context: it cannot remember any content from prior turns. Except for basic settings (such as model invocation path, API key, etc.), all other parameters of the DashScope model and the local model are kept consistent.

I have tried adjusting numerous configurations in openclaw.json (e.g., session persistence, context inclusion, history forwarding), but none of them took effect whatsoever.

Does OpenClaw completely lack support for local lightweight models? Additionally, there are also adaptation issues with tool call functionality for local models.

Any guidance from experts would be greatly appreciated.

Steps to reproduce

  1. Install Ollama locally and pull the qwen3.5:9b model.
  2. Configure OpenClaw to use the local qwen3.5:9b model.

Expected behavior

Conversations retain full context/memory in the WebUI chat interface.

Actual behavior

Conversations have no context/memory at all in the WebUI chat interface; the TUI also suffers from complete memory loss.

OpenClaw version

2026.3.13

Operating system

win11+wsl+ubuntu 24.04

Install method

curl fsSL https://openclaw.ai/install.sh | bash

Model

"ollama-qwen3-5-9b/qwen3.5:9b

Provider / routing chain

opeclaw -- ollama --qwen3.5-9b

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

Fix Plan

To resolve the issue of conversation context loss with the local QWEN3.5-9B model in OpenClaw, follow these steps:

  1. Check Session Persistence Configuration: Ensure that session persistence is enabled in your openclaw.json configuration file. Look for the session_persistence parameter and set it to true if it's not already.
  2. Verify Context Inclusion: Make sure that context inclusion is enabled for the local model. You can do this by checking the context_inclusion parameter in the openclaw.json file and setting it to true.
  3. History Forwarding: Confirm that history forwarding is correctly configured. This might involve setting history_forwarding to true in the configuration file.
  4. Model Invocation Path and API Key: Double-check that the model invocation path and API key are correctly set for the local QWEN3.5-9B model in the OpenClaw configuration.
  5. Update OpenClaw Configuration for Local Models: If you haven't already, update the OpenClaw configuration to specifically support local lightweight models. This might involve adding or modifying entries in the openclaw.json file related to local model support.

Example configuration adjustments in openclaw.json:

{
  "session_persistence": true,
  "context_inclusion": true,
  "history_forwarding": true,
  "models": {
    "qwen3.5-9b": {
      "type": "local",
      "path": "/path/to/qwen3.5-9b/model",
      "api_key": "your_api_key_here"
    }
  }
}

Replace "/path/to/qwen3.5-9b/model" and "your_api_key_here" with your actual model path and API key.

Verification

After making these changes, restart OpenClaw and test the conversation functionality again to see if the context is retained between turns.

Extra Tips

  • Ensure that your OpenClaw version is up to date, as newer versions may include fixes for issues like this.
  • If issues persist, consider checking the OpenClaw logs for any error messages related to session persistence or context handling.
  • For further assistance, consult the OpenClaw documentation or community forums, where you may find more detailed guides or troubleshooting tips specific to your setup.

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

Conversations retain full context/memory in the WebUI chat interface.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING