Skip to content

fix(db): reconcile shared-state models with Supabase migrations - #2624

Draft
groupthinking wants to merge 3 commits into
mainfrom
fix/2169-reconcile-models-migrations
Draft

groupthinking wants to merge 3 commits into
mainfrom
fix/2169-reconcile-models-migrations

Conversation

@groupthinking

@groupthinking groupthinking commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Canonical issue

Closes #2664.

Refs #2169 (AUDIT-007). This reconciles shared-state SQL ownership and startup hardening; unmanaged legacy SQL and live migration application remain separate work. The broader audit must remain open.

Result

SharedSQLStateStore creates local SQLite tables and requires migrated PostgreSQL tables. Startup verifies the actual PostgreSQL security state, including legacy tables that already have every expected column:

  • Bind PostgreSQL runtime tables to public, matching the schema inspected even with a hostile search_path.
  • Require enabled and forced RLS, deny direct and inherited client privileges, reject client BYPASSRLS/superuser attributes, require server BYPASSRLS and effective grants, and secure serial sequences.
  • Keep SharedStateSchemaError within SQLAlchemyError so the separately narrowed optional-store setup boundary can degrade safely; unexpected construction bugs still propagate.
  • Document the plain-PostgreSQL role prerequisites without applying any role or schema changes externally.
  • Complete the inventory for performance_metrics_optimized and mcp_contexts and correct the index-tooling note.
  • Add isolated disposable PostgreSQL acceptance with read-only GitHub permissions and no deployment/database/provider secrets.
  • Integrate main 512a2558f73d6281b6a880548bedf140b7e30292; disable Vercel deployment for this exact review branch in both root and app configuration using git.deploymentEnabled.

Verified evidence — November 12, 2026

Current head: 2bd4aa5b1590bcd21a1911c1beecbc4bd2193864, tree 88dfebdc81dc3478dd8873b9532b3d5bb2d73895. The final follow-up changes only the migration documentation. Its application source is identical to hosted acceptance head 190fc17f7b38a19978094e08aaf3deac5f745c59.

Actual PostgreSQL 16.2 acceptance: 13/13 passed. GitHub run 43347589645, job 131630572786 records migration applied twice, dedicated server-role writes and fresh-store readback, rejection of legacy create_all security, disabled/unforced RLS, direct and inherited client grants, client BYPASSRLS and superuser, missing service grants, client sequence privileges, server without BYPASSRLS, and public-schema writes despite a hostile search_path. The runner verified no IP listener, then stopped and deleted its temporary database.

Local Python 3.12.14, pytest 9.2.0, SQLAlchemy 2.1.8:

env -u DATABASE_URL -u EVENTRELAY_SHARED_STATE_DATABASE_URL PYTHONPATH=src python -m pytest tests/unit/test_schema_inventory.py tests/unit/test_shared_sql_state.py tests/unit/test_agent_orchestrator.py tests/unit/test_session_orchestration.py -o addopts='' -o log_cli=false -q

101 passed, 1 skipped, exit 0. The skip is the separate environment-gated PostgreSQL unit test; the hosted acceptance above independently used real PostgreSQL. Five initial new hardening regressions failed against the old source. PostgreSQL catalog SQL parses; whitespace and script compile checks pass. Independent review identified schema-shadowing/inherited-ACL gaps; these corrections and the hosted acceptance cover them.

Combined #2624/#2626/#2628 source validation: 208 passed, 1 skipped, exit 0. SharedStateSchemaError degradation was directly checked without database access. A separate combined deployment/classifier regression confirms failed Vercel work preserves GitHub provenance and returns failure; the fully successful positive control remains successful. Local suites retain one pre-existing unawaited-AsyncMock warning.

Remaining gates and production

Keep draft, unmerged and undeployed. Current-head hosted CI/security and the issue-link gate remain active. This does not apply migrations to Supabase or any production database; application of the checked-in migration remains a deliberate authorized human step. The initial local PostgreSQL attempt was blocked by Unix-socket permissions, and was replaced by the successful hosted acceptance above. No production, paid extraction, provider execution or deployment acceptance is claimed.

- Add apps/web/supabase/migrations/20261109062000_create_service_role_shared_state_tables.sql
  for shared_sessions, shared_timeline_events and shared_a2a_messages, matching the
  SQLAlchemy tables exactly; idempotent; RLS enabled and forced, service_role only.
- SharedSQLStateStore: create_all only on SQLite; on Postgres verify tables/columns and
  raise SharedStateSchemaError naming the migration.
- Add docs/schema_inventory.json and update docs/MIGRATION_TRUTH.md.
- Add tests/unit/test_schema_inventory.py (migration vs model drift, forced RLS) and
  tests/unit/test_shared_sql_state.py.

Refs #2169
Copilot AI max review requested due to automatic review settings November 9, 2026 06:24
@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
v0-uvai Ready Ready Preview, v0 Nov 9, 2026 6:24am UTC

