fix: stop stale tombstones from deleting re-visited sites#7
Merged
Conversation
When a user removed a site, then re-visited it via visit_site (or re-created it via create_new_site/import_site_key), the site would briefly appear and then vanish before the user could see it. Root cause: the KnownSites handler applied tombstones unconditionally, even legacy-delegate tombstones that had already been superseded by the current delegate's authoritative response, and even tombstones whose prefix was currently live in SITES due to an explicit re-add. Fix: extract the tombstone-application decision into a pure function filter_applicable_tombstones with two rules: 1. If the response is from a legacy delegate AND the current delegate has already responded (CURRENT_SITES_LOADED), drop the legacy tombstone. The current delegate is authoritative for the removal set. 2. If the tombstone's prefix is currently live in SITES (user just re-added), drop it regardless of source. Live intent beats a stale removal record. This also closes the race where a save_known_sites write hasn't landed yet when an already-in-flight load_known_sites response arrives. Includes 6 unit tests covering the primary bug and its edge cases. [AI-assisted - Claude]
Adds two unit tests for filter_applicable_tombstones requested by the PR reviews: - empty_tombstones_yields_empty_result: sanity case for every flag combination, locks down the iterator path against future refactors. - applies_current_delegate_tombstone_after_current_loaded: the production steady-state combination (is_legacy=false, current_sites_loaded=true, prefix not live) was not previously exercised by any test, even though it's the common case. Also documents the two new tombstone-application rules in AGENTS.md under "Known-Sites Tombstone Convention" so the next person touching the KnownSites response handler preserves them. [AI-assisted - Claude]
Contributor
Author
Review feedback addressed (all 5 reviewers + Codex)Thanks for the reviews. Pushed 411b35e with the changes below. Addressed
Acknowledged but not applicable / out of scope
[AI-assisted - Claude] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a user removed a site and then tried to re-visit it (same session or after a refresh), the site would briefly appear in the sidebar and then vanish before the user could read it. Reported on Matrix by Ivvor:
Root cause
The `KnownSites` response handler in `ui/src/freenet_api/delegate.rs` applied tombstone records unconditionally:
The existing `CURRENT_SITES_LOADED` gate only protected legacy real records, not legacy tombstones.
Approach
Extract the tombstone-application decision into a pure function `filter_applicable_tombstones` with two rules:
The pure-function split makes the logic unit-testable without mocking the delegate runtime or Dioxus signals. The call site now builds a live-prefix set once and delegates the filter decision.
Testing
Six unit tests in `delegate.rs` covering:
All pass. `cargo fmt` + `cargo clippy -p delta-ui -- -D warnings` clean.
[AI-assisted - Claude]