Improved the pauses between indexing steps and between files of the Batch Processing Assistant (#1240)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-27 14:39:17 +01:00
1 parent a117074972
commit 899139c88b
32 files changed
+787 -425

No files matched your search

@@ -200,18 +200,9 @@ else
@T("Processing pace")
</MudText>
@if (MinimumDelayIsManaged)
{
<MudAlert Severity="Severity.Info" Dense="true" Class="mb-3">
@(string.Format(TA("Your organization requires a pause of at least {0} seconds between files."), this.ManagedMinimumDelaySeconds))
</MudAlert>
}
else
{
<MudTextSlider T="int" Label="@T("Minimum pause between files")" Min="@DataBatchProcessing.MIN_DELAY_SECONDS" Max="@DataBatchProcessing.MAX_DELAY_SECONDS" Step="1" Unit="@T("seconds")" @bind-Value="@this.minimumDelaySeconds" Disabled="@(() => this.isProcessingBatch)"/>
}
<MudTextSlider T="int" Label="@T("Maximum pause between files")" Min="@this.EffectiveMinimumDelaySeconds" Max="@DataBatchProcessing.MAX_DELAY_SECONDS" Step="1" Unit="@T("seconds")" @bind-Value="@this.maximumDelaySeconds" Disabled="@(() => this.isProcessingBatch)"/>
<ConfigurationPauseRange Limits="@DataBatchProcessing.PAUSE_LIMITS" IsSetting="false" Disabled="@(() => this.isProcessingBatch)" OptionDescription="@T("Pause between files")"
Minimum="@(() => this.MinimumDelaySeconds)" MinimumUpdate="@(value => this.minimumDelaySeconds = value)" IsMinimumLocked="@(() => DataBatchProcessing.IsMinimumPauseLocked)"
Maximum="@(() => this.MaximumDelaySeconds)" MaximumUpdate="@(value => this.maximumDelaySeconds = value)" IsMaximumLocked="@(() => DataBatchProcessing.IsMaximumPauseLocked)"/>
<MudJustifiedText Typo="Typo.body2" Class="mb-3">
@T("Before the next file starts, AI Studio waits for a random number of whole seconds from this interval. The minimum is always 6 seconds and the maximum is 300 seconds (5 minutes). Restored files and the end of a run do not add another pause.")
@@ -1,5 +1,5 @@
using AIStudio.Settings;
using AIStudio.Settings.DataModel;
using AIStudio.Tools.Pauses;
using Microsoft.AspNetCore.Components;
@@ -10,27 +10,40 @@ public partial class AssistantBatchProcessing
[Inject]
private ThreadSafeRandom Rng { get; init; } = null!;
private static bool MinimumDelayIsManaged => ManagedConfiguration.TryGet(x => x.BatchProcessing, x => x.MinimumDelaySeconds, out var meta)
&& meta.ManagedMode is not null;
/// <summary>
/// The lower bound of the pause between two files as it stands.
/// </summary>
/// <remarks>
/// A bound which a configuration plugin locks belongs to the organization, so it comes from the
/// settings, whatever this assistant held before, e.g., in a session from before the lock.
/// </remarks>
private int MinimumDelaySeconds => DataBatchProcessing.IsMinimumPauseLocked
? this.SettingsManager.ConfigurationData.BatchProcessing.MinimumDelaySeconds
: this.minimumDelaySeconds;
private int ManagedMinimumDelaySeconds => Math.Clamp(this.SettingsManager.ConfigurationData.BatchProcessing.MinimumDelaySeconds,
DataBatchProcessing.MIN_DELAY_SECONDS,
DataBatchProcessing.MAX_DELAY_SECONDS);
/// <summary>
/// The upper bound of the pause between two files as it stands, cf. MinimumDelaySeconds.
/// </summary>
private int MaximumDelaySeconds => DataBatchProcessing.IsMaximumPauseLocked
? this.SettingsManager.ConfigurationData.BatchProcessing.MaximumDelaySeconds
: this.maximumDelaySeconds;
private int EffectiveMinimumDelaySeconds => MinimumDelayIsManaged ? this.ManagedMinimumDelaySeconds
: Math.Clamp(this.minimumDelaySeconds, DataBatchProcessing.MIN_DELAY_SECONDS, DataBatchProcessing.MAX_DELAY_SECONDS);
private (int Minimum, int Maximum) GetEffectiveDelayRange()
{
var minimum = this.EffectiveMinimumDelaySeconds;
var maximum = Math.Clamp(this.maximumDelaySeconds, minimum, DataBatchProcessing.MAX_DELAY_SECONDS);
return (minimum, maximum);
}
/// <summary>
/// The bounds of the pause between two files which apply to a run, cf. PauseRange.GetEffective.
/// </summary>
private PauseRange EffectivePauseRange => PauseRange.GetEffective(
DataBatchProcessing.PAUSE_LIMITS,
this.MinimumDelaySeconds,
() => DataBatchProcessing.IsMinimumPauseLocked,
this.MaximumDelaySeconds,
() => DataBatchProcessing.IsMaximumPauseLocked);
/// <summary>
/// Waits for a random, inclusive duration before the next file starts.
/// </summary>
private async Task WaitBeforeNextFileAsync(int minimumSeconds, int maximumSeconds, CancellationToken token)
/// <param name="range">The bounds of the pause, as they apply to the run.</param>
/// <param name="token">Ends the wait when the user stops the run.</param>
private async Task WaitBeforeNextFileAsync(PauseRange range, CancellationToken token)
{
if (token.IsCancellationRequested)
return;
@@ -38,12 +51,12 @@ public partial class AssistantBatchProcessing
// ThreadSafeRandom is the application-wide singleton. Batch runs must
// not create private Random instances because several runs may execute
// concurrently in different assistant sessions.
this.pauseBeforeNextFileSeconds = this.Rng.Next(minimumSeconds, maximumSeconds + 1);
this.pauseBeforeNextFileSeconds = this.Rng.Next(range.MinimumSeconds, range.MaximumSeconds + 1);
this.Logger.LogInformation("Batch processing waits {DelaySeconds} seconds before starting the next file.", this.pauseBeforeNextFileSeconds);
await this.CheckpointAssistantSession();
await this.RefreshAssistantUIAsync();
try
{
await Task.Delay(TimeSpan.FromSeconds(this.pauseBeforeNextFileSeconds), token);
@@ -119,7 +119,7 @@ public partial class AssistantBatchProcessing
{
this.isProcessingBatch = true;
var stopwatch = Stopwatch.StartNew();
var delayRange = this.GetEffectiveDelayRange();
var pauseRange = this.EffectivePauseRange;
this.Logger.LogInformation(
"Batch processing started. InputDirectory='{InputDirectory}', OutputDirectory='{OutputDirectory}', TotalFiles={TotalFiles}, RestoredFiles={RestoredFiles}, Model='{Model}', MinimumDelaySeconds={MinimumDelaySeconds}, MaximumDelaySeconds={MaximumDelaySeconds}.",
this.inputDirectory,
@@ -127,8 +127,8 @@ public partial class AssistantBatchProcessing
this.fileResults.Count,
this.fileResults.Count(fileResult => fileResult.Status is BatchProcessingFileStatus.DONE),
this.ProviderSettings.Model,
delayRange.Minimum,
delayRange.Maximum);
pauseRange.MinimumSeconds,
pauseRange.MaximumSeconds);
// We use the cancellation token of the assistant base class, which
// creates it before it calls us and disposes it after we returned.
@@ -166,7 +166,7 @@ public partial class AssistantBatchProcessing
var anotherFileIsWaiting = this.fileResults.Skip(index + 1).Any(nextFile => nextFile.Status is not BatchProcessingFileStatus.DONE);
if (anotherFileIsWaiting)
await this.WaitBeforeNextFileAsync(delayRange.Minimum, delayRange.Maximum, token);
await this.WaitBeforeNextFileAsync(pauseRange, token);
}
}
finally
@@ -213,8 +213,8 @@ public partial class AssistantBatchProcessing : AssistantBaseCore<SettingsDialog
this.csvFileName = string.Empty;
this.csvSeparator = BatchProcessingCsvSeparator.SEMICOLON;
this.customCsvSeparator = string.Empty;
this.minimumDelaySeconds = MinimumDelayIsManaged ? this.ManagedMinimumDelaySeconds : DataBatchProcessing.DEFAULT_MIN_DELAY_SECONDS;
this.maximumDelaySeconds = Math.Clamp(DataBatchProcessing.DEFAULT_MAX_DELAY_SECONDS, this.minimumDelaySeconds, DataBatchProcessing.MAX_DELAY_SECONDS);
this.minimumDelaySeconds = DataBatchProcessing.DEFAULT_MIN_DELAY_SECONDS;
this.maximumDelaySeconds = DataBatchProcessing.DEFAULT_MAX_DELAY_SECONDS;
return;
}
@@ -236,9 +236,8 @@ public partial class AssistantBatchProcessing : AssistantBaseCore<SettingsDialog
this.csvFileName = settings.CsvFileName;
this.csvSeparator = settings.CsvSeparator;
this.customCsvSeparator = settings.CustomCsvSeparator;
this.minimumDelaySeconds = MinimumDelayIsManaged ? this.ManagedMinimumDelaySeconds
: Math.Clamp(settings.MinimumDelaySeconds, DataBatchProcessing.MIN_DELAY_SECONDS, DataBatchProcessing.MAX_DELAY_SECONDS);
this.maximumDelaySeconds = Math.Clamp(settings.MaximumDelaySeconds, this.minimumDelaySeconds, DataBatchProcessing.MAX_DELAY_SECONDS);
this.minimumDelaySeconds = settings.MinimumDelaySeconds;
this.maximumDelaySeconds = settings.MaximumDelaySeconds;
}
private async Task LoadConfiguredPromptFileAsync()