Skip to content

fix(code-reviews): fix incremental review flag and add logging#1207

Merged
alex-alecu merged 2 commits intomainfrom
fix/incremental-review-flag-and-logging
Mar 18, 2026
Merged

fix(code-reviews): fix incremental review flag and add logging#1207
alex-alecu merged 2 commits intomainfrom
fix/incremental-review-flag-and-logging

Conversation

@alex-alecu
Copy link
Copy Markdown
Contributor

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

Summary

Follow-up for #927

The incremental review feature flag was evaluated with a hardcoded 'server-config-fetch' distinctId instead of the actual owner's userId, making per-user/org targeting in PostHog non-functional. This meant the flag always resolved the same way regardless of which user or org triggered the review. Additionally, the entire incremental review decision path had zero logging, making it impossible to debug from Axiom why a review used full mode instead of incremental.

This PR passes owner.userId to the flag evaluation (matching the pattern already used for the PR gate flag in the same file) and adds log lines at each decision point: flag evaluation result, previous review lookup outcome, and the prompt workflow gate that selects incremental vs full mode.

Verification

  • pnpm typecheck — passes cleanly across all workspace projects

Visual Changes

N/A

Reviewer Notes

  • The flag fix on line 325 mirrors the existing correct pattern at line 410 (isFeatureFlagEnabled('code-review-pr-gate', owner.userId)).
  • owner.userId is always present — it's a required field in both variants of the OwnerSchema discriminated union. For orgs, it's a synthetic bot ID like 'bot-code-review-{orgId}'.
  • Logging uses logExceptInTest consistently and truncates SHAs to 8 characters, matching existing conventions.
  • Issue App Builder - Add session-based message pagination #3 from the investigation (rapid push cancellation preventing incremental base) is intentionally not addressed here — it's an architectural design constraint that needs product discussion.

isFeatureFlagEnabled(FEATURE_FLAG_INCREMENTAL_REVIEW) was using the
default distinctId 'server-config-fetch' instead of the owner's userId,
making the flag evaluate globally rather than per-user/org. This matches
the pattern already used for the 'code-review-pr-gate' flag on line 398.
Add observability for the incremental review decision path:

- Log feature flag evaluation result with owner ID in
  prepareReviewPayload, so Axiom shows whether the flag was on/off
  for a given review.
- Log when no previous completed review is found (flag on but no
  incremental base available).
- Log in generateReviewPrompt when the three-way gate
  (previousHeadSha + incrementalTemplate + summaryComment) falls
  back to full workflow despite having a previousHeadSha, including
  which condition failed.

Previously, the entire incremental decision path was silent, making
it impossible to debug from Axiom why a review used full mode.
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Mar 18, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • src/lib/code-reviews/prompts/generate-prompt.ts
  • src/lib/code-reviews/triggers/prepare-review-payload.ts

Reviewed by gpt-5.4-20260305 · 604,166 tokens

@alex-alecu alex-alecu merged commit 1416140 into main Mar 18, 2026
18 checks passed
@alex-alecu alex-alecu deleted the fix/incremental-review-flag-and-logging branch March 18, 2026 13:17
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