From fd7681ee14e34ebb2743e157027d21313accd2e4 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Sat, 5 Dec 2026 00:36:37 +0800 Subject: [PATCH] Bound GitHub reaction polls to 30 days Co-Authored-By: Claude Code --- .../__tests__/github-reaction-poll.test.ts | 27 +++++++++++++++++++ .../src/handlers/github-reaction-poll.ts | 17 ++++++++++++ 2 files changed, 44 insertions(+) diff --git a/packages/outpost/queue/src/handlers/__tests__/github-reaction-poll.test.ts b/packages/outpost/queue/src/handlers/__tests__/github-reaction-poll.test.ts index f940845..97720e2 100644 --- a/packages/outpost/queue/src/handlers/__tests__/github-reaction-poll.test.ts +++ b/packages/outpost/queue/src/handlers/__tests__/github-reaction-poll.test.ts @@ -32,6 +32,7 @@ import { handleGithubReactionPoll, COMMENT_DELETED_FEEDBACK, GITHUB_REACTION_POLL_CONCURRENCY, + GITHUB_REACTION_POLL_MAX_AGE_DAYS, } from '../github-reaction-poll.js'; import { JobType } from '../../types.js'; @@ -207,6 +208,7 @@ describe('handleGithubReactionPoll', () => { isAiGenerated: true, feedback: null, externalCommentId: { not: null }, + createdAt: { gte: expect.any(Date) }, ticket: { source: { in: ['GITHUB_ISSUE'] }, }, @@ -222,6 +224,31 @@ describe('handleGithubReactionPoll', () => { }, }); }); + + it('bounds the query to messages created within the reaction-poll age window', async () => { + const now = new Date('2026-12-05T12:00:00.000Z'); + const expectedCutoff = new Date( + now.getTime() - GITHUB_REACTION_POLL_MAX_AGE_DAYS * 24 * 60 * 60 * 1000, + ); + mockMessageFindMany.mockResolvedValue([]); + + vi.useFakeTimers({ toFake: ['Date'] }); + vi.setSystemTime(now); + try { + await handleGithubReactionPoll({}, context); + } finally { + vi.useRealTimers(); + } + + expect(GITHUB_REACTION_POLL_MAX_AGE_DAYS).toBe(30); + expect(mockMessageFindMany).toHaveBeenCalledWith( + expect.objectContaining({ + where: expect.objectContaining({ + createdAt: { gte: expectedCutoff }, + }), + }), + ); + }); describe('GitHub lookup concurrency', () => { // Production had 256 pending messages. Read one at a time at ~240ms each, // the poll ran past its 30s job timeout on every attempt and dead-lettered. diff --git a/packages/outpost/queue/src/handlers/github-reaction-poll.ts b/packages/outpost/queue/src/handlers/github-reaction-poll.ts index 3e23dbd..062d5f2 100644 --- a/packages/outpost/queue/src/handlers/github-reaction-poll.ts +++ b/packages/outpost/queue/src/handlers/github-reaction-poll.ts @@ -13,6 +13,12 @@ * poll needs one GitHub round trip per pending message, and that list only * grows. At 256 messages the serial loop overran the 30s job timeout on every * attempt, and the job was dead-lettered after each scheduled run. + * + * Polling is also bounded to recent AI messages. A message that stays at + * `feedback: null` would otherwise be re-polled every 24 hours forever; a + * reporter who reacts after GITHUB_REACTION_POLL_MAX_AGE_DAYS is an accepted + * miss. The cutoff is row `createdAt`, not actual GitHub post time, so a + * delayed post that succeeds across the boundary may also be missed. */ import { prisma } from '@copilotkit/outpost/db'; @@ -33,6 +39,13 @@ import type { GithubReactionPollPayload, JobResult, JobHandlerContext } from '.. */ export const GITHUB_REACTION_POLL_CONCURRENCY = 8; +/** + * Maximum age of a message whose reactions the poll will still check. Use an + * exact 24-hour multiple rather than calendar-day arithmetic so the window is + * stable across local time zones and DST changes. + */ +export const GITHUB_REACTION_POLL_MAX_AGE_DAYS = 30; + /** * Terminal `feedback` value for a message whose GitHub comment no longer exists. * It takes the message out of the `feedback: null` set this job polls, so a @@ -56,11 +69,15 @@ export async function handleGithubReactionPoll( ): Promise { await context.reportProgress(10); + const reactionWindowStart = new Date( + Date.now() - GITHUB_REACTION_POLL_MAX_AGE_DAYS * 24 * 60 * 60 * 1000, + ); const pendingMessages = await prisma.message.findMany({ where: { isAiGenerated: true, feedback: null, externalCommentId: { not: null }, + createdAt: { gte: reactionWindowStart }, ticket: { // GITHUB_DISCUSSION excluded: discussion comments are created via GraphQL // and their externalCommentId is a GraphQL node_id, not a numeric REST