| 884 | .set( |
| 885 | buildAttemptUpdateData({ |
| 886 | status: params.status, |
| 887 | sessionId: params.sessionId, |
| 888 | cliSessionId: params.cliSessionId, |
| 889 | executionId: params.executionId, |
| 890 | errorMessage: params.errorMessage, |
| 891 | terminalReason: params.terminalReason, |
| 892 | startedAt: params.startedAt, |
| 893 | completedAt: params.completedAt, |
| 894 | }) |
| 895 | ) |
| 896 | .where(eq(cloud_agent_code_review_attempts.id, targetAttempt.id)) |
| 897 | .returning(); |
| 898 | |
| 899 | if (!updated) { |
| 900 | throw new Error('Failed to update code review attempt'); |
| 901 | } |
| 902 | |
| 903 | return updated; |
| 904 | } catch (error) { |
| 905 | captureException(error, { |
| 906 | tags: { operation: 'updateCodeReviewAttemptForCallback' }, |
| 907 | extra: { params }, |
| 908 | }); |
| 909 | throw error; |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | export async function hasInfraRetryAttempt(codeReviewId: string): Promise<boolean> { |
| 914 | try { |
| 915 | const [attempt] = await db |
| 916 | .select({ id: cloud_agent_code_review_attempts.id }) |
| 917 | .from(cloud_agent_code_review_attempts) |
| 918 | .where( |
| 919 | and( |
| 920 | eq(cloud_agent_code_review_attempts.code_review_id, codeReviewId), |
| 921 | eq(cloud_agent_code_review_attempts.retry_reason, 'infra_failure') |
| 922 | ) |
| 923 | ) |
| 924 | .limit(1); |
| 925 | |
| 926 | return !!attempt; |
| 927 | } catch (error) { |
| 928 | captureException(error, { |
| 929 | tags: { operation: 'hasInfraRetryAttempt' }, |
| 930 | extra: { codeReviewId }, |
| 931 | }); |
| 932 | throw error; |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | export async function ensureCurrentCodeReviewAttemptFromReview( |
| 937 | review: CloudAgentCodeReview, |
| 938 | analyticsEnabledAtDispatch?: boolean |
| 939 | ): Promise<CloudAgentCodeReviewAttempt> { |
| 940 | let attempt = await getLatestCodeReviewAttempt(review.id); |
| 941 | if (attempt) { |
| 942 | if ( |
| 943 | attempt.status === 'pending' && |