Skip to content

fix(graph_dbs): sanitize nested metadata before Neo4j writes#1178

Open
kyan-du wants to merge 1 commit intoMemTensor:mainfrom
kyan-du:fix/neo4j-sanitize-skill-memory-map
Open

fix(graph_dbs): sanitize nested metadata before Neo4j writes#1178
kyan-du wants to merge 1 commit intoMemTensor:mainfrom
kyan-du:fix/neo4j-sanitize-skill-memory-map

Conversation

@kyan-du
Copy link

@kyan-du kyan-du commented Mar 8, 2026

Summary

  • sanitize nested metadata values before writing Neo4j node properties
  • apply the same sanitization in both Neo4j enterprise and community graph DB implementations
  • add a regression test covering skill-memory style nested metadata

Problem

Neo4j node properties only accept primitive values or arrays of primitives. Some MemOS flows (especially SkillMemory and feedback-related flows) can produce nested metadata like:

  • scripts: dict
  • others: dict
  • nested objects under info
  • arrays containing dict items

Those values can reach SET n += $metadata and trigger errors like:

  • Property values can only be of primitive types or arrays thereof
  • CypherTypeError: Map{} encountered

Fix

This PR adds a small sanitization layer before Neo4j writes:

  • keep primitive values as-is
  • keep arrays of primitives as-is
  • serialize dict values to JSON strings
  • serialize nested list items that are dict/list values

This keeps metadata readable while making it safe for Neo4j property storage.

Validation

  • reproduced the issue locally with SkillMemory-style metadata
  • verified the sanitized metadata no longer contains Neo4j-invalid map values
  • verified a real /product/add flow successfully created SkillMemory without the previous Neo4j Map{} error

@kyan-du
Copy link
Author

kyan-du commented Mar 8, 2026

This PR addresses the root cause described in #1172 and partially in #1122.

The existing _flatten_info_fields() fix (from #1122) handles the top-level info dict, but other dict-typed fields (scripts, others, and nested objects inside info) still reach Neo4j as Map{} values.

This PR adds a universal sanitization step that catches all remaining cases.

@kyan-du kyan-du force-pushed the fix/neo4j-sanitize-skill-memory-map branch from 2fc7a17 to d954e4e Compare March 8, 2026 18:03
@kyan-du kyan-du force-pushed the fix/neo4j-sanitize-skill-memory-map branch from d954e4e to 760a8e7 Compare March 8, 2026 18:05
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.

1 participant