fix: make recall resilient to transient database contention - #72
Open
Liyuk wants to merge 1 commit into
Open
Conversation
Two related reliability fixes for the graph-memory:recall context DSH
injects on every prompt assembly:
- src/store/db.ts: configure PRAGMA busy_timeout = 5000 in openDb so a
write that collides with another connection's transaction (e.g. a second
DSH process sharing ~/.dsh/graph-memory/graph-memory.db) waits for the
lock instead of failing instantly with SQLITE_BUSY ("database is locked").
- dsh.ts: evict a recall from recallCache when it fails. Previously the
rejected Promise stayed pinned, so every subsequent system-prompt/assemble
re-awaited it and logged "[graph-memory] DSH recall failed" on each round
until the next agent/inbox/claimed cleared it - a single transient error
became a per-round failure.
Adds regression tests: busy_timeout is configured on every connection plus
a cross-process write-wait test, and the recall cache is evicted on failure
while successful recalls stay cached.
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.
What
Fixes the
graph-memory:recallcontext that DSH injects into every prompt assembly failing repeatedly — a single transient error turned into a per-round failure.1.
src/store/db.ts— configurePRAGMA busy_timeoutopenDbsetjournal_mode = WALandforeign_keys = ONbut no busy timeout. When two connections to the same database file write concurrently (e.g. a second DSH process sharing~/.dsh/graph-memory/graph-memory.db), the colliding write fails immediately withSQLITE_BUSY("database is locked"). Withbusy_timeout = 5000the connection waits for the lock so transient contention is retried instead of surfacing as a spurious recall/extraction failure.2.
dsh.ts— evict a failed recall fromrecallCacheThe assembly handler caches
{ query, value: recaller.recall(query) }per agent. If that Promise rejects, the rejected Promise stays pinned in the cache, and every subsequentsystem-prompt/assemblere-awaits it — logging[graph-memory] DSH recall failedon every round until the nextagent/inbox/claimedclears the entry. The catch block now evicts the entry (guarded by the current query) so the next assembly performs a fresh recall.Tests
test/db.test.ts— assertsbusy_timeoutis configured on every connection, plus a cross-process test: a child process holds a write lock, and this process' write must block and then succeed instead of throwing instantly.test/dsh-recall-cache.test.ts— asserts a failed recall is evicted (the next assembly retries, recall invoked twice) while successful recalls stay cached (invoked once across three assemblies).npm test: 111 tests pass (13 files).npm run buildcompiles cleanly.Notes
npm run buildrequires the optional peeropenclawto be present (it providesopenclaw/plugin-sdktypes forindex.ts); CI's plainnpm installinstalls it.@photostructure/sqliteis a synchronous binding, so with two connections in the same process,busy_timeoutretries block the event loop (the lock holder can't commit until the retry gives up). That is why the contention test is cross-process — the real multi-host scenario.