From d90c722c7d859f098a5d945969cb5cecbbc94377 Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 1 Jan 2026 08:14:26 -0800 Subject: [PATCH] fix(android): simplify keygen join to match Electron behavior exactly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed polling fallback and simplified to match Electron's design: - If joinSession returns sessionStatus="in_progress", trigger keygen immediately - Otherwise wait for session_started gRPC event Added debug log to show sessionStatus value for troubleshooting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../presentation/viewmodel/MainViewModel.kt | 33 ++++--------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt b/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt index 94a22202..de346562 100644 --- a/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt +++ b/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt @@ -498,36 +498,15 @@ class MainViewModel @Inject constructor( _uiState.update { it.copy(isLoading = false) } - // If session is already in_progress, trigger keygen immediately (Solution B from Electron) + // Match Electron behavior exactly: + // If session is already in_progress, trigger keygen immediately + // Otherwise wait for session_started event from gRPC subscription + android.util.Log.d("MainViewModel", "Join result sessionStatus: ${joinResult.sessionStatus}") if (joinResult.sessionStatus == "in_progress") { - android.util.Log.d("MainViewModel", "Session already in_progress, triggering keygen immediately") + android.util.Log.d("MainViewModel", "Session already in_progress, triggering keygen immediately (Solution B)") startKeygenAsJoiner() } else { - // Otherwise, wait for session_started event - // But also poll session status immediately and after delays in case we missed the event - // This handles the race condition where session_started is sent before we're ready - // The last joiner triggers session_started but can't receive it themselves - viewModelScope.launch { - // Poll multiple times with short delays - for (attempt in 1..5) { - delay(500) // Check every 500ms - val joinInfo = pendingJoinKeygenInfo - if (joinInfo == null || joinInfo.sessionId != sessionInfo.sessionId) { - android.util.Log.d("MainViewModel", "Polling cancelled - keygen already started or session changed") - break - } - android.util.Log.d("MainViewModel", "Polling session status (attempt $attempt)...") - val statusResult = repository.getSessionStatus(sessionInfo.sessionId) - statusResult.onSuccess { status -> - if (status.status == "in_progress" && pendingJoinKeygenInfo != null) { - android.util.Log.d("MainViewModel", "Session is now in_progress (detected via polling attempt $attempt), triggering keygen") - startKeygenAsJoiner() - } - } - // If keygen was triggered, break out of loop - if (pendingJoinKeygenInfo == null) break - } - } + android.util.Log.d("MainViewModel", "Joined session ${sessionInfo.sessionId}, waiting for session_started event") } }, onFailure = { e ->