Skip to content

feat(openclaw-nowledge-mem): make thread truncation configurable#102

Merged
wey-gu merged 1 commit into
nowledge-co:mainfrom
blessonism:fix/openclaw-nowledge-max-thread-message-chars
Mar 17, 2026
Merged

feat(openclaw-nowledge-mem): make thread truncation configurable#102
wey-gu merged 1 commit into
nowledge-co:mainfrom
blessonism:fix/openclaw-nowledge-max-thread-message-chars

Conversation

@blessonism

@blessonism blessonism commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Motivation

The plugin currently hard-truncates each captured OpenClaw thread message to 800 chars before persistence. This makes Nowledge thread history much less useful for reviewing long OpenClaw conversations, especially when inbound messages include envelope metadata or injected memory context.

What this change does

  • Adds a new config key: maxThreadMessageChars
  • Keeps backward compatibility with default 800
  • Applies the configured limit when normalizing OpenClaw user/assistant messages before thread persistence
  • Exposes the new setting in:
    • openclaw.plugin.json configSchema
    • UI hints
    • nowledge_mem_status
    • README docs

Suggested defaults

  • default: 800
  • range: 200-20000

Files changed

  • src/config.js
  • src/hooks/capture.js
  • src/tools/status.js
  • openclaw.plugin.json
  • README.md

Validation already done locally

  • Plugin imports cleanly after the change
  • Runtime config parsing confirms maxThreadMessageChars is read from pluginConfig
  • OpenClaw instance successfully reloaded with maxThreadMessageChars: 4000
  • Thread capture continues to work after reload

Notes for reviewers

This change intentionally does not remove truncation entirely. It only converts the current hard-coded limit into a documented config option so users can tune fidelity vs noise/storage for their own OpenClaw workflows.

Closes #101

Summary by CodeRabbit

  • New Features

    • Added configurable message truncation for thread capture via maxThreadMessageChars (default 800, range 200–20,000).
  • Documentation

    • Updated plugin README, config examples, UI hints, and status output to surface the new configuration and its source.

@coderabbitai

coderabbitai Bot commented Mar 8, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a configurable maxThreadMessageChars (integer, default 800, range 200–20000) to the OpenClaw mem plugin: schema/UI hint, README examples, cascaded config resolution, threaded through capture/truncation logic, and exposed in the status output.

Changes

Cohort / File(s) Summary
Plugin manifest & README
nowledge-mem-openclaw-plugin/openclaw.plugin.json, nowledge-mem-openclaw-plugin/README.md
Add maxThreadMessageChars to configSchema and UI hints; document persistent config example with "maxThreadMessageChars": 800.
Configuration cascade
nowledge-mem-openclaw-plugin/src/config.js
Introduce canonical key and env var (NMEM_MAX_THREAD_MESSAGE_CHARS), resolve value via file → pluginConfig → env → default (800), clamp to [200,20000], record source in _sources.
Capture pipeline
nowledge-mem-openclaw-plugin/src/hooks/capture.js
Thread maxMessageChars through truncate(), normalizeRoleMessage(), appendOrCreateThread(); handlers (buildAgentEndCaptureHandler, buildBeforeResetCaptureHandler) forward config into capture flow; default constant introduced.
Status tooling
nowledge-mem-openclaw-plugin/src/tools/status.js
Render maxThreadMessageChars and its source in status output and include in details.config.

Sequence Diagram(s)

sequenceDiagram
    participant Admin as Admin/UI
    participant Plugin as OpenClaw Plugin
    participant Capture as Capture Handler
    participant Storage as Thread Storage

    Admin->>Plugin: set maxThreadMessageChars (config / env)
    Plugin->>Plugin: resolve config (file → pluginConfig → env → default)
    Capture->>Plugin: capture event (agent_end / before_reset)
    Plugin->>Capture: provide resolved maxThreadMessageChars
    Capture->>Capture: normalize messages (truncate using maxThreadMessageChars)
    Capture->>Storage: appendOrCreateThread(persist truncated messages)
    Plugin->>Status: expose maxThreadMessageChars and source
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I nibbled code and found a key,
From eight hundred to more liberty,
Threads keep more words, I dance and sing,
Configured bounds, a joyous thing—
Hops of bytes and memory glee.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: making thread truncation configurable via a new maxThreadMessageChars setting.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from issue #101: adds configurable maxThreadMessageChars key with default 800 and range 200-20000, applies it to thread capture normalization, exposes it in config schema, UI hints, README, and status output.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the maxThreadMessageChars configuration feature as specified in issue #101; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@nowledge-mem-openclaw-plugin/src/config.js`:
- Around line 237-252: ALLOWED_KEYS currently omits "maxThreadMessageChars" so
plugin configs using that key are rejected and the parsed value isn't exposed
because it's not included in the returned config object; add the string
"maxThreadMessageChars" to the ALLOWED_KEYS array (where other keys like
maxContextTokens are listed) and add a property maxThreadMessageChars:
maxThreadMessageChars to the object returned by the config function so the
computed value (and its source in _sources.maxThreadMessageChars) is exposed as
cfg.maxThreadMessageChars at runtime.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a08b1837-e049-4a5d-85f4-78a5c901f134

