Repository navigation
Conversation
Add nullable organization_id (FK to organizations, ON DELETE RESTRICT) and organization_source (enum: workspace, chatd, effective_group) columns to aibridge_interceptions, with a check constraint that keeps them set or unset together. RecordInterceptionRequest gains organization_id (18) and organization_source (19), and the aibridged API moves to v1.5. The server stores a valid pair and otherwise logs a warning and stores NULLs, so a bad pair never fails the user's request. Nothing sends the fields yet. Part of AIGOV-712.
7119bcc to
b4350b4
Compare
| // API v1.5: | ||
| // - Adds organization_id and organization_source to RecordInterceptionRequest. |
There was a problem hiding this comment.
In case we merge this before the release freeze, this can actually be included in v1.4
| case rawID == "": | ||
| return uuid.NullUUID{}, database.NullAIBridgeInterceptionOrganizationSource{}, xerrors.New("organization source set without organization ID") | ||
| case rawSource == "": | ||
| return uuid.NullUUID{}, database.NullAIBridgeInterceptionOrganizationSource{}, xerrors.New("organization ID set without organization source") | ||
| } |
There was a problem hiding this comment.
nit: I don't think these two checks are needed: an empty ID already fails uuid.Parse, and an empty source fails source.Valid(). I would suggest to remove them.
| -- RESTRICT: organizations are soft-deleted, so this only blocks a manual hard | ||
| -- delete, and attribution must never silently vanish. | ||
| ALTER TABLE aibridge_interceptions | ||
| ADD COLUMN organization_id uuid REFERENCES organizations(id) ON DELETE RESTRICT, |
There was a problem hiding this comment.
nit: Should we add an index on organization_id? We'll need to filter interceptions by org later, for example when listing sessions in the API and UI. Can be done as a follow-up, but we should add it to linear, so it is not forgotten
| // interceptionOrganization parses the optional organization attribution. It | ||
| // returns both values valid or neither, so an invalid pair never fails the record. |
There was a problem hiding this comment.
very-nit: it can theoretically happen that the org is a valid UUID, but not an org, but that will fail the FK on insert. Can we say that the function only checks the format and that the caller is expected to send an existing org?
| }) | ||
| } | ||
|
|
||
| func TestAIBridgeInterceptionOrganizationColumns(t *testing.T) { |
There was a problem hiding this comment.
nit: these subtests seem to follow a similar pattern, so a table driven test structure should be possible and make the tests easier to read. Wdyt?
Index aibridge_interceptions.organization_id, drop the redundant one-sided empty checks in interceptionOrganization, document that it checks only the format, and make the organization column test table-driven.
Adds
organization_id(FK toorganizations,ON DELETE RESTRICT) andorganization_source(new enum:workspace,chatd,effective_group) toaibridge_interceptions, with a check constraint that keeps them set or unset together. Cost and pricing run later, inRecordTokenUsage, so they need the organization that AIGOV-716a resolves once per request stored on the interception row.RecordInterceptionRequestgainsorganization_id(18) andorganization_source(19), and the aibridged API moves to v1.5.RecordInterceptionstores a valid pair; any other combination is logged as a warning and stored as NULLs, so a gateway bug never turns into an HTTP 500 for the user. A well-formed ID for an organization that does not exist fails on the FK, like an unknowninitiator_id. Nothing sends the fields yet, so behaviour is unchanged until AIGOV-716a.Malformed values are stored as empty, not rejected. A failed
RecordInterceptionreturns HTTP 500 to the user, so the server logs a warning and stores NULLs instead. The one exception is a well-formed ID for an organization that does not exist: the foreign key rejects it, the same as an unknowninitiator_idtoday.Part of AIGOV-712
This PR was generated by Coder Agents on behalf of @SasSwart.