Skip to content

feat(bitbucket): add Code Reviewer support#4291

Open
eshurakov wants to merge 5 commits into
mainfrom
faceted-plank
Open

feat(bitbucket): add Code Reviewer support#4291
eshurakov wants to merge 5 commits into
mainfrom
faceted-plank

Conversation

@eshurakov

Copy link
Copy Markdown
Contributor

Summary

  • Adds Bitbucket Code Reviewer support across web, worker, git-token-service, code-review infra, and wrapper CLI.
  • Installs workspace webhooks using supported Bitbucket pull request events, verifies signed delivery, queues reviews, and publishes inline Code Review Findings through batch comments.
  • Cleans up Bitbucket Code Reviewer state, queued/running reviews, and workspace webhooks when Code Reviewer is disabled or a Workspace Access Token is disconnected.

Verification

N/A

Visual Changes

N/A

Reviewer Notes

Review focus: Bitbucket webhook lifecycle, command guard allowlist, and integration disconnect cleanup.

Comment thread services/cloud-agent-next/src/session-service.ts Fixed
DROP INDEX "UQ_cloud_agent_code_reviews_repo_pr_sha";--> statement-breakpoint
ALTER TABLE "cloud_agent_code_reviews" ADD COLUMN "platform_repository_id" text;--> statement-breakpoint
ALTER TABLE "cloud_agent_code_reviews" ADD COLUMN "platform_workspace_id" text;--> statement-breakpoint
CREATE UNIQUE INDEX "UQ_cloud_agent_code_reviews_user_identity" ON "cloud_agent_code_reviews" USING btree ("owned_by_user_id","platform","platform_integration_id","platform_repository_id","pr_number","head_sha") WHERE "cloud_agent_code_reviews"."owned_by_user_id" is 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: New uniqueness is inactive until the backfill runs

platform_repository_id is still NULL for every existing row when these indexes are created, and Postgres unique indexes treat NULL values as distinct. Because line 1 drops the old repo/PR/head uniqueness first, a rolling deploy can insert duplicate reviews until the UPDATE at lines 7-13 populates this column. Populate/backfill the new identity before replacing the old uniqueness constraint.


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

"store_id": "342a86d9e3a94da698e82d0c6e2a36f0",
"secret_name": "BITBUCKET_OAUTH_CREDENTIAL_ACTIVE_KEY_ID_PROD",
},
],

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: BITBUCKET_OAUTH_CREDENTIAL_ACTIVE_KEY_ID is still required at runtime

BitbucketWorkspaceAccessTokenAuthorizationService.decrypt() still reads env.BITBUCKET_OAUTH_CREDENTIAL_ACTIVE_KEY_ID to unwrap stored workspace tokens. Removing the binding here, and again under env.dev, leaves that env unset in deployed workers, so Bitbucket code-review lookups will fall back to secret_missing / temporarily_unavailable. Keep the binding or add an equivalent vars entry before shipping this config change.


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

@kilo-code-bot

kilo-code-bot Bot commented Jun 28, 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
services/cloud-agent-next/src/types.ts 52 parseCanonicalBitbucketCloneUrl() now accepts ssh:// URLs, which broadens Bitbucket code-review admission past the repo's canonical HTTPS clone-url contract.

Fix these issues in Kilo Cloud

Files Reviewed (3 files)
  • services/cloud-agent-next/src/session-service.test.ts - 0 issues
  • services/cloud-agent-next/src/session-service.ts - 0 issues
  • services/cloud-agent-next/src/types.ts - 1 issue
Previous Review Summaries (4 snapshots, latest commit a01f56b)

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

Previous review (commit a01f56b)

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
packages/db/src/migrations/0174_absent_rumiko_fujikawa.sql 13 The new unique indexes are still created without CONCURRENTLY, so this migration can block writes on the populated cloud_agent_code_reviews table during deploy.
services/cloud-agent-next/src/session-service.ts 1107 The SSH fallback only covers scp-style git@host:path clone URLs; valid ssh://git@... GitLab and Bitbucket URLs still return undefined, so those legacy sessions keep missing the provider env vars they rely on.

Fix these issues in Kilo Cloud

