From 72041a611f8c2e1f6ec6c34998ed8ba8b83f628c Mon Sep 17 00:00:00 2001 From: Ram Date: Mon, 11 Sep 2023 20:52:36 +0530 Subject: [PATCH 1/3] fix: Added retry config and showed error from subtask in web --- integrations/openai/src/completions.ts | 18 ++++++++++++++++++ packages/trigger-sdk/src/io.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/integrations/openai/src/completions.ts b/integrations/openai/src/completions.ts index e52013a201..952fcbac5e 100644 --- a/integrations/openai/src/completions.ts +++ b/integrations/openai/src/completions.ts @@ -52,6 +52,24 @@ export class Completions { ...(client.organization ? { "OpenAI-Organization": client.organization } : {}), }, body: JSON.stringify(params), + }, + { + "500-599": { + strategy: "backoff", + limit: 5, + minTimeoutInMs: 1000, + maxTimeoutInMs: 30000, + factor: 1.8, + randomize: true, + }, + "429": { + strategy: "backoff", + limit: 10, + minTimeoutInMs: 1000, + maxTimeoutInMs: 60000, + factor: 2, + randomize: true, + }, } ); diff --git a/packages/trigger-sdk/src/io.ts b/packages/trigger-sdk/src/io.ts index 9f80b33e4b..489e8d1d35 100644 --- a/packages/trigger-sdk/src/io.ts +++ b/packages/trigger-sdk/src/io.ts @@ -527,7 +527,7 @@ export class IO { task, }); - throw new Error(task.error ?? "Task errored"); + throw new Error(task.error ?? JSON.stringify(task?.output)); } if (task.status === "WAITING") { From 7935044749b0dc327f9f19ff1cdd82d530403e9e Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Tue, 12 Sep 2023 16:21:40 +0100 Subject: [PATCH 2/3] Still fallback to "Task errored" if there's no output --- packages/trigger-sdk/src/io.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/trigger-sdk/src/io.ts b/packages/trigger-sdk/src/io.ts index 489e8d1d35..1e3574e0d1 100644 --- a/packages/trigger-sdk/src/io.ts +++ b/packages/trigger-sdk/src/io.ts @@ -527,7 +527,7 @@ export class IO { task, }); - throw new Error(task.error ?? JSON.stringify(task?.output)); + throw new Error(task.error ?? task?.output ? JSON.stringify(task.output) : "Task errored"); } if (task.status === "WAITING") { From aed1f58ea2e93615ed16bd884c627a252b568b36 Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Tue, 12 Sep 2023 16:25:01 +0100 Subject: [PATCH 3/3] Create rude-carrots-enjoy.md --- .changeset/rude-carrots-enjoy.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/rude-carrots-enjoy.md diff --git a/.changeset/rude-carrots-enjoy.md b/.changeset/rude-carrots-enjoy.md new file mode 100644 index 0000000000..925c540e2a --- /dev/null +++ b/.changeset/rude-carrots-enjoy.md @@ -0,0 +1,6 @@ +--- +"@trigger.dev/sdk": patch +"@trigger.dev/openai": patch +--- + +Errors now bubbled up. OpenAI background retrying improved