Skip to content

Commit 3938a3c

Browse files
Fix pacing scope and progress math overflow
- Make embedding pacing timestamp static to match static request lock scope - Use long arithmetic in percent progress threshold comparison to avoid overflow
1 parent c453ff3 commit 3938a3c

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

EssentialCSharp.Chat.Shared/Services/EmbeddingService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public partial class EmbeddingService(
3434
private readonly EmbeddingRetryOptions _retryOptions = ValidateRetryOptions(retryOptions?.Value ?? new EmbeddingRetryOptions());
3535
private readonly ILogger<EmbeddingService>? _logger = logger;
3636
private static readonly SemaphoreSlim _embeddingRequestLock = new(1, 1);
37-
private DateTimeOffset _lastEmbeddingRequestStartedUtc = DateTimeOffset.MinValue;
37+
private static DateTimeOffset _lastEmbeddingRequestStartedUtc = DateTimeOffset.MinValue;
3838

3939
// Only allow simple identifiers: letters, digits, and underscores, starting with a letter or underscore.
4040
private static readonly Regex _safeIdentifierRegex = new(@"^[a-zA-Z_][a-zA-Z0-9_]*$", RegexOptions.Compiled);
@@ -404,7 +404,7 @@ void LogProgressIfNeeded()
404404
if (knownTotalChunks is > 0)
405405
{
406406
while (nextProgressPercentToLog <= 100
407-
&& totalCount * 100 >= knownTotalChunks.Value * nextProgressPercentToLog)
407+
&& (long)totalCount * 100 >= (long)knownTotalChunks.Value * nextProgressPercentToLog)
408408
{
409409
LogEmbeddingProgressPercent(_logger, totalCount, knownTotalChunks.Value, nextProgressPercentToLog, adaptiveBatchSize);
410410
nextProgressPercentToLog += 10;

0 commit comments

Comments
 (0)