@@ -20,6 +20,7 @@ const DEFAULT_MAX_DURATION_MS = 3 * 60 * 1000;
2020const DIRECT_SYNC_ENV = "STACK_EXTERNAL_DB_SYNC_DIRECT" ;
2121const POLLER_CLAIM_LIMIT_ENV = "STACK_EXTERNAL_DB_SYNC_POLL_CLAIM_LIMIT" ;
2222const DEFAULT_POLL_CLAIM_LIMIT = 1000 ;
23+ const STALE_REQUEST_THRESHOLD_MS = 60 * 1000 ;
2324
2425function parseMaxDurationMs ( value : string | undefined ) : number {
2526 if ( ! value ) return DEFAULT_MAX_DURATION_MS ;
@@ -90,7 +91,6 @@ export const GET = createSmartRouteHandler({
9091 span . setAttribute ( "stack.external-db-sync.max-duration-ms" , maxDurationMs ) ;
9192 span . setAttribute ( "stack.external-db-sync.poll-interval-ms" , pollIntervalMs ) ;
9293 span . setAttribute ( "stack.external-db-sync.poller-claim-limit" , pollerClaimLimit ) ;
93- span . setAttribute ( "stack.external-db-sync.direct-sync" , directSyncEnabled ( ) ) ;
9494 span . setAttribute ( "stack.external-db-sync.stale-claim-minutes" , staleClaimIntervalMinutes ) ;
9595
9696 let totalRequestsProcessed = 0 ;
@@ -172,11 +172,13 @@ export const GET = createSmartRouteHandler({
172172 }
173173
174174 const flowControl = options . flowControl as UpstashRequest [ "flowControl" ] ;
175+ const deduplicationId = options . deduplicationId as UpstashRequest [ "deduplicationId" ] ;
175176
176177 return {
177178 url : fullUrl ,
178179 body : options . body ,
179180 ...( flowControl ? { flowControl } : { } ) ,
181+ ...( deduplicationId ? { deduplicationId } : { } )
180182 } ;
181183 }
182184
@@ -243,6 +245,24 @@ export const GET = createSmartRouteHandler({
243245 return { stopReason : "disabled" , processed : 0 } ;
244246 }
245247
248+ const staleRequests = await globalPrismaClient . $queryRaw < { id : string , startedFulfillingAt : Date } [ ] > `
249+ SELECT "id", "startedFulfillingAt"
250+ FROM "OutgoingRequest"
251+ WHERE "startedFulfillingAt" IS NOT NULL
252+ AND "startedFulfillingAt" < NOW() - ${ STALE_REQUEST_THRESHOLD_MS } * INTERVAL '1 millisecond'
253+ LIMIT 10
254+ ` ;
255+ iterationSpan . setAttribute ( "stack.external-db-sync.stale-count" , staleRequests . length ) ;
256+ if ( staleRequests . length > 0 ) {
257+ captureError (
258+ "poller-stale-outgoing-requests" ,
259+ new StackAssertionError (
260+ `Found ${ staleRequests . length } outgoing request(s) with startedFulfillingAt older than ${ STALE_REQUEST_THRESHOLD_MS } ms` ,
261+ { staleRequestIds : staleRequests . map ( r => r . id ) } ,
262+ ) ,
263+ ) ;
264+ }
265+
246266 const pendingRequests = await claimPendingRequests ( ) ;
247267 iterationSpan . setAttribute ( "stack.external-db-sync.pending-count" , pendingRequests . length ) ;
248268
0 commit comments