@linear-code
linear-code Bot marked this pull request as ready for review November 9, 2026 06:24
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added documentation Improvements or additions to documentation python labels Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🔍 PR Validation

⚠️ Large PR detected (1014 lines changed)

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ Repository reconciliation: this PR does not reference exactly one canonical issue.

Please add a Closes #<issue> reference in the PR description so it can be tracked against the delivery plan.

See governance: #898

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

✅ E2E Test Results: ALL TESTS PASSED

Metric Value
Status 🟢 GREEN
Total Tests
Passed 16
Failed
Deployment https://v0-uvai-8sukae215-garv1.vercel.app
Test Output
very request without persisting it�[32m 1�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mTemplate Gallery�[2m > �[22mhomepage returns 200 with HTML�[32m 207�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mTemplate Gallery�[2m > �[22mfeatures page contains template/workflow markup�[33m 352�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mTemplate Gallery�[2m > �[22mfeatures page surfaces at least 5 workflow/template indicators�[33m 439�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mVideo Pack Pipeline�[2m > �[22mPOST /api/video/pack accepts a YouTube URL without hanging�[33m 2146�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mVideo Pack Pipeline�[2m > �[22mGET /api/video/pack resolves to a ready pack with evidence lineage�[33m 805�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mError Handling�[2m > �[22mmissing URL returns 400, not a hang�[32m 203�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mError Handling�[2m > �[22minvalid URL returns 400 quickly, not a hang�[32m 187�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mError Handling�[2m > �[22mPOST /api/video/pack with no body returns 400�[32m 182�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mDashboard�[2m > �[22m/dashboard returns 200�[32m 290�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mDashboard�[2m > �[22m/dashboard contains agent or pipeline visualization markup�[32m 255�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mAPI Health�[2m > �[22mGET /api returns a response (not 404)�[33m 302�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mAPI Health�[2m > �[22mretired /api/pipeline routes are gone (no pipeline served)�[32m 100�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mStatic Assets�[2m > �[22mhomepage has proper meta tags�[32m 188�[2mms�[22m�[39m
 �[32m✓�[39m tests/e2e/pipeline.test.ts�[2m > �[22mEventRelay E2E — Live Deployment�[2m > �[22mStatic Assets�[2m > �[22m/features page returns 200�[33m 489�[2mms�[22m�[39m

�[2m Test Files �[22m �[1m�[32m1 passed�[39m�[22m�[90m (1)�[39m
�[2m      Tests �[22m �[1m�[32m16 passed�[39m�[22m�[90m (16)�[39m
�[2m   Start at �[22m 06:25:16
�[2m   Duration �[22m 7.89s�[2m (transform 40ms, setup 0ms, import 51ms, tests 7.75s, environment 0ms)�[22m


Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The schema check accepts unhardened legacy PostgreSQL tables, allowing initialization without required RLS and restricted grants despite the documented fail-closed guarantee.

3 open issues
What changed in this PR

This PR establishes checked-in migration ownership for shared session and agent-message storage in EventRelay, UVAI’s internal runtime, addressing schema drift tracked in #2169.

Changes:

  • Adds a Supabase migration for three shared-state tables, with forced row-level security and service-role-only grants.
  • Keeps automatic table creation on SQLite while checking table and column presence on other databases.
  • Adds schema inventory and persistence tests, and documents ownership, access requirements, unresolved sources, and manual deployment steps.
File Description
tests/​unit/​test_shared_sql_state.py Tests SQLite persistence, schema checks, and opt-in PostgreSQL behavior.
tests/​unit/​test_schema_inventory.py Checks inventory paths, model/migration alignment, and security declarations.
src/​youtube_extension/​services/​shared_sql_state.py Restricts automatic schema creation to SQLite and adds validation elsewhere.
docs/​schema_inventory.json Maps tables to migrations and records unreconciled SQL sources.
docs/​MIGRATION_TRUTH.md Documents schema ownership, access rules, and deployment requirements.
apps/​web/​supabase/​migrations/​20261109062000_create_service_role_shared_state_tables.sql Defines shared-state tables, indexes, forced row-level security, and restricted grants.

Review effort: Max

Comment thread docs/schema_inventory.json Resolved
@groupthinking
groupthinking marked this pull request as draft November 13, 2026 01:48
Check public schema, forced RLS, effective client access, server role attributes/grants, serial ACLs, and expected schema-error type. Document plain PostgreSQL prerequisites and complete inventory. Add disposable PostgreSQL acceptance CI and disable this exact branch deployment.

Refs #2169
@github-actions github-actions Bot added the ci/cd label Nov 13, 2026
All 13 disposable PostgreSQL 16.2 security/persistence cases passed in run 43347589645 on the unchanged application source. Production migration remains a separate human step.

Refs #2169

This branch was successfully deployed

1 active (outdated) deployment
Preview — cfeeaa68 Deployed Nov 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/cd documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate shared-state PostgreSQL security and migration access

3 participants