fix(storage): purge orphaned feature_set_members after the refactor (migration 017) - #167
Merged
Merged
Conversation
The #151 refactor changed a feature member's identity from a qualified "server_id/tool_name" string to the server_features.id UUID, but no migration converted the rows migration 001's default ("Starter") set had accumulated. On upgraded installs those members survived as orphans whose member_id resolves to no live feature, so the FeatureSets card counted the raw rows (e.g. "93 members") while the detail/resolver matched against live feature ids and found none selected — the set effectively granted 0 tools. Migration 017 deletes feature_set_members that point at a feature or feature set that no longer exists. Those members already resolve to nothing, so this changes no effective behavior — it makes the count honest and leaves the Starter set empty, identical to a freshly created Space (the new model gives Starter no special routing role; unmapped sessions deny + expose @mux meta-tools regardless). Idempotent; valid members kept. Adds a migration test covering keep-valid / purge-orphan. Signed-off-by: Mohammod Al Amin Ashik <maa.ashik00@gmail.com>
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.
Symptom
After upgrading stable → beta, the Starter FeatureSet shows a member count (e.g. "93 members") but the detail panel shows 0 selected, and it persists even after uninstalling every server — i.e. the set effectively grants 0 tools despite the count.
Root cause
The #151 refactor changed a feature member's identity from a qualified
server_id/tool_namestring to theserver_features.idUUID, but no migration converted the rows that migration 001'sdefault(now "Starter") set had accumulated under the old model. Those members survived as orphans whosemember_idresolves to no live feature:feature_set_membersrows → "93",member_idagainst liveserver_features.id→ 0.Migration 006 collapsed the
all/server-allsets and deleted their members, but never reconciled the surviving default set's members.Fix — migration 017
Delete
feature_set_membersthat point at a feature or feature set that no longer exists:These members already resolve to nothing, so this changes no effective behavior — it makes the count honest and leaves Starter empty, identical to a freshly created Space. (Confirmed earlier: the resolver never falls back to the Starter/active set — unmapped sessions deny and expose only
@muxmeta-tools — so an empty Starter is correct, not a regression.) Idempotent; any valid member a user added under the new model is kept.Tests
tests/database/migrations.rs::test_017_purges_orphaned_feature_set_membersseeds one valid + two orphaned members and asserts only the resolvable one survives. All 5 migration tests pass; pre-commit (fmt/clippy/eslint/typecheck) green.Follow-up (not in this PR)
Uninstalling a server deletes its
server_featuresbut not thefeature_set_membersreferencing them, so a custom set can re-accumulate orphans over time. Options: cascade the cleanup indelete_by_server, or have the FeatureSets card count only resolvable members. Happy to do either next.