From 7c455d9759183354dbac47fa4f50d1aafe66f1f6 Mon Sep 17 00:00:00 2001 From: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 Date: Wed, 5 Aug 2026 01:59:07 -0400 Subject: [PATCH] fix(desktop): serialize generation-sensitive epoch tests with SCOPE_GENERATION_TEST_LOCK test_full_tail_stop_spawn_receipt_register_save and test_relay_mesh_preflight_precedes_stop both capture the scope generation via current_scope_generation() and call into restart_under_captured_epoch_for or restart_local_agent_on_config_change_for, which validate the generation under a lock. Without SCOPE_GENERATION_TEST_LOCK, a concurrent test calling next_scope_generation() can advance the counter between capture and validation, causing the epoch to return Skipped instead of the expected outcome. Both tests now hold SCOPE_GENERATION_TEST_LOCK for the duration of their execution, matching the serialization pattern used by the workspace-transition tests. Co-authored-by: Will Pfleger Signed-off-by: Will Pfleger --- .../src/commands/global_agent_config_epoch_tests.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/desktop/src-tauri/src/commands/global_agent_config_epoch_tests.rs b/desktop/src-tauri/src/commands/global_agent_config_epoch_tests.rs index 2e8365bfd..42dd8448a 100644 --- a/desktop/src-tauri/src/commands/global_agent_config_epoch_tests.rs +++ b/desktop/src-tauri/src/commands/global_agent_config_epoch_tests.rs @@ -24,6 +24,7 @@ use super::*; /// the captured definitions_dir so the spawn_fn can assert they arrive. #[tokio::test] async fn test_full_tail_stop_spawn_receipt_register_save() { + use crate::managed_agents::scope::SCOPE_GENERATION_TEST_LOCK; use crate::managed_agents::{ storage::save_managed_agents_at, BackendKind, ManagedAgentPairRuntime, ManagedAgentRecord, ManagedAgentRuntimeKey, @@ -31,6 +32,11 @@ async fn test_full_tail_stop_spawn_receipt_register_save() { use std::sync::{Arc, Mutex}; use tauri::Manager; + // Serialize generation-sensitive work across parallel tests. + let _gen_guard = SCOPE_GENERATION_TEST_LOCK + .lock() + .unwrap_or_else(|e| e.into_inner()); + let tmp = tempfile::tempdir().unwrap(); let pubkey = "bb".repeat(32); let relay_url = "wss://test.relay"; @@ -431,12 +437,18 @@ async fn test_full_tail_stop_spawn_receipt_register_save() { async fn test_relay_mesh_preflight_precedes_stop() { use super::super::restart_local_agent_on_config_change_for; use crate::commands::global_agent_config::RestartOutcome; + use crate::managed_agents::scope::SCOPE_GENERATION_TEST_LOCK; use crate::managed_agents::storage::save_managed_agents_at; use crate::managed_agents::{ BackendKind, ManagedAgentPairRuntime, ManagedAgentRecord, ManagedAgentRuntimeKey, }; use tauri::Manager; + // Serialize generation-sensitive work across parallel tests. + let _gen_guard = SCOPE_GENERATION_TEST_LOCK + .lock() + .unwrap_or_else(|e| e.into_inner()); + let tmp = tempfile::tempdir().unwrap(); let app = make_mock_app();