Files Reviewed (3 files)
  • packages/db/src/migrations/0174_absent_rumiko_fujikawa.sql - 1 issue
  • services/cloud-agent-next/src/session-service.ts - 1 issue
  • services/cloud-agent-next/src/session-service.test.ts - 0 issues

Previous review (commit a3e5861)

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
packages/db/src/migrations/0174_absent_rumiko_fujikawa.sql 13 The new unique indexes are still created without CONCURRENTLY, so this migration can block writes on the populated cloud_agent_code_reviews table during deploy.
services/cloud-agent-next/src/session-service.ts 1107 Restricting fallback inference to https: URLs drops legacy SSH GitLab and Bitbucket clone URLs, so platform-less sessions stop receiving the provider env vars they still rely on.

Fix these issues in Kilo Cloud

Files Reviewed (4 files)
  • packages/db/src/migrations/0174_absent_rumiko_fujikawa.sql - 1 issue
  • services/cloud-agent-next/src/session-service.ts - 1 issue
  • services/cloud-agent-next/src/session-service.test.ts - 0 issues
  • services/git-token-service/wrangler.jsonc - 0 issues

Previous review (commit f642092)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • apps/web/src/lib/cloud-agent/bitbucket-integration-helpers.ts

Previous review (commit 15e3d51)

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
packages/db/src/migrations/0174_absent_rumiko_fujikawa.sql 4 Replacement unique indexes are created before platform_repository_id is backfilled, so duplicate reviews can slip through while the new key column is still NULL.
services/git-token-service/wrangler.jsonc 61 The BITBUCKET_OAUTH_CREDENTIAL_ACTIVE_KEY_ID binding was removed even though runtime decryption still requires it, which leaves Bitbucket review lookups unavailable after deploy.

Fix these issues in Kilo Cloud

Files Reviewed (123 files)
  • packages/db/src/migrations/0174_absent_rumiko_fujikawa.sql - 1 issue
  • services/git-token-service/wrangler.jsonc - 1 issue
  • Remaining 121 changed files reviewed with no additional high-confidence findings

Reviewed by gpt-5.4-20260305 · Input: 125.3K · Output: 9.9K · Cached: 793.3K

Review guidance: REVIEW.md from base branch main

WHERE "platform_repository_id" IS NULL;
--> statement-breakpoint
DROP INDEX "UQ_cloud_agent_code_reviews_repo_pr_sha";--> statement-breakpoint
CREATE UNIQUE INDEX "UQ_cloud_agent_code_reviews_user_identity" ON "cloud_agent_code_reviews" USING btree ("owned_by_user_id","platform","platform_integration_id","platform_repository_id","pr_number","head_sha") WHERE "cloud_agent_code_reviews"."owned_by_user_id" is 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: These unique indexes still lock a populated table during deploy

The UPDATE immediately above backfills existing rows, so cloud_agent_code_reviews is already populated when these indexes are built. Creating them without CONCURRENTLY will block concurrent writes for the duration of the index build, which is the table-locking migration pattern we try to avoid on live tables.


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

return undefined;
}

if (url.protocol !== 'https:') return undefined;

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: SSH clone URLs stop getting legacy GitLab or Bitbucket env setup

parseSessionMetadata() still accepts legacy gitUrl strings verbatim, including SSH forms like git@gitlab.com:group/repo.git. With the new https: gate here, platform-less legacy sessions now fall back to effectivePlatform === undefined, so the GitLab or Bitbucket env vars stop being injected even though the old substring fallback handled those stored clone URLs.


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

if (url.hostname !== 'bitbucket.org' || url.port || url.search || url.hash) return null;
if (url.protocol === 'https:') {
if (url.username || url.password) return null;
} else if (url.protocol === 'ssh:') {

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: parseCanonicalBitbucketCloneUrl() no longer enforces the canonical HTTPS clone-URL contract

This helper also backs Bitbucket code-review admission in router/schemas.ts, so accepting ssh://git@bitbucket.org/... here now lets new review sessions through with non-canonical clone URLs. The rest of the repo still treats SSH Bitbucket clone URLs as invalid canonical identities, so this creates a mismatch between session admission and downstream URL validation.


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.

2 participants