feat(BA-6931): add deployments and usage_buckets retention purgers#12958
Merged
Conversation
HyeockJinKim
added a commit
that referenced
this pull request
Jul 19, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds ordered retention cleanup for deployments and usage buckets.
Changes:
- Generalizes retention queries with
RetentionPurgerSpec. - Adds deployment and usage-bucket retention catalogs and tests.
- Centralizes terminal and declined-state definitions.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/unit/manager/repositories/retention/test_retention_repository.py |
Adds database-backed retention tests. |
src/ai/backend/manager/repositories/retention/purgers.py |
Generalizes retention query specifications. |
src/ai/backend/manager/repositories/retention/db_source/db_source.py |
Wires new retention categories. |
src/ai/backend/manager/errors/retention.py |
Updates unsupported-category documentation. |
src/ai/backend/manager/data/vfolder/types.py |
Defines declined invitation states. |
src/ai/backend/manager/data/role_invitation/types.py |
Defines declined role-invitation states. |
src/ai/backend/manager/data/deployment/types.py |
Defines route and replica-group terminal states. |
changes/12958.feature.md |
Documents the retention feature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @lru_cache(maxsize=1) | ||
| def terminal_statuses(cls) -> set[ReplicaGroupLifecycle]: | ||
| """Replica-group lifecycles that will not transition further.""" | ||
| return {cls.DRAINED, cls.FAILED} |
Comment on lines
+232
to
+234
| RetentionPurgerSpec( | ||
| DomainUsageBucketRow, DomainUsageBucketRow.period_end, threshold | ||
| ), |
Comment on lines
+223
to
+224
| RetentionCategory.USAGE_BUCKETS: ( | ||
| RetentionPurgerSpec( |
Wire the two ordered-delete retention categories into the shared catalog: - deployments: DESTROYED endpoints past destroyed_at (revisions drained by endpoint id first, policies/auto_scaling_rules cascade); terminal routings and replica_groups swept on their own boundary; endpoint_tokens by expiry. - usage_buckets: each bucket kind on period_end with its FK-less entries drained first. Generalize the purger into a single RetentionPurgerSpec (local or foreign-key boundary) built by one _catalog(threshold), replacing the descriptor layer. Move terminal-status definitions onto the enums (RouteStatus/ReplicaGroupLifecycle terminal_statuses, RoleInvitationState/VFolderInvitationState declined_states); invitation retention keeps ACCEPTED rows and purges only declined ones. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
Summary
destroyed_at; FK-lessdeployment_revisionsdrained by endpoint id first;deployment_policies/endpoint_auto_scaling_rulescascade; terminalroutings/replica_groupsswept on their ownupdated_atboundary so routes/groups retired under a still-live endpoint don't linger;endpoint_tokensby expiry) and usage_buckets (each bucket kind onperiod_endwith its FK-lessusage_bucket_entriesdrained first).RetentionPurgerSpec(local boundary, or foreign-key boundary for FK-less children) built by one_catalog(threshold), removing the descriptor/build_speclayer and the two prior spec classes.RouteStatus/ReplicaGroupLifecycle.terminal_statuses(),RoleInvitationState/VFolderInvitationState.declined_states()). Invitation retention purges only declined (rejected/canceled) rows and keeps ACCEPTED — acceptance writes a durableuser_roles/vfolder_permissionsrecord, so the invitation is history, but it is retained conservatively.Test plan
pants fmt/fix/lintpass on the changesetpants check(mypy) clean across changed filespants test tests/unit/manager/repositories/retention/— deployments (endpoint boundary + lifecycle filter, cascade, endpoint_tokens expiry, FK-less child), terminal routings/replica_groups under a live endpoint, usage_buckets ordered entries→buckets (no orphans, all three kinds), catalog completenessResolves BA-6931
🤖 Generated with Claude Code