From c145370e0f7778c0744ed9e27fd20dca23bf788b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 13 Sep 2026 19:01:47 +0200 Subject: [PATCH] State that observers run outside the cache gate Cut 3's second Soul pass found Watch observers and OnUpdate running while the gate was held on re-pull and commit, which deadlocks a subscriber that waits on a thread reading the cache, and a throwing handler that could leave a store holding records the cache dropped. Observers now publish after the outermost gate exit, and stores adopt their loaded view first. Also corrects the flush wording, which described only single-file stores. Co-Authored-By: Claude Opus 5 --- docs/cultcache-migration-cut.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/cultcache-migration-cut.md b/docs/cultcache-migration-cut.md index ecb379a42..2ca50a203 100644 --- a/docs/cultcache-migration-cut.md +++ b/docs/cultcache-migration-cut.md @@ -583,7 +583,14 @@ home store, before `_entries` changes. `ExpectUnchanged`) protect against a concurrent change to the same records. - An attached store uses its cache's gate as its own lock (`CacheBackingStore.Gate`, Cut 3 fix `5aad137`), so cache and store locks - cannot be taken out of order. + cannot be taken out of order. The cache also takes the gate around each + store's pull, which covers third-party stores that do not lock it themselves. +- Observers never run under the gate (Soul, Cut 3 second pass): `Watch` + observers and `OnUpdate` are published after the outermost gate exit on + every path, because a subscriber that blocks on another thread which reads + the cache would otherwise deadlock. A store adopts its loaded view before + anything is published, so a throwing handler cannot leave the store holding + records the cache dropped. - One key lives in one store: a write or load that would put a key already held from another store throws and changes nothing. - `OnUpdate` fires for loads only, as before the migration; writers publish @@ -804,8 +811,11 @@ the behavior change. may carry conditions, per-record `(schemaId, storedAt)` identity or whole-store unchanged, evaluated under the store's exclusive lock, and a failed condition is a lost race, not an error; **conditional commit is the - only safe multi-process write: a plain flush writes the whole snapshot and - is last-writer-wins, so processes sharing a store must all use conditional + only write protected against a concurrent change to the same records: a + plain flush or unconditional commit on a single-file store writes the + cache's snapshot and is last-writer-wins, and on a directory store lands its + changed pages onto the current manifest, last-writer-wins per key, so + processes that must not overwrite each other's changes use conditional commit**; batch and conditional commit are specified for C# and not yet implemented there; Rust implements both; TS and Python implement neither yet) and