Repository navigation
fix(state-store): the switch to WAL is best effort wherever a native connection opens the store - #2024
Merged
Conversation
…connection opens the store Signed-off-by: Felipe Marzochi <fmarzochi@gmail.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.



Why
Right after the v1.1.23 tag, the
mainrun for d424ee6 went red in one lane (ubuntu-latest, Node 20, npm):tests/lib/state-store-concurrency.test.js, casetest_mcp_server_style_concurrency_with_hook_writers, withSQLITE_BUSY: database is lockedthrown by the process that simulates the memory server, while the same tree passed the other 22 lanes, the tag's own CI and the pull request's. The rerun passed; ten local runs passed. The shape is the onescripts/hooks/state-db-writer.jsalready documents for itself:PRAGMA journal_mode = WALneeds the file to itself and the busy handler does not always cover that step, so processes opening the same store at the same moment seeSQLITE_BUSYat once. The hook writer retried; the memory server did not (memory-db.tsat start,memory-misc-tools.tsindetect_patterns), nor did the test's simulated server. On a saturated machine the real server's start could fail the same way.What changes
scripts/lib/state-store/sqlite-compat.js:enableWalBestEffort(db)moves here from the hook writer, next to the engine chooser: twenty attempts fifty milliseconds apart onSQLITE_BUSY, then the mode is left to the next opener; any other error still surfaces; a store already in WAL is left alone.scripts/hooks/state-db-writer.js: imports the helper instead of carrying its own copy. Same behavior.mcp/servers/egc-memory/src/sqlite-compat.ts: exposes the helper through the typed door;memory-db.tsandmemory-misc-tools.tscall it afterbusy_timeoutinstead of the bare pragma (the misc tool also sets the timeout before the switch now).tests/lib/state-store-concurrency.test.js: the native writer of the mixed-engine case and the simulated server switch WAL through the helper.tests/scripts/sqlite-compat.test.js: a new case with a fake connection pins the retry, the quiet give-up after twenty busy answers, the rethrow of another error and the untouched WAL store.CHANGELOG.mdanddocs/ROADMAP.md: the entry (fix(state-store): the switch to WAL is best effort wherever a native connection opens the store #2024).WAL is a performance setting, not a correctness one: every query still waits through
busy_timeoutwhatever the journal mode.Proof
node tests/scripts/sqlite-compat.test.js: 24 passed, 0 failed.node tests/lib/state-store-concurrency.test.js: 17 passed, 0 failed (the simulated server case included, with the built memory server present).node tests/hooks/state-db-writer.test.js: 5 passed.npx tsc --noEmit -p mcp/servers/egc-memory: clean; the server rebuilt.