Skip to content

feat(BA-6931): add deployments and usage_buckets retention purgers#12958

Merged
HyeockJinKim merged 2 commits into
mainfrom
BA-6931
Jul 19, 2026
Merged

feat(BA-6931): add deployments and usage_buckets retention purgers#12958
HyeockJinKim merged 2 commits into
mainfrom
BA-6931

Conversation

@HyeockJinKim

Copy link
Copy Markdown
Collaborator

Summary

  • Wire the two ordered-delete retention categories into the shared catalog: deployments (DESTROYED endpoints past destroyed_at; FK-less deployment_revisions drained by endpoint id first; deployment_policies/endpoint_auto_scaling_rules cascade; terminal routings/replica_groups swept on their own updated_at boundary so routes/groups retired under a still-live endpoint don't linger; endpoint_tokens by expiry) and usage_buckets (each bucket kind on period_end with its FK-less usage_bucket_entries drained first).
  • Generalize the purger into a single RetentionPurgerSpec (local boundary, or foreign-key boundary for FK-less children) built by one _catalog(threshold), removing the descriptor/build_spec layer and the two prior spec classes.
  • Move terminal-status definitions onto their enums (RouteStatus/ReplicaGroupLifecycle.terminal_statuses(), RoleInvitationState/VFolderInvitationState.declined_states()). Invitation retention purges only declined (rejected/canceled) rows and keeps ACCEPTED — acceptance writes a durable user_roles/vfolder_permissions record, so the invitation is history, but it is retained conservatively.

Test plan

  • pants fmt/fix/lint pass on the changeset
  • pants check (mypy) clean across changed files
  • pants 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 completeness

Resolves BA-6931

🤖 Generated with Claude Code

@HyeockJinKim
HyeockJinKim requested a review from a team as a code owner July 19, 2026 14:53
Copilot AI review requested due to automatic review settings July 19, 2026 14:53
@github-actions github-actions Bot added size:XL 500~ LoC comp:manager Related to Manager component labels Jul 19, 2026
HyeockJinKim added a commit that referenced this pull request Jul 19, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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(
HyeockJinKim and others added 2 commits July 20, 2026 00:35
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>
@HyeockJinKim
HyeockJinKim merged commit 1b14eef into main Jul 19, 2026
31 checks passed
@HyeockJinKim
HyeockJinKim deleted the BA-6931 branch July 19, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants