SQUARE-23-Insight-AI-one-per-customer - #1141
Merged
Merged
Conversation
- bin-ai-manager: Add design doc for enforcing one active type=insight AI per customer
- bin-ai-manager: Address design review feedback
- bin-ai-manager: Address design review feedback
- bin-ai-manager: Address design review feedback
- bin-ai-manager: Add implementation plan for one-insight-AI-per-customer constraint
- bin-ai-manager: Address implementation plan review feedback
- bin-ai-manager: Add active_insight_key SQLite test-schema stand-in and regression test for one-insight-AI-per-customer
- bin-dbscheme-manager: Add ai_ais.active_insight_key migration enforcing one active Insight AI per customer
- bin-ai-manager: Translate ai_ais duplicate-key error into AI_INSIGHT_ALREADY_EXISTS (409) in Create
- bin-ai-manager: Translate ai_ais duplicate-key error into AI_INSIGHT_ALREADY_EXISTS (409) in all three Update branches
- bin-ai-manager: Extract shared helper for AI_INSIGHT_ALREADY_EXISTS translation, eliminating 4-way duplication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enforces at most one active (non-deleted) type=insight AI per customer at the DB level, with a clear 409 API error on violation, per SQUARE-23. A generated column plus unique index on ai_ais mirrors the existing ai_aicalls.active_reference_key precedent (VOIP-1234); aihandler translates the resulting duplicate-key error into cerrors.AlreadyExists across every reachable Create/Update path.
Migration is not applied to any shared environment by this PR. Before it is applied, customers with 2+ existing active Insight AIs must be identified via a read-only audit query and resolved (default proposal: keep the most recently created, matching square-admin's existing fallback) via the existing DELETE /ais/{id} API — see docs/plans/2026-07-29-insight-ai-one-per-customer-design.md section 3 for the full audit/cleanup approach.