Problem
ai_usage_events (src/db/schema.ts) already records AI usage/cost per event, but has no installation_id/tenant column — identity today is only recoverable indirectly via actor/route/metadata_json. A central hosted-billing aggregator (shared by both ORB and AMS once AMS's storage migration lands) needs a real tenant column to attribute usage without parsing free-form metadata.
Area
src/db/schema.ts (aiUsageEvents), src/db/repositories.ts (recordAiUsageEvent and its callers), a new migration.
Proposal
Add an installation_id (or tenant_id) column, backfill-nullable for existing self-host rows (self-host has no installation concept and should keep working unchanged), populated going forward by hosted containers at insert time.
Note this table double-purposes as a BYOK key-lifecycle audit log too (model prefixed byok:...) — the new column applies to both purposes; don't special-case one away.
Deliverables
Links & Resources
Problem
ai_usage_events(src/db/schema.ts) already records AI usage/cost per event, but has noinstallation_id/tenant column — identity today is only recoverable indirectly viaactor/route/metadata_json. A central hosted-billing aggregator (shared by both ORB and AMS once AMS's storage migration lands) needs a real tenant column to attribute usage without parsing free-form metadata.Area
src/db/schema.ts(aiUsageEvents),src/db/repositories.ts(recordAiUsageEventand its callers), a new migration.Proposal
Add an
installation_id(ortenant_id) column, backfill-nullable for existing self-host rows (self-host has no installation concept and should keep working unchanged), populated going forward by hosted containers at insert time.Note this table double-purposes as a BYOK key-lifecycle audit log too (
modelprefixedbyok:...) — the new column applies to both purposes; don't special-case one away.Deliverables
recordAiUsageEventaccepts and writes itsumAiCostForTenantSince) mirroring the existingsumAiEstimatedNeuronsSince/sumByokAiUsageForRepoSincepatternLinks & Resources
src/db/schema.ts:1289(aiUsageEvents),src/db/repositories.ts:3556(recordAiUsageEvent)