From 49a6c109b76c57238e2515bb43e0e3deddbd81ba Mon Sep 17 00:00:00 2001 From: Peterino Date: Thu, 26 Nov 2026 20:53:08 -0700 Subject: [PATCH] Handle large working copies in the desktop client A working copy with 44,702 new files produced an 8.3 MB change list, over the 1 MiB line limit on both sides of the service socket, so the GUI dropped the connection and reconnected in a loop. - Raise the limit to 256 MiB from the service and 64 MiB to it, and show an oversized message as an error instead of reconnecting. - Draw only the visible rows of the CHANGES list, and build the lock list only when LOCK is pressed rather than every frame. - Match the chosen paths in submit with a set. - Treat sync on a repository with no revisions yet as up to date, rather than surfacing Lore's "No remote configured". --- desktop/gui/src/explorer.cpp | 24 ++++++++++++++++++------ desktop/gui/src/main.cpp | 2 ++ desktop/gui/src/service_client.cpp | 18 +++++++++++++----- desktop/gui/src/service_client.hpp | 2 ++ desktop/service/src/server.rs | 16 ++++++++++++---- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/desktop/gui/src/explorer.cpp b/desktop/gui/src/explorer.cpp index f70d488..dc678fe 100644 --- a/desktop/gui/src/explorer.cpp +++ b/desktop/gui/src/explorer.cpp @@ -906,14 +906,16 @@ void Explorer::DrawChanges(const model::Workspace &ws, model::Repo &repo, Explor host.LoadChanges(); ImGui::SameLine(0, 12); // Files someone else has locked stay out of the submit whatever is chosen. + // Counted every frame over what may be tens of thousands of changes: no copies here. int checked = 0, blocked = 0; - std::vector to_lock; + bool lockable = false; + auto can_lock = [](const model::Change &c) { return c.lock.empty() && c.action != model::Action::Delete; }; + const bool none_unchecked = repo.unchecked.empty(); for (const auto &c : repo.changes) { - bool on = !repo.unchecked.count(c.path) && !c.Blocked(); + bool on = !c.Blocked() && (none_unchecked || !repo.unchecked.count(c.path)); checked += on; blocked += c.Blocked(); - if (on && c.lock.empty() && c.action != model::Action::Delete) - to_lock.push_back(c.path); + lockable = lockable || (on && can_lock(c)); } if (theme::Button("ALL", !repo.changes.empty())) repo.unchecked.clear(); @@ -922,8 +924,13 @@ void Explorer::DrawChanges(const model::Workspace &ws, model::Repo &repo, Explor for (const auto &c : repo.changes) repo.unchecked.insert(c.path); ImGui::SameLine(0, 12); - if (theme::Button("LOCK", connected && !busy && ws.signed_in && !to_lock.empty())) + if (theme::Button("LOCK", connected && !busy && ws.signed_in && lockable)) { + std::vector to_lock; + for (const auto &c : repo.changes) + if (!c.Blocked() && !repo.unchecked.count(c.path) && can_lock(c)) + to_lock.push_back(c.path); host.Lock(to_lock); + } if (ImGui::IsItemHovered()) ImGui::SetTooltip("lock the chosen files nobody holds yet"); ImGui::SameLine(0, 16); @@ -943,7 +950,12 @@ void Explorer::DrawChanges(const model::Workspace &ws, model::Repo &repo, Explor Note("scanning"); else if (repo.changes.empty()) Note(ws.ahead ? "nothing changed here; unpushed revisions remain" : "nothing changed here"); - for (const auto &c : repo.changes) { + // Only the rows in view are drawn: a first import lists every file in the tree. + ImGuiListClipper clipper; + clipper.Begin(int(repo.changes.size()), kRowH); + while (clipper.Step()) + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i) { + const model::Change &c = repo.changes[size_t(i)]; ImGui::PushID(c.path.c_str()); bool on = !repo.unchecked.count(c.path) && !c.Blocked(); if (theme::Row("change", false, kRowH) && !c.Blocked()) { diff --git a/desktop/gui/src/main.cpp b/desktop/gui/src/main.cpp index d5ab98d..c741602 100644 --- a/desktop/gui/src/main.cpp +++ b/desktop/gui/src/main.cpp @@ -861,6 +861,8 @@ void App::HandleIncoming() { greeted_ = false; break; case ServiceClient::Incoming::Kind::Disconnected: + if (incoming.detail != "connection closed") + error_ = "lost the service: " + incoming.detail; greeted_ = false; have_status_ = false; pending_.clear(); diff --git a/desktop/gui/src/service_client.cpp b/desktop/gui/src/service_client.cpp index 2b148fa..ee48074 100644 --- a/desktop/gui/src/service_client.cpp +++ b/desktop/gui/src/service_client.cpp @@ -22,7 +22,9 @@ constexpr int kStartWaitMs = 5000; // How often to retry while unavailable, and to try starting it again. constexpr int kRetryMs = 2000; constexpr int kRespawnMs = 15000; -constexpr size_t kMaxLine = 1u << 20; +// The longest message taken from the service. A workspace's change list runs to about 190 +// bytes a file, so this holds over a million changed files. +constexpr size_t kMaxLine = size_t(256) << 20; int64_t NowMs() { using namespace std::chrono; @@ -139,6 +141,7 @@ void ServiceClient::Run() { if (Connect()) { SetState(State::Connected); Push({Incoming::Kind::Connected, {}, {}}); + closed_because_.clear(); Serve(); Close(); if (stop_) @@ -147,8 +150,9 @@ void ServiceClient::Run() { std::lock_guard lock(mutex_); outgoing_.clear(); } - SetState(State::Connecting, "connection closed"); - Push({Incoming::Kind::Disconnected, {}, "connection closed"}); + std::string why = closed_because_.empty() ? "connection closed" : closed_because_; + SetState(State::Connecting, why); + Push({Incoming::Kind::Disconnected, {}, why}); if (!SleepUnlessStopped(300)) break; continue; @@ -275,8 +279,10 @@ void ServiceClient::Serve() { Push({Incoming::Kind::Message, std::move(message), {}}); buffer.erase(0, newline + 1); } - if (buffer.size() > kMaxLine) + if (buffer.size() > kMaxLine) { + closed_because_ = "a message from the service was over " + std::to_string(kMaxLine >> 20) + " MiB"; break; + } } else if (which == WAIT_OBJECT_0 + 1) { std::deque lines; { @@ -404,8 +410,10 @@ void ServiceClient::Serve() { Push({Incoming::Kind::Message, std::move(message), {}}); buffer.erase(0, newline + 1); } - if (buffer.size() > kMaxLine) + if (buffer.size() > kMaxLine) { + closed_because_ = "a message from the service was over " + std::to_string(kMaxLine >> 20) + " MiB"; return; + } } } } diff --git a/desktop/gui/src/service_client.hpp b/desktop/gui/src/service_client.hpp index be7fd57..4c4acdf 100644 --- a/desktop/gui/src/service_client.hpp +++ b/desktop/gui/src/service_client.hpp @@ -81,6 +81,8 @@ class ServiceClient { std::atomic restart_requested_{false}; mutable std::mutex mutex_; + // Set by the reading thread when it gives up on the connection, for the disconnect. + std::string closed_because_; std::string detail_; std::deque outgoing_; std::vector incoming_; diff --git a/desktop/service/src/server.rs b/desktop/service/src/server.rs index 7043a06..dd0bb70 100644 --- a/desktop/service/src/server.rs +++ b/desktop/service/src/server.rs @@ -77,8 +77,9 @@ mod watch; use watch::Watches; -/// The longest message accepted from a frontend. -const MAX_LINE: u64 = 1 << 20; +/// The longest message accepted from a frontend. SUBMIT names every chosen file, about 60 bytes +/// each, so this takes over a million. +const MAX_LINE: u64 = 64 << 20; /// How many branches `history` reads, and revisions per branch by default. const MAX_BRANCHES: usize = 12; const DEFAULT_HISTORY: u32 = 50; @@ -680,7 +681,13 @@ impl Service { match synced { Ok(()) => Ok(Ok(outcome)), Err(error) if lore::is_overlap(&error) => Ok(Err(lore::describe("sync", &error))), - Err(error) => Err(lore_failure("sync", error)), + // Lore refuses to sync a branch that has no revision here or on the remote, as + // a new repository's has until its first push, with "No remote configured". + // There is nothing to sync, which is not an error. + Err(error) => match lore::status(lore, &path, false) { + Ok(position) if position.status.local_number == 0 && position.status.remote_number == 0 => Ok(Ok(None)), + _ => Err(lore_failure("sync", error)), + }, } }) .await; @@ -727,10 +734,11 @@ impl Service { if !paths.is_empty() { // Leave staged only what was chosen. let position = lore::status(lore, &path, true).map_err(|error| lore_failure("status", error))?; + let chosen: std::collections::HashSet<&String> = paths.iter().collect(); let unwanted: Vec = position .files .iter() - .filter(|file| file.staged && !paths.contains(&file.path)) + .filter(|file| file.staged && !chosen.contains(&file.path)) .map(|file| file.path.clone()) .collect(); if !unwanted.is_empty() {