Skip to content

Revert "Revert "Revert "fix: scope sub_agent_skills unique constraint to tenant/project/agent"""#2215

Merged
amikofalvy merged 1 commit into
mainfrom
revert-2207-revert-2205-revert-2190-fix/sub-agent-skills-unique-constraint
Feb 20, 2026
Merged

Revert "Revert "Revert "fix: scope sub_agent_skills unique constraint to tenant/project/agent"""#2215
amikofalvy merged 1 commit into
mainfrom
revert-2207-revert-2205-revert-2190-fix/sub-agent-skills-unique-constraint

Conversation

@amikofalvy
Copy link
Copy Markdown
Collaborator

Reverts #2207

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 20, 2026

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

Project Deployment Actions Updated (UTC)
agents-api Ready Ready Preview, Comment Feb 20, 2026 8:16am
agents-docs Ready Ready Preview, Comment Feb 20, 2026 8:16am
agents-manage-ui Ready Ready Preview, Comment Feb 20, 2026 8:16am

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 20, 2026

⚠️ No Changeset found

Latest commit: 123ee38

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@amikofalvy amikofalvy merged commit 7847ae1 into main Feb 20, 2026
4 of 9 checks passed
@amikofalvy amikofalvy deleted the revert-2207-revert-2205-revert-2190-fix/sub-agent-skills-unique-constraint branch February 20, 2026 08:12
Copy link
Copy Markdown
Contributor

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

PR Review Summary

(3) Total Issues | Risk: High

⚠️ Note: This PR has already been merged. This review documents identified concerns for awareness and potential follow-up.

🔴❗ Critical (1) ❗🔴

Inline Comments:

  • 🔴 Critical: manage-schema.ts:293 Cross-tenant data isolation gap — unique constraint (subAgentId, skillId) lacks tenant scoping, allowing one tenant's configuration to block another tenant from using the same ID combination

🟠⚠️ Major (1) 🟠⚠️

🟠 1) subAgentSkills.cross-tenant.test.ts Deleted regression test removes multi-tenant isolation coverage

Issue: The deleted test file contained explicit validation that different tenants CAN use the same (subAgentId, skillId) combination without constraint violations, and that the same tenant/agent CANNOT create duplicates. This was a regression test for the original fix in PR #2190.

Why: Without this test, future changes could reintroduce the same isolation bug without any automated detection. The remaining subAgentSkills.scoping.test.ts tests query-level scoping, not constraint-level uniqueness behavior.

Fix: If the narrower constraint is intentional and permanent, document why cross-tenant collision is acceptable for this table. If not intentional, restore the test along with the tenant-scoped constraint in a follow-up PR.

Refs:

🟡 Minor (1) 🟡

🟡 1) 0010_oval_angel.sql Migration file deletion may cause schema drift

Issue: The migration that widened the unique constraint was deleted rather than rolled back via a new migration. If any database environment (staging, production) applied migration 0010 before this revert, those databases now have the tenant-scoped constraint while the schema file claims the narrower constraint.

Why: Schema drift between Drizzle-managed schema and actual database state can cause unexpected db:check or db:generate results, and potentially silent data integrity issues.

Fix: Verify whether migration 0010 was ever applied to any persistent environment. If so, create a rollback migration (0011) to explicitly revert the constraint change. Document the verification in the PR or follow-up issue.

Refs:

  • data-model-changes skill — "NEVER edit existing migration SQL files after they've been applied - create new migrations instead"

💡 APPROVE WITH SUGGESTIONS

Summary: This PR has already been merged, so this review serves as documentation. The primary concern is a multi-tenant data isolation gap: the narrowed unique constraint (subAgentId, skillId) allows one tenant's configuration choices to block another tenant from using the same ID combination. This appears to be an operational compromise (the revert chain suggests migration difficulties) rather than an intentional architectural decision.

Recommended follow-up:

  1. File an issue to track re-implementing the tenant-scoped constraint with a reliable migration strategy
  2. Verify no cross-tenant collisions exist in production data
  3. Consider whether sub_agent_id generation should use globally unique IDs (e.g., nanoid) to mitigate the risk
Discarded (2)
Location Issue Reason Discarded
manage-schema.ts Inconsistent uniqueness pattern across join tables Other join tables (subAgentToolRelations, etc.) intentionally lack unique constraints to allow different configurations via different id values. The pattern inconsistency is acceptable given different use cases.
_journal.json Migration journal may be inconsistent Journal correctly shows no entry for migration 0010, indicating proper handling via pnpm db:drop or equivalent.
Reviewers (5)
Reviewer Returned Main Findings Consider While You're Here Inline Comments Pending Recs Discarded
pr-review-security-iam 1 0 0 0 1 0 0
pr-review-architecture 4 1 0 0 0 0 1
pr-review-breaking-changes 3 1 0 0 0 0 1
pr-review-tests 2 0 0 0 0 0 0
pr-review-standards 1 0 0 0 0 0 0
Total 11 2 0 0 1 0 2

Note: Findings from multiple reviewers merged due to overlapping identification of the same cross-tenant isolation issue.

table.subAgentId,
table.skillId
),
unique('sub_agent_skills_sub_agent_skill_unique').on(table.subAgentId, table.skillId),
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.

🔴 CRITICAL: Cross-tenant data isolation gap in unique constraint

Issue: The unique constraint (subAgentId, skillId) lacks tenant scoping. Since subAgentId is scoped per-agent (not globally unique via the PK at line 282) and skillId is scoped per-project (FK at line 288-291), different tenants using the same subAgentId and skillId combination will collide at the database level.

Why: This is a multi-tenant isolation bug. If Tenant A creates a sub_agent_skill with (subAgentId='qa-agent', skillId='summarize'), Tenant B cannot create the same logical combination in their own project — the database will reject it with a unique constraint violation. This violates tenant isolation and could cause one tenant's configuration choices to affect another tenant's ability to configure their agents.

Fix: The constraint should include tenant scoping columns to match the FK patterns used elsewhere in the table:

unique('sub_agent_skills_sub_agent_skill_unique').on(
  table.tenantId,
  table.projectId,
  table.agentId,
  table.subAgentId,
  table.skillId
)

Refs:

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