Skip to content

fix(test): eliminate memory::ops flakes under cargo-llvm-cov (#2722)#2737

Merged
graycyrus merged 1 commit into
tinyhumansai:mainfrom
M3gA-Mind:fix/memory-ops-test-isolation
May 27, 2026
Merged

fix(test): eliminate memory::ops flakes under cargo-llvm-cov (#2722)#2737
graycyrus merged 1 commit into
tinyhumansai:mainfrom
M3gA-Mind:fix/memory-ops-test-isolation

Conversation

@M3gA-Mind
Copy link
Copy Markdown
Contributor

@M3gA-Mind M3gA-Mind commented May 27, 2026

Summary

  • Sets busy_timeout(15s) on the UnifiedMemory SQLite connection in init.rs, immediately after Connection::open(), before any execute_batch() calls. Without this, concurrent writes from background ingestion workers hit SQLITE_BUSY immediately (no retry) under cargo-llvm-cov's slower execution — causing the tool_memory .expect("put normal") panic.
  • Adds IngestionState::reset_for_test() (#[cfg(test)]) that zeroes queue_depth and clears running state while preserving completion history, then calls it at the start of memory_ingestion_status_reflects_initialized_client_snapshot to replace the delta-baseline workaround from fix(test): make memory ingestion-status test residue-robust (queue_depth delta) #2721 with a structural fix.
  • Adds three regression tests: connection_has_busy_timeout_set, reset_for_test_clears_queue_depth_and_running_state, reset_for_test_preserves_completion_history.

Root cause

Two independent causes behind the flakes seen in #2717 CI runs:

  1. SQLITE_BUSY on writesUnifiedMemory had no busy_timeout set, so any concurrent write attempt (background ingestion worker + test write) failed immediately instead of retrying. chunks/store.rs already uses 15 s; unified/init.rs now does too.

  2. queue_depth residueIngestionState.queue_depth is an AtomicUsize on the process-global MemoryClient singleton, shared across all memory::ops tests. Background ingestion workers started by earlier tests outlive the GLOBAL_MEMORY_TEST_LOCK body, leaving residue that inflated absolute queue_depth assertions.

Test plan

  • cargo test -p openhuman -- memory::ingestion::state::tests::reset_for_test — 2 passed
  • cargo test -p openhuman -- memory_store::unified::init::tests::connection_has_busy_timeout — 1 passed
  • cargo test -p openhuman -- memory::ops::sync::tests — 6 passed
  • cargo test -p openhuman -- memory::ops::tool_memory::tests — 2 passed
  • cargo fmt --all -- --check — clean
  • cargo check -p openhuman — no new errors

Closes #2722

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced database connection stability by implementing automatic timeout configurations to prevent lock contention.
  • Tests

    • Improved test isolation mechanisms to prevent state carryover between test runs.
    • Added verification tests for database configuration settings.
  • Documentation

    • Updated development guidelines for testing practices and database stability.

Review Change Stack

Two root causes:
1. UnifiedMemory had no busy_timeout — concurrent writes from background
   ingestion workers hit SQLITE_BUSY immediately (no retry), causing
   the tool_memory .expect("put normal") panic under llvm-cov's slower
   execution. Fix: set busy_timeout(15s) on Connection::open, matching
   the chunks/store.rs pattern.
2. IngestionState.queue_depth AtomicUsize was never reset between tests
   — residue from prior tests' background workers inflated queue_depth
   assertions. Fix: add reset_for_test() (cfg(test)) that zeroes
   queue_depth and clears running state while preserving completion
   history; call it at the start of the status snapshot test.

Both changes are covered by regression tests.

Closes tinyhumansai#2722
@M3gA-Mind M3gA-Mind requested a review from a team May 27, 2026 08:02
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ade8a823-2c13-47c8-910f-fd5490ffd964

📥 Commits

Reviewing files that changed from the base of the PR and between 6efed78 and a4ecbf1.

📒 Files selected for processing (4)
  • .claude/memory.md
  • src/openhuman/memory/ingestion/state.rs
  • src/openhuman/memory/ops/sync.rs
  • src/openhuman/memory_store/unified/init.rs

📝 Walkthrough

Walkthrough

This PR fixes intermittent test flakiness in memory::ops tests under cargo-llvm-cov by addressing two causes of cross-test residue: accumulated IngestionState.queue_depth and SQLite write contention. It introduces a test-only reset helper, applies it to an existing test, configures SQLite busy_timeout, and updates documentation.

Changes

Test flakiness fixes for memory::ops

Layer / File(s) Summary
IngestionState test reset mechanism
src/openhuman/memory/ingestion/state.rs, .claude/memory.md
IngestionState::reset_for_test() zeros queue_depth and clears in-flight state while preserving completion history, with two new unit tests validating selective reset behavior. Documentation clarifies that GLOBAL_MEMORY_TEST_LOCK does not cover background ingestion, and instructs tests to call reset_for_test() at start.
Apply reset to memory ops sync test
src/openhuman/memory/ops/sync.rs
The memory_ingestion_status_reflects_initialized_client_snapshot test now resets global ingestion state at setup via reset_for_test() and expects an absolute queue depth of 1 instead of computing a baseline delta.
SQLite busy_timeout configuration and verification
src/openhuman/memory_store/unified/init.rs, .claude/memory.md
UnifiedMemory initialization now sets 15-second busy_timeout on the SQLite connection immediately after opening, with error context propagation. A new unit test verifies the pragma is set. Documentation establishes the rule that all new SQLite connections must set busy_timeout = 15s to mitigate concurrent ingestion/test write contention.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • tinyhumansai/openhuman#2721: Both PRs modify the same memory_ingestion_status_reflects_initialized_client_snapshot test to handle process-global IngestionState.queue_depth residue across tests (one via baseline+delta, the other via state.reset_for_test()).
  • tinyhumansai/openhuman#2649: Both PRs modify test setup in src/openhuman/memory/ops/sync.rs to avoid cross-test residue in the shared global memory client, with main PR using state.reset_for_test() while prior PR adds GLOBAL_MEMORY_TEST_LOCK serialization.

Suggested labels

rust-core, memory

Suggested reviewers

  • graycyrus
  • senamakel

Poem

🐰 A queue that grows without a reset,
And SQLite locks that fail the test—
We wipe the slate, set timeouts long,
Now flaky tests sing steady songs. 🎵

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly summarizes the main change: fixing test flakiness in memory::ops under cargo-llvm-cov coverage runs, which is the primary objective across all modified files.
Linked Issues check ✅ Passed All coding requirements from issue #2722 are met: SQLite busy_timeout is set (15s) to prevent SQLITE_BUSY failures, IngestionState::reset_for_test() zeros queue_depth and clears running state while preserving history, and three regression tests are added covering the fixes.
Out of Scope Changes check ✅ Passed All changes directly address the stated objectives: busy_timeout configuration, reset_for_test helper, test isolation fix, and regression tests. The .claude/memory.md update documents the fixes. No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure. memory Memory store, memory tree, recall, summarization, and embeddings in src/openhuman/memory/. labels May 27, 2026
@M3gA-Mind
Copy link
Copy Markdown
Contributor Author

Code Review — PR #2737

fix(test): eliminate memory::ops flakes under cargo-llvm-cov (#2722)

Overview

Fixes two independent root causes behind intermittent memory::ops test failures under cargo-llvm-cov: (1) missing busy_timeout on the UnifiedMemory SQLite connection causing immediate SQLITE_BUSY under concurrent writes, and (2) queue_depth residue left by background ingestion workers outliving the GLOBAL_MEMORY_TEST_LOCK scope.

What Passed ✅

  • Structural fixes, not workarounds — delta-baseline approach from fix(test): make memory ingestion-status test residue-robust (queue_depth delta) #2721 correctly replaced with explicit reset_for_test()
  • reset_for_test() is #[cfg(test)]-gated — cannot ship in production builds ✅
  • busy_timeout set immediately after Connection::open() and before execute_batch() — correct placement ✅
  • .claude/memory.md documents the pattern for future contributors — excellent knowledge capture ✅
  • connection_has_busy_timeout_set pins the SQLite PRAGMA value as a regression test ✅
  • Three new regression tests cover both fix paths and their invariants ✅
  • All CI checks green ✅

Recommendations

  • Minor: connection_has_busy_timeout_set asserts timeout > 0 — consider asserting timeout >= 15_000 (ms) to pin the minimum threshold and catch a future accidental reduction.
  • Note (pre-existing): Background workers that outlive a reset_for_test() call may later invoke dequeue() on a zeroed AtomicUsize, causing wrapping to usize::MAX. This is pre-existing and outside scope, but worth documenting in the reset_for_test() doc comment.

Verdict: Approve ✅ — Clean, well-motivated fix with appropriate regression tests and documentation.

@M3gA-Mind
Copy link
Copy Markdown
Contributor Author

PR Review — fix(test): eliminate memory::ops flakes under cargo-llvm-cov (#2722)

Status: ✅ All CI checks passing.

What this PR does

Fixes two independent root causes of memory::ops test flakiness under cargo-llvm-cov:

  1. SQLITE_BUSY on writesUnifiedMemory had no busy_timeout set, so concurrent write attempts (background ingestion worker + test write) failed immediately. busy_timeout(15s) is now set immediately after Connection::open(), before any execute_batch(), mirroring chunks/store.rs.
  2. queue_depth residueIngestionState.queue_depth is a process-global AtomicUsize shared across all memory::ops tests. Background ingestion workers outlive the GLOBAL_MEMORY_TEST_LOCK body, leaving residue. reset_for_test() (test-only) zeroes queue depth and clears running state while preserving completion history.

Code quality

  • busy_timeout(15s) placed before execute_batch() — optimal, mirrors the SQLITE_BUSY_TIMEOUT pattern in chunks/store.rs
  • reset_for_test() is #[cfg(test)]-gated — not callable in production code
  • SeqCst ordering on the atomic store is consistent with surrounding load/store calls
  • ✅ Replacing baseline_depth + 1 delta assertion with reset_for_test() + absolute 1 is a cleaner invariant — tests the real postcondition, not the delta
  • connection_has_busy_timeout_set test verifies via PRAGMA busy_timeout — catches future regressions if the timeout is accidentally removed
  • .claude/memory.md updates document the busy_timeout pattern and reset_for_test() usage for future contributors
  • ✅ Root cause documented clearly in PR body; easy to validate

No issues found

The change is minimal (86 additions, 7 deletions across 4 files), correct, and well-tested. Recommend merge.

Copy link
Copy Markdown
Contributor

@graycyrus graycyrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks great — solid fix for the cargo-llvm-cov flakes. The two-pronged approach (SQLite busy-timeout + global state reset) is clean, well-tested, and matches existing patterns in the codebase.

One CI check is failing though: test / Rust Core Tests (Windows — secrets ACL). This looks unrelated to your changes (you're touching memory/ingestion, not secrets), so it might be a transient Windows flake. Either way, once CI is 100% green, i'll approve this. Can you give it a bump or check if that test is flaky on main?

@graycyrus graycyrus merged commit 035f344 into tinyhumansai:main May 27, 2026
34 of 41 checks passed
graycyrus added a commit to graycyrus/openhuman that referenced this pull request May 27, 2026
Merge upstream/main to pick up fix(test): eliminate memory::ops flakes
under cargo-llvm-cov (tinyhumansai#2722/tinyhumansai#2737) which fixes the pre-existing
execute_success_path_persists_rule_in_isolated_workspace test failure.

Also add devWorkflow i18n keys to the new Polish (pl) locale chunk
added upstream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

memory Memory store, memory tree, recall, summarization, and embeddings in src/openhuman/memory/. rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory::ops tests flake under cargo-llvm-cov from shared global client (queue residue + SQLite write contention)

2 participants