Skip to content

fix(api): an app in no organization with an organization's id leaves its limits to support - #2400

Merged
thesyncim merged 6 commits into
mainfrom
fix/ai-3765-shared-id-limits
Nov 25, 2026
Merged

thesyncim merged 6 commits into
mainfrom
fix/ai-3765-shared-id-limits

Conversation

@thesyncim

@thesyncim thesyncim commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Problem
For its spend limits, an app in no organization is its own organization, by its own id. Nothing said who manages the limits kept under an id that is also an organization's.

Fix

  • limitsCaller answers an app in no organization 403 forbidden when its id is also an organization's it is not in (sharedID). This covers every customer operation on limits, usage, resets, grants and GET /v1/teams, with one message whatever the request names. They all declare 403, so the spec does not change.
  • An organization is one with Members (AI-3735: no foreign app by organization id in teams #2383); the app is in it when it is one of them. The read goes to Postgres, not the cache.
  • An app recorded in the organization of its own id is one of its apps and keeps its limits. An app in no organization with no such organization is unchanged.
  • A call on limits that names an organization records its app there before it is answered, when the app is recorded elsewhere or nowhere. Enforcer.Join does it in the background, and once per router. An app recorded there already costs one read by primary key. A lookup or a record that fails answers 500.
  • Admission and the manage operations are unchanged. There is no migration.

Tests

  • SelfHostedLimitsSuite (limits_shared_id_test.go): over HTTP, one test per operation, in which the app is refused and the organization is not; with an organization known by a registration, of two apps, or seen later, an app seen elsewhere, and one no longer in its own. A limit and a grant made by an app recorded elsewhere are its organization's. These fail without the change, as do the two on a lookup or a record that fails.
  • TestAnAppInTheOrganizationOfItsOwnIdKeepsItsLimits, TestALimitOfASharedIdHoldsTheAppsWorkAndTheOrganizations, TestStaffManageTheLimitsOfASharedId and TestStaffsLimitRecordsNoApp pass without it too: they hold what does not change.
  • TestAnAppRecordedInItsOrganizationIsNotRecordedAgain holds the new record to a mismatch.
  • TestAnAppInNoOrganizationReadsOnlyItself, TestAnAppInNoOrganizationsOrganizationIsItselfAlone and TestAnAppInNoOrganizationsTeamsAreItsOwnWorks now record the app in the organization of its own id, so that they still reach the reads they check.
  • TestAnAppReadsItsOwnSpendWhateverOrganizationIsRecordedForIt moves the record in the middle of the read; TestAnAppWithAnOrganizationsIdKeepsTheLimitsOfTheOneItNames holds the check to requests that name none.

Part of AI-3765

@thesyncim thesyncim added data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review and removed data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review labels Nov 24, 2026
@thesyncim thesyncim added the data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review label Nov 25, 2026

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

VERDICT: GO

Reviewed 486abb5 merged onto current main (b86e02f). CI on the head: all checks pass, Integration (router) included.

No Blocker and no Should fix. There are two Questions, inline. Neither blocks the merge: both are about behaviour that was already there before this PR, and they belong to the rest of AI-3765.

What I checked

  • All 12 customer operations that take limits go through limitsCaller: list, create, get, update, delete, usage, reset, grant create, grant list, revoke, unrevoke and GET /v1/teams. The manage operations do not. No other path keys limit rows by the app's own id. getSpend with scope=organization reads only the app's own spend, and account and policies need an organization.
  • Mutations: 21 checked, 0 survived. 9 change the logic of limitsCaller, sharedID and recordOrganization: drop the record, record after the answer in a goroutine, always upsert, record only an app with no record, ignore the lookup or upsert error, drop len(members) > 0, drop !slices.Contains, let a sharedID error through. 12 switch one call site at a time back to the base's limitsCaller. Each one fails a test in SelfHostedLimitsSuite.
  • LimitsSuite, SelfHostedLimitsSuite, AccountSuite, SelfHostedAccountSuite and PoliciesSuite pass on the merged tree. go vet -tags integration ./internal/api/ and gofmt are clean, and openapi.yaml and the JS types match their source.
  • A self-hosted app in no organization, with no organization of its id, behaves as before. The only change for it is one more read, Members.
  • recordOrganization runs for the same request as Enforcer.Join, with the same organization, so the two writes agree. Its errors take the 500 path. The 403 text is fixed words and holds no deployment settings.
  • There is no migration, no new dependency and no spec change. No skill or doc line still describes the old rule.

Comment thread acceleration/internal/api/limits.go Resolved
Comment thread acceleration/internal/api/limits.go Resolved

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving on the reviewer's GO (#2400 (review)).

@thesyncim
thesyncim merged commit 61dd717 into main Nov 25, 2026
13 checks passed
@thesyncim
thesyncim deleted the fix/ai-3765-shared-id-limits branch November 25, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review docs project-info

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants