Skip to content

feat(code-reviewer) add council review type data model#4500

Open
St0rmz1 wants to merge 7 commits into
mainfrom
feat/council-data-model
Open

feat(code-reviewer) add council review type data model#4500
St0rmz1 wants to merge 7 commits into
mainfrom
feat/council-data-model

Conversation

@St0rmz1

@St0rmz1 St0rmz1 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds the data model and entitlement foundation for enterprise "council" (multi-specialist) code reviews. This does not run council reviews yet; it introduces the persisted shape, the review-run type, and a single enterprise-only entitlement gate so later PRs can build execution on top.

Changes

  • Migration 0182 adds two columns to cloud_agent_code_reviews: review_type (text NOT NULL DEFAULT 'standard') and nullable trigger_source. Reflected in packages/db/src/schema.ts and the generated snapshot/journal.
  • Adds council domain schemas in packages/db/src/schema-types.ts: CodeReviewType (standard | council), CodeReviewTriggerSource (manual | webhook), specialist roles, CouncilVote, CouncilAggregationStrategy, CouncilSpecialist, and CodeReviewCouncilConfig. Adds an optional council field to CodeReviewAgentConfigSchema.
  • Adds council-entitlement.ts with the entitlement predicate (isCouncilEntitledPlan, enterprise-only) and assertCouncilCreationAllowed, a single enforcement point that throws FORBIDDEN when a council review is created without entitlement. Local development bypasses the gate.
  • Wires assertCouncilCreationAllowed into both review-creation paths (createCodeReview and createCodeReviewIfAbsentInTransaction) and persists review_type / trigger_source via codeReviewInsertValues.
  • Extends CreateReviewParamsSchema with optional reviewType and triggerSource.
  • De-duplicates the wire contract in @kilocode/worker-utils/review-agents.ts to import CODE_REVIEW_TYPES and COUNCIL_AGGREGATION_STRATEGIES from @kilocode/db/schema-types, so the stored council config and the code-reviewer to cloud-agent wire contract share one source of truth.

Verification

  • No manual testing performed. This is data-model and entitlement plumbing with no execution path yet; covered by updating the existing code-review-status route test fixture. Migration 0182 is a metadata-only column add (constant default), so no backfill runs.

Visual Changes

N/A

Reviewer Notes

  • The aggregation_strategy enum intentionally omits weighted until per-specialist vote weights exist in the config.
  • The config-save entitlement guard (assertCouncilConfigAllowed) is intentionally deferred to the PR that adds a council config-save path, so it lands with its first caller instead of as an unused export. Running a council review is already gated at the creation boundary.
  • Council entitlement is enterprise-only and org-owned; personal owners are never entitled.

platform_project_id: params.platformProjectId ?? null,
manual_config: params.manualConfig ?? null,
review_type: params.reviewType ?? 'standard',
trigger_source: params.triggerSource ?? null,

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.

WARNING: New reviews discard their known trigger provenance

Every current production caller omits triggerSource, including manual jobs and the GitHub, GitLab, and Bitbucket webhook paths, so this fallback writes NULL for all new reviews. That makes known manual/webhook origins indistinguishable from legacy rows and leaves the new field unpopulated; have those creation paths pass manual or webhook explicitly.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 34a03ae. All five code-review creation paths now pass an explicit triggerSource, so new rows record their origin instead of writing NULL:

  • lib/code-reviews/manual-code-review-jobs.tsmanual
  • lib/integrations/platforms/github/webhook-handlers/pull-request-handler.tswebhook
  • lib/integrations/platforms/gitlab/webhook-handlers/merge-request-handler.tswebhook
  • lib/integrations/platforms/bitbucket/manual-code-review-trigger.tsmanual
  • app/api/webhooks/bitbucket/[integrationId]/route.tswebhook

The ?? null fallback in codeReviewInsertValues stays only as a safety net for any future/unknown caller. Regression coverage added: the GitHub and GitLab handler tests assert createCodeReview is called with triggerSource: 'webhook', and the Bitbucket webhook route test asserts the persisted row has trigger_source: 'webhook'. The latest review reflects this file as 0 issues.

@kilo-code-bot

kilo-code-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/db/src/migrations/0183_great_mercury.sql 1 Migration can block the live reviews table
Files Reviewed (19 files)
  • apps/web/src/app/api/internal/code-review-status/[reviewId]/route.test.ts - 0 issues
  • apps/web/src/app/api/webhooks/bitbucket/[integrationId]/route.test.ts - 0 issues
  • apps/web/src/app/api/webhooks/bitbucket/[integrationId]/route.ts - 0 issues
  • apps/web/src/lib/code-reviews/core/council-entitlement.test.ts - 0 issues
  • apps/web/src/lib/code-reviews/core/council-entitlement.ts - 0 issues
  • apps/web/src/lib/code-reviews/core/schemas.ts - 0 issues
  • apps/web/src/lib/code-reviews/db/code-reviews.ts - 0 issues
  • apps/web/src/lib/code-reviews/manual-code-review-jobs.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/bitbucket/manual-code-review-trigger.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/github/webhook-handlers/pull-request-handler.test.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/github/webhook-handlers/pull-request-handler.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/gitlab/webhook-handlers/merge-request-handler.test.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/gitlab/webhook-handlers/merge-request-handler.ts - 0 issues
  • packages/db/src/migrations/0183_great_mercury.sql - 1 issue
  • packages/db/src/migrations/meta/0183_snapshot.json - 0 issues
  • packages/db/src/migrations/meta/_journal.json - 0 issues
  • packages/db/src/schema-types.ts - 0 issues
  • packages/db/src/schema.ts - 0 issues
  • packages/worker-utils/src/review-agents.ts - 0 issues

