Spensara Spensara Knowledge Base & Documentation Repository

Repository Docs & Knowledge Base

Consolidated Spensara documentation repository (722 Markdown & architecture documents in ../repository)
Built Word Documents (.docx): Spensara Overview (.docx) Capability Assessment (.docx) Brink POS Ingestion Analysis (.docx) The Borg Ingestion Architecture (.docx)

Implementation Specs (157)

Detailed engineering and feature implementation specifications.
implementation-specs/specs/SingleStoreRedshiftRuntimeReadPath/TASK2.1.md 2,768 bytes · Updated Oct 23, 2026 10:44 AM EDT
Raw File

TASK 2.1: Update Warehouse Query Tools to Use Tenant-Resolved Redshift

Summary

Update the anomaly detector data access tool path so SQL queries execute against the resolved tenant Redshift database instead of the shared PostgreSQL warehousedb connection.

This task keeps the existing tool shape where practical, but changes the connection source.

Dependencies

  • TASK 1.2 (runtime services wired to tenant warehouse foundation)

Files to Modify

1. backend/Kds.Ai.AnomalyDetector/Tools/WarehouseQueryToolProvider.cs

Update or replace the provider so it:

  • uses the runtime tenant resolver,
  • resolves the active tenant warehouse mapping,
  • opens a tenant Redshift connection through the warehouse foundation connection factory,
  • no longer depends on the keyed warehousedb NpgsqlDataSource for migrated warehouse reads.

2. backend/Kds.Ai.AnomalyDetector/DependencyInjectionExtensions.cs

Update service registration to remove or stop using the shared warehouse data source for this migrated path.

Keep DataAccessAgentFactory behavior stable unless constructor dependencies need to change.

Required Behavior

The query tool provider must:

  • resolve one tenant id for each tool execution,
  • reject missing or inactive tenant mappings before query execution,
  • open the resolved tenant Redshift database,
  • execute read-only queries with the existing timeout limit,
  • preserve result-size limits,
  • preserve JSON output shape where practical,
  • log tenant context without leaking secrets.

The query tool provider must not:

  • let the agent choose the database,
  • accept tenant_database through prompt/tool arguments,
  • use the shared PostgreSQL warehousedb read connection for migrated runtime queries.

Status

Completed.

Implemented in:

  • backend/Kds.Ai.AnomalyDetector/Tools/WarehouseQueryToolProvider.cs
  • backend/Kds.Ai.AnomalyDetector/DependencyInjectionExtensions.cs
  • backend/Kds.Ai.AnomalyDetector/Kds.Ai.AnomalyDetector.csproj

Acceptance Criteria

  • [x] Query tool provider opens tenant-resolved Redshift connections
  • [x] Query tool provider rejects missing tenant mapping
  • [x] Query tool provider rejects inactive tenant mapping
  • [x] Shared PostgreSQL warehousedb data source is no longer used by the migrated query tool path
  • [x] Existing command timeout settings remain enforced
  • [x] Existing max rows/max result chars settings remain enforced
  • [x] JSON result shape remains compatible where practical
  • [x] Data access agent factory still builds successfully
  • [x] Solution builds without errors

Notes

  • Keep this task focused on connection routing.
  • Serving-only restrictions are handled in TASK 2.2.
  • Prompt/tool wording is handled in TASK 2.3.