Skip to content

fix(memos-local-plugin): add maxTokens to LlmSchema & SkillEvolverSchema - #1896

Open
chouti wants to merge 3 commits into
MemTensor:mainfrom
chouti:fix/llm-schema-add-max-tokens
Open

fix(memos-local-plugin): add maxTokens to LlmSchema & SkillEvolverSchema#1896
chouti wants to merge 3 commits into
MemTensor:mainfrom
chouti:fix/llm-schema-add-max-tokens

Conversation

@chouti

@chouti chouti commented Jun 8, 2026

Copy link
Copy Markdown

Problem

Reasoning models (e.g. deepseek-reasoner, o1*, gpt-5-thinking) consume hundreds of tokens on chain-of-thought before emitting JSON content. When llm.json reflection / skillEvolver.crystallize is called with the legacy hard-coded max_tokens: 1024, the response is truncated mid-JSON and the bridge logs llm.json malformed 73+ times in a single reflection cycle.

Result: episodes never close, recoveryReason: "dirty_reward_rescore" piles up, and the MemOS viewer reports bridge.status: disconnected even though the daemon is alive.

Reproduction

llm:
  provider: openai_compatible
  endpoint: https://api.deepseek.com/v1
  model: deepseek-reasoner       # or any reasoning model
  apiKey: sk-...
algorithm:
  lightweightMemory:
    enabled: false               # full self-evolution ON

Start bridge with no override of max_tokens. After ~1 episode:

[bridge] llm.json malformed at 2026-06-08T...Z (attempt 1)
[bridge] llm.json malformed at 2026-06-08T...Z (attempt 2)
... × 73

Direct curl confirms root cause: API returns finish_reason: "length" with truncated content.

Fix

Add maxTokens (default 4_000) to LlmSchema and SkillEvolverSchema. Reasonable budget for reasoning models while still clamping below OpenAI's 32k ceiling.

  • LlmSchema.maxTokens: NumberInRange(4000, 1024, 32768)
  • SkillEvolverSchema.maxTokens: NumberInRange(4000, 1024, 32768)
  • Corresponding defaults in defaults.ts for old configs

TypeBox's Value.Default already preserves user-supplied fields, so the change is backward compatible — old configs without maxTokens get the 4_000 default; new configs can override.

Verification

Before patch:

  • 73 malformed per reflection cycle
  • bridge.status: disconnected

After patch (config unchanged, schema updated):

  • 0 malformed across 141 episodes
  • bridge.status: connected
  • Viewer loads (200 OK)

Files changed

  • apps/memos-local-plugin/core/config/schema.ts (+15 lines, 2 field defs)
  • apps/memos-local-plugin/core/config/defaults.ts (+2 lines, 2 default values)
 apps/memos-local-plugin/core/config/defaults.ts |  2 ++
 apps/memos-local-plugin/core/config/schema.ts   | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

Reasoning models (deepseek-reasoner, o1*, gpt-5-thinking) consume
hundreds of tokens on chain-of-thought. The hard-coded 1024 cap on
LLM JSON reflection caused 73+ 'llm.json malformed' errors per
episode, blocking episode closure and disconnecting the bridge.

- Add maxTokens: NumberInRange(4000, 1024, 32768) to LlmSchema
- Add maxTokens: NumberInRange(4000, 1024, 32768) to SkillEvolverSchema
- Add corresponding defaults in defaults.ts (backward compat)

TypeBox's Value.Default preserves user-supplied fields, so old
configs without maxTokens get the 4000 default; new configs can
override.
@Memtensor-AI
Memtensor-AI changed the base branch from main to dev-20260604-v2.0.19 June 10, 2026 15:42
@Memtensor-AI
Memtensor-AI changed the base branch from dev-20260604-v2.0.19 to dev-v2.0.22 July 1, 2026 13:15
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Automated Test Results: FAILED

Cloud test-engine rerun against dev-v2.0.22 failed.

  • Run: tr-7d12f792-72f on cloud test-engine 10010

  • Verdict: fail_code_bug

  • Summary: Tests failed. Failed cases: test

  • memos_local_plugin/unit: 0 passed, 1 failed, 0 skipped

  • memos_local_plugin/smoke: 0 passed, 0 failed, 0 skipped

  • memos_local_plugin/contract: 0 passed, 0 failed, 0 skipped

Failed cases:

  • test: e}
    11:26:01.223 WARN [core.memory.l2.events] listener_threw kind="l2.candidate.added" err={name,message}
    11:26:05.033 WARN [core.skill.events] listener_threw kind="skill.archived" err={name,message}
    11:26:05.033 WARN [core.skill.events] listener_threw kind="skill.archived" err={name,message}
    11:26:06.675 WARN [core.retrieval.events] listener_threw kind="retrieval.started" err="bad listener"
    11:26:06.675 WARN [core.retrieval.events] listener_threw kind="retrieval.started" err="bad listener"

Do not merge until this is fixed and cloud tests pass.

@CarltonXiang
CarltonXiang deleted the branch MemTensor:main July 3, 2026 07:25
@syzsunshine219 syzsunshine219 reopened this Jul 3, 2026
@syzsunshine219
syzsunshine219 changed the base branch from dev-v2.0.22 to main July 3, 2026 08:22
@Memtensor-AI Memtensor-AI added the area:plugin OpenClaw & Hermes label Jul 8, 2026
@Memtensor-AI
Memtensor-AI requested a review from bittergreen July 8, 2026 11:44
@Memtensor-AI Memtensor-AI added the area:model llm + embedder + reranker label Jul 9, 2026
@Memtensor-AI Memtensor-AI removed area:model llm + embedder + reranker needs-audit labels Jul 9, 2026
@Memtensor-AI Memtensor-AI added the status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 label Aug 6, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #1896
Task: c3f809a70b09c2e6
Base: main
Head: fix/llm-schema-add-max-tokens

OpenCodeReview: No comments generated. Looks good to me.

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

✅ Automated Test Results: PASSED

All tests passed (103/103 executed). memos_local_plugin/unit: 103/103. Duration: 13s [advisory, non-gating] AI-generated tests on branch test/auto-gen-c3f809a70b09c2e6-20260806195541: 77/78 passed, 1 failed — these do NOT affect the PR verdict; review the branch manually.

Branch: fix/llm-schema-add-max-tokens

@Memtensor-AI Memtensor-AI added status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发 and removed status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Aug 6, 2026

@Hun-ger Hun-ger left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for addressing this issue. The truncation problem is still present on main, and the added runtime wiring tests for both shared and dedicated LLM clients are valuable.
Before merging, please reconsider the global 1024–32768 validation range. This is a provider-agnostic configuration, so a minimum of 1024 prevents legitimate smaller budgets, while the 32768 upper bound rejects models that support larger outputs. Please use a more permissive provider-neutral range, or only validate that the value is a positive integer.
Once the range and corresponding tests are updated, this should be ready for another review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:plugin OpenClaw & Hermes status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants