Skip to content

Commit 6ee674d

Browse files
Gavin Williamsclaude
andcommitted
fix(web): wrap ack reactions in 1500ms timeout to avoid blocking webhook
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c22fe46 commit 6ee674d

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

  • packages/web/src/app/api/(server)/webhook

packages/web/src/app/api/(server)/webhook/route.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ if (env.GITLAB_REVIEW_AGENT_TOKEN) {
130130
}
131131
}
132132

133+
const ACK_TIMEOUT_MS = 1500;
134+
135+
const ackWithTimeout = (promise: Promise<unknown>, label: string): Promise<void> => {
136+
const timeout = new Promise<void>(resolve => setTimeout(resolve, ACK_TIMEOUT_MS));
137+
return Promise.race([promise, timeout]).then(
138+
() => { /* success or timeout — proceed */ },
139+
(error) => { logger.warn(`${label}: ${error}`); },
140+
);
141+
};
142+
133143
export const POST = async (request: NextRequest) => {
134144
const body = await request.json();
135145
const headers = Object.fromEntries(Array.from(request.headers.entries(), ([key, value]) => [key.toLowerCase(), value]));
@@ -186,16 +196,15 @@ export const POST = async (request: NextRequest) => {
186196

187197
const octokit = await githubApp.getInstallationOctokit(body.installation.id);
188198

189-
try {
190-
await octokit.rest.reactions.createForIssueComment({
199+
await ackWithTimeout(
200+
octokit.rest.reactions.createForIssueComment({
191201
owner,
192202
repo: repositoryName,
193203
comment_id: body.comment.id,
194204
content: env.REVIEW_AGENT_ACK_REACTION as "-1" | "+1" | "laugh" | "confused" | "heart" | "hooray" | "rocket" | "eyes",
195-
});
196-
} catch (error) {
197-
logger.warn(`Failed to add acknowledgment reaction to GitHub comment: ${error}`);
198-
}
205+
}),
206+
'Failed to add acknowledgment reaction to GitHub comment',
207+
);
199208

200209
const { data: pullRequest } = await octokit.rest.pulls.get({
201210
owner,
@@ -258,16 +267,15 @@ export const POST = async (request: NextRequest) => {
258267
if (noteBody === `/${env.REVIEW_AGENT_REVIEW_COMMAND}`) {
259268
logger.info('Review agent review command received on GitLab MR, processing');
260269

261-
try {
262-
await gitlabClient.MergeRequestNoteAwardEmojis.award(
270+
await ackWithTimeout(
271+
gitlabClient.MergeRequestNoteAwardEmojis.award(
263272
parsed.data.project.id,
264273
parsed.data.merge_request.iid,
265274
parsed.data.object_attributes.id,
266275
env.REVIEW_AGENT_ACK_REACTION,
267-
);
268-
} catch (error) {
269-
logger.warn(`Failed to add acknowledgment emoji to GitLab note: ${error}`);
270-
}
276+
),
277+
'Failed to add acknowledgment emoji to GitLab note',
278+
);
271279

272280
const mrPayload: GitLabMergeRequestPayload = {
273281
object_kind: "merge_request",

0 commit comments

Comments
 (0)