Skip to content

feat(code-reviews): incremental reviews on follow-up pushes#927

Open
alex-alecu wants to merge 14 commits intomainfrom
feat/code-review-on-push
Open

feat(code-reviews): incremental reviews on follow-up pushes#927
alex-alecu wants to merge 14 commits intomainfrom
feat/code-review-on-push

Conversation

@alex-alecu
Copy link
Contributor

@alex-alecu alex-alecu commented Mar 9, 2026

Summary

On follow-up pushes, code reviews was starting completely from scratch — re-reading every file, re-analyzing everything. This PR adds incremental mode: when a previous completed review exists for the same PR, the agent gets the old summary + inline comments + previous HEAD SHA so it can git diff only what changed.

  • New DB query findPreviousCompletedReview to find the last completed review SHA
  • New incrementalReviewWorkflow prompt section in both GitHub and GitLab templates
  • generateReviewPrompt swaps in the incremental workflow when conditions are met
  • prepareReviewPayload checks the code-review-incremental feature flag, looks up the previous SHA, and passes it through
  • Falls back to full review when: flag is off, no prior completed review, no summary comment, or force push broke history

Test plan

  • Unit tests for generateReviewPrompt with and without previousHeadSha (7 new tests)
  • Type check passes
  • Lint passes
  • Existing tests still pass
  • Manual: create PR, push, wait for review, push again — verify incremental prompt is generated
  • Manual: verify force push fallback works (agent falls back to gh pr diff)

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 9, 2026

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
src/lib/code-reviews/triggers/prepare-review-payload.ts 318 Incremental rollout uses the shared server-config-fetch distinct ID, so PostHog targeting applies globally instead of per owner.
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
N/A N/A None.

Fix these issues in Kilo Cloud

Files Reviewed (7 files)
  • src/lib/code-reviews/core/constants.ts - 0 issues
  • src/lib/code-reviews/db/code-reviews.ts - 0 issues
  • src/lib/code-reviews/prompts/default-prompt-template-gitlab.json - 0 issues
  • src/lib/code-reviews/prompts/default-prompt-template.json - 0 issues
  • src/lib/code-reviews/prompts/generate-prompt.test.ts - 0 issues
  • src/lib/code-reviews/prompts/generate-prompt.ts - 0 issues
  • src/lib/code-reviews/triggers/prepare-review-payload.ts - 1 issue

@alex-alecu alex-alecu force-pushed the feat/code-review-on-push branch 2 times, most recently from 84d0d37 to f787f24 Compare March 9, 2026 08:51
// 4. Generate auth token for cloud agent with bot identifier
// 4. Check for previous completed review (incremental review optimization)
let previousHeadSha: string | null = null;
const incrementalEnabled = await isFeatureFlagEnabled(FEATURE_FLAG_INCREMENTAL_REVIEW);
Copy link
Contributor

Choose a reason for hiding this comment

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

WARNING: Incremental-review rollout is evaluated against a shared PostHog bucket

isFeatureFlagEnabled() defaults distinctId to 'server-config-fetch', so this call ignores the current review owner. Any percentage rollout or targeted rule for code-review-incremental will therefore turn incremental mode on for everyone or no one instead of the intended subset. Pass the same distinct ID you already use for code-review flags here.

Suggested change
const incrementalEnabled = await isFeatureFlagEnabled(FEATURE_FLAG_INCREMENTAL_REVIEW);
const incrementalEnabled = await isFeatureFlagEnabled(FEATURE_FLAG_INCREMENTAL_REVIEW, owner.userId);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Kilo fix it

Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't apply this fix automatically this time.

The auto-fix run failed before it could push an updated commit.

Next steps:

  • Retry with more guidance, or apply the fix manually.
  • Session ID: agent_4ab0cb7c-0039-49da-a9ea-b4bd6a84015e
Technical details
Network connection lost.

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 9, 2026

🤖 Auto-Fix Update

I successfully implemented changes to fix this issue, but encountered an error while creating the pull request:

Branch 'session/agent_4ab0cb7c-0039-49da-a9ea-b4bd6a84015e' does not exist on GitHub. The branch may not have been pushed yet. Please ensure the Cloud Agent successfully pushed the branch before creating a PR.

The changes are available on branch session/agent_4ab0cb7c-0039-49da-a9ea-b4bd6a84015e.

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