diff --git a/src/hnsw/hnswIndex.ts b/src/hnsw/hnswIndex.ts index 9c72eca6..b95f4938 100644 --- a/src/hnsw/hnswIndex.ts +++ b/src/hnsw/hnswIndex.ts @@ -1092,7 +1092,7 @@ export class HNSWIndex { prodLog.info(`HNSW: Using cloud pagination strategy (${storageType})`) let hasMore = true - let cursor: string | undefined = undefined + let offset = 0 // v5.7.11: Use offset-based pagination instead of cursor (bug fix for infinite loop) while (hasMore) { // Fetch batch of nouns from storage (cast needed as method is not in base interface) @@ -1103,7 +1103,7 @@ export class HNSWIndex { nextCursor?: string } = await (this.storage as any).getNounsWithPagination({ limit: batchSize, - cursor + offset // v5.7.11: Pass offset for proper pagination (previously passed cursor which was ignored) }) // Set total count on first batch @@ -1161,7 +1161,7 @@ export class HNSWIndex { // Check for more data hasMore = result.hasMore - cursor = result.nextCursor + offset += batchSize // v5.7.11: Increment offset for next page } } diff --git a/src/hnsw/typeAwareHNSWIndex.ts b/src/hnsw/typeAwareHNSWIndex.ts index 03e5e112..ac02e673 100644 --- a/src/hnsw/typeAwareHNSWIndex.ts +++ b/src/hnsw/typeAwareHNSWIndex.ts @@ -452,7 +452,7 @@ export class TypeAwareHNSWIndex { // Load ALL nouns ONCE and route to correct type indexes // This is O(N) instead of O(42*N) from the previous parallel approach - let cursor: string | undefined = undefined + let offset = 0 // v5.7.11: Use offset-based pagination instead of cursor (bug fix for infinite loop) let hasMore = true let totalLoaded = 0 const loadedByType = new Map() @@ -465,7 +465,7 @@ export class TypeAwareHNSWIndex { totalCount?: number } = await (this.storage as any).getNounsWithPagination({ limit: batchSize, - cursor + offset // v5.7.11: Pass offset for proper pagination (previously passed cursor which was ignored) }) // Route each noun to its type index @@ -530,7 +530,7 @@ export class TypeAwareHNSWIndex { } hasMore = result.hasMore - cursor = result.nextCursor + offset += batchSize // v5.7.11: Increment offset for next page // Progress logging if (totalLoaded % 1000 === 0) { diff --git a/src/storage/adapters/optimizedS3Search.ts b/src/storage/adapters/optimizedS3Search.ts index 03db4cb7..6b1f0dc4 100644 --- a/src/storage/adapters/optimizedS3Search.ts +++ b/src/storage/adapters/optimizedS3Search.ts @@ -105,10 +105,10 @@ export class OptimizedS3Search { } } } - + // Determine if there are more items - const hasMore = listResult.hasMore || nouns.length >= limit - + const hasMore = listResult.hasMore || nouns.length > limit // v5.7.11: Fixed >= to > (was causing infinite loop) + // Set next cursor let nextCursor: string | undefined if (hasMore && nouns.length > 0) { @@ -188,10 +188,10 @@ export class OptimizedS3Search { } } } - + // Determine if there are more items - const hasMore = listResult.hasMore || verbs.length >= limit - + const hasMore = listResult.hasMore || verbs.length > limit // v5.7.11: Fixed >= to > (was causing infinite loop) + // Set next cursor let nextCursor: string | undefined if (hasMore && verbs.length > 0) { diff --git a/src/storage/baseStorage.ts b/src/storage/baseStorage.ts index 90b09336..6bedbccc 100644 --- a/src/storage/baseStorage.ts +++ b/src/storage/baseStorage.ts @@ -1083,7 +1083,7 @@ export abstract class BaseStorage extends BaseStorageAdapter { public async getNounsWithPagination(options: { limit: number offset: number - cursor?: string + cursor?: string // v5.7.11: Currently ignored (offset-based pagination). Cursor support planned for v5.8.0 filter?: { nounType?: string | string[] service?: string | string[] @@ -1097,7 +1097,7 @@ export abstract class BaseStorage extends BaseStorageAdapter { }> { await this.ensureInitialized() - const { limit, offset = 0, filter } = options + const { limit, offset = 0, filter } = options // cursor intentionally not extracted (not yet implemented) const collectedNouns: HNSWNounWithMetadata[] = [] const targetCount = offset + limit // Early termination target @@ -1188,7 +1188,7 @@ export abstract class BaseStorage extends BaseStorageAdapter { // Apply pagination (v5.5.0: Efficient slicing after early termination) const paginatedNouns = collectedNouns.slice(offset, offset + limit) - const hasMore = collectedNouns.length >= targetCount + const hasMore = collectedNouns.length > targetCount // v5.7.11: Fixed >= to > (was causing infinite loop) return { items: paginatedNouns, @@ -1218,7 +1218,7 @@ export abstract class BaseStorage extends BaseStorageAdapter { public async getVerbsWithPagination(options: { limit: number offset: number - cursor?: string + cursor?: string // v5.7.11: Currently ignored (offset-based pagination). Cursor support planned for v5.8.0 filter?: { verbType?: string | string[] sourceId?: string | string[] @@ -1234,7 +1234,7 @@ export abstract class BaseStorage extends BaseStorageAdapter { }> { await this.ensureInitialized() - const { limit, offset = 0, filter } = options + const { limit, offset = 0, filter } = options // cursor intentionally not extracted (not yet implemented) const collectedVerbs: HNSWVerbWithMetadata[] = [] const targetCount = offset + limit // Early termination target @@ -1302,7 +1302,7 @@ export abstract class BaseStorage extends BaseStorageAdapter { // Apply pagination (v5.5.0: Efficient slicing after early termination) const paginatedVerbs = collectedVerbs.slice(offset, offset + limit) - const hasMore = collectedVerbs.length >= targetCount + const hasMore = collectedVerbs.length > targetCount // v5.7.11: Fixed >= to > (was causing infinite loop) return { items: paginatedVerbs, @@ -1628,7 +1628,7 @@ export abstract class BaseStorage extends BaseStorageAdapter { // Apply pagination (slice for offset) const paginatedVerbs = collectedVerbs.slice(offset, offset + limit) - const hasMore = collectedVerbs.length >= targetCount + const hasMore = collectedVerbs.length > targetCount // v5.7.11: Fixed >= to > (was causing infinite loop) return { items: paginatedVerbs, diff --git a/src/utils/rebuildCounts.ts b/src/utils/rebuildCounts.ts index 277ca198..9456ba4e 100644 --- a/src/utils/rebuildCounts.ts +++ b/src/utils/rebuildCounts.ts @@ -64,10 +64,13 @@ export async function rebuildCounts(storage: BaseStorage): Promise