📥 Commits

Reviewing files that changed from the base of the PR and between 47c52f9 and 16ec0a3.

📒 Files selected for processing (5)
  • nowledge-mem-openclaw-plugin/README.md
  • nowledge-mem-openclaw-plugin/openclaw.plugin.json
  • nowledge-mem-openclaw-plugin/src/config.js
  • nowledge-mem-openclaw-plugin/src/hooks/capture.js
  • nowledge-mem-openclaw-plugin/src/tools/status.js

Comment thread nowledge-mem-openclaw-plugin/src/config.js
@wey-gu

wey-gu commented Mar 10, 2026

Copy link
Copy Markdown
Member

@blessonism thanks!
sorry we released a new version but didnt reflect in main before your contribution? could you please help rebase?

@blessonism blessonism force-pushed the fix/openclaw-nowledge-max-thread-message-chars branch from 16ec0a3 to 7c4c044 Compare March 10, 2026 09:48

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
nowledge-mem-openclaw-plugin/src/hooks/capture.js (1)

379-389: Rename _cfg to cfg since it's now used.

The underscore prefix conventionally signals an intentionally unused parameter, but _cfg is now accessed on line 388. This is inconsistent with buildAgentEndCaptureHandler which uses cfg directly.

♻️ Suggested fix for naming consistency
-export function buildBeforeResetCaptureHandler(client, _cfg, logger) {
+export function buildBeforeResetCaptureHandler(client, cfg, logger) {
 	return async (event, ctx) => {
 		const reason = typeof event?.reason === "string" ? event.reason : undefined;
 		await appendOrCreateThread({
 			client,
 			logger,
 			event,
 			ctx,
 			reason,
-			maxMessageChars: _cfg?.maxThreadMessageChars,
+			maxMessageChars: cfg.maxThreadMessageChars,
 		});
 	};
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nowledge-mem-openclaw-plugin/src/hooks/capture.js` around lines 379 - 389,
The parameter name _cfg in buildBeforeResetCaptureHandler is misleading because
it implies the argument is unused while the function reads
_cfg.maxThreadMessageChars; rename the parameter to cfg (matching
buildAgentEndCaptureHandler) and update all references inside
buildBeforeResetCaptureHandler (e.g., _cfg?.maxThreadMessageChars) to use
cfg?.maxThreadMessageChars to restore naming consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@nowledge-mem-openclaw-plugin/src/hooks/capture.js`:
- Around line 379-389: The parameter name _cfg in buildBeforeResetCaptureHandler
is misleading because it implies the argument is unused while the function reads
_cfg.maxThreadMessageChars; rename the parameter to cfg (matching
buildAgentEndCaptureHandler) and update all references inside
buildBeforeResetCaptureHandler (e.g., _cfg?.maxThreadMessageChars) to use
cfg?.maxThreadMessageChars to restore naming consistency.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 05610cb7-ae54-42aa-ac75-801f650f2dca

📥 Commits

Reviewing files that changed from the base of the PR and between 16ec0a3 and 7c4c044.

📒 Files selected for processing (5)
  • nowledge-mem-openclaw-plugin/README.md
  • nowledge-mem-openclaw-plugin/openclaw.plugin.json
  • nowledge-mem-openclaw-plugin/src/config.js
  • nowledge-mem-openclaw-plugin/src/hooks/capture.js
  • nowledge-mem-openclaw-plugin/src/tools/status.js
🚧 Files skipped from review as they are similar to previous changes (3)
  • nowledge-mem-openclaw-plugin/openclaw.plugin.json
  • nowledge-mem-openclaw-plugin/src/config.js
  • nowledge-mem-openclaw-plugin/README.md

@blessonism

Copy link
Copy Markdown
Contributor Author

@wey-gu 已按你的建议把分支 rebase 到最新的 upstream/main,并解决了所有冲突(README / openclaw.plugin.json / src/config.js / src/tools/status.js)。

同时保留了 main 上新增的 recallMinScore 和本 PR 的 maxThreadMessageChars 两个配置项(schema、文档、config 解析、status 输出均已对齐)。

刚刚已 force-push 更新 PR,麻烦你这边再看下 CI/Review,谢谢!

@wey-gu wey-gu merged commit cdcea3e into nowledge-co:main Mar 17, 2026
1 check passed
@wey-gu

wey-gu commented Mar 17, 2026

Copy link
Copy Markdown
Member

THANKS a lot @blessonism !

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.

Feature request: make OpenClaw thread capture truncation configurable

2 participants