Skip to content

feat(code-reviews): add manual jobs#4273

Open
alex-alecu wants to merge 3 commits into
mainfrom
chore/local-testing-code-reviews
Open

feat(code-reviews): add manual jobs#4273
alex-alecu wants to merge 3 commits into
mainfrom
chore/local-testing-code-reviews

Conversation

@alex-alecu

Copy link
Copy Markdown
Contributor

Summary

Manual Code Reviewer jobs can now be started from the Jobs card for personal users and organizations. In normal environments, jobs use the connected GitHub or GitLab account and post results back to the change. In local development, jobs can review public GitHub and GitLab changes without provider credentials and show the result in Kilo only.

Verification

  1. In local development, enable the dev UI, open Code Reviewer, start a job from a public GitHub or GitLab URL, and confirm the result appears in Kilo without provider comments.
  2. With a connected GitHub or GitLab account, start a manual job from the Jobs card and confirm the review posts back to the change.
  3. Retry or cancel a local manual job and confirm it stays read-only and never gains provider credentials.

Visual Changes

N/A

Reviewer Notes

Manual jobs store their model, effort, instructions, and output mode on the job so retries keep the same behavior. Local jobs are intentionally limited to explicit local development and public github.com or gitlab.com changes.

);

export const organizationReviewAgentRouter = createTRPCRouter({
createManualReviewJob: organizationMemberMutationProcedure

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: Manual review creation skips organization billing enforcement

This new mutation uses organizationMemberMutationProcedure, unlike the other organization code-review write paths in this router that go through organizationBillingMutationProcedure. As a result, members can start manual review jobs even when the organization is blocked by subscription or billing checks, which is a permission regression for a capacity-consuming action.


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.

No change needed. This path still checks that the org has an active plan, and using the billing-only path would stop regular members from starting jobs.

@@ -0,0 +1,8 @@
DROP INDEX "UQ_cloud_agent_code_reviews_repo_pr_sha";--> statement-breakpoint
ALTER TABLE "cloud_agent_code_reviews" ADD COLUMN "manual_config" jsonb;--> statement-breakpoint
CREATE UNIQUE INDEX "UQ_cloud_agent_code_reviews_webhook_integration_repo_pr_sha" ON "cloud_agent_code_reviews" USING btree ("platform_integration_id","repo_full_name","pr_number","head_sha") WHERE "cloud_agent_code_reviews"."manual_config" IS 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: Non-concurrent indexes will block writes on a hot table

cloud_agent_code_reviews is already populated and written continuously by the review queue. Building these four unique indexes with plain CREATE UNIQUE INDEX takes a write-blocking lock for the duration of each build, so deploying this migration can stall or fail live review creation and status updates. These indexes need to be created concurrently in a separate migration step.


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.

Done in caeef16.

@kilo-code-bot

kilo-code-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

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

WARNING

File Line Issue
packages/db/src/migrations/0174_smiling_shadow_king.sql 3 Committing before the replacement unique indexes finish opens a duplicate window
Files Reviewed (9 files)
  • apps/web/src/components/code-reviews/CodeReviewJobsCard.tsx - 0 issues
  • apps/web/src/lib/code-reviews/db/code-reviews.test.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/routers/code-reviews-router.test.ts - 0 issues
  • packages/db/src/migrations/0174_smiling_shadow_king.sql - 1 issue
  • packages/db/src/migrations/meta/0174_snapshot.json - 0 issues
  • packages/db/src/migrations/meta/_journal.json - 0 issues
  • packages/db/src/schema.ts - 0 issues
Previous Review Summaries (2 snapshots, latest commit caeef16)

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

Previous review (commit caeef16)

Status: 1 Issue Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

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

WARNING

File Line Issue
packages/db/src/migrations/0174_high_the_spike.sql 3 Committing before the replacement unique indexes finish opens a duplicate window
Files Reviewed (5 files)
  • packages/db/src/migrations/0174_brainy_vapor.sql - 0 issues
  • packages/db/src/migrations/0174_high_the_spike.sql - 1 issue
  • packages/db/src/migrations/meta/0174_snapshot.json - 0 issues
  • packages/db/src/migrations/meta/_journal.json - 0 issues
  • packages/db/src/schema.ts - 0 issues

Previous review (commit 72fcba5)

Status: 2 Issues Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

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

WARNING

File Line Issue
apps/web/src/routers/organizations/organization-code-reviews-router.ts 78 Manual review creation skips organization billing enforcement
packages/db/src/migrations/0174_brainy_vapor.sql 3 Non-concurrent indexes will block writes on a hot table
Files Reviewed (31 files)
  • apps/web/src/app/(app)/code-reviews/ReviewAgentPageClient.tsx - 0 issues
  • apps/web/src/app/(app)/code-reviews/page.tsx - 0 issues
  • apps/web/src/app/(app)/organizations/[id]/code-reviews/ReviewAgentPageClient.tsx - 0 issues
  • apps/web/src/app/(app)/organizations/[id]/code-reviews/page.tsx - 0 issues
  • apps/web/src/app/api/internal/code-review-status/[reviewId]/route.test.ts - 0 issues
  • apps/web/src/app/api/internal/code-review-status/[reviewId]/route.ts - 0 issues
  • apps/web/src/components/code-reviews/CodeReviewJobsCard.tsx - 0 issues
  • apps/web/src/components/code-reviews/CodeReviewStreamView.tsx - 0 issues
  • apps/web/src/lib/code-reviews/core/schemas.ts - 0 issues
  • apps/web/src/lib/code-reviews/db/code-reviews.test.ts - 0 issues
  • apps/web/src/lib/code-reviews/db/code-reviews.ts - 0 issues
  • apps/web/src/lib/code-reviews/dispatch/dispatch-pending-reviews.test.ts - 0 issues
  • apps/web/src/lib/code-reviews/dispatch/dispatch-pending-reviews.ts - 0 issues
  • apps/web/src/lib/code-reviews/manual-code-review-jobs.ts - 0 issues
  • apps/web/src/lib/code-reviews/manual-config.ts - 0 issues
  • apps/web/src/lib/code-reviews/prompts/generate-prompt.ts - 0 issues
  • apps/web/src/lib/code-reviews/session-log.ts - 0 issues
  • apps/web/src/lib/code-reviews/triggers/prepare-review-payload.test.ts - 0 issues
  • apps/web/src/lib/code-reviews/triggers/prepare-review-payload.ts - 0 issues
  • apps/web/src/lib/config.server.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/adapter.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/gitlab/webhook-handlers/merge-request-handler.ts - 0 issues
  • apps/web/src/routers/code-reviews-router.ts - 0 issues
  • apps/web/src/routers/code-reviews/code-reviews-router.ts - 0 issues
  • apps/web/src/routers/organizations/organization-code-reviews-router.ts - 1 issue
  • packages/db/src/migrations/0174_brainy_vapor.sql - 1 issue
  • packages/db/src/migrations/meta/0174_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

Reviewed by gpt-5.4-20260305 · Input: 94.7K · Output: 12.4K · Cached: 474.9K

Review guidance: REVIEW.md from base branch main

Comment on lines +4 to +6
CREATE UNIQUE INDEX "UQ_cloud_agent_code_reviews_manual_user_repo_pr_sha" ON "cloud_agent_code_reviews" USING btree ("owned_by_user_id","repo_full_name","pr_number","head_sha") WHERE "cloud_agent_code_reviews"."manual_config" IS NOT NULL AND "cloud_agent_code_reviews"."owned_by_user_id" IS NOT NULL;--> statement-breakpoint
CREATE UNIQUE INDEX "UQ_cloud_agent_code_reviews_manual_org_repo_pr_sha" ON "cloud_agent_code_reviews" USING btree ("owned_by_organization_id","repo_full_name","pr_number","head_sha") WHERE "cloud_agent_code_reviews"."manual_config" IS NOT NULL AND "cloud_agent_code_reviews"."owned_by_organization_id" IS NOT NULL;--> statement-breakpoint
CREATE UNIQUE INDEX "UQ_cloud_agent_code_reviews_active_provider_publisher" ON "cloud_agent_code_reviews" USING btree ("platform_integration_id","repo_full_name","pr_number") WHERE "cloud_agent_code_reviews"."platform_integration_id" IS NOT NULL

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.

@kilocode-bot do we really need new indexes just because we added manual_config ?

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.

Yes, the new indexes are genuinely needed — but it's deeper than just "a new column was added." Here's the breakdown:

Why the old index had to be dropped

The original UQ_cloud_agent_code_reviews_repo_pr_sha was a global unique key on (repo_full_name, pr_number, head_sha). That breaks once manual jobs exist, because:

  • A webhook-driven review and a manual review of the same commit can legitimately coexist.
  • Different users can each manually review the same public PR at the same SHA (local dev mode). The old index would cause the second user's job to collide.

Why 4 partial indexes instead of 1

The feature introduces multiple distinct identity scopes, and the unique key column differs per scope:

Index Enforces
..._webhook_integration_repo_pr_sha One webhook review per integration + repo/pr/sha
..._manual_user_repo_pr_sha One manual review per user + repo/pr/sha
..._manual_org_repo_pr_sha One manual review per org + repo/pr/sha
..._active_provider_publisher At most one active review posting back to the provider per integration + repo/PR (no sha — prevents concurrent comment threads)

The 4th index is the most important for correctness — it prevents two jobs from simultaneously writing to the same GitHub/GitLab PR comment thread, even at different SHAs.

One minor simplification possible

The two manual indexes (user + org) could be merged into a single WHERE manual_config IS NOT NULL index using COALESCE(owned_by_user_id::text, owned_by_organization_id::text) as the key, since the owner_check constraint already guarantees only one is set. The current two-index form is more explicit and readable though — reasonable tradeoff.

Bottom line: The split is justified by the feature's semantics, not index bloat. The only real simplification would be merging the two manual owner indexes into one.

@@ -0,0 +1,10 @@
DROP INDEX "UQ_cloud_agent_code_reviews_repo_pr_sha";--> statement-breakpoint
ALTER TABLE "cloud_agent_code_reviews" ADD COLUMN "manual_config" jsonb;--> statement-breakpoint
COMMIT;--> 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: Committing before the replacement unique indexes finish opens a duplicate window

This COMMIT makes the drop of UQ_cloud_agent_code_reviews_repo_pr_sha visible before any of the new scoped unique indexes exist. Because cloud_agent_code_reviews is still accepting writes while lines 4-7 build concurrently, duplicate review rows can slip in for the same webhook/manual identity, which can then make one of the new unique index builds fail or leave bad duplicates behind if the migration is retried.


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

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