Repository navigation
Description
Automated Schema Validation Report
Date: 2026-04-24
Result: 14 critical P1 schema drift issues — schema.py cannot be read alone to understand the full database structure. No P0 runtime crashes (two-pass migration system compensates at startup), but the architectural invariant is broken.
Critical Findings (P1)
1. Tables Created Only in Migrations, Not in schema.py (9 tables)
These tables exist at runtime via migrations but have no CREATE TABLE in db/schema.py's TABLES dict. The subscription_credentials case is especially problematic: it's listed in schema.py's docstring and used as a FK target in agent_ownership, but missing from TABLES.
| Table | Migration | Impact |
|---|---|---|
agent_notifications |
agent_notifications |
Platform notifications |
subscription_credentials |
subscription_credentials |
Referenced as FK in agent_ownership |
subscription_rate_limit_events |
subscription_rate_limit_tracking |
Rate-limit tracking |
slack_workspaces |
slack_channel_agents |
Documented in architecture.md |
slack_channel_agents |
slack_channel_agents |
Documented in architecture.md |
slack_active_threads |
slack_channel_agents |
Documented in architecture.md |
telegram_bindings |
telegram_bindings |
Telegram integration |
telegram_chat_links |
telegram_bindings |
Telegram user tracking |
telegram_group_configs |
telegram_group_configs |
Telegram groups |
2. Columns Added by Migrations But Missing from schema.py DDL (9 columns)
schema.py's CREATE TABLE statements are incomplete — 9 columns exist at runtime via migrations only. These columns are present on both fresh and existing installs (via the two-pass system), but schema.py cannot be used as a reference for the true column list.
agent_ownership (3 columns):
full_capabilities INTEGER DEFAULT 0— migrationagent_ownership_full_capabilitiesmax_backlog_depth INTEGER DEFAULT 50— migrationbacklog_supportvoice_system_prompt TEXT— migrationagent_ownership_voice_prompt
schedule_executions (6 columns):
source_user_id,source_user_email,source_agent_name,source_mcp_key_id,source_mcp_key_name— migrationexecution_origin_trackingclaude_session_id— migrationexecution_session_trackingfan_out_id— migrationexecution_fan_out_id
3. Ad-Hoc CREATE TABLE Outside schema.py and migrations.py (Invariant #3 Violation)
Multiple CREATE TABLE statements found in router and service code — all violate Architectural Invariant #3 ("Schema in db/schema.py, Migrations in db/migrations.py"):
| File | Table | Database |
|---|---|---|
routers/processes.py:781 |
process_schedules |
Separate scheduler DB |
services/process_engine/repositories/sqlite_definitions.py:70 |
process_definitions |
Separate process DB |
services/process_engine/repositories/sqlite_executions.py:75,99 |
process_executions, step_executions |
Separate process DB |
services/process_engine/repositories/sqlite_events.py:86 |
execution_events |
Separate process DB |
services/process_engine/repositories/audit.py:62 |
audit_entries |
Separate process DB |
services/process_engine/services/templates.py:117 |
process_templates |
Separate templates DB |
services/process_engine/services/alerts.py:163,178 |
cost_thresholds, cost_alerts |
Separate alerts DB |
The Process Engine uses separate SQLite files, which provides isolation but bypasses the schema/migration system entirely.
Informational Findings (P2 — Documentation Drift)
Column name mismatches between architecture.md and actual schema.py:
| Table | architecture.md says | schema.py actually has |
|---|---|---|
mcp_api_keys |
last_used TIMESTAMP |
last_used_at TEXT |
mcp_api_keys |
use_count INTEGER |
usage_count INTEGER |
access_requests |
created_at TEXT NOT NULL |
requested_at TEXT NOT NULL |
access_requests |
channel TEXT NOT NULL |
channel TEXT (nullable) |
access_requests |
decided_by TEXT |
decided_by INTEGER |
agent_permissions |
granted_by TEXT NOT NULL |
created_by TEXT NOT NULL |
agent_ownership |
7 columns shown | 22+ actual columns |
Recommended Actions (Prioritized)
- Add missing tables to schema.py TABLES dict — 9 migration-only tables should be represented in schema.py for discoverability. The migration still handles existing installs; schema.py handles fresh installs.
- Add missing columns to schema.py CREATE TABLE statements — 9 columns across 2 tables should be in schema.py DDL so schema.py is the complete reference.
- Create a Process Engine schema module — extract all ad-hoc
CREATE TABLEfromservices/process_engine/into adb/process_engine_schema.pyfollowing the same pattern asdb/schema.py. - Move
process_schedulescreation fromrouters/processes.pyto migrations.py. - Fix architecture.md column names — 6 wrong column names documented (P2, low urgency).
Generated by scheduled /validate-schema run
Activity
vybe commentedon Apr 27, 2026
Superseded by #529 (2026-04-27 run, 20 issues found — includes all issues from this report plus new ones).