Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix(providers): keep async jobs pending when a progress poll hits a transport error (#336)

Sharky Wang636270fe70fc
diff --git a/packages/provider-beatapi/src/provider.ts b/packages/provider-beatapi/src/provider.ts
index 48b47eb0..bbb62ba9 100644
--- a/packages/provider-beatapi/src/provider.ts
+++ b/packages/provider-beatapi/src/provider.ts
@@ -181,7 +181,13 @@ function endpoint(client: BeatApiClient, pollIntervalMs: number, maxOperationMs:
if (Date.now() - handle.startedAt > maxOperationMs) {
return { status: "failed", receipt, failure: { code: "BEATAPI_OPERATION_TIMEOUT", message: `BeatAPI task ${handle.taskId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
}
- const task = await client.json(`/v1/tasks/${encodeURIComponent(handle.taskId)}`, apiKey(context.credentials));
+ let task: Record<string, unknown>;
+ try {
+ task = await client.json(`/v1/tasks/${encodeURIComponent(handle.taskId)}`, apiKey(context.credentials));
+ } catch (error) {
+ if (error instanceof BeatApiHttpError && error.status < 500) return { ...failure(error), receipt };
+ return { ...wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: "retrying" }), receipt };
+ }
const status = String(task.status);
if (pendingStatuses.includes(status)) {
return { ...wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: status }), receipt };
diff --git a/packages/provider-hiapi/src/provider.ts b/packages/provider-hiapi/src/provider.ts
index c9870473..236564b1 100644
--- a/packages/provider-hiapi/src/provider.ts
+++ b/packages/provider-hiapi/src/provider.ts
@@ -155,7 +155,13 @@ function endpoint(client: HiApiClient, pollIntervalMs: number, maxOperationMs: n
if (Date.now() - handle.startedAt > maxOperationMs) {
return { status: "failed", receipt, failure: { code: "HIAPI_OPERATION_TIMEOUT", message: `HiAPI task ${handle.taskId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
}
- const task = await client.json(`/v1/tasks/${encodeURIComponent(handle.taskId)}`, apiKey(context.credentials));
+ let task: Record<string, unknown>;
+ try {
+ task = await client.json(`/v1/tasks/${encodeURIComponent(handle.taskId)}`, apiKey(context.credentials));
+ } catch (error) {
+ if (error instanceof HiApiHttpError && error.status < 500) return { ...failure(error), receipt };
+ return { ...wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: "retrying" }), receipt };
+ }
const status = String(task.status);
if (status === "queued" || status === "handling" || status === "archiving") {
return { ...wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: status }), receipt };
diff --git a/packages/provider-hypihub/src/provider.ts b/packages/provider-hypihub/src/provider.ts
index 7b88fe9f..8ecbebc3 100644
--- a/packages/provider-hypihub/src/provider.ts
+++ b/packages/provider-hypihub/src/provider.ts
@@ -494,7 +494,14 @@ function endpoint(client: HypiHubClient, pollIntervalMs: number, maxOperationMs:
receipt: { id: handle.jobId },
failure: { code: "HYPIHUB_OPERATION_TIMEOUT", message: `HypiHub job ${handle.jobId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
}
- const job = await client.json(`/jobs/${encodeURIComponent(handle.jobId)}`, authFor(context, client)); const status = job.status;
+ let job: Record<string, unknown>;
+ try {
+ job = await client.json(`/jobs/${encodeURIComponent(handle.jobId)}`, authFor(context, client));
+ } catch (error) {
+ if (error instanceof HypiHubHttpError && error.status < 500) return failure(error);
+ return wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: "retrying" });
+ }
+ const status = job.status;
if (status === "queued" || status === "running" || status === "in_progress") return wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: String(status) });
const rejected = hypiHubJobFailure(job, handle.jobId);
if (rejected !== undefined) return { ...failure(rejected), receipt: { id: handle.jobId } };
diff --git a/packages/provider-hypihub/test/provider.test.ts b/packages/provider-hypihub/test/provider.test.ts
index b8bb3b03..0c0f1d9a 100644
--- a/packages/provider-hypihub/test/provider.test.ts
+++ b/packages/provider-hypihub/test/provider.test.ts
@@ -786,7 +786,7 @@ test("HypiHub exposes model groups beneath its own total capacity", async () =>
assert.throws(() => createHypiHubProvider({ capabilityConcurrency: { invented: 1 } }), /unknown HypiHub capacity/);
});
-test("HypiHub polling errors and operation deadlines fail without settlement polling", async () => {
+test("HypiHub operation deadlines fail while polling transport errors keep the job pending", async () => {
const request = need({});
let requests = 0;
const registry = new EndpointRegistry();
@@ -807,8 +807,8 @@ test("HypiHub polling errors and operation deadlines fail without settlement pol
assert.equal(timedOut.status === "failed" && timedOut.failure.code, "HYPIHUB_OPERATION_TIMEOUT");
assert.equal(requests, 0);
const offline = await endpoint.poll({ ...common, handle: { ...common.handle, startedAt: Date.now() } });
- assert.equal(offline.status, "failed");
- assert.match(offline.status === "failed" ? offline.failure.message : "", /offline/);
+ assert.equal(offline.status, "pending");
+ assert.equal(offline.status === "pending" && offline.progress?.phase, "retrying");
assert.equal(requests, 1);
});
diff --git a/packages/provider-monid/src/provider.ts b/packages/provider-monid/src/provider.ts
index 023070a0..c52f046b 100644
--- a/packages/provider-monid/src/provider.ts
+++ b/packages/provider-monid/src/provider.ts
@@ -202,7 +202,13 @@ function endpoint(client: MonidClient, pollIntervalMs: number, maxOperationMs: n
if (Date.now() - handle.startedAt > maxOperationMs) {
return { status: "failed", receipt, failure: { code: "MONID_OPERATION_TIMEOUT", message: `Monid run ${handle.runId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
}
- const run = await client.getRun(handle.runId, apiKey(context.credentials));
+ let run: Record<string, unknown>;
+ try {
+ run = await client.getRun(handle.runId, apiKey(context.credentials));
+ } catch (error) {
+ if (error instanceof MonidHttpError && error.status < 500) return { ...failure(error), receipt };
+ return { ...wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: "retrying" }), receipt };
+ }
const status = String(run.status);
if (!monidTerminalStatuses.includes(status as typeof monidTerminalStatuses[number])) {
return { ...wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: status }), receipt };
diff --git a/packages/provider-pollo/src/provider.ts b/packages/provider-pollo/src/provider.ts
index ff3ffdcd..b5035dcb 100644
--- a/packages/provider-pollo/src/provider.ts
+++ b/packages/provider-pollo/src/provider.ts
@@ -133,7 +133,13 @@ function endpoint(client: PolloClient, pollIntervalMs: number, maxOperationMs: n
if (Date.now() - handle.startedAt > maxOperationMs) {
return { status: "failed", receipt, failure: { code: "POLLO_OPERATION_TIMEOUT", message: `Pollo task ${handle.taskId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
}
- const task = await client.json(`/v1/generation/${encodeURIComponent(handle.taskId)}/status`, apiKey(context.credentials));
+ let task: Record<string, unknown>;
+ try {
+ task = await client.json(`/v1/generation/${encodeURIComponent(handle.taskId)}/status`, apiKey(context.credentials));
+ } catch (error) {
+ if (error instanceof PolloHttpError && error.status < 500) return { ...failure(error), receipt };
+ return { ...wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: "retrying" }), receipt };
+ }
assert(Array.isArray(task.generations) && task.generations.length > 0, "Pollo task has no generations");
const generations = task.generations.map((item, index) => object(item, `Pollo generation ${index + 1}`));
const rejected = polloTaskFailure(generations, handle.taskId);
diff --git a/packages/provider-tokendance/src/provider.ts b/packages/provider-tokendance/src/provider.ts
index 3fee0ca2..08be4264 100644
--- a/packages/provider-tokendance/src/provider.ts
+++ b/packages/provider-tokendance/src/provider.ts
@@ -208,7 +208,14 @@ function endpoint(client: TokenDanceClient, pollIntervalMs: number, maxOperation
if (Date.now() - handle.startedAt > maxOperationMs) {
return { status: "failed", receipt, failure: { code: "TOKENDANCE_OPERATION_TIMEOUT", message: `TokenDance task ${handle.taskId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
}
- const task = taskBody(route.protocol, await client.json(paths[route.protocol].task(handle.taskId), apiKey(context.credentials)));
+ let response: Record<string, unknown>;
+ try {
+ response = await client.json(paths[route.protocol].task(handle.taskId), apiKey(context.credentials));
+ } catch (error) {
+ if (error instanceof TokenDanceHttpError && error.status < 500) return { ...failure(error), receipt };
+ return { ...wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: "retrying" }), receipt };
+ }
+ const task = taskBody(route.protocol, response);
const status = String(task.status);
if (status === "queued" || status === "running") return { ...wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: status }), receipt };
const rejected = tokenDanceTaskFailure(task, handle.taskId);