Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions assistant/src/daemon/handlers/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,20 @@ export function handleHistoryRequest(
if (m.role === 'assistant' && m.id) {
const linked = getAttachmentsForMessageUnscoped(m.id);
if (linked.length > 0) {
// Skip embedding base64 data for attachments larger than 512KB to keep
// the history_response payload small enough for the client to decode
// reliably. The client fetches large attachment data lazily via HTTP.
// Skip embedding base64 data for large video attachments to keep the
// history_response payload small. Only videos have a lazy-fetch path on
// the client, so non-video attachments always keep their inline data.
const MAX_INLINE_B64_SIZE = 512 * 1024;
attachments = linked.map((a) => ({
id: a.id,
filename: a.originalFilename,
mimeType: a.mimeType,
data: a.dataBase64.length > MAX_INLINE_B64_SIZE ? '' : a.dataBase64,
...(a.dataBase64.length > MAX_INLINE_B64_SIZE ? { sizeBytes: a.sizeBytes } : {}),
}));
attachments = linked.map((a) => {
const omit = a.mimeType.startsWith('video/') && a.dataBase64.length > MAX_INLINE_B64_SIZE;
return {
id: a.id,
filename: a.originalFilename,
mimeType: a.mimeType,
data: omit ? '' : a.dataBase64,
...(omit ? { sizeBytes: a.sizeBytes } : {}),
};
});
}
}
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,19 @@ struct InlineVideoAttachmentView: View {
do {
let base64 = try await fetchAttachmentData(port: port, attachmentId: attachmentId)
guard let data = Data(base64Encoded: base64) else {
await MainActor.run { isLoading = false }
await MainActor.run {
isLoading = false
failed = true
}
return
}
try data.write(to: destURL)
await MainActor.run { isLoading = false }
} catch {
await MainActor.run { isLoading = false }
await MainActor.run {
isLoading = false
failed = true
}
Comment on lines +201 to +204

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid marking playback failed on save I/O errors

This catch handles both fetch failures and data.write(to: destURL) failures, so setting failed = true here can switch the attachment into the “Could not play video” state even when playback is actually fine and only the save destination failed (for example, permission denied or disk full). That regresses the user flow by turning a save-specific error into a persistent playback failure.

Useful? React with 👍 / 👎.

}
}
} else {
Expand All @@ -211,7 +217,13 @@ struct InlineVideoAttachmentView: View {
Task {
do {
let base64 = try await fetchAttachmentData(port: port, attachmentId: attachmentId)
guard let data = Data(base64Encoded: base64) else { return }
guard let data = Data(base64Encoded: base64) else {
await MainActor.run {
isLoading = false
failed = true
}
return
}
let fileURL = safeTempURL()
try data.write(to: fileURL)
await MainActor.run {
Expand Down