Skip to content

fix(access): move group members to the default before deletion - #2705

Closed
Quick104 wants to merge 4 commits into
mainfrom
fix/v1-access-group-delete-policy
Closed

Quick104 wants to merge 4 commits into
mainfrom
fix/v1-access-group-delete-policy

Conversation

@Quick104

@Quick104 Quick104 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1402
Validation tasks: none

Deleting an access group through v1 clears its members' group assignments. Members without overrides then inherit the permissive no-group policy, which can silently grant permissions the deleted group denied. This fix moves them to the administrator's default group, matching v2's existing transfer behavior.

This partially repairs #1402. A destination picker, explicit no-group selection and existing ungrouped accounts remain outside this PR.

Approach

All store deletion entry points use the existing atomic transfer transaction. It advances affected accounts' policy revisions and preserves their overrides and sign-ins. If a populated group has no default destination, both APIs return the existing 409 conflict code without changing state. Empty non-default groups can still be deleted.

This is a critical security correction to the frozen v1 bridge. No request or response fields change; v2's OpenAPI now declares its existing DELETE conflict response. The API documentation describes both versions. Apple and Android need no caller changes; Jellyfin uses the same policy resolver. The Access and Accounts manual pages remain accurate.

Validation

  • Reproduced before and after on an isolated development sandbox with synthetic accounts. Checked v1/v2 transfer, missing-default rejection, unchanged overrides and sign-ins, default-group protection and unauthorized deletion.
  • Database tests pass for every deletion entry point, policy revisions, destination policy, empty groups and injected rollback. The complete access package passes with its expected synthetic library fixture. All query-budget pins and database contracts pass, including the three new CI registrations.
  • Build, vet, changed-line lint, router recovery lint, web checks and generated-contract/documentation gates pass. Prometheus rules pass on the builder; the local image pull was blocked by Docker DNS.
  • The full Go suite has six failures that reproduce on the exact base: resource capabilities, two Jellyfin playback-route tests and three NFO filesystem tests. The initial access run's two library-ID fixture failures also reproduce on the base; supplying the expected synthetic library makes the full package pass.
  • No passed validation case covers group deletion. User management / access groups / invites — Server #1196 C1/C2 and User management / access groups / invites — Web admin #1197 C1/C2 cover policy enforcement, group and account setup, and invitations; none of them deletes a group, so they are unaffected. Project-board discovery was limited by missing read:project scope; these tasks were read directly.
  • Review follow-up 4282c064e folds the move into DeleteConditional with no behavior change. Its access DB tests pass, and a local server built from it repeated the v1/v2 transfer, default-group 409, missing-default 409 (state unchanged) and empty-group deletion checks with synthetic accounts.

Evidence

Live API/database observations, correlated request logs and failing/passing regression output cover base 365e3d436 and head 4bd570974. The later refactor commit 4282c064e changes no behavior; its checks are listed under Validation. Development build metadata has no VCS revision; synchronized source hashes and rebuilt binary hashes are recorded separately.

Evidence: https://evidence.siloserver.org/r/silo-server/issue-1402-delete-policy/

Risks

The default group's policy intentionally replaces the source group's inherited policy. Deleting a populated group in an invalid legacy state without a default now requires setting a destination first. No migration is needed.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows the behavior change.

AI Disclosure

  • Harness: T3 Code through the Codex harness.
  • Tool(s): Codex; T3 Code delegate_task; Claude provider for cross-provider review.
  • Model(s): gpt-6.1-sol implementation and code review; claude-opus-5-5 plan and adversarial review.
  • Involvement: Fully AI-generated and agent-verified; no independent human verification claimed.
  • Adversarial review: Claude plan review checked the transaction and contract approach; its accurate conflict message and DELETE 409 declaration recommendations were adopted. Isolated Sol code reviews and sweep checked implementation 922191ded with no candidates. Claude PR review at 4bd570974 checked the full diff, deletion callers, concurrency, rollback and contracts, and independently repeated the failing/passing database tests. It found no actionable defects and posted nothing.
  • Review (/silo review mode, Claude Code with claude-opus-5-5, Codex gpt-6.1-sol cross-provider round) at 4bd570974 found two low-severity cleanups, fixed in 4282c064e: a redundant delete dispatch left after both store methods began moving members, and a test asserting the parent sentinel instead of ErrGroupDestinationRequired.

