@tiens.nguyen/gonext-local-worker 1.0.34 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -113,6 +113,14 @@ async function workerFetch(path, init = {}) {
113
113
  return fetch(url, { ...init, headers });
114
114
  }
115
115
 
116
+ async function ensureWorkerOk(res, context) {
117
+ if (res.ok) return;
118
+ const snippet = (await res.text().catch(() => "")).trim().slice(0, 500);
119
+ throw new Error(
120
+ `${context} failed ${res.status}${snippet ? `: ${snippet}` : ""}`
121
+ );
122
+ }
123
+
116
124
  if (args[0] === "ws-ping-test") {
117
125
  if (!apiBase || !workerKey) {
118
126
  console.error(
@@ -407,7 +415,7 @@ async function runChatJob(job) {
407
415
  logModelResponseToWorker(jobId, payload.modelId, fullText);
408
416
 
409
417
  const totalTimeSeconds = (Date.now() - start) / 1000;
410
- await workerFetch(`/api/worker/jobs/${jobId}`, {
418
+ const doneRes = await workerFetch(`/api/worker/jobs/${jobId}`, {
411
419
  method: "PATCH",
412
420
  body: JSON.stringify({
413
421
  jobStatus: "completed",
@@ -416,6 +424,7 @@ async function runChatJob(job) {
416
424
  totalTimeSeconds,
417
425
  }),
418
426
  });
427
+ await ensureWorkerOk(doneRes, `complete PATCH jobId=${jobId}`);
419
428
  console.log(`[gonext-worker] completed ${jobId} (${totalTimeSeconds.toFixed(1)}s)`);
420
429
  } catch (e) {
421
430
  if (flushTimer) {
@@ -425,7 +434,7 @@ async function runChatJob(job) {
425
434
  await flushTail;
426
435
  await flushChunks().catch(() => {});
427
436
  const message = e instanceof Error ? e.message : String(e);
428
- await workerFetch(`/api/worker/jobs/${jobId}`, {
437
+ const failRes = await workerFetch(`/api/worker/jobs/${jobId}`, {
429
438
  method: "PATCH",
430
439
  body: JSON.stringify({
431
440
  jobStatus: "failed",
@@ -433,6 +442,13 @@ async function runChatJob(job) {
433
442
  totalTimeSeconds: (Date.now() - start) / 1000,
434
443
  }),
435
444
  });
445
+ if (!failRes.ok) {
446
+ const snippet = (await failRes.text().catch(() => "")).trim().slice(0, 500);
447
+ console.error(
448
+ `[gonext-worker] failed status PATCH also failed ${failRes.status} jobId=${jobId}` +
449
+ (snippet ? ` response=${snippet}` : "")
450
+ );
451
+ }
436
452
  console.error(`[gonext-worker] failed ${jobId}:`, message);
437
453
  }
438
454
  }
@@ -559,10 +575,11 @@ async function runLocalHealthJob(job) {
559
575
  console.log(
560
576
  `[gonext-worker] local_health ${jobId} start (ollamaUrls=${ollamaPayloadCount}, mlx=${payload?.mlxOpenAiBaseUrl ? "yes" : "no"})`
561
577
  );
562
- await workerFetch(`/api/worker/jobs/${jobId}`, {
578
+ const runRes = await workerFetch(`/api/worker/jobs/${jobId}`, {
563
579
  method: "PATCH",
564
580
  body: JSON.stringify({ jobStatus: "running" }),
565
581
  });
582
+ await ensureWorkerOk(runRes, `mark running local_health jobId=${jobId}`);
566
583
  try {
567
584
  const ollamaBases = Array.isArray(payload?.ollamaBaseUrls)
568
585
  ? payload.ollamaBaseUrls.map(normalizeBaseUrl).filter(Boolean)
@@ -665,7 +682,7 @@ async function runLocalHealthJob(job) {
665
682
  mlx,
666
683
  };
667
684
  const totalTimeSeconds = (Date.now() - start) / 1000;
668
- await workerFetch(`/api/worker/jobs/${jobId}`, {
685
+ const doneRes = await workerFetch(`/api/worker/jobs/${jobId}`, {
669
686
  method: "PATCH",
670
687
  body: JSON.stringify({
671
688
  jobStatus: "completed",
@@ -674,13 +691,14 @@ async function runLocalHealthJob(job) {
674
691
  totalTimeSeconds,
675
692
  }),
676
693
  });
694
+ await ensureWorkerOk(doneRes, `complete local_health jobId=${jobId}`);
677
695
  const onlineCount = ollamaSources.filter((s) => s.online).length;
678
696
  console.log(
679
697
  `[gonext-worker] completed local_health ${jobId} (${totalTimeSeconds.toFixed(1)}s) summary: ollamaOnline=${onlineCount}/${ollamaSources.length}, mlx=${mlx ? (mlx.online ? "online" : "offline") : "n/a"}`
680
698
  );
681
699
  } catch (e) {
682
700
  const message = e instanceof Error ? e.message : String(e);
683
- await workerFetch(`/api/worker/jobs/${jobId}`, {
701
+ const failRes = await workerFetch(`/api/worker/jobs/${jobId}`, {
684
702
  method: "PATCH",
685
703
  body: JSON.stringify({
686
704
  jobStatus: "failed",
@@ -688,6 +706,13 @@ async function runLocalHealthJob(job) {
688
706
  totalTimeSeconds: (Date.now() - start) / 1000,
689
707
  }),
690
708
  });
709
+ if (!failRes.ok) {
710
+ const snippet = (await failRes.text().catch(() => "")).trim().slice(0, 500);
711
+ console.error(
712
+ `[gonext-worker] local_health fail PATCH also failed ${failRes.status} jobId=${jobId}` +
713
+ (snippet ? ` response=${snippet}` : "")
714
+ );
715
+ }
691
716
  console.error(`[gonext-worker] failed local_health ${jobId}:`, message);
692
717
  }
693
718
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gonext-local-worker",
3
- "version": "1.0.34",
3
+ "version": "1.0.36",
4
4
  "description": "Polls GoNext cloud API for async local LLM jobs and runs them against Ollama/OpenAI-compatible servers on this Mac",
5
5
  "type": "module",
6
6
  "license": "MIT",