Skip to content

feat(server): add tenant scaffolding and targets schema (1/7)#178

Draft
abhinav-galileo wants to merge 1 commit intomainfrom
abhi/rfc-1-1-pr1-tenant-targets
Draft

feat(server): add tenant scaffolding and targets schema (1/7)#178
abhinav-galileo wants to merge 1 commit intomainfrom
abhi/rfc-1-1-pr1-tenant-targets

Conversation

@abhinav-galileo
Copy link
Copy Markdown
Collaborator

@abhinav-galileo abhinav-galileo commented Apr 20, 2026

Summary

  • Adds additive tenant_id scaffolding (String(64), default "default-tenant") to agents, controls, policies, agent_controls, agent_policies, with DB-level server_default so unscoped writes keep working.
  • Adds new targets and target_controls tables for attaching controls to typed, tenant-scoped targets (e.g. a log stream).
  • Backfills existing rows to the default tenant and flips columns to NOT NULL.
  • Behavior-preserving: read paths remain unscoped; new target tables exist but are not yet wired into runtime resolution or management APIs.

Intentional deviations and decisions

  • target_type instead of bare type for clarity and to avoid shadowing Python's builtin.
  • policy_controls.tenant_id omitted: tenant scope is inherited transitively via policy_id / control_id.
  • tenant_id indexes omitted: read paths are unscoped in this phase, so an index would carry write cost for no benefit. Add alongside the PR that introduces tenant-scoped reads.
  • FK cascades on target_controls: target_id uses ON DELETE CASCADE (attachment has no meaning without the target); control_id uses the default restrictive behavior so control deletion does not silently fan into attachments.

Deferrals

  • updated_at on new tables: omitted - no live repo pattern for automatic maintenance. Defer until a pattern is chosen repo-wide.
  • control_execution_events.tenant_id: deferred; observability tables are out of scope here.
  • tenants table, target_targets DAG, tenant-scoped uniqueness on agent/control/policy names, lazy target upsert, runtime resolution, SDK/UI changes: all deferred to follow-up PRs.

Test plan

  • make check clean locally (lint + mypy + tests across all packages)
  • New migration tests cover: backfill correctness across all 5 tables, new table creation with uniqueness, post-migration server_default behavior, downgrade completeness
  • New ORM tests cover: Target / TargetControl round-trip, (tenant_id, target_type, external_id) uniqueness, (target_id, control_id) uniqueness, ON DELETE CASCADE behavior, implicit default tenant on unscoped writes for Agent / Control / Policy

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Additive, behavior-preserving. tenant_id defaults to 'default-tenant' and
is inert in this phase; new target tables exist but are not yet wired into
runtime resolution or management APIs.
@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr1-tenant-targets branch from a79bcbb to 6ea16b3 Compare April 20, 2026 19:39
@abhinav-galileo abhinav-galileo changed the title feat(server): RFC 1.1 PR1 - tenant scaffolding + targets schema feat(server): add tenant scaffolding and targets schema (1/4) Apr 20, 2026
@abhinav-galileo abhinav-galileo changed the title feat(server): add tenant scaffolding and targets schema (1/4) feat(server): add tenant scaffolding and targets schema (1/5) Apr 20, 2026
@abhinav-galileo abhinav-galileo changed the title feat(server): add tenant scaffolding and targets schema (1/5) feat(server): add tenant scaffolding and targets schema (1/6) Apr 20, 2026
@abhinav-galileo abhinav-galileo changed the title feat(server): add tenant scaffolding and targets schema (1/6) feat(server): add tenant scaffolding and targets schema (1/7) Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant