diff --git a/ExtractorUtils/Unstable/Tasks/CheckInWorker.cs b/ExtractorUtils/Unstable/Tasks/CheckInWorker.cs index ca5fb0ba..c4c575ef 100644 --- a/ExtractorUtils/Unstable/Tasks/CheckInWorker.cs +++ b/ExtractorUtils/Unstable/Tasks/CheckInWorker.cs @@ -254,14 +254,37 @@ private async Task ReportCheckIn(CancellationToken token) } else { - newErrors = _errors.Values.ToList(); + newErrors = new List(_errors.Values); + foreach (var err in _errors.Values) + { + // Modifying err since it's an object reference in the dictionary, so changes will be reflected when we write the check-in, + // but we want to log the full error before truncating. + _logger.LogInformation("Error: {ExternalId}, Level: {Level}, Description: {Description}, Details: {Details}, Task: {Task}, StartTime: {StartTime}, EndTime: {EndTime}", + err.ExternalId, err.Level, err.Description, err.Details, err.Task, err.StartTime, err.EndTime); + if (err.Description != null && err.Description.Length > 5000) + { + _logger.LogWarning("Truncating description for error {ExternalId} to 5,000 characters. Original length was {OriginalLength}", err.ExternalId, err.Description.Length); + err.Description = err.Description.Substring(0, 5000); + } + else if (err.Details != null && err.Details.Length > 5000) + { + _logger.LogWarning("Error {ExternalId} has details exceeding 5,000 characters, truncating. Original length was {OriginalLength}", err.ExternalId, err.Details.Length); + err.Details = err.Details.Substring(0, 5000); + } + } _errors.Clear(); taskUpdates = _taskUpdates; _taskUpdates = new List(); } } - newErrors.Sort((a, b) => (a.EndTime ?? a.StartTime).CompareTo(b.EndTime ?? b.StartTime)); + newErrors.Sort((a, b) => + { + long? aTime = a.EndTime ?? a.StartTime; + long? bTime = b.EndTime ?? b.StartTime; + // Handle null timestamps by treating them as 0 (earliest possible time) + return (aTime ?? 0).CompareTo(bTime ?? 0); + }); taskUpdates.Sort((a, b) => a.Timestamp.CompareTo(b.Timestamp)); while (!token.IsCancellationRequested)