Repository navigation
AI-3735: no foreign app by organization id in teams - #2383
Conversation
GET /v1/teams, on a router with no usage service or for an app in no organization, sums the request rows of AppOrganizations.Apps, which always holds the organization's own id as an app. So another customer's app whose id matched was counted: for an organization, the app whose id is the organization's; for an app in no organization, every app seen under an organization of the app's id. Their teams, spend and app ids were answered as the caller's. Spend.Teams now takes billed, as Spend.Subject does: a billed organization counts its Members (Apps without its own id), an app in no organization itself alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7c9ba14 to
58974dc
Compare
thesyncim
left a comment
There was a problem hiding this comment.
Reviewed at 58974dc. The production change is right and I found no defect in it: both new tests fail on the old code, and 17 of 21 mutants were killed. What needs a change is the merge with current main (first inline comment); the rest is tests and nits. In the body, the route is /v1/stats/spend?scope=organization, not /v1/spend, and a Part of AI-3735 line would help.
- insertRequest in the teams test and in spent, since #2377 removed Requests.Insert. - A billed organization's teams count every app seen under it, the one whose id is the organization's among them. Leaving out the organization's own id, or reading registered apps only, passed before. - The unbilled Spend.Teams read looks up no apps: one sum a shard. - The explain seed records customer-7 and customer-107 under org-7, and a billed Spend.Teams case reads their IN list by index. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review. All five threads have replies. From the review summary:
|
thesyncim
left a comment
There was a problem hiding this comment.
Re-reviewed at f0aad6b: every earlier comment is answered, the new tests kill the variants that passed before, and I have no open finding on the code or tests. The one thing left is the conflict with main (inline). I'll approve once it's resolved that way and CI is green.
thesyncim
left a comment
There was a problem hiding this comment.
No findings at f0aad6b (note: PR is still CONFLICTING with main on acceleration/internal/api/limits_test.go from #2386, as flagged on the open thread — just needs a merge from main before merging).
Checked and sound: all five prior review threads are addressed (insertRequest, TestAnOrganizationsTeamsAreTheWorkOfEveryAppSeenUnderIt, unbilled budget in TestSpendQueryBudgets, billed Spend.Teams of an organization explain case, and the pre-existing background-join question answered); Spend.Teams delegates to AppOrganizations.Members when billed and [organizationID] when !billed; generated.sh reports no spec/client drift; and all CI checks passed on f0aad6b.
spent keeps main's InsertMany and this branch's usage categories. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Part of AI-3735.
Why
Follow-up to #2372 (merged), from its review.
GET /v1/teamshas the same app-id/organization-id collision #2372 fixed inSpend.Subject. On a router with no usage service, or for an app in no organization, it sums the request rows ofAppOrganizations.Apps(org). That list always includes the organization's own id as an app, so another customer's app whose id matches was answered as the caller's: its team names, spend and app id.organizationis the app's own id): every app seen under an organization of that id is counted./v1/stats/spend?scope=organizationalso usesApps, but it filtersrequests.organization_idas well, so a foreign row never matches. It is unchanged.How it works
MembersisAppswithout the organization's own id prepended.Appsis now[organization] + Members, unchanged for its other callers.teamSpend(account.go) already hadbilledand now passes it on.Members.Validation
SelfHostedAccountSuite/TestTeamsLeaveOutAnAppWhoseIdIsTheOrganizationsSelfHostedLimitsSuite/TestAnAppInNoOrganizationsTeamsAreItsOwnWorksSelfHostedLimitsSuite/TestAnOrganizationsTeamsAreTheWorkOfEveryAppSeenUnderItStoreSuite/TestSpendQueryBudgets(unbilledSpend.Teams)StoreSuite/TestEveryHotTableIsReadByIndex/Spend.Teams of an organizationINlist of two apps is not read byrequests_customer_spend_idxSpend.Teamswithgo test -overlay.go test -overlay, aSpend.Teamsreading registered apps only, and one leaving out the organization's own id, both pass every earlier test and failTestAnOrganizationsTeamsAreTheWorkOfEveryAppSeenUnderIt. An unbilled read that also looks up the organization's apps fails the new budget.billedthrough: a constantfalsefails the existingTestTeamsSumTheRequestsThisMonth, and a constanttruefails the no-organization test above.customer-7andcustomer-107underorg-7, which the seed's requests already name, so the billed case sums two apps. The unbilledSpend.Teamscase stays.mainat 09bcd98 (refactor(store): remove code nothing in production calls #2377 removedRequests.Insert): the teams test andspent(limits_test.go) useinsertRequest, the same change as test(api): insert limits test requests with insertRequest #2388 forspent.SelfHostedAccountSuite,SelfHostedLimitsSuite,AccountSuiteandLimitsSuite; the store'sTestSpendQueryBudgetsand the wholeTestEveryHotTableIsReadByIndex;go vet -tags integration ./...inacceleration/.🤖 Generated with Claude Code