Repository navigation
Conversation
b175ea2 to
cb4e496
Compare
SasSwart
left a comment
There was a problem hiding this comment.
Initial Self Review
| // Resolve the effective group for attribution, independent of whether the | ||
| // model is priced. | ||
| effectiveGroup, ok, err := budget.ResolveUserEffectiveGroup(ctx, s.store, intc.InitiatorID, s.budgetPolicy) | ||
| effectiveGroup, ok, err := budget.ResolveUserEffectiveGroup(ctx, s.store, intc.InitiatorID, uuid.NullUUID{}, s.budgetPolicy) |
There was a problem hiding this comment.
as per my previous comment, I think we should propagate org awareness back up the call stack to the callers of resolveTokenUsageCost, but as a follow-up
cb4e496 to
a37f1d1
Compare
db38ba8 to
c81cdac
Compare
ssncferreira
left a comment
There was a problem hiding this comment.
LGTM 👍 just a note that GetUserAIBudgetOverrideWithOrganization needs to take deleted orgs into account
| // and Everyone group count, and the organization must not be deleted. When it | ||
| // is null, groups from all of the user's organizations count. |
There was a problem hiding this comment.
nit: maybe "When it is null, resolution is site-wide: the override, group budgets and Everyone groups from all of the user's organizations count"? That makes it clear the override and Everyone group take part too, not just group budgets.
| FROM user_ai_budget_overrides | ||
| WHERE user_id = @user_id; | ||
|
|
||
| -- name: GetUserAIBudgetOverrideWithOrganization :one |
There was a problem hiding this comment.
Could we reuse GetUserAIBudgetOverride with an optional organization_id, instead of adding a second query? It could also return the group's org for the resolver. Wdyt?
There was a problem hiding this comment.
If we merge them, the AND organizations.deleted = false check is awkward. Should you still be able to view and delete overrides for an organization that has been soft deleted?
I'm going to keep them separate for now, but I'm happy to merge them in a follow-up if you want to explore this further?
budget.ResolveUserAIBudget and budget.ResolveUserEffectiveGroup take an optional organization. When it is set, only that organization's override, group budgets and Everyone group count. When it is null, resolution is unchanged. budget.EffectiveGroup also reports the organization of the resolved group. Budget resolution reads the override through a new query, GetUserAIBudgetOverrideWithOrganization, so the CRUD query stays as it is. All callers pass a null organization, so behaviour does not change. Part of AIGOV-715.
c81cdac to
8705414
Compare
AI budget resolution searches all of a user's groups across every organization. Whichever group wins determines the organization. #31120 needs to resolve inside a known organization, and it needs to know which organization site-wide resolution picked.
Add an
organizationID uuid.NullUUIDargument tobudget.ResolveUserAIBudgetandbudget.ResolveUserEffectiveGroup. When it is set, count only that organization's override, group budgets and Everyone group. An organization that is unknown, deleted or that the user is not a member of resolves to nothing. When it is null, resolve exactly as before. Return the winning group's organization inbudget.EffectiveGroup.OrganizationID.Read the override through a new resolution-only query,
GetUserAIBudgetOverrideWithOrganization, so that the CRUD queryGetUserAIBudgetOverrideand the admin endpoints stay untouched. Add a nullableorganization_idfilter toGetHighestGroupAIBudgetByUserandGetUserEveryoneFallbackGroup.Every caller passes null, so behaviour is unchanged. There is no migration and no proto change.
Scoping to an organization can lift a limit: a user capped in org B has no limit in org A if A has no budgets. AIGOV-711 intends this, and it takes effect in #31120.
Part of AIGOV-715.
This PR was generated by Coder Agents on behalf of @SasSwart.