From c0d50e622eca4075d78396eb8e1c624713bc2d72 Mon Sep 17 00:00:00 2001 From: lforst <8118419+lforst@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:45:46 +0000 Subject: [PATCH 1/2] fix(logger): Keep automatic attachment uploads enabled after a failure --- js/src/logger/core.ts | 17 ++++++----------- js/src/span-customizer.test.ts | 23 ++++++++++++++++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/js/src/logger/core.ts b/js/src/logger/core.ts index 299391d6d..1dd214eaa 100644 --- a/js/src/logger/core.ts +++ b/js/src/logger/core.ts @@ -3549,7 +3549,6 @@ class HTTPBackgroundLogger implements BackgroundLogger { private _pendingBytes: number = 0; private _disabled = false; - private automaticAttachmentsDisabled = false; private queueDropLoggingState = { numDropped: 0, @@ -3816,20 +3815,16 @@ class HTTPBackgroundLogger implements BackgroundLogger { ); return true; }); - for (const attachment of automatic) { - if (this.automaticAttachmentsDisabled) break; - try { + try { + for (const attachment of automatic) { const status = await attachment.upload(); if (status.upload_status === "error") throw new Error("Automatic attachment upload failed"); - } catch { - this.automaticAttachmentsDisabled = true; - debugLogger.warn( - "Automatic attachment uploads disabled after an upload failure; exporting original inline media.", - ); } - } - if (this.automaticAttachmentsDisabled && automatic.length) { + } catch { + debugLogger.warn( + "Automatic attachment upload failed. Exporting original inline media for this batch.", + ); for (const group of allItems) { for (let i = 0; i < group.length; i++) { group[i] = restoreAutomaticAttachments( diff --git a/js/src/span-customizer.test.ts b/js/src/span-customizer.test.ts index a0f7095b4..30f58df43 100644 --- a/js/src/span-customizer.test.ts +++ b/js/src/span-customizer.test.ts @@ -1409,18 +1409,27 @@ describe("onSpanExport", () => { }); } else { expect(exported.input).toEqual(expected); - // A failed pipeline skips uploads for subsequent spans and keeps inline data. const later = processInputAttachments(input, true); - const laterUpload = vi.spyOn( - later.state[0].content[2].image_url, - "upload", - ); + const laterUpload = vi + .spyOn(Attachment.prototype, "upload") + .mockResolvedValue({ upload_status: "done" }); const next = logger.startSpan({ name: "next" }); next.log({ input: later }); next.end(); await logger.flush(); - expect(laterUpload).not.toHaveBeenCalled(); - expect(rows.find((row) => row.id === next.id)?.input).toEqual(expected); + expect(laterUpload).toHaveBeenCalledTimes(2); + expect(rows.find((row) => row.id === next.id)?.input).toMatchObject({ + state: [ + { + content: [ + { type: "input_text", text: "inspect" }, + { image_url: "[redacted]" }, + { image_url: later.state[0].content[2].image_url.reference }, + { image_url: later.state[0].content[3].image_url.reference }, + ], + }, + ], + }); } expect(uploads[0]).not.toHaveBeenCalled(); expect(uploads[1]).toHaveBeenCalledOnce(); From 34f479cde0e3314e6c87251f3ee58d2e1c224a8e Mon Sep 17 00:00:00 2001 From: lforst <8118419+lforst@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:02:32 +0000 Subject: [PATCH 2/2] Update PR #2837 --- .changeset/fix-automatic-attachment-uploads.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fix-automatic-attachment-uploads.md diff --git a/.changeset/fix-automatic-attachment-uploads.md b/.changeset/fix-automatic-attachment-uploads.md new file mode 100644 index 000000000..edd62aa9a --- /dev/null +++ b/.changeset/fix-automatic-attachment-uploads.md @@ -0,0 +1,5 @@ +--- +"braintrust": patch +--- + +fix(logger): Keep automatic attachment uploads enabled after a failure