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
5 changes: 5 additions & 0 deletions .changeset/fix-automatic-attachment-uploads.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"braintrust": patch
---

fix(logger): Keep automatic attachment uploads enabled after a failure
17 changes: 6 additions & 11 deletions js/src/logger/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3549,7 +3549,6 @@ class HTTPBackgroundLogger implements BackgroundLogger {
private _pendingBytes: number = 0;

private _disabled = false;
private automaticAttachmentsDisabled = false;

private queueDropLoggingState = {
numDropped: 0,
Expand Down Expand Up @@ -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(
Expand Down
23 changes: 16 additions & 7 deletions js/src/span-customizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down