Fix these issues in Kilo Cloud

Previous Review Summaries (2 snapshots, latest commit 34a03ae)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 34a03ae)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/lib/code-reviews/core/council-entitlement.ts 30 Enterprise plan label bypasses expired entitlement
packages/db/src/migrations/0183_great_mercury.sql 1 Migration can block the live reviews table
Files Reviewed (18 files)
  • apps/web/src/app/api/internal/code-review-status/[reviewId]/route.test.ts - 0 issues
  • apps/web/src/app/api/webhooks/bitbucket/[integrationId]/route.test.ts - 0 issues
  • apps/web/src/app/api/webhooks/bitbucket/[integrationId]/route.ts - 0 issues
  • apps/web/src/lib/code-reviews/core/council-entitlement.ts - 1 issue
  • apps/web/src/lib/code-reviews/core/schemas.ts - 0 issues
  • apps/web/src/lib/code-reviews/db/code-reviews.ts - 0 issues
  • apps/web/src/lib/code-reviews/manual-code-review-jobs.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/bitbucket/manual-code-review-trigger.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/github/webhook-handlers/pull-request-handler.test.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/github/webhook-handlers/pull-request-handler.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/gitlab/webhook-handlers/merge-request-handler.test.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/gitlab/webhook-handlers/merge-request-handler.ts - 0 issues
  • packages/db/src/migrations/0183_great_mercury.sql - 1 issue
  • packages/db/src/migrations/meta/0183_snapshot.json - 0 issues
  • packages/db/src/migrations/meta/_journal.json - 0 issues
  • packages/db/src/schema-types.ts - 0 issues
  • packages/db/src/schema.ts - 0 issues
  • packages/worker-utils/src/review-agents.ts - 0 issues

Fix these issues in Kilo Cloud

Previous review (commit c7cf98a)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/lib/code-reviews/db/code-reviews.ts 209 New reviews discard their known trigger provenance
Files Reviewed (10 files)
  • apps/web/src/app/api/internal/code-review-status/[reviewId]/route.test.ts - 0 issues
  • apps/web/src/lib/code-reviews/core/council-entitlement.ts - 0 issues
  • apps/web/src/lib/code-reviews/core/schemas.ts - 0 issues
  • apps/web/src/lib/code-reviews/db/code-reviews.ts - 1 issue
  • packages/db/src/migrations/0183_great_mercury.sql - 0 issues
  • packages/db/src/migrations/meta/0183_snapshot.json - 0 issues
  • packages/db/src/migrations/meta/_journal.json - 0 issues
  • packages/db/src/schema-types.ts - 0 issues
  • packages/db/src/schema.ts - 0 issues
  • packages/worker-utils/src/review-agents.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by gpt-5.6-sol-20260709 · Input: 138.9K · Output: 17.7K · Cached: 1.7M

Review guidance: REVIEW.md from base branch main

Comment thread apps/web/src/lib/code-reviews/core/council-entitlement.ts Outdated
@@ -0,0 +1,2 @@
ALTER TABLE "cloud_agent_code_reviews" ADD COLUMN "review_type" text DEFAULT 'standard' NOT NULL;--> statement-breakpoint

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.

**[WARNING]: Migration can block the live reviews table

Each ALTER TABLE needs an ACCESS EXCLUSIVE lock on the populated cloud_agent_code_reviews table. The constant default avoids a table rewrite on modern PostgreSQL, but the migration can still queue behind long-running traffic and then block all reads and writes when it acquires the lock. Use the repository's deployment-safe lock strategy, such as a short lock_timeout with retry or an explicitly controlled maintenance window.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not addressing this one, by design. A few reasons:

  1. No such convention exists in this repo. None of the 97+ ADD COLUMN migrations under packages/db/src/migrations/ use lock_timeout, SET LOCAL, or a retry wrapper — including main's own same-day 0182_powerful_blacklash.sql. There is no "repository deployment-safe lock strategy" to adopt here.

  2. It would violate a hard repo rule. packages/db/AGENTS.md: "Do not hand-write or edit generated DDL, snapshots, or journal entries." This SQL is Drizzle-generated; adding lock pragmas means editing generated DDL. Only intentional data backfills may be appended after the generated DDL.

  3. Not specific to this change. On our PostgreSQL, an ADD COLUMN with a constant default is a metadata-only operation, so the ACCESS EXCLUSIVE lock is held briefly. The 'queue behind a long-running transaction' risk applies identically to every ADD COLUMN migration in the repo; it's a fleet-wide operational/tooling posture, not something to bolt onto one feature migration.

If we want lock-safe migrations, that's a separate change to the migration tooling/convention that should apply to all migrations, tracked on its own.

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