diff --git a/src/app_network.cpp b/src/app_network.cpp index c2ad22f..4e68bce 100644 --- a/src/app_network.cpp +++ b/src/app_network.cpp @@ -2765,6 +2765,7 @@ void App::resetChatSession() chat_db_.lock(); chat_identity_provisioned_ = false; chat_identity_fetch_in_flight_ = false; + chat_fast_scan_in_flight_ = false; // a stale in-flight fast-scan is dropped by its session guard chat_identity_unavailable_ = false; // Invalidate any in-flight identity fetch that captured the PREVIOUS wallet's secret, so its // completion callback can't provision that secret under the new wallet. @@ -3178,7 +3179,8 @@ void App::fastScanChatMemos() if (addr.empty()) return; chat_fast_scan_in_flight_ = true; - worker_->post([this, addr]() -> rpc::RPCWorker::MainCb { + const int scanGen = chat_session_generation_; // guard: drop the result if the wallet switches/locks + worker_->post([this, addr, scanGen]() -> rpc::RPCWorker::MainCb { std::vector metadata; try { rpc::RPCClient::TraceScope trace("HushChat / 0-conf fast scan"); @@ -3208,7 +3210,11 @@ void App::fastScanChatMemos() } } } catch (const std::exception&) {} - return [this, metadata = std::move(metadata)]() mutable { + return [this, scanGen, metadata = std::move(metadata)]() mutable { + // The wallet was switched/locked between post and now — this metadata belongs to the previous + // session. resetChatSession already reset the in-flight flag, so just drop; clearing it here + // would clobber a new session's own in-flight scan (mirrors the broadcast/identity guards). + if (scanGen != chat_session_generation_) return; chat_fast_scan_in_flight_ = false; if (metadata.empty()) return; // Skip HIDDEN conversations — the mempool fast path deliberately doesn't surface them; they