Skip to content

Commit e61cc0a

Browse files
reakaleekclaude
andcommitted
fix: preserve search_after position when retrying with new PIT
When a PIT expired mid-pagination, the retry was resetting the cursor to null, silently restarting from the beginning. Now the retry preserves the original search_after sort values and only replaces the PIT ID. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bfb710a commit e61cc0a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/services/Elastic.Documentation.Search/ChangesGateway.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public async Task<ChangesResult> GetChangesAsync(ChangesRequest request, Cancel
3535
{
3636
LogPitExpired(logger);
3737
pitId = await OpenPit(ctx);
38-
response = await Search(request with { Cursor = null }, pitId, fetchSize, ctx);
38+
var updatedCursor = request.Cursor with { PitId = pitId };
39+
response = await Search(request with { Cursor = updatedCursor }, pitId, fetchSize, ctx);
3940
}
4041

4142
if (!response.IsValidResponse)
@@ -178,6 +179,6 @@ private static ChangesResult BuildResult(SearchResponse<DocumentationDocument> r
178179
[LoggerMessage(Level = LogLevel.Debug, Message = "Opened new PIT: {PitId}")]
179180
private static partial void LogPitOpened(ILogger logger, string pitId);
180181

181-
[LoggerMessage(Level = LogLevel.Warning, Message = "PIT expired or not found, opening a new one and retrying without search_after")]
182+
[LoggerMessage(Level = LogLevel.Warning, Message = "PIT expired or not found, opening a new one and retrying with existing search_after position")]
182183
private static partial void LogPitExpired(ILogger logger);
183184
}

0 commit comments

Comments
 (0)