Skip to content

fix(tests): serialize backend-env tests behind one lock (fixes flaky Rust Core Coverage) - #5267

Merged
graycyrus merged 1 commit into
tinyhumansai:mainfrom
graycyrus:fix/medulla-env-test-race
Jul 29, 2026
Merged

fix(tests): serialize backend-env tests behind one lock (fixes flaky Rust Core Coverage)#5267
graycyrus merged 1 commit into
tinyhumansai:mainfrom
graycyrus:fix/medulla-env-test-race

Conversation

@graycyrus

@graycyrus graycyrus commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Root cause: BACKEND_URL / VITE_BACKEND_URL / OPENHUMAN_MEDULLA_BASE_URL are process-global env vars mutated by tests across several modules under uncoordinated locks. Under the full-suite coverage lane (parallel test threads across modules) those mutations race and flip medulla::ops's "unconfigured" assertions — pre-existing since #5260, deterministic under Rust Core Coverage, blocking every Rust PR's coverage lane.

Investigation found this was already mostly fixed on main: d125b857f introduced api::config::backend_env_test_lock() as the crate-wide lock and routed api::config, core::cli_tests, medulla::ops, and medulla::resolve through it. integrations::client_tests and socket::ws_loop_tests only reference these vars in comments/log assertions — they never mutate them, so no change was needed.

The one remaining gap: composio::ops_tests mutates BACKEND_URL via EnvVarGuard::set in two mock-backend tests, serialized only by its own module-local TEST_ENV_LOCK — which doesn't coordinate with the crate-wide lock the other modules use, leaving the race open.

  • Route composio_get_user_profile_via_mock_returns_provider_profile and composio_sync_gmail_via_mock_stores_skill_document_and_updates_outcome through api::config::backend_env_test_lock() (in addition to their existing TEST_ENV_LOCK, kept for the other config vars those tests touch).

Unblocks the Rust Core Coverage lane for #5265 and every Rust PR.

Test plan

  • cargo fmt --all
  • GGML_NATIVE=OFF cargo test --manifest-path Cargo.toml -- medulla::ops api::config composio::ops_tests core::cli integrations::client socket::ws_loop — the 5 medulla::ops tests (incl. the 2 previously-racing not_configured.../status_reports_unconfigured...) pass, 0 failed
  • cargo clippy -p openhuman -- -D warnings — clean

…e-wide env lock

api::config::backend_env_test_lock() already unifies the BACKEND_URL /
VITE_BACKEND_URL / OPENHUMAN_MEDULLA_BASE_URL race across api::config,
core::cli_tests, and medulla::ops/resolve (tinyhumansai#5260 fallout). composio::ops_tests
was the one remaining spot mutating BACKEND_URL via EnvVarGuard under its own
module-local TEST_ENV_LOCK, which doesn't serialize against the other
modules' std::env mutations on the same process-global var — the same class
of race that broke the medulla "unconfigured" assertions under the full-suite
Rust Core Coverage lane. Route both mock-backend tests through the shared
lock as well; TEST_ENV_LOCK stays for its other config vars.
@graycyrus
graycyrus requested a review from a team July 29, 2026 17:10
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Two Composio tests now acquire a shared process-global environment lock before mutating BACKEND_URL, preventing concurrent test interference without changing production logic or public APIs.

Changes

Backend environment test synchronization

Layer / File(s) Summary
Guard BACKEND_URL mutations
src/openhuman/composio/ops_tests.rs
The user-profile and Gmail synchronization tests hold backend_env_test_lock() while using EnvVarGuard to modify BACKEND_URL.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Suggested labels: rust-core

Suggested reviewers: al629176, senamakel

Poem

I’m a rabbit with a lock in hand,
Guarding URLs across the test-land.
Two tests wait, then hop along,
No racing vars can spoil the song.
Production code stays still and bright!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: serializing backend-env tests to fix flaky Rust coverage.

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

@coderabbitai coderabbitai Bot added the rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure. label Jul 29, 2026
@greptile-apps

greptile-apps Bot commented Jul 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR closes the last remaining lock coordination gap that caused flaky Rust Core Coverage failures: two tests in composio::ops_tests mutated BACKEND_URL via EnvVarGuard while only holding the module-local TEST_ENV_LOCK, which does not coordinate with the crate-wide backend_env_test_lock used by api::config, core::cli_tests, and the medulla test modules.

  • Adds backend_env_test_lock() acquisition to composio_get_user_profile_via_mock_returns_provider_profile and composio_sync_gmail_via_mock_stores_skill_document_and_updates_outcome, keeping TEST_ENV_LOCK for the other config vars each test also touches.
  • No production code is modified; the change is entirely in test infrastructure.

Confidence Score: 5/5

Test-only change that adds a second mutex acquisition to two existing tests; no production code is touched and the lock ordering is consistent with every other caller in the codebase.

The change is minimal and targeted — two lines of lock acquisition in test code. No other caller acquires backend_env_test_lock and then TEST_ENV_LOCK, so the lock ordering cannot produce a deadlock. The crate-wide lock was already proven on the other four modules; this closes the only remaining gap.

Files Needing Attention: No files require special attention. src/openhuman/composio/ops_tests.rs is the sole changed file and the diff is straightforward lock-acquisition boilerplate.

Important Files Changed

Filename Overview
src/openhuman/composio/ops_tests.rs Adds crate-wide backend_env_test_lock() to two tests that previously mutated BACKEND_URL under only the module-local TEST_ENV_LOCK, closing the remaining race against other modules' env-mutating tests.

Sequence Diagram

sequenceDiagram
    participant T1 as composio_get_user_profile test
    participant T2 as composio_sync_gmail test
    participant T3 as medulla::ops / api::config tests

    Note over T1,T3: Before this PR - race on BACKEND_URL
    T1->>T1: acquire TEST_ENV_LOCK
    T3->>T3: acquire backend_env_test_lock
    T1--xT3: BACKEND_URL mutated concurrently - flaky assertions

    Note over T1,T3: After this PR - fully serialized
    T1->>T1: acquire TEST_ENV_LOCK
    T1->>T1: acquire backend_env_test_lock
    T1->>T1: EnvVarGuard::set(BACKEND_URL, ...)
    T1->>T1: run test body
    T1->>T1: release backend_env_test_lock
    T1->>T1: release TEST_ENV_LOCK
    T3->>T3: acquire backend_env_test_lock
    T3->>T3: mutate BACKEND_URL
    T3->>T3: run test body
    T3->>T3: release backend_env_test_lock
Loading

Reviews (1): Last reviewed commit: "fix(tests): serialize composio's BACKEND..." | Re-trigger Greptile

@graycyrus
graycyrus merged commit 0f66d38 into tinyhumansai:main Jul 29, 2026
27 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

1 participant