Commit 4b3865d
authored
fix(graph_dbs): sanitize nested metadata before Neo4j writes (#1178)
## 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{}` errorFile tree
3 files changed
+56
-1
lines changed- src/memos/graph_dbs
- tests/graph_dbs
3 files changed
+56
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
75 | 96 | | |
76 | 97 | | |
77 | 98 | | |
| |||
212 | 233 | | |
213 | 234 | | |
214 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
215 | 239 | | |
216 | 240 | | |
217 | 241 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
| |||
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
| 63 | + | |
| 64 | + | |
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
| |||
135 | 142 | | |
136 | 143 | | |
137 | 144 | | |
| 145 | + | |
138 | 146 | | |
139 | 147 | | |
140 | 148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
0 commit comments