Skip to content

fix(active-memory): skip non-string entries in pluginConfig.agents du… - #68837

Closed
SimbaKingjoe wants to merge 1 commit into
openclaw:mainfrom
SimbaKingjoe:fix/memory-search-nonstring-entry
Closed

SimbaKingjoe wants to merge 1 commit into
openclaw:mainfrom
SimbaKingjoe:fix/memory-search-nonstring-entry

Conversation

@SimbaKingjoe

Copy link
Copy Markdown
Contributor

fix(active-memory): skip non-string entries in pluginConfig.agents during normalization

Summary

  • Problem: The normalizePluginConfig function previously called .map((agentId) => agentId.trim()) directly on raw.agents without first filtering out non-string values. When pluginConfig.agents contained non-string entries (e.g., null, 42, or other invalid types), the .trim() method would throw a runtime error (agentId.trim is not a function), causing the plugin registration to crash.
  • Why it matters: Users or external integrations could inadvertently provide malformed configuration (e.g., mixed-type arrays, legacy config structures, or JSON parsing artifacts) that would break the entire active-memory plugin registration, making memory features unavailable without clear error messaging.
  • What changed: Added a type guard filter filter((agentId): agentId is string => typeof agentId === "string") before the .map() and .filter(Boolean) chain. Non-string entries are now silently skipped during normalization, and only valid string agent IDs proceed through trimming and empty-string filtering.
  • What did NOT change: Behavior for valid agents arrays (all string entries) remains identical. The plugin's runtime functionality, hooks, and memory search logic are completely unaffected. No changes to public API or configuration schema.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • 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 #
  • Related #
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: The normalization logic assumed raw.agents would always be an array of strings. When non-string values appeared, calling .trim() on them caused a runtime TypeError because non-string primitives (and null/undefined) lack a .trim() method.
  • Missing detection / guardrail: No unit test covered a scenario where pluginConfig.agents contained non-string entries. Existing tests only validated the happy path with clean string arrays.
  • Contributing context (if known): The original implementation likely prioritized simplicity over defensive programming, trusting that configuration inputs would always be well-formed. The fix adds a defensive type guard without changing the intended behavior.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: extensions/active-memory/index.test.ts (new test case: "tolerates non-string entries in pluginConfig.agents without crashing register")
  • Scenario the test should lock in: pluginConfig.agents set to ["main", null, 42, "", " support "] (mixed valid strings, null, number, and empty string). Registration should not throw, and valid agent IDs (including "support" after trimming) should still trigger the expected hooks.
  • Why this is the smallest reliable guardrail: A focused unit test that directly invokes plugin.register() with malformed configuration isolates the regression without requiring full integration or E2E setup.
  • Existing test that already covers this (if any): None.
  • If no new test is added, why not: N/A – a regression test has been added as part of this PR.

User‑visible / Behavior Changes

None. This fix prevents a crash that would otherwise occur with malformed configuration. Users with correctly configured agents arrays will see no difference. Users with malformed config will now see the plugin register successfully (with non-string entries ignored) instead of crashing.

Diagram (if applicable)

Before:
[pluginConfig.agents = ["main", null, 42]] → .map(agentId => agentId.trim())
→ TypeError: agentId.trim is not a function → plugin registration crashes

After:
[pluginConfig.agents = ["main", null, 42]]
→ .filter(agentId => typeof agentId === "string") → ["main"]
→ .map(agentId => agentId.trim()) → ["main"]
→ .filter(Boolean) → ["main"]
→ plugin registers successfully for agent "main"

@greptile-apps

greptile-apps Bot commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a defensive type guard filter in normalizePluginConfig to skip non-string entries in pluginConfig.agents before calling .trim(), preventing a TypeError crash when malformed configuration arrays (e.g. containing null or numeric values) are provided. A regression test is included that validates the fix with a mixed-type array and confirms that trimmed string values survive normalization and correctly trigger hooks.

Confidence Score: 5/5

Safe to merge — minimal, focused fix with a matching regression test and no behavior change for valid configs.

The change is a one-line-equivalent type guard that exactly mirrors the existing defensive pattern already used for allowedChatTypes in the same function. The test covers the described failure scenario end-to-end. No API, schema, or runtime logic is altered.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(active-memory): skip non-string entr..." | Re-trigger Greptile

@steipete

Copy link
Copy Markdown
Contributor

Closing this as not reproducible on current main after Codex review.

Current main rejects mixed-type plugins.entries.active-memory.config.agents before Active Memory registration or live reload, so the reported runtime crash path is not reproducible in shipped OpenClaw behavior. The PR is a reasonable defensive hardening, but it does not fix a bug that survives the existing manifest/config validation pipeline.

What I checked:

  • Active Memory helper would only fail if handed unvalidated mixed types: normalizePluginConfig() still trims raw.agents entries directly after an Array.isArray check, so the claimed throw would require a malformed array to reach this helper at runtime. (extensions/active-memory/index.ts:620, 938b53698ec1)
  • Manifest schema already requires string-only agents: The bundled Active Memory manifest defines configSchema.properties.agents as an array whose items are strings, so non-string entries are invalid config. (extensions/active-memory/openclaw.plugin.json:10, 938b53698ec1)
  • Plugin loader validates config before register(api): validatePluginConfig() runs against the manifest schema, rejects invalid config, and createApi(...) receives pluginConfig: validatedConfig.value, not raw config. (src/plugins/loader.ts:2525, 938b53698ec1)
  • Runtime config reload also validates plugin config and fails closed: validateConfigObjectWithPlugins() validates each enabled plugin entry against its manifest schema, and loadConfig() throws on invalid config instead of returning it to runtime callers. (src/config/validation.ts:1201, 938b53698ec1)
  • Active Memory live refresh reads through validated runtime config: The plugin's live config path uses resolveLivePluginConfigObject(api.runtime.config?.loadConfig, "active-memory", ...), so it consumes the same validated runtime config boundary rather than arbitrary raw values. (extensions/active-memory/index.ts:1886, 938b53698ec1)
  • Existing tests already enforce fail-fast behavior for invalid plugin config: src/plugins/loader.test.ts has a loader test asserting that invalid plugin config causes plugin load failure rather than successful registration. (src/plugins/loader.test.ts:4098, 938b53698ec1)

Codex Review notes: reviewed against 938b53698ec1.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants