fix(test): pin OPENHUMAN_WORKSPACE under TEST_ENV_LOCK in memory documents tests#2712
Conversation
…ments tests The `memory::ops::documents` tests resolve the workspace from the `OPENHUMAN_WORKSPACE` env var (`memory_init` → `current_workspace_dir` → `Config::load_or_init`), but only held `GLOBAL_MEMORY_TEST_LOCK` — not the env-var lock (`TEST_ENV_LOCK`) that `config`/`update`/autonomy tests take when they set or clear `OPENHUMAN_WORKSPACE`. Under `cargo-llvm-cov` timing a sibling test could change the env between a documents test's setup and its `memory_init` call, making `memory_init` fail intermittently (e.g. `envelope_memory_handlers_report_counts_and_statuses`). `ensure_memory_client()` now returns a guard that holds `TEST_ENV_LOCK` and pins `OPENHUMAN_WORKSPACE` to the shared memory workspace for the test's duration; `ensure_shared_memory_client()` returns that workspace path so the env var and the bound client agree. Lock order is `GLOBAL_MEMORY_TEST_LOCK` → `TEST_ENV_LOCK` (no path takes the reverse), so there is no deadlock. `documents` is the only `memory::ops` test module that reads the workspace from the env, so the change is scoped there. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR updates test infrastructure for shared-memory RPC tests to prevent race conditions on the ChangesShared-memory RPC test isolation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Summary
Rust Core Coverage (cargo-llvm-cov)failure onmemory::ops::documents::tests::envelope_memory_handlers_report_counts_and_statuses(a9637 passed; 1 failedflake that recurs under coverage timing).documentstest helper now pinsOPENHUMAN_WORKSPACEunderTEST_ENV_LOCKfor the test's duration, so sibling tests can't change the env var mid-run.#[cfg(test)]/ test-support).Problem
memory::ops::documentstests resolve the workspace from theOPENHUMAN_WORKSPACEenv var (memory_init→current_workspace_dir→Config::load_or_init), but they only heldGLOBAL_MEMORY_TEST_LOCK— notTEST_ENV_LOCK, the lock thatconfig::ops/update::ops/ autonomy-settings tests take when theyset_var/remove_varOPENHUMAN_WORKSPACE. Undercargo-llvm-cov's instrumented timing, a sibling test can change the env between a documents test's setup and itsmemory_initcall, somemory_initresolves a stale/removed workspace and fails intermittently.documentsis the onlymemory::opsmodule that reads the workspace from the env (kv_graph/sync/tool_memorydon't), so they're unaffected.Solution
ensure_memory_client()now returns aWorkspaceEnvGuardthat holdsTEST_ENV_LOCKand pinsOPENHUMAN_WORKSPACEto the shared memory workspace for the test's duration (restoring the prior value on drop). The two documents tests already capture it aslet _env = ensure_memory_client();.ensure_shared_memory_client()returns the shared workspace path so the env var and the bound client agree.GLOBAL_MEMORY_TEST_LOCK→TEST_ENV_LOCK(the test takes the memory lock first, then the guard takes the env lock); no code path takes them in the reverse order, so there is no deadlock. This mirrors the existingupdate::opstests, which takeTEST_ENV_LOCKfor the same reason.Submission Checklist
documentstests now serialize onTEST_ENV_LOCKand pass deterministically. Verified the full parallelcargo test --librun withdocumentsgreen and no deadlock.documentstests themselves.Closes #NNN— no tracked issue; this is a CI flake fix found while landing feat(approval): consolidate on ApprovalGate + persistent "Always allow" list #2706 (its coverage job recurs on this test).Impact
Rust Core Coveragedeterministic for this test; unblocks every PR that currently inherits this flake (e.g. feat(approval): consolidate on ApprovalGate + persistent "Always allow" list #2706 once rebased on top). No runtime/product code touched.Related
composio::action_tool/composio::opsmock state) observed in the same suite — out of scope here; can be a follow-up.AI Authored PR Metadata
Linear Issue
Commit & Branch
fix/documents-env-race-test-isolationd492b1baValidation Run
pnpm --filter openhuman-app format:check— N/A (noapp/changes);cargo fmt --checkcleanpnpm typecheck— no TypeScript changedcargo test --lib openhuman::memory::ops::documents::tests(2 pass); fullcargo test --librun withdocumentsgreen, no deadlockcargo fmt --checkclean;cargo check --testsclean;cargo clippy --libclean (changed files produce zero findings)Validation Blocked
command:fullcargo test --libshows pre-existing unrelated flakes (composio::*) andcargo clippy --testsshows pre-existingapprox_constantlints inrpc_log/pformat/vectors/store_testserror:unrelated to this changeimpact:none on this fix; noted as separate follow-upsBehavior Changes
Parity Contract
ensure_shared_memory_client()still binds the same shared workspace; callers that ignore the new return value are unaffected.Duplicate / Superseded PR Handling
Summary by CodeRabbit