# Find Dominant Body Bug: Mutual SOI Issue ## Overview This documents the remaining issue with `find_dominant_body()` when two similar-mass bodies are positioned within each other's sphere of influence (SOI). **Date:** January 20, 2026 **Status:** Failing Test (Test 4 from test_plan_invalid_parent_assignment.md) **Related:** `docs/test_plan_invalid_parent_assignment.md` --- ## Test Case 4: Mutual SOI - Similar Mass Planets **Purpose:** Edge case: two Earth-like planets positioned within each other's SOI **Actual Result:** ❌ **STILL FAILS** (separate issue, not fixed by spacecraft validation) **Config:** `tests/configs/mutual_soi_close.toml` **Setup:** - PlanetA: mass = 5.972e24 kg, position = {1.496e11, 0, 0} - PlanetB: mass = 5.972e24 kg, position = {1.501e11, 0, 0} - Separation: 5e8 meters (500 million km) - Planet SOI: ~9.25e8 meters (925 million km) - **Both planets within each other's SOI** **Why This Fails:** - Both planets start with parent=0 (Sun) - Both are within each other's SOI - `find_dominant_body()` logic selects closest body within SOI - Result: PlanetA selects PlanetB as parent, PlanetB selects PlanetA as parent - Config validation passes (both are ≥ parent.radius + body.radius from Sun) **Key Assertions:** ```cpp // Both should orbit Sun (not each other) REQUIRE(sim->bodies[PLANET_A_IDX].parent_index == SUN_IDX); REQUIRE(sim->bodies[PLANET_B_IDX].parent_index == SUN_IDX); // Planets should never have each other as parents for (int parent : history.planet_a_parents) { REQUIRE(parent != PLANET_B_IDX); } for (int parent : history.planet_b_parents) { REQUIRE(parent != PLANET_A_IDX); } ``` **Expected Behavior (Option A):** - Both planets should continue orbiting Sun - Neither should become other's parent - This requires future fix to `find_dominant_body()` logic (mass hierarchy check) --- ## Future Work ### Current Status Tests 1-3 from the parent assignment test suite are now passing. Test 4 continues to fail, documenting a separate mutual SOI issue. ### Potential Fixes for Test 4 1. Add mass hierarchy check to `find_dominant_body()` 2. Prevent mutual SOI assignments for similar-mass bodies 3. Detect and reject invalid configs at load time 4. Implement proper N-body interaction or restricted 3-body solution ### Enhanced Detection - SOI overlap detection at config load time - Automatic correction of invalid parent assignments - Validation warnings for edge cases --- ## References - `src/simulation.cpp:64-107` - `find_dominant_body()` implementation - `tests/configs/mutual_soi_close.toml` - Test configuration for mutual SOI case - `tests/test_invalid_parent_assignment.cpp` - Test suite implementation