Skip to content

Schema Validation: 14 critical drift issues — schema.py not canonical source of truth #480

Closed

Description

@vybe

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 — migration agent_ownership_full_capabilities
  • max_backlog_depth INTEGER DEFAULT 50 — migration backlog_support
  • voice_system_prompt TEXT — migration agent_ownership_voice_prompt

schedule_executions (6 columns):

  • source_user_id, source_user_email, source_agent_name, source_mcp_key_id, source_mcp_key_name — migration execution_origin_tracking
  • claude_session_id — migration execution_session_tracking
  • fan_out_id — migration execution_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)

  1. 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.
  2. 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.
  3. Create a Process Engine schema module — extract all ad-hoc CREATE TABLE from services/process_engine/ into a db/process_engine_schema.py following the same pattern as db/schema.py.
  4. Move process_schedules creation from routers/processes.py to migrations.py.
  5. Fix architecture.md column names — 6 wrong column names documented (P2, low urgency).

Generated by scheduled /validate-schema run

Activity

  1. added
    priority-p1
    type-bug
    automated
    on Apr 24, 2026
  2. vybe commented on Apr 27, 2026

    @vybe
    ContributorAuthor

    Superseded by #529 (2026-04-27 run, 20 issues found — includes all issues from this report plus new ones).

  3. added
    complexity-medium
    theme-infrastructure
    on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    automatedcomplexity-mediumpriority-p1theme-infrastructuretype-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions