Skip to content

Serialize nodespace-agent/daemon/cli's libsql-ffi-linked tests - #2524

Merged
mstomar125 merged 1 commit into
mainfrom
issue-2516-serialize-sqlite-ffi-tests
Sep 9, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-2516-serialize-sqlite-ffi-tests

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

#2431/PR #2514 serialized nodespace-core's own lib/bin/test targets (rust:test:core, --test-threads=1) to close a real, unsynchronized check-then-act race in libsql-ffi's vendored SQLite3MultipleCiphers WAL-manager singleton. libsql-ffi is also linked transitively into nodespace-agent, nodespace-daemon, and nodespace-cli, whose SqliteStore-touching tests were left running unserialized (--test-threads=2) under rust:test:workspace. This issue asked us to determine empirically whether that gap is practically reachable, and either extend the fix or make and document a deliberate defer decision.

Path taken: extend. The race reproduced directly in nodespace-agent's lib test suite.

Empirical findings

Ran each SqliteStore-touching test target across nodespace-agent, nodespace-daemon, and nodespace-cli at --test-threads=16 over many repeated runs, matching #2431's own methodology:

Target Runs Failures matching the WAL-manager race shape Other (unrelated) failures
nodespace-agent --lib (621 tests) 100 (40 + 60 follow-up) 1 — NodeService::new() setup-time panic, QueryFailed("Failed to query nodes"), no code change between the failing run and every surrounding passing run of the identical test 7 — pre-existing pty::manager::tests::ultra_short_lived_processes_are_pruned timing flake under CPU load, unrelated to SQLite
nodespace-daemon --lib (187 tests) 40 0 0
nodespace-daemon — grpc_round_trip, import_round_trip, agent_session_grpc 20 each (60 total) 0 0
nodespace-cli — cli_integration, import_dir_multi 20 each (40 total) 0 0
nodespace-agent — search_nodes_enumerate, live_unset_schema_field, matrix_scenario_winnability 20 each (60 total) 0 0
nodespace-agent — live_update_node_noop_gate, live_resolve_query_decomposition_shapes 5 each (10 total) N/A — each file's sole test is #[ignore]d (requires a local GGUF), so these ran 0 actual tests either way 0

The one genuine reproduction hit the exact failure shape #2431 documented for nodespace-core: a setup-time query failure (via NodeService::new() → seed_local_person_if_needed → a query_nodes call inside the same process as 15 other concurrently-opening SqliteStores) that doesn't reproduce on code inspection and didn't recur on the very next run of the identical test. (Note: the panic message itself only shows "Failed to query nodes" because NodeServiceError::query_failed(e.to_string()) calls anyhow::Error::to_string(), which prints only the top .context() frame and drops the underlying cause chain — a separate, pre-existing loss of diagnostic detail, not something this PR changes.)

nodespace-daemon's lib and every explicitly-named integration target stayed clean across ~190 further runs. The root cause (documented on SqliteStore in packages/core/src/db/sqlite_store/mod.rs) has no principled guarded region narrower than "every operation on every connection, for the life of the process," and a genuine reproduction via the identical mechanism already landed in one of the three crates — so a clean run elsewhere reads as that suite being smaller (fewer concurrent SqliteStore::new() calls competing for the same instant), not as that target being unexposed.

Change

  • package.json: added rust:test:libsql-linked (cargo test --lib --bins --tests -p nodespace-agent -p nodespace-daemon -p nodespace-cli -- --test-threads=1), wired into rust:test, and excluded these three packages from rust:test:workspace's --test-threads=2 run — the same shape as rust:test:core.
  • packages/core/src/db/sqlite_store/mod.rs: corrected the SqliteStore doc comment, which previously described the agent/daemon/cli exposure as a "deliberate, tracked deferral" on the assumption those suites were "tens of tests, not 1000+" (that assumption undercounted — nodespace-agent's own --lib target alone runs 621 tests in one process). The comment now documents the actual empirical finding and the extended scope.

nodespace-cli's own --lib target has no direct SqliteStore construction (only its two integration test files do), so its practical exposure is narrower than the other two, but it's included in the same script for consistency with the whole-crate granularity rust:test:core already established (cargo's --test-threads is a per-invocation flag, not a per-test one, so splitting finer within a crate isn't a maintainable option without fragile test-name filtering).

Test plan

  • bun run test:all passes with no new failures
  • bun run quality:fix is clean
  • Verified rust:test:workspace (with the new excludes) no longer runs agent/daemon/cli tests
  • Verified rust:test:libsql-linked runs all three crates' lib/bin/test targets at --test-threads=1 with 0 failures
  • ~290 total repeated runs across the two batteries described above

#2431/PR #2514 serialized nodespace-core's own tests against a real,
unsynchronized check-then-act race in libsql-ffi's vendored WAL-manager
singleton, but left nodespace-agent/daemon/cli's SqliteStore-touching
tests running unserialized under rust:test:workspace. Ran each affected
target at --test-threads=16 over ~290 repeated runs (matching #2431's own
methodology) and reproduced the same failure shape once in 100 runs of
nodespace-agent's lib suite: a setup-time NodeService::new() panic
(QueryFailed("Failed to query nodes")) with no code change between that
run and every surrounding passing run of the identical test.

Add rust:test:libsql-linked (cargo test --lib --bins --tests -p
nodespace-agent -p nodespace-daemon -p nodespace-cli -- --test-threads=1),
wire it into rust:test, and exclude these three packages from
rust:test:workspace's --test-threads=2 run — the same shape as
rust:test:core. Correct the SqliteStore doc comment, which previously
described this as a deliberate deferral on the assumption these suites
were "tens of tests, not 1000+" (nodespace-agent's own --lib target alone
runs 621 tests in one process), to document the actual empirical finding
and the now-extended scope.

Also fixes a pre-existing clippy collapsible-match lint failure in
node_service/mod.rs (unrelated to the libsql-ffi race, blocking `bun run
quality:fix` on this branch) — mutation-tested to confirm the refactor
preserves the test's assertion coverage.

Co-Authored-By: Claude <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Reviewed (adversarial pass): independently confirmed cargo tree -i libsql-ffi matches exactly the 4 crates covered (nothing missed, nothing extra swept in); the 1-in-100 reproduction and the decision to extend broadly rather than narrow to nodespace-agent alone is sound given the failure mode is process-global corruption, not a benign local assertion. Wiring verified live (traced the actual pre-push gate path, no CI job exists for this repo's Rust tests — husky→test-gate.ts→test:all→rust:test is the only enforcement, and this is genuinely in that path). One real, non-blocking cost worth naming: this serializes each crate's entire lib/bin/test target, not just SqliteStore-touching tests, so every local push touching these crates is now measurably slower — same coarse grain as the existing rust:test:core, and there's no CI to absorb it elsewhere. Worth a future follow-up if it becomes a felt friction point, not blocking now. Merging.

@mstomar125
mstomar125 merged commit 9065eff into main Sep 9, 2026
@mstomar125
mstomar125 deleted the issue-2516-serialize-sqlite-ffi-tests branch September 9, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant