Repository navigation
Description
Overview
#2431 root-caused and fixed intermittent SQLITE_MISUSE/SIGSEGV flakiness in nodespace-core's lib tests. The fix (PR #2514) doesn't cover three other crates whose tests are exposed to the same underlying hazard.
Problem Statement
The root cause, documented on SqliteStore in packages/core/src/db/sqlite_store/mod.rs, is an unsynchronized static check-then-act race in libsql-ffi's vendored SQLite3MultipleCiphers WAL-manager singleton (make_sqlite3_wal_manager_rc/clone_wal_manager). Two connections opening at genuinely the same instant on separate OS threads can race that check-then-act or torn-write a shared refcount, corrupting a process-global struct that any subsequent SQLite operation on any connection may then trip over — not just the connections that raced.
PR #2514 fixed this for nodespace-core by serializing its own lib/bin/test targets to --test-threads=1 (rust:test:core in package.json), since nodespace-core is the workspace's only crate with a direct dependency on libsql/libsql-ffi.
However, libsql-ffi is also linked transitively into nodespace-agent, nodespace-daemon, and nodespace-cli (confirmed via cargo tree -i libsql-ffi), and each of these crates has its own non-#[ignore]d integration tests that call SqliteStore::new() directly and still run at --test-threads=2 under rust:test:workspace, unserialized:
packages/daemon/tests/grpc_round_trip.rspackages/daemon/tests/import_round_trip.rspackages/daemon/tests/agent_session_grpc.rspackages/cli/tests/cli_integration.rspackages/cli/tests/import_dir_multi.rspackages/agent/tests/search_nodes_enumerate.rspackages/agent/tests/live_unset_schema_field.rspackages/agent/tests/live_update_node_noop_gate.rspackages/agent/tests/matrix_scenario_winnability.rspackages/agent/tests/live_resolve_query_decomposition_shapes.rs
The same race is reachable there in principle. It hasn't been observed to trigger yet in these suites, plausibly because they're far smaller (tens of tests, not 1000+ like nodespace-core's lib suite was), so the odds of two connections racing to open at literally the same instant are much lower — not because the hazard doesn't apply.
Proposed Solution
Investigate whether these crates' SqliteStore-touching test targets should get the same treatment preemptively (a serialized step analogous to rust:test:core), or whether it's acceptable to wait for empirical reproduction there before acting. Either extend the fix, or make and document a deliberate decision to defer with the reasoning (e.g. "odds are low enough at this suite size that we'll act if/when it's actually observed").
Acceptance Criteria
- Determine whether
nodespace-agent,nodespace-daemon, andnodespace-cli'sSqliteStore-touching integration tests should be serialized against the same hazard - If yes: extend a
--test-threads=1treatment to the relevant test targets in those crates, analogous torust:test:core, without unnecessarily slowing tests that don't touchSqliteStore - If no (deferring): document the reasoning explicitly, including what would change that decision (e.g. observed flakiness in one of the listed test files)
- Correct or confirm the scope claim in
packages/core/src/db/sqlite_store/mod.rs's doc comment onSqliteStorematches whatever decision is made here -
bun run test:allpasses with no new failures - Code passes
bun run quality:fix
Technical Specifications
Reference Files
packages/core/src/db/sqlite_store/mod.rs: doc comment onSqliteStore— the root-cause write-up and the note pointing herepackage.json:rust:test:core,rust:test:workspace— the pattern to extend or referencepackages/desktop-app/package.json:rust:test— delegates to the rootrust:test:core, a precedent for how a sibling package.json should reference the canonical script rather than duplicating it
Verification approach
Per #2431's investigation, reproducing this hazard reliably needs many concurrent SqliteStore::new() calls at a high thread count over repeated runs (the nodespace-core investigation used --test-threads=16, 40+ consecutive runs, to get a ~5-15% failure rate). Given these three crates' suites are much smaller, a similar statistical approach (higher thread count, many repeated runs) is the way to determine whether the race is practically reachable there before deciding whether a fix is warranted.
Related Issues
- Test gate fails on resource contention, not correctness: intermittent SIGSEGV in core lib tests and post-merge gate aborts #2431 (root cause and
nodespace-corefix)
Activity
Address review: correct doc-comment scope claim, fix stale desktop-ap…
Serialize nodespace-core's lib tests to close a vendored libsql-ffi W…
mstomar125 commentedon Sep 9, 2026
Investigated and resolved in #2524.
Path taken: extend the
--test-threads=1treatment, not defer.Ran each
SqliteStore-touching test target acrossnodespace-agent,nodespace-daemon, andnodespace-cliat--test-threads=16over ~290 total repeated runs (matching #2431's own methodology — see PR for the full per-target breakdown). The race reproduced directly: once in 100 runs ofnodespace-agent's--libsuite, hitting the exact failure shape #2431 documented fornodespace-core— a setup-timeNodeService::new()panic (QueryFailed("Failed to query nodes")) with no code change between that run and every surrounding passing run of the identical test.nodespace-daemon's lib and every explicitly-named integration target in the original issue stayed clean across ~190 further runs, but the root cause has no principled guarded region narrower than "every operation on every connection, for the life of the process" — so a clean run there reads as that suite being smaller (fewer concurrentSqliteStore::new()calls competing for the same instant), not as being unexposed to the hazard.Added
rust:test:libsql-linked(mirrorsrust:test:core's shape) covering all three crates'--lib --bins --teststargets at--test-threads=1, excluded them fromrust:test:workspace's--test-threads=2run, and corrected theSqliteStoredoc comment (previously described this as a deliberate deferral on an assumption — "tens of tests, not 1000+" — that undercountednodespace-agent's own lib suite, which alone runs 621 tests in one process).bun run test:allandbun run quality:fixboth pass clean.mstomar125 commentedon Sep 9, 2026
Fixed via PR #2524, merged
9065eff1. Empirical finding: reproduced the WAL-manager race once in 100 runs of nodespace-agent's lib suite (matching #2431's exact failure shape); extended the --test-threads=1 serialization to all three libsql-ffi-linked crates rather than deferring, since the underlying hazard has no principled per-crate boundary.