From 5f86b10f057c8af7e53b8b503d8845f2254b1df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Thu, 3 Sep 2026 19:58:52 +0200 Subject: [PATCH] Fix unseed error paths and seeded repo filter Unseeding only deletes the policy row, so a node defaulting to `allow` keeps seeding: `unseed` now reports `DefaultPolicySeeds` instead of claiming success, and both callers refresh in a `finally` so a failed `clean` no longer leaves a stale row behind. --- crates/radicle-tauri/src/commands/repo.rs | 3 +- crates/radicle-types/src/error.rs | 7 ++ crates/radicle-types/src/traits/repo.rs | 15 ++-- crates/test-http-api/src/api.rs | 7 +- src/components/SidebarRepoList.svelte | 88 +++++++++++++++-------- src/lib/invoke.ts | 2 +- 6 files changed, 81 insertions(+), 41 deletions(-) diff --git a/crates/radicle-tauri/src/commands/repo.rs b/crates/radicle-tauri/src/commands/repo.rs index 4e62ce92a..c1a9af2f8 100644 --- a/crates/radicle-tauri/src/commands/repo.rs +++ b/crates/radicle-tauri/src/commands/repo.rs @@ -19,8 +19,9 @@ pub async fn list_repos( #[tauri::command] pub async fn list_repos_summary( ctx: tauri::State<'_, AppState>, + show: Show, ) -> Result, Error> { - blocking(ctx, |ctx| ctx.list_repos_summary()).await + blocking(ctx, move |ctx| ctx.list_repos_summary(show)).await } #[tauri::command] diff --git a/crates/radicle-types/src/error.rs b/crates/radicle-types/src/error.rs index ca38f2f96..a1fb11903 100644 --- a/crates/radicle-types/src/error.rs +++ b/crates/radicle-types/src/error.rs @@ -39,6 +39,13 @@ pub enum Error { #[error("you have already reviewed this revision")] ReviewExists, + /// Unseeding had no effect because the node seeds everything by default. + #[error( + "this node's default seeding policy is 'allow', so it keeps seeding this repository; \ + change `node.seedingPolicy` in your Radicle config to stop" + )] + DefaultPolicySeeds, + /// Init Error error. #[error(transparent)] InitError(#[from] radicle::rad::InitError), diff --git a/crates/radicle-types/src/traits/repo.rs b/crates/radicle-types/src/traits/repo.rs index 9479529fd..7dad0582e 100644 --- a/crates/radicle-types/src/traits/repo.rs +++ b/crates/radicle-types/src/traits/repo.rs @@ -386,7 +386,7 @@ pub trait Repo: Profile { Ok::<_, Error>(entries) } - fn list_repos_summary(&self) -> Result, Error> { + fn list_repos_summary(&self, show: Show) -> Result, Error> { let profile = self.profile(); let storage = &profile.storage; let policies = profile.policies()?; @@ -394,11 +394,7 @@ pub trait Repo: Profile { let mut entries = Vec::new(); for RepositoryInfo { rid, doc, .. } in repos { - // `rad unseed` only drops the seeding policy; the repository stays - // in storage. This list backs the sidebar, which is about what you - // seed, so an unseeded repo has to leave it even though its files - // are still on disk — otherwise unseeding looks like it did nothing. - if !policies.is_seeding(&rid)? { + if !policies.is_seeding(&rid)? && show == Show::Seeded { continue; } @@ -927,6 +923,13 @@ pub trait Repo: Profile { profile.unseed(rid, &mut node)?; + // Unseeding deletes the repository's policy row, so a node whose + // default seeding policy is `allow` carries on seeding it. Saying so is + // better than reporting success and leaving the repo where it was. + if profile.policies()?.is_seeding(&rid)? { + return Err(Error::DefaultPolicySeeds); + } + Ok(()) } diff --git a/crates/test-http-api/src/api.rs b/crates/test-http-api/src/api.rs index 283990a45..d6d15989a 100644 --- a/crates/test-http-api/src/api.rs +++ b/crates/test-http-api/src/api.rs @@ -165,8 +165,11 @@ async fn repo_count_handler(State(ctx): State) -> impl IntoResponse { Ok::<_, Error>(Json(repos)) } -async fn list_repos_summary_handler(State(ctx): State) -> impl IntoResponse { - let repos = ctx.list_repos_summary()?; +async fn list_repos_summary_handler( + State(ctx): State, + Json(Options { show }): Json, +) -> impl IntoResponse { + let repos = ctx.list_repos_summary(show)?; Ok::<_, Error>(Json(repos)) } diff --git a/src/components/SidebarRepoList.svelte b/src/components/SidebarRepoList.svelte index 135d35da2..53e20505a 100644 --- a/src/components/SidebarRepoList.svelte +++ b/src/components/SidebarRepoList.svelte @@ -40,6 +40,7 @@ import type { Config } from "@bindings/config/Config"; import type { RepoInfo } from "@bindings/repo/RepoInfo"; import type { RepoSummary } from "@bindings/repo/RepoSummary"; + import type { CrossfadeParams } from "svelte/transition"; import { onMount } from "svelte"; import { flip } from "svelte/animate"; @@ -209,13 +210,21 @@ duration: ANIMATION_DURATION_MS, // A row leaving with no counterpart is either the repo being unseeded, or a // filter/refresh that should not animate at all. - fallback: (node, params) => - (params as { key?: string }).key !== undefined && - (params as { key?: string }).key === unseedingRid + fallback: (node: Element, params: CrossfadeParams & { key?: string }) => + params.key !== undefined && params.key === unseedingRid ? fadeCollapse(node, ANIMATION_DURATION_MS) : { duration: 0 }, }); + // Normally cleared when the row finishes its outro; the timer is only a + // backstop for a row that leaves without ever running one, which would + // otherwise leave every later list change animating. + function clearUnseeding(rid: string) { + if (unseedingRid === rid) { + unseedingRid = undefined; + } + } + // Fades the row out while collapsing the space it occupies, so the rows below // rise into the gap as it closes. `animate:flip` cannot do this on its own: a // row mid-out-transition still takes up its full height, so flip measures no @@ -271,20 +280,34 @@ ]); } + // Ordered like the CLI: drop the seeding policy first, then let storage prune + // what it can. `clean` keeps the local node's and the delegates' refs, so a + // repo we have published to survives in a reduced form. Throws, so each + // caller decides how loud a failure is. + async function stopSeeding(rid: string, clean = false) { + await invoke("unseed", { rid }); + if (clean) { + await invoke("clean", { rid }); + } + } + + // The pending-fetch list's trash button, which stays quiet on failure. The + // list still refreshes: dropping the policy row is what removes a repo from + // it, and that happens before anything can throw. async function unseed(rid: string) { try { - await invoke("unseed", { rid }); - await reloadRepos(); + await stopSeeding(rid); } catch (error) { console.error("Unseed failed", error); + } finally { + await reloadRepos().catch(error => + console.error("Reloading repos failed", error), + ); } } // Unseeding drops the seeding policy and removes the repo from this list, so // it goes through a confirmation rather than firing straight off a menu item. - // It does not reuse `unseed` above, which swallows its error to keep the - // pending-fetch list's trash button quiet — here the error has to reach the - // dialog. function confirmUnseed(repo: RepoSummary) { show({ component: ConfirmUnseed, @@ -292,29 +315,30 @@ name: repo.name, rid: repo.rid, async confirm(clean: boolean) { - await invoke("unseed", { rid: repo.rid }); - // Ordered like the CLI: drop the seeding policy first, then let - // storage prune what it can. `clean` keeps the local node's and the - // delegates' refs, so a repo we have published to survives in a - // reduced form. - if (clean) { - await invoke("clean", { rid: repo.rid }); - } - // Marked before the list refreshes so the row that disappears fades - // out instead of blinking away, and the rows below glide up into the - // gap. Cleared once both halves have run. + // Marked before the commands run so the row that disappears fades out + // instead of blinking away, and the rows below glide up into the gap. unseedingRid = repo.rid; try { - await reloadRepos(); + await stopSeeding(repo.rid, clean); } finally { - setTimeout(() => { - unseedingRid = undefined; - }, ANIMATION_DURATION_MS * 2); - } - // The repo the user is looking at just went away; its route would - // resolve to nothing. - if (activeRid() === repo.rid) { - await router.push({ resource: "inbox" }); + // `unseed` goes first, so it may well have succeeded even when + // `clean` threw. Refresh either way rather than leave a row behind + // for a repo that is no longer seeded. + await reloadRepos().catch(error => + console.error("Reloading repos failed", error), + ); + setTimeout( + () => clearUnseeding(repo.rid), + ANIMATION_DURATION_MS * 2, + ); + // The repo the user is looking at may have just gone away; its + // route would resolve to nothing. + if ( + activeRid() === repo.rid && + !repos.some(r => r.rid === repo.rid) + ) { + await router.push({ resource: "inbox" }); + } } }, }, @@ -714,7 +738,8 @@ {...{ [DRAG_RID_ATTRIBUTE]: repo.rid }} animate:flip={{ duration: animationDuration }} in:receive={{ key: repo.rid, duration: animationDuration }} - out:send={{ key: repo.rid, duration: animationDuration }}> + out:send={{ key: repo.rid, duration: animationDuration }} + onoutroend={() => clearUnseeding(repo.rid)}> {@render repoRowInner(repo, true)} {/each} @@ -783,7 +808,7 @@ - All Repos + Seeded Repos {#if !sidebarCollapsed.value && unpinnedReposCount > 1} + out:send={{ key: repo.rid, duration: animationDuration }} + onoutroend={() => clearUnseeding(repo.rid)}> {@render repoRowInner(repo, false)} {/each} diff --git a/src/lib/invoke.ts b/src/lib/invoke.ts index bc40819ab..279eaeee7 100644 --- a/src/lib/invoke.ts +++ b/src/lib/invoke.ts @@ -224,7 +224,7 @@ export const cachedGetCommitDiff = cached( * unseeding) go through invalidateReposSummary(). */ export const cachedListReposSummary = cached( - () => invoke("list_repos_summary"), + () => invoke("list_repos_summary", { show: "seeded" }), () => "list_repos_summary", { max: 1, ttl: 30_000 }, );