Skip to content

fix: use per-model context window and preserve user config in OpenClaw sync#13666

Merged
kangfenmao merged 4 commits intomainfrom
fix/openclaw-config-overwrite
Mar 25, 2026
Merged

fix: use per-model context window and preserve user config in OpenClaw sync#13666
kangfenmao merged 4 commits intomainfrom
fix/openclaw-config-overwrite

Conversation

@SiinXu
Copy link
Copy Markdown
Collaborator

@SiinXu SiinXu commented Mar 20, 2026

Summary

Fixes #13665

  • Preserve user modifications in OpenClaw config across restarts. Previously syncProviderConfig() fully overwrote the model config on every sync, discarding user changes (vision, custom context window, etc.). Now uses a merge strategy: user-modified fields are preserved via object spread, Cherry Studio-managed fields (id, name) always take precedence.
  • Remove hardcoded MODEL_CONTEXT_WINDOWS map — context window defaults are delegated to OpenClaw's built-in MODEL_CONTEXT_WINDOWS in opencode-zen-models.ts. Cherry Studio only provides 128000 as fallback for new/unknown models on first sync.
  • Extract OpenClawModelConfig interface with index signature to support arbitrary user-added fields without type errors.

Before

models: provider.models.map((m) => ({
  id: m.id,
  name: m.name,
  contextWindow: 128000  // hardcoded for ALL models, overwrites every restart
}))

After

const existing = existingModelMap.get(m.id)
return {
  ...existing,           // preserve user's OpenClaw modifications
  id: m.id,              // Cherry Studio managed fields always win
  name: m.name,
  contextWindow: existing?.contextWindow ?? 128000  // OpenClaw handles model-specific values
}

Test plan

  • pnpm test:main — 514 passed (including 44 OpenClawService tests)
  • pnpm typecheck — node + web both pass
  • pnpm format — no issues
  • Manual: sync provider to OpenClaw → modify vision/context in OpenClaw → restart → verify settings preserved

🤖 Generated with Claude Code

SiinXu and others added 3 commits March 19, 2026 17:44
The `topicId` and `userMessage` parameters were swapped when calling
`knowledgeSearchTool()` in searchOrchestrationPlugin, causing knowledge
base searches to use corrupted tracing context and incorrect query text.
This resulted in knowledge base content not being delivered to the model.

Fixes #13609

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Siin Xu <[email protected]>
…w sync

Previously, syncProviderConfig() hardcoded contextWindow to 128000 for
all models and fully overwrote the OpenClaw provider config on every
sync, discarding user modifications (e.g., vision, custom context
window).

Changes:
- Add MODEL_CONTEXT_WINDOWS map with correct values for common models
  (aligned with OpenClaw's opencode-zen-models.ts)
- Use getContextWindow() to resolve per-model context window by ID
  prefix matching, falling back to 128000 for unknown models
- Merge existing model config instead of overwriting: user-modified
  fields in OpenClaw are preserved via object spread, while Cherry
  Studio-managed fields (id, name) always take precedence
- Extract OpenClawModelConfig interface with index signature to support
  arbitrary user-added fields

Fixes #13665

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Siin Xu <[email protected]>
…w's built-in defaults

Let OpenClaw handle model-specific context window sizes via its internal
MODEL_CONTEXT_WINDOWS. Cherry Studio only needs to preserve user modifications
and provide a 128000 fallback for new models.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Siin Xu <[email protected]>
@kangfenmao kangfenmao requested a review from DeJeune March 21, 2026 09:16
@kangfenmao kangfenmao merged commit 4f7ca28 into main Mar 25, 2026
10 checks passed
@kangfenmao kangfenmao deleted the fix/openclaw-config-overwrite branch March 25, 2026 10:36
MyPrototypeWhat pushed a commit that referenced this pull request Mar 30, 2026
…w sync (#13666)

## Summary

Fixes #13665

- **Preserve user modifications** in OpenClaw config across restarts.
Previously `syncProviderConfig()` fully overwrote the model config on
every sync, discarding user changes (vision, custom context window,
etc.). Now uses a merge strategy: user-modified fields are preserved via
object spread, Cherry Studio-managed fields (`id`, `name`) always take
precedence.
- **Remove hardcoded `MODEL_CONTEXT_WINDOWS` map** — context window
defaults are delegated to OpenClaw's built-in `MODEL_CONTEXT_WINDOWS` in
`opencode-zen-models.ts`. Cherry Studio only provides `128000` as
fallback for new/unknown models on first sync.
- **Extract `OpenClawModelConfig` interface** with index signature to
support arbitrary user-added fields without type errors.

### Before
```typescript
models: provider.models.map((m) => ({
  id: m.id,
  name: m.name,
  contextWindow: 128000  // hardcoded for ALL models, overwrites every restart
}))
```

### After
```typescript
const existing = existingModelMap.get(m.id)
return {
  ...existing,           // preserve user's OpenClaw modifications
  id: m.id,              // Cherry Studio managed fields always win
  name: m.name,
  contextWindow: existing?.contextWindow ?? 128000  // OpenClaw handles model-specific values
}
```

## Test plan

- [x] `pnpm test:main` — 514 passed (including 44 OpenClawService tests)
- [x] `pnpm typecheck` — node + web both pass
- [x] `pnpm format` — no issues
- [ ] Manual: sync provider to OpenClaw → modify vision/context in
OpenClaw → restart → verify settings preserved

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Siin Xu <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: suyao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenClaw model config overwritten on every sync — contextWindow hardcoded to 128000, user modifications lost

3 participants