Commit daedfb1
committed
fix: serialize ChromaCollection writes via flock at the backend seam
Claude Code spawns one mcp_server.py process per open terminal; stop hooks
spawn additional short-lived writers (diary writes, `mempalace mine`
subprocesses). All open independent PersistentClient instances against the
same palace directory. ChromaDB has no inter-process write locking —
concurrent col.add/upsert/update/delete from N processes corrupts the HNSW
segment, causing the next read to SIGSEGV in chromadb_rust_bindings.
Fix: `_palace_write_lock(palace_path)` — a contextmanager using
fcntl.flock(LOCK_EX) on `$palace/.write.lock` — wraps all four write
methods of ChromaCollection (add, upsert, update, delete). Because every
caller (mcp_server, miner, convo_miner, palace) reaches ChromaDB through
this adapter, all writes serialize automatically across processes.
RFC 001 made ChromaCollection the single boundary for all ChromaDB writes,
which is the correct home for concurrency control. No caller needs to
know the lock exists.
ChromaCollection now accepts palace_path in its constructor; passed by
ChromaBackend.get_collection and the legacy create_collection shim.
Adapters constructed without a path (some tests) skip locking, same
behavior as before.
flock auto-releases on process death — a mid-write crash cannot deadlock
future writers.
On Windows, fcntl is unavailable — yields without locking. Windows users
running multiple MCP server processes against the same palace remain
exposed to the underlying ChromaDB concurrency issue; palace-daemon,
which provides proper asyncio read/write/mine semaphores, is the
recommended path for multi-client setups on any platform.
Test plan: 1094 tests pass locally.1 parent 8ac98f0 commit daedfb1
2 files changed
Lines changed: 75 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
11 | 20 | | |
12 | 21 | | |
13 | 22 | | |
| |||
177 | 186 | | |
178 | 187 | | |
179 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
180 | 230 | | |
181 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
182 | 237 | | |
183 | | - | |
| 238 | + | |
184 | 239 | | |
| 240 | + | |
185 | 241 | | |
186 | 242 | | |
187 | | - | |
| 243 | + | |
188 | 244 | | |
189 | 245 | | |
190 | 246 | | |
| |||
193 | 249 | | |
194 | 250 | | |
195 | 251 | | |
196 | | - | |
| 252 | + | |
| 253 | + | |
197 | 254 | | |
198 | 255 | | |
199 | 256 | | |
200 | 257 | | |
201 | 258 | | |
202 | 259 | | |
203 | 260 | | |
204 | | - | |
| 261 | + | |
| 262 | + | |
205 | 263 | | |
206 | 264 | | |
207 | 265 | | |
| |||
220 | 278 | | |
221 | 279 | | |
222 | 280 | | |
223 | | - | |
| 281 | + | |
| 282 | + | |
224 | 283 | | |
225 | 284 | | |
226 | 285 | | |
| |||
364 | 423 | | |
365 | 424 | | |
366 | 425 | | |
367 | | - | |
| 426 | + | |
| 427 | + | |
368 | 428 | | |
369 | 429 | | |
370 | 430 | | |
| |||
539 | 599 | | |
540 | 600 | | |
541 | 601 | | |
542 | | - | |
| 602 | + | |
543 | 603 | | |
544 | 604 | | |
545 | 605 | | |
| |||
582 | 642 | | |
583 | 643 | | |
584 | 644 | | |
585 | | - | |
| 645 | + | |
586 | 646 | | |
587 | 647 | | |
588 | 648 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
| 223 | + | |
| 224 | + | |
224 | 225 | | |
225 | 226 | | |
226 | 227 | | |
227 | 228 | | |
228 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
229 | 233 | | |
230 | 234 | | |
231 | 235 | | |
| |||
0 commit comments