@@ -7,7 +7,7 @@ import { createLogger } from '@sim/logger'
77import { describeError , getErrorMessage } from '@sim/utils/errors'
88import { sleep } from '@sim/utils/helpers'
99import { backoffWithJitter } from '@sim/utils/retry'
10- import { and , eq , isNull , lte , or } from 'drizzle-orm'
10+ import { and , eq , gte , isNull , lt , lte , or } from 'drizzle-orm'
1111import { isTest } from '@/lib/core/config/env-flags'
1212import { generateRequestId } from '@/lib/core/utils/request'
1313import { McpClient } from '@/lib/mcp/client'
@@ -53,6 +53,17 @@ function failureCacheKey(workspaceId: string, serverId: string): string {
5353 return `workspace:${ workspaceId } :server:${ serverId } :failure`
5454}
5555
56+ export function getTimestampMillisecondBounds ( timestamp : string ) : {
57+ startInclusive : Date
58+ endExclusive : Date
59+ } {
60+ const startInclusive = new Date ( timestamp )
61+ return {
62+ startInclusive,
63+ endExclusive : new Date ( startInclusive . getTime ( ) + 1 ) ,
64+ }
65+ }
66+
5667const FAILURE_CACHE_SENTINEL : McpTool [ ] = [ ]
5768
5869type DiscoveryOutcome =
@@ -417,12 +428,13 @@ class McpService {
417428 ) : Promise < boolean > {
418429 try {
419430 const now = new Date ( )
420- const configUpdatedAt = new Date ( update . configUpdatedAt )
431+ const configUpdatedAt = getTimestampMillisecondBounds ( update . configUpdatedAt )
421432 const publicationConditions = and (
422433 eq ( mcpServers . id , serverId ) ,
423434 eq ( mcpServers . workspaceId , workspaceId ) ,
424435 isNull ( mcpServers . deletedAt ) ,
425- eq ( mcpServers . updatedAt , configUpdatedAt ) ,
436+ gte ( mcpServers . updatedAt , configUpdatedAt . startInclusive ) ,
437+ lt ( mcpServers . updatedAt , configUpdatedAt . endExclusive ) ,
426438 or (
427439 isNull ( mcpServers . lastToolsRefresh ) ,
428440 lte ( mcpServers . lastToolsRefresh , update . discoveryStartedAt )
@@ -531,6 +543,7 @@ class McpService {
531543 discoveryStartedAt : Date
532544 ) : Promise < boolean > {
533545 try {
546+ const configUpdatedAtBounds = getTimestampMillisecondBounds ( configUpdatedAt )
534547 const updatedServers = await db
535548 . update ( mcpServers )
536549 . set ( {
@@ -544,7 +557,8 @@ class McpService {
544557 eq ( mcpServers . id , serverId ) ,
545558 eq ( mcpServers . workspaceId , workspaceId ) ,
546559 isNull ( mcpServers . deletedAt ) ,
547- eq ( mcpServers . updatedAt , new Date ( configUpdatedAt ) ) ,
560+ gte ( mcpServers . updatedAt , configUpdatedAtBounds . startInclusive ) ,
561+ lt ( mcpServers . updatedAt , configUpdatedAtBounds . endExclusive ) ,
548562 or (
549563 isNull ( mcpServers . lastToolsRefresh ) ,
550564 lte ( mcpServers . lastToolsRefresh , discoveryStartedAt )
0 commit comments