fix(code-reviews): guard retrigger races#4352
Conversation
| } | ||
|
|
||
| function isPostgresUniqueViolation(error: unknown): boolean { | ||
| return error instanceof Error && 'code' in error && error.code === '23505'; |
There was a problem hiding this comment.
WARNING: Unique-violation detection likely never fires because it only checks the top-level error.code
This codebase's own isUniqueViolation helper in apps/web/src/routers/admin/credit-campaigns-router.ts documents that Drizzle (this repo pins drizzle-orm@0.45.2) wraps the underlying pg error in a DrizzleQueryError, so the Postgres error code lives on error.cause.code, not error.code. That helper explicitly checks both the top-level error and error.cause for this reason.
isPostgresUniqueViolation here only checks error.code, so a real 23505 raised by UQ_cloud_agent_code_reviews_active_provider_publisher when resetCodeReviewForRetry races another dispatch will likely fall through to the generic throw error; path instead of the intended friendly CONFLICT — undermining the race-guard this PR is meant to add. This path also has no test coverage exercising the actual unique-violation catch.
| return error instanceof Error && 'code' in error && error.code === '23505'; | |
| return error instanceof Error && 'code' in error && (error.code === '23505' || (error.cause instanceof Error && 'code' in error.cause && error.cause.code === '23505')); |
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Executive SummaryThe new Overview
Issue Details (click to expand)WARNING
Files Reviewed (6 files)
Fix these issues in Kilo Cloud Reviewed by claude-sonnet-5-20260630 · Input: 80 · Output: 33.2K · Cached: 4.5M Review guidance: REVIEW.md from base branch |
Summary
Fixes Code Reviewer retry so retrying an old failed review no longer crashes when another review is already running for the same pull request. The retry now stops with a clear message if a newer review is already active. If an older review looks stuck, the user is asked before Kilo cancels it and retries the newer failed review.
Verification
Visual Changes
N/A
Reviewer Notes
The DB-backed router test could not be run locally because Docker was unavailable. The main risk area is the handoff where Kilo cancels an older active review before retrying the failed review.