Note

Fix access-group deletion to move members to the default group

  • GroupStore.DeleteConditional now moves members of a non-default group to the default group in the same transaction, increments their policy revisions, then deletes the source group (group_store.go)
  • Deleting a populated group with no default destination now fails unchanged with ErrGroupDestinationRequired, returned as HTTP 409 by both the v1 and v2 handlers; empty groups stay deletable and default-group deletion stays rejected
  • Removes the separate memberMovingGroupStore interface and DeleteMovingMembers path from the handler layer; all deletion now goes through DeleteConditional
  • Covers the new behavior with DB tests for membership preservation, missing-default rejection, and rollback on a failed move, plus OpenAPI/TypeScript contract updates
  • Behavioral Change: deleting a group no longer leaves its members unassigned via foreign-key clearing — they land in the default group with a bumped policy revision

Macroscope summarized 4282c06.

@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 19, 2026
@silo-kody

silo-kody Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage labels Oct 19, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 19, 2026

Copy link
Copy Markdown

The Validation tasks: line is inaccurate. #1196 C1's recorded API checks use /api/v2 policy endpoints and do not exercise group deletion. #1197 C1/C2 cover web-admin setup and invitation flows; the v2 default-destination delete behavior is unchanged by this PR, and the new 409 applies only when a populated group has no default destination. Please update the line to Validation tasks: none.

Suggested fix: change Validation tasks: changes #1196 C1 to Validation tasks: none.

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4eddffec-1e45-4dc9-96c3-249711ec45f1
📥 Commits

Reviewing files that changed from the base of the PR and between 4bd5709 and 4282c06.

📒 Files selected for processing: 6
  • internal/access/group_delete_test.go
  • internal/access/group_store.go
  • internal/access/group_store_test.go
  • internal/api/handlers/admin_access_group_delete_test.go
  • internal/api/handlers/admin_access_group_service.go
  • internal/api/handlers/recommendation_scope_test.go
💤 Files with no reviewable changes: 1
  • internal/api/handlers/recommendation_scope_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

📝 Walkthrough

Access-group deletion now moves members to the default group and advances their policy revisions. Deleting the default group or a populated group without a default destination returns HTTP 409. Database and handler tests cover reassignment, rejection, rollback, and error propagation.

Changes: Access Group Deletion

Layer / File(s) Summary
Member reassignment and deletion rules
internal/access/group_store.go, internal/access/group_delete_test.go, internal/access/group_guard_test.go, internal/access/group_store_test.go, scripts/ci/db-contracts.txt
Deletion moves members to the default group and advances their policy revisions. Populated groups cannot be deleted without a default destination, while empty groups can. Database tests cover successful moves, unchanged state, and rollback.
Deletion service wiring and test doubles
internal/api/handlers/admin_access_group_service.go, internal/api/handlers/admin_access_group_delete_test.go, internal/api/handlers/recommendation_scope_test.go
The service now uses DeleteConditional for all deletions. The separate DeleteMovingMembers interface and path are removed.
API conflict responses and contract
internal/api/handlers/access_groups.go, internal/apiv2/admin_access_groups.go, contracts/api/v2/openapi.json, web/src/api/v2/schema.ts, docs/admin-users-api.md
Both routes map the missing-destination error to HTTP 409. API contracts and documentation describe atomic member reassignment and deletion conflict conditions.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant DeleteAdminAccessGroup
  participant GroupStore
  participant Database
  DeleteAdminAccessGroup->>GroupStore: DeleteConditional
  GroupStore->>Database: Move members and advance policy revisions
  GroupStore->>Database: Delete access group transactionally
  Database-->>GroupStore: Commit or rollback
  GroupStore-->>DeleteAdminAccessGroup: Deletion result
Loading

Suggested reviewers: rhainland, rangodj

Merge Risk: ⚪ Minimal · up to 4282c

No identified issue currently blocks merging the access-group deletion change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: moving group members to the default group before deletion.
Description check Passed The description directly explains the security problem, implementation approach, validation, risks, and scope of the access-group deletion changes.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 4bd5709. The fix is sound: every deletion path now runs the existing move-then-delete transaction, and I found no concurrency or rollback gap. Locking the source row FOR UPDATE makes a concurrent assignment into the group either land before the move or fail its foreign key check after the delete.

Two low-severity cleanups are inline. I'm fixing both in a commit on this branch, so there's no need to change them yourself.

One PR-body correction, also mine to make: the Validation tasks: line says changes #1196 C1, but C1's recorded checks read the effective policy of accounts in groups that already exist. None of them deletes a group, and this diff doesn't touch policy resolution, so the line should be Validation tasks: none. The Macroscope comment above says the same thing.

Comment thread internal/access/group_store.go Resolved
Comment thread internal/access/group_delete_test.go Resolved
Delete and DeleteConditional now both move members to the default group,
so DeleteMovingMembers and the v2 service's dispatch between the two
methods no longer chose anything. The transaction now lives in
DeleteConditional, the service calls it directly, and the handler test
that pinned which method ran is gone. The no-default test asserts
ErrGroupDestinationRequired, the error that selects its 409 message.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

silo-kody Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104

Copy link
Copy Markdown
Contributor Author

Review summary

Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)

Reviewed head: 4282c064e (review started at 4bd570974).

Deleting a group through the frozen v1 route left its members with no group, which gives them the permissive no-group policy. That is a privilege widening, and fixing it fits what the API contract allows on the v1 bridge: critical fixes only. The change reuses the move-then-delete transaction that v2 already ran, so every delete path now does the same thing. It adds no setting and no new operation; the only contract change is declaring the 409 that v2 already returned for the default group.

Addressed in this review (both low severity, fixed in 4282c064e):

  • Once both store methods moved members, the v2 service still chose between them through a memberMovingGroupStore type assertion, and a handler test pinned which method ran. The transaction now lives in DeleteConditional, DeleteMovingMembers and the dispatch are gone, and the service calls DeleteConditional directly.
  • TestGroupDeletionWithoutDefaultDB asserted the parent sentinel. It now asserts ErrGroupDestinationRequired, and it fails if the store returns the plain default-group error.
  • The PR body's Validation tasks: line now reads none, as the Macroscope comment suggested.

Verification of the follow-up commit. The internal/access package passes against a fresh migrated database once its two expected synthetic libraries exist, including all three new DB contract tests. internal/apiv2 passes. In internal/api/handlers, only TestAdminSubtitleListPageDB and TestCatalogTransferPersistsJobsAndSignedLink fail; they are unrelated and also fail on a fresh database on main. make lint-changed reports 0 issues. A sandbox could not be created (the build host had no free Docker network address pools), so I ran a server built from 4282c064e against a throwaway database with synthetic accounts:

  • v1 and v2 deletes of a populated group return 204; the members land in the default group and their access_policy_revision goes up by one.
  • Deleting the default group returns 409 with the existing message.
  • With the default flag cleared in SQL, deleting a populated group returns 409 ("Set a default access group before deleting a group with members.") on both v1 and v2, and the member's group and revision stay unchanged. An empty group still deletes with 204.

The existing evidence page covers 4bd570974. The follow-up commit changes no behavior, so those observations still hold.

Remaining issues: none blocking. Two things predate this PR and are outside its scope. Both handlers read the member list for the recommendations rebuild before the delete transaction, so an account assigned to the group in that gap is moved but its recommendations are not rebuilt; reads still apply the current policy. The v2 create and update operations can return 409 but do not declare it in the OpenAPI document.

Validated features: none affected. I couldn't list passed cases from the v1.0 board because the token lacks read:project, so I read the access tasks directly. #1196 C1/C2 and #1197 C1/C2 cover policy enforcement, group and account setup, and invitations; none of them deletes a group.

User manual: unaffected. The Access and Accounts pages on siloserver.org don't describe group deletion.

Apple and Android: no change needed. Neither app calls the access-group delete route, and the web admin uses v2.

Cross-provider round: Codex (gpt-6.1-sol) reviewed 4bd570974 read-only. It found no blocking defects and raised the same two cleanups and the validation-line correction. It confirmed the locking against concurrent assignment and default changes, and that Jellyfin compatibility uses the same policy resolver.

Reviewed by Claude Code (claude-opus-5-5) running the /silo review workflow, with a Codex gpt-6.1-sol second opinion. The fixes were written and verified by the agent; no independent human verification is claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant