fix(openclaw): fall back to sessionKey when ctx.channelId is a provider name#871
Closed
octo-patch wants to merge 2 commits intovectorize-io:mainfrom
Closed
Conversation
MCP tool bridges (Claude Code, Cursor, etc.) sometimes serialize JSON arrays and objects as strings during transport, causing Pydantic to reject the input with a validation error. The agent then retries with the same broken format, wasting tokens and silently losing memories. Add defensive coercion at two layers: HTTP API (http.py): - RecallRequest: field_validator on types and tags (mode="before") that parses JSON-string arrays back into lists - MemoryItem: field_validator on metadata (mode="before") that parses JSON-string objects back into dicts (tags coercion was already present) MCP tools (mcp_tools.py): - build_content_dict: coerce metadata from JSON string to dict, matching the existing tags coercion in the same function - both recall() variants: coerce types and tags from JSON strings before passing to the memory engine All coercions are backward-compatible — correctly-typed inputs pass through unchanged. Fixes vectorize-io#849
…er name (fixes vectorize-io#854) Some OpenClaw providers (e.g. Discord) populate ctx.channelId with the platform/provider name (e.g. "discord") rather than the actual channel identifier. This caused all Discord channel memories to merge into a single bank regardless of which channel was active, defeating per-channel isolation configured via dynamicBankGranularity. The fix detects when ctx.channelId matches a known provider name (discord, telegram, slack, etc.) and treats it as missing, allowing the sessionKey fallback parser to supply the real channel ID.
nicoloboschi
requested changes
Apr 7, 2026
Collaborator
nicoloboschi
left a comment
There was a problem hiding this comment.
LGTM, except for the API files changed, can you keep the PR only for openclaw? thanks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #854
Problem
Some OpenClaw providers (e.g. Discord) populate
ctx.channelIdwith the platform/provider name (e.g."discord") rather than the actual channel identifier (e.g."1472750640760623226"). Becausectx.channelIdhas priority over the sessionKey fallback inderiveBankId(), all Discord channel memories merged into a single bank (main::discord) regardless of which channel was active — defeating per-channel isolation for users withdynamicBankGranularity: ["agent", "channel"].Debug output from the issue:
Solution
In
deriveBankId(), check ifctx.channelIdexactly matches a known provider/platform name (discord, telegram, slack, whatsapp, signal, matrix, irc, line). If it does, treat the value as missing and fall through to thesessionParsed.channelderived from the sessionKey, which correctly carries the real channel identifier.Only exact case-insensitive matches are filtered — channel names like
"slack-general"or"my-discord-bot"pass through unchanged.Testing
derive-bank-id.test.ts:ctx.channelId = "discord"uses the channel extracted from the sessionKey instead."slack-general"(which contains a provider name as substring) is preserved correctly.