@infernetprotocol/cli 0.1.52 → 0.1.54

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.
package/commands/start.js CHANGED
@@ -48,7 +48,7 @@ import { executeChatJob, failChatJob, shutdownEngine } from '../lib/chat-executo
48
48
  import { gatherCoarseSpecs } from './register.js';
49
49
  import { checkModelFits, formatFitFailure } from '../lib/model-fit.js';
50
50
  import { downloadHfModel, resolveHfToken } from '../lib/hf-model.js';
51
- import { startVllmServe, vllmInstalled, waitForVllmModel, extractVllmError } from '../lib/vllm.js';
51
+ import { startVllmServe, stopVllmServe, vllmInstalled, waitForVllmModel, extractVllmError } from '../lib/vllm.js';
52
52
  import { detectGpus, detectHost } from '@infernetprotocol/gpu';
53
53
  import { getOrCreateModelKey, getModelPublicKeys } from '../lib/model-key.js';
54
54
  import { pullLatestBinary } from './upgrade.js';
@@ -643,24 +643,55 @@ async function runDaemon(args, ctx) {
643
643
  // model name so chat requests + served_models match, but the
644
644
  // engine underneath is vLLM.
645
645
  const token = process.env.HF_TOKEN || (await resolveHfToken().catch(() => null));
646
+ // Step 1/3 — download weights.
647
+ await client.updateCommandProgress(id, {
648
+ phase: 'download', step: 1, steps: 3, status: 'downloading weights'
649
+ }).catch(() => {});
646
650
  const localPath = await downloadHfModel(hfRepo, token);
647
651
  // Don't report "completed" on spawn — wait until vLLM has
648
652
  // mapped the weights and /v1/models actually lists the model.
649
653
  // If it never comes up (OOM, unsupported arch, gated repo),
650
654
  // fail the command WITH the log root cause instead of lying.
655
+ // Step 2/3 — start the engine + wait for it to serve.
656
+ await client.updateCommandProgress(id, {
657
+ phase: 'serve', step: 2, steps: 3, status: 'starting vLLM engine', pct: 0
658
+ }).catch(() => {});
651
659
  const serve = await startVllmServe({ source: hfRepo, servedName: modelName, token });
652
660
  process.stdout.write(`[${new Date().toISOString()}] ${modelName} (${hfRepo}) downloaded; waiting for vLLM to load weights…\n`);
653
- // Slow (virtualized) GPUs can take 10+ min to bring the
654
- // engine up; match vLLM's raised VLLM_ENGINE_READY_TIMEOUT_S.
655
- const vllmWaitMs = Number(process.env.VLLM_ENGINE_READY_TIMEOUT_S || 1800) * 1000;
656
- const up = await waitForVllmModel(modelName, { pid: serve.pid, timeoutMs: vllmWaitMs });
661
+ // Auto-cancel ceiling: give up after VLLM_INSTALL_TIMEOUT_S
662
+ // (default 10 min). Each tick reports progress AND checks
663
+ // whether the owner cancelled (the progress response echoes
664
+ // the command status) so a stuck install can be stopped.
665
+ const vllmWaitMs = Number(process.env.VLLM_INSTALL_TIMEOUT_S || 600) * 1000;
666
+ const up = await waitForVllmModel(modelName, {
667
+ pid: serve.pid,
668
+ timeoutMs: vllmWaitMs,
669
+ onTick: async ({ elapsedMs, timeoutMs }) => {
670
+ const pct = Math.min(99, Math.round((elapsedMs / timeoutMs) * 100));
671
+ const resp = await client.updateCommandProgress(id, {
672
+ phase: 'serve', step: 2, steps: 3, status: 'starting vLLM engine', pct
673
+ }).catch(() => null);
674
+ if (resp?.status === 'cancelled') return 'cancel';
675
+ }
676
+ });
677
+ if (up.cancelled) {
678
+ await stopVllmServe().catch(() => {});
679
+ invalidateSpecsCache();
680
+ process.stdout.write(`[${new Date().toISOString()}] ${modelName} install cancelled — stopped vLLM\n`);
681
+ return; // status is already 'cancelled'; don't complete
682
+ }
657
683
  if (!up.serving) {
684
+ await stopVllmServe().catch(() => {});
658
685
  const tail = await extractVllmError();
659
686
  throw new Error(
660
687
  `vLLM failed to serve ${modelName} (${hfRepo}): ${up.reason}.` +
661
688
  (tail ? `\n--- vllm.log (root cause) ---\n${tail}` : ' (no vllm.log output)')
662
689
  );
663
690
  }
691
+ // Step 3/3 — serving.
692
+ await client.updateCommandProgress(id, {
693
+ phase: 'serve', step: 3, steps: 3, status: 'serving', pct: 100
694
+ }).catch(() => {});
664
695
  invalidateSpecsCache();
665
696
  result = {
666
697
  model: modelName,
package/lib/vllm.js CHANGED
@@ -150,8 +150,9 @@ export async function extractVllmError({ headLines = 16, tailLines = 30, fallbac
150
150
  * appears, bails early if the process dies, and times out otherwise.
151
151
  * A 9B model maps to GPU in ~1-2 min, so the default budget is generous.
152
152
  */
153
- export async function waitForVllmModel(servedName, { pid = null, timeoutMs = 300_000, intervalMs = 3000 } = {}) {
154
- const deadline = Date.now() + timeoutMs;
153
+ export async function waitForVllmModel(servedName, { pid = null, timeoutMs = 300_000, intervalMs = 3000, onTick = null } = {}) {
154
+ const start = Date.now();
155
+ const deadline = start + timeoutMs;
155
156
  while (Date.now() < deadline) {
156
157
  if (pid && !isPidAlive(pid)) {
157
158
  return { serving: false, reason: 'vLLM process exited during startup (check the log tail below)' };
@@ -160,9 +161,19 @@ export async function waitForVllmModel(servedName, { pid = null, timeoutMs = 300
160
161
  if (servedName ? models.includes(servedName) : models.length > 0) {
161
162
  return { serving: true, models };
162
163
  }
164
+ // Per-tick hook: report progress + let the caller abort (user cancel).
165
+ // Returning 'cancel' (or a truthy .cancel) stops the wait immediately.
166
+ if (onTick) {
167
+ try {
168
+ const r = await onTick({ elapsedMs: Date.now() - start, timeoutMs });
169
+ if (r === 'cancel' || r?.cancel) {
170
+ return { serving: false, cancelled: true, reason: 'cancelled by user' };
171
+ }
172
+ } catch { /* onTick is best-effort */ }
173
+ }
163
174
  await sleep(intervalMs);
164
175
  }
165
- return { serving: false, reason: `timed out after ${Math.round(timeoutMs / 1000)}s waiting for /v1/models to list ${servedName}` };
176
+ return { serving: false, timedOut: true, reason: `timed out after ${Math.round(timeoutMs / 1000)}s waiting for /v1/models to list ${servedName}` };
166
177
  }
167
178
 
168
179
  /** True when the tracked serve pid is alive AND /v1/models answers. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infernetprotocol/cli",
3
- "version": "0.1.52",
3
+ "version": "0.1.54",
4
4
  "description": "GPU-node CLI / daemon for the Infernet Protocol — register a GPU server with a Supabase control plane and start earning.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,12 +30,12 @@
30
30
  "ora": "^9.4.0",
31
31
  "react": "^17.0.2",
32
32
  "react-blessed": "^0.7.2",
33
- "@infernetprotocol/config": "0.1.52",
34
- "@infernetprotocol/auth": "0.1.52",
35
- "@infernetprotocol/deploy-providers": "0.1.52",
36
- "@infernetprotocol/rpc-adapter": "0.1.52",
37
- "@infernetprotocol/gpu": "0.1.52",
38
- "@infernetprotocol/engine": "0.1.52"
33
+ "@infernetprotocol/auth": "0.1.54",
34
+ "@infernetprotocol/deploy-providers": "0.1.54",
35
+ "@infernetprotocol/config": "0.1.54",
36
+ "@infernetprotocol/engine": "0.1.54",
37
+ "@infernetprotocol/gpu": "0.1.54",
38
+ "@infernetprotocol/rpc-adapter": "0.1.54"
39
39
  },
40
40
  "repository": {
41
41
  "type": "git",