From 3c365e8786f6fdb29602ab4ff75eb9cbb1f3302a Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Tue, 10 Nov 2026 14:08:38 -0600 Subject: [PATCH 1/2] Keep the newest log entries when trimming an oversized diagnostic report The report was cut to the server's 10 MB limit by keeping its first bytes, which dropped the most recent device log entries and every section after the log. Keep the first 1 MB (build details and device state) and fill the rest from the end, cutting at line breaks. --- .../IssueReport/SendIssueReportView.swift | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/LoopSupportKitUI/IssueReport/SendIssueReportView.swift b/LoopSupportKitUI/IssueReport/SendIssueReportView.swift index 80fa484..6c9f297 100644 --- a/LoopSupportKitUI/IssueReport/SendIssueReportView.swift +++ b/LoopSupportKitUI/IssueReport/SendIssueReportView.swift @@ -219,9 +219,8 @@ struct SendIssueReportView: View { var attachments = screenshots.map(\.attachment) if includeDiagnosticReport, let generateDiagnosticReport { let report = await generateDiagnosticReport() - // Stay under the server's per-file limit; decoding repairs a character cut in half - let text = String(decoding: report.utf8.prefix(Self.maxAttachmentBytes - 4), as: UTF8.self) - attachments.append(.init(filename: "diagnostic-report.txt", contentType: "text/plain; charset=utf-8", data: Data(text.utf8))) + let data = Self.fitted(Data(report.utf8), toBytes: Self.maxAttachmentBytes - 4) + attachments.append(.init(filename: "diagnostic-report.txt", contentType: "text/plain; charset=utf-8", data: data)) } let report = IssueReport( title: title.isEmpty ? nil : String(title.prefix(200)), @@ -243,6 +242,20 @@ struct SendIssueReportView: View { } } + /// Keeps the start of the report (build details and device state) and as much of its end as fits, + /// cutting at line breaks, so an oversized report loses its oldest log entries rather than its newest. + static func fitted(_ data: Data, toBytes limit: Int, headBytes: Int = 1_000_000) -> Data { + guard data.count > limit else { return data } + let marker = Data("\n[… older entries removed to fit the size limit …]\n".utf8) + let newline = UInt8(ascii: "\n") + let headLimit = min(headBytes, limit / 2) + let headEnd = data[..<(data.startIndex + headLimit)].lastIndex(of: newline).map { $0 + 1 } ?? data.startIndex + let tailLimit = limit - (headEnd - data.startIndex) - marker.count + let tailCut = data.endIndex - tailLimit + let tailStart = data[tailCut...].firstIndex(of: newline).map { $0 + 1 } ?? data.endIndex + return data[.. IssueReport.Contact? { func clean(_ value: String?) -> String? { let value = value?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" From 1ee28d1501421428ea415a8b57ad215819b6f8a3 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Tue, 10 Nov 2026 14:44:23 -0600 Subject: [PATCH 2/2] Allow a 20 MB diagnostic report The issue server now accepts attachments up to 20 MiB. Screenshots keep the 10 MB limit. --- LoopSupportKitUI/IssueReport/SendIssueReportView.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LoopSupportKitUI/IssueReport/SendIssueReportView.swift b/LoopSupportKitUI/IssueReport/SendIssueReportView.swift index 6c9f297..988481a 100644 --- a/LoopSupportKitUI/IssueReport/SendIssueReportView.swift +++ b/LoopSupportKitUI/IssueReport/SendIssueReportView.swift @@ -29,6 +29,7 @@ struct SendIssueReportView: View { private static let maxDescriptionLength = 20_000 private static let maxScreenshots = 8 private static let maxAttachmentBytes = 10_000_000 + private static let maxDiagnosticReportBytes = 20_000_000 private struct Screenshot: Identifiable { let id = UUID() @@ -219,7 +220,7 @@ struct SendIssueReportView: View { var attachments = screenshots.map(\.attachment) if includeDiagnosticReport, let generateDiagnosticReport { let report = await generateDiagnosticReport() - let data = Self.fitted(Data(report.utf8), toBytes: Self.maxAttachmentBytes - 4) + let data = Self.fitted(Data(report.utf8), toBytes: Self.maxDiagnosticReportBytes) attachments.append(.init(filename: "diagnostic-report.txt", contentType: "text/plain; charset=utf-8", data: data)) } let report = IssueReport(