@nosana/node 1.1.84 → 1.1.85-rc

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.
Files changed (180) hide show
  1. package/dist/.env +2 -1
  2. package/dist/package.json +1 -1
  3. package/dist/packages/job-runtime/src/host/HostClient.d.ts +20 -4
  4. package/dist/packages/job-runtime/src/host/HostClient.js +35 -2
  5. package/dist/packages/job-runtime/src/host/contract.d.ts +27 -7
  6. package/dist/packages/job-runtime/src/host/contract.js +43 -7
  7. package/dist/packages/job-runtime/src/runtime/runJob.d.ts +8 -5
  8. package/dist/packages/job-runtime/src/runtime/runJob.js +44 -17
  9. package/dist/packages/vm-orchestrator/src/CidRegistry.d.ts +67 -0
  10. package/dist/packages/vm-orchestrator/src/CidRegistry.js +168 -0
  11. package/dist/packages/vm-orchestrator/src/GpuPool.d.ts +27 -0
  12. package/dist/packages/vm-orchestrator/src/GpuPool.js +41 -0
  13. package/dist/packages/vm-orchestrator/src/Hypervisor.d.ts +66 -0
  14. package/dist/packages/vm-orchestrator/src/Hypervisor.js +7 -0
  15. package/dist/packages/vm-orchestrator/src/QemuHypervisor.d.ts +62 -0
  16. package/dist/packages/vm-orchestrator/src/QemuHypervisor.js +185 -0
  17. package/dist/packages/vm-orchestrator/src/QemuHypervisorConfig.d.ts +61 -0
  18. package/dist/packages/vm-orchestrator/src/QemuHypervisorConfig.js +37 -0
  19. package/dist/packages/vm-orchestrator/src/QemuVmInstance.d.ts +37 -0
  20. package/dist/packages/vm-orchestrator/src/QemuVmInstance.js +44 -0
  21. package/dist/packages/vm-orchestrator/src/QmpClient.d.ts +43 -0
  22. package/dist/packages/vm-orchestrator/src/QmpClient.js +103 -0
  23. package/dist/packages/vm-orchestrator/src/VmSpec.d.ts +21 -0
  24. package/dist/packages/vm-orchestrator/src/VmSpec.js +30 -0
  25. package/dist/packages/vm-orchestrator/src/VmStateManager.d.ts +16 -0
  26. package/dist/packages/vm-orchestrator/src/VmStateManager.js +30 -0
  27. package/dist/packages/vm-orchestrator/src/bootAttempt.d.ts +31 -0
  28. package/dist/packages/vm-orchestrator/src/bootAttempt.js +193 -0
  29. package/dist/packages/vm-orchestrator/src/bootErrors.d.ts +33 -0
  30. package/dist/packages/vm-orchestrator/src/bootErrors.js +67 -0
  31. package/dist/packages/vm-orchestrator/src/buildCloudInit.d.ts +33 -0
  32. package/dist/packages/vm-orchestrator/src/buildCloudInit.js +55 -0
  33. package/dist/packages/vm-orchestrator/src/buildQemuArgs.d.ts +33 -0
  34. package/dist/packages/vm-orchestrator/src/buildQemuArgs.js +127 -0
  35. package/dist/packages/vm-orchestrator/src/diskSizing.d.ts +18 -0
  36. package/dist/packages/vm-orchestrator/src/diskSizing.js +41 -0
  37. package/dist/packages/vm-orchestrator/src/firmware.d.ts +5 -0
  38. package/dist/packages/vm-orchestrator/src/firmware.js +18 -0
  39. package/dist/packages/vm-orchestrator/src/hostAccess/VmHostAccess.d.ts +22 -0
  40. package/dist/packages/vm-orchestrator/src/hostAccess/VmHostAccess.js +33 -0
  41. package/dist/packages/vm-orchestrator/src/hostAccess/deviceProblems.d.ts +3 -0
  42. package/dist/packages/vm-orchestrator/src/hostAccess/deviceProblems.js +17 -0
  43. package/dist/packages/vm-orchestrator/src/hostAccess/findVmHostAccessProblems.d.ts +9 -0
  44. package/dist/packages/vm-orchestrator/src/hostAccess/findVmHostAccessProblems.js +17 -0
  45. package/dist/packages/vm-orchestrator/src/hostAccess/gpuProblems.d.ts +6 -0
  46. package/dist/packages/vm-orchestrator/src/hostAccess/gpuProblems.js +42 -0
  47. package/dist/packages/vm-orchestrator/src/hostAccess/index.d.ts +1 -0
  48. package/dist/packages/vm-orchestrator/src/hostAccess/index.js +1 -0
  49. package/dist/packages/vm-orchestrator/src/hostAccess/memlockProblems.d.ts +6 -0
  50. package/dist/packages/vm-orchestrator/src/hostAccess/memlockProblems.js +18 -0
  51. package/dist/packages/vm-orchestrator/src/hostAccess/workRootProblems.d.ts +7 -0
  52. package/dist/packages/vm-orchestrator/src/hostAccess/workRootProblems.js +30 -0
  53. package/dist/packages/vm-orchestrator/src/hostDevices.d.ts +12 -0
  54. package/dist/packages/vm-orchestrator/src/hostDevices.js +12 -0
  55. package/dist/packages/vm-orchestrator/src/hostTools.d.ts +25 -0
  56. package/dist/packages/vm-orchestrator/src/hostTools.js +39 -0
  57. package/dist/packages/vm-orchestrator/src/imageCache.d.ts +25 -0
  58. package/dist/packages/vm-orchestrator/src/imageCache.js +73 -0
  59. package/dist/packages/vm-orchestrator/src/imageDownload.d.ts +31 -0
  60. package/dist/packages/vm-orchestrator/src/imageDownload.js +85 -0
  61. package/dist/packages/vm-orchestrator/src/index.d.ts +19 -0
  62. package/dist/packages/vm-orchestrator/src/index.js +15 -0
  63. package/dist/packages/vm-orchestrator/src/memlockLimit.d.ts +5 -0
  64. package/dist/packages/vm-orchestrator/src/memlockLimit.js +23 -0
  65. package/dist/packages/vm-orchestrator/src/nvidiaHolders.d.ts +11 -0
  66. package/dist/packages/vm-orchestrator/src/nvidiaHolders.js +74 -0
  67. package/dist/packages/vm-orchestrator/src/pciNuma.d.ts +7 -0
  68. package/dist/packages/vm-orchestrator/src/pciNuma.js +18 -0
  69. package/dist/packages/vm-orchestrator/src/pciSysfs.d.ts +21 -0
  70. package/dist/packages/vm-orchestrator/src/pciSysfs.js +47 -0
  71. package/dist/packages/vm-orchestrator/src/processes.d.ts +37 -0
  72. package/dist/packages/vm-orchestrator/src/processes.js +102 -0
  73. package/dist/packages/vm-orchestrator/src/sockets.d.ts +21 -0
  74. package/dist/packages/vm-orchestrator/src/sockets.js +58 -0
  75. package/dist/packages/vm-orchestrator/src/sweepVmImageCache.d.ts +19 -0
  76. package/dist/packages/vm-orchestrator/src/sweepVmImageCache.js +132 -0
  77. package/dist/packages/vm-orchestrator/src/util.d.ts +14 -0
  78. package/dist/packages/vm-orchestrator/src/util.js +33 -0
  79. package/dist/packages/vm-orchestrator/src/vfioBinding.d.ts +27 -0
  80. package/dist/packages/vm-orchestrator/src/vfioBinding.js +163 -0
  81. package/dist/packages/vm-orchestrator/src/vmImageResolver.d.ts +20 -0
  82. package/dist/packages/vm-orchestrator/src/vmImageResolver.js +62 -0
  83. package/dist/packages/vm-orchestrator/src/vsockBridge.d.ts +20 -0
  84. package/dist/packages/vm-orchestrator/src/vsockBridge.js +27 -0
  85. package/dist/packages/vm-orchestrator/src/workDirs.d.ts +49 -0
  86. package/dist/packages/vm-orchestrator/src/workDirs.js +79 -0
  87. package/dist/src/NodeManager/configs/configs.d.ts +4 -0
  88. package/dist/src/NodeManager/configs/configs.js +3 -0
  89. package/dist/src/NodeManager/db/index.d.ts +10 -0
  90. package/dist/src/NodeManager/db/index.js +4 -0
  91. package/dist/src/NodeManager/monitoring/log/NodeLog.d.ts +2 -0
  92. package/dist/src/NodeManager/monitoring/log/NodeLog.js +21 -0
  93. package/dist/src/NodeManager/monitoring/log/console/ConsoleLogger.d.ts +8 -0
  94. package/dist/src/NodeManager/monitoring/log/console/ConsoleLogger.js +29 -5
  95. package/dist/src/NodeManager/monitoring/log/vmSetupLog.d.ts +11 -0
  96. package/dist/src/NodeManager/monitoring/log/vmSetupLog.js +33 -0
  97. package/dist/src/NodeManager/node/Node.d.ts +2 -0
  98. package/dist/src/NodeManager/node/Node.js +12 -5
  99. package/dist/src/NodeManager/node/job/ContainerJobRuntime.d.ts +141 -0
  100. package/dist/src/NodeManager/node/job/ContainerJobRuntime.js +419 -0
  101. package/dist/src/NodeManager/node/job/JobRuntimeEnvironment.d.ts +74 -0
  102. package/dist/src/NodeManager/node/job/JobRuntimeEnvironment.js +1 -0
  103. package/dist/src/NodeManager/node/job/JobRuntimeHost.d.ts +6 -2
  104. package/dist/src/NodeManager/node/job/JobRuntimeHost.js +13 -2
  105. package/dist/src/NodeManager/node/job/JobRuntimeSession.d.ts +12 -9
  106. package/dist/src/NodeManager/node/job/JobRuntimeSession.js +42 -71
  107. package/dist/src/NodeManager/node/job/VmJobRuntime.d.ts +109 -0
  108. package/dist/src/NodeManager/node/job/VmJobRuntime.js +258 -0
  109. package/dist/src/NodeManager/node/job/VmJobRuntimeConfig.d.ts +33 -0
  110. package/dist/src/NodeManager/node/job/VmJobRuntimeConfig.js +1 -0
  111. package/dist/src/NodeManager/node/job/buildJobRuntimeEnv.d.ts +41 -0
  112. package/dist/src/NodeManager/node/job/buildJobRuntimeEnv.js +25 -0
  113. package/dist/src/NodeManager/node/job/followFile.d.ts +14 -0
  114. package/dist/src/NodeManager/node/job/followFile.js +57 -0
  115. package/dist/src/NodeManager/node/job/jobHandler.d.ts +3 -3
  116. package/dist/src/NodeManager/node/job/jobHandler.js +7 -7
  117. package/dist/src/NodeManager/node/job/keepFailedConsole.d.ts +7 -0
  118. package/dist/src/NodeManager/node/job/keepFailedConsole.js +52 -0
  119. package/dist/src/NodeManager/node/job/selectJobRuntimeEnvironment.d.ts +50 -0
  120. package/dist/src/NodeManager/node/job/selectJobRuntimeEnvironment.js +117 -0
  121. package/dist/src/NodeManager/node/market/benchmark.d.ts +3 -3
  122. package/dist/src/NodeManager/node/market/benchmark.js +3 -3
  123. package/dist/src/NodeManager/node/market/marketHandler.d.ts +3 -3
  124. package/dist/src/NodeManager/node/market/marketHandler.js +3 -3
  125. package/dist/src/NodeManager/node/resource/resourceManager.d.ts +1 -1
  126. package/dist/src/NodeManager/node/resource/resourceManager.js +1 -1
  127. package/dist/src/NodeManager/provider/Provider.d.ts +3 -121
  128. package/dist/src/NodeManager/provider/Provider.js +3 -369
  129. package/dist/src/NodeManager/provider/vmHost/VmNodeOptions.d.ts +14 -0
  130. package/dist/src/NodeManager/provider/vmHost/VmNodeOptions.js +1 -0
  131. package/dist/src/NodeManager/provider/vmHost/capacity.d.ts +16 -0
  132. package/dist/src/NodeManager/provider/vmHost/capacity.js +47 -0
  133. package/dist/src/NodeManager/provider/vmHost/gpus.d.ts +19 -0
  134. package/dist/src/NodeManager/provider/vmHost/gpus.js +83 -0
  135. package/dist/src/NodeManager/provider/vmHost/index.d.ts +5 -0
  136. package/dist/src/NodeManager/provider/vmHost/index.js +4 -0
  137. package/dist/src/NodeManager/provider/vmHost/readVmSpec.d.ts +11 -0
  138. package/dist/src/NodeManager/provider/vmHost/readVmSpec.js +22 -0
  139. package/dist/src/NodeManager/provider/vmHost/setup/PrepareVmHostSystem.d.ts +27 -0
  140. package/dist/src/NodeManager/provider/vmHost/setup/PrepareVmHostSystem.js +25 -0
  141. package/dist/src/NodeManager/provider/vmHost/setup/fileOwnership.d.ts +6 -0
  142. package/dist/src/NodeManager/provider/vmHost/setup/fileOwnership.js +22 -0
  143. package/dist/src/NodeManager/provider/vmHost/setup/hostUser.d.ts +15 -0
  144. package/dist/src/NodeManager/provider/vmHost/setup/hostUser.js +25 -0
  145. package/dist/src/NodeManager/provider/vmHost/setup/index.d.ts +2 -0
  146. package/dist/src/NodeManager/provider/vmHost/setup/index.js +2 -0
  147. package/dist/src/NodeManager/provider/vmHost/setup/memlockLimits.d.ts +6 -0
  148. package/dist/src/NodeManager/provider/vmHost/setup/memlockLimits.js +12 -0
  149. package/dist/src/NodeManager/provider/vmHost/setup/prepareVmHost.d.ts +17 -0
  150. package/dist/src/NodeManager/provider/vmHost/setup/prepareVmHost.js +90 -0
  151. package/dist/src/NodeManager/provider/vmHost/setup/sudoCaller.d.ts +5 -0
  152. package/dist/src/NodeManager/provider/vmHost/setup/sudoCaller.js +35 -0
  153. package/dist/src/NodeManager/provider/vmHost/vmHostEnv.d.ts +20 -0
  154. package/dist/src/NodeManager/provider/vmHost/vmHostEnv.js +24 -0
  155. package/dist/src/NodeManager/provider/vmHost/workRoot.d.ts +14 -0
  156. package/dist/src/NodeManager/provider/vmHost/workRoot.js +84 -0
  157. package/dist/src/NodeManager/repository/NodeRepository.d.ts +12 -2
  158. package/dist/src/NodeManager/repository/NodeRepository.js +21 -1
  159. package/dist/src/cli/commands/prune/command.js +2 -1
  160. package/dist/src/cli/commands/run/action.d.ts +2 -2
  161. package/dist/src/cli/commands/run/action.js +15 -34
  162. package/dist/src/cli/commands/run/command.js +7 -2
  163. package/dist/src/cli/commands/sharedOptions/--config.d.ts +2 -0
  164. package/dist/src/cli/commands/sharedOptions/--config.js +2 -0
  165. package/dist/src/cli/commands/sharedOptions/--environment.d.ts +6 -0
  166. package/dist/src/cli/commands/sharedOptions/--environment.js +6 -0
  167. package/dist/src/cli/commands/sharedOptions/--gpu.js +5 -2
  168. package/dist/src/cli/commands/sharedOptions/--node-limits.d.ts +9 -0
  169. package/dist/src/cli/commands/sharedOptions/--node-limits.js +24 -0
  170. package/dist/src/cli/commands/sharedOptions/index.d.ts +3 -0
  171. package/dist/src/cli/commands/sharedOptions/index.js +3 -0
  172. package/dist/src/cli/commands/start/command.js +7 -2
  173. package/dist/src/cli/commands/vm-setup/action.d.ts +10 -0
  174. package/dist/src/cli/commands/vm-setup/action.js +14 -0
  175. package/dist/src/cli/commands/vm-setup/command.d.ts +3 -0
  176. package/dist/src/cli/commands/vm-setup/command.js +11 -0
  177. package/dist/src/cli/createNosanaCli.d.ts +1 -0
  178. package/dist/src/cli/createNosanaCli.js +4 -1
  179. package/npm-shrinkwrap.json +10 -2
  180. package/package.json +1 -1
package/dist/.env CHANGED
@@ -1,6 +1,7 @@
1
1
  BACKEND_SOLANA_ADDRESS=7rFPFnxjXHC2sfDy3qrDa9pEb4j49oivMuV7e8sYDPmB
2
2
  FRP_SERVER_IMAGE=registry.hub.docker.com/nosana/frpc:v1.0.45
3
- JOB_RUNTIME_IMAGE="nosana/job-runtime:v0.2.7"
3
+ JOB_RUNTIME_IMAGE="nosana/job-runtime:v0.3.0"
4
+ GOLDEN_VM_IMAGE=https://models.nosana.io/golden-vm/cuda13-580-dev-2/golden-vm-cuda13-580-dev-2.qcow2
4
5
  RESOURCE_MANAGER_IMAGE=registry.hub.docker.com/nosana/resource-manager:v1.1.19
5
6
  FRP_SERVER_PORT=7000
6
7
  MIN_DISK_SPACE=25
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosana/node",
3
- "version": "1.1.84",
3
+ "version": "1.1.85-rc",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "nosana-node": "./dist/src/index.js"
@@ -1,4 +1,14 @@
1
1
  import type { StopReason } from '../taskManager/stopReasons.js';
2
+ import { type JobRuntimeStatus } from './contract.js';
3
+ /** How the client retries; each defaults to the constant of its name. */
4
+ export interface HostClientOptions {
5
+ /** How long to wait between tries of a node that does not answer. */
6
+ retryDelayMs?: number;
7
+ /** How many times a request the node does not answer is tried. */
8
+ retryAttempts?: number;
9
+ /** How long the last status, the result, is tried for. */
10
+ finalStatusTimeoutMs?: number;
11
+ }
2
12
  /** The node answered, with a failure: not something a retry fixes. */
3
13
  export declare class HostRequestError extends Error {
4
14
  }
@@ -11,12 +21,18 @@ export declare class HostClient {
11
21
  private readonly socketPath;
12
22
  private readonly retryDelayMs;
13
23
  private readonly retryAttempts;
14
- constructor(socketPath: string, options?: {
15
- retryDelayMs?: number;
16
- retryAttempts?: number;
17
- });
24
+ private readonly finalStatusTimeoutMs;
25
+ constructor(socketPath: string, options?: HostClientOptions);
18
26
  /** An authorization header the node signed for the job address. */
19
27
  signAuth(signal?: AbortSignal): Promise<string>;
28
+ /**
29
+ * Hands the node the job's status, which it keeps in the job's directory.
30
+ * One while the job runs is tried a few times, for up to a minute; the last
31
+ * one, carrying the result, for up to 30 minutes. Either bound covers a
32
+ * request the node never answers. Rejects when the node never took it, or
33
+ * refused it.
34
+ */
35
+ reportStatus(status: JobRuntimeStatus, signal?: AbortSignal): Promise<void>;
20
36
  /**
21
37
  * Resolves with the reason once the node wants the job stopped. Waits out a
22
38
  * node that is down for as long as it is down.
@@ -4,6 +4,19 @@ import { abortError, retry, sleep } from '../utils/abort.js';
4
4
  /** How long the sidecar keeps trying a node that does not answer (a restart). */
5
5
  const DEFAULT_RETRY_DELAY_MS = 5_000;
6
6
  const DEFAULT_RETRY_ATTEMPTS = 120;
7
+ /**
8
+ * A status while the job runs is tried this often, for at most this long,
9
+ * then dropped: the next one carries the job's state anyway, and a node that
10
+ * hangs does not hold up the ones behind it.
11
+ */
12
+ const STATUS_RETRY_ATTEMPTS = 3;
13
+ const STATUS_TIMEOUT_MS = 60_000;
14
+ /**
15
+ * How long the last status, the result, is tried for: a node restarting
16
+ * during the finish loses nothing, and one that never comes back cannot hold
17
+ * the sidecar forever.
18
+ */
19
+ const DEFAULT_FINAL_STATUS_TIMEOUT_MS = 30 * 60_000;
7
20
  /** The node answered, with a failure: not something a retry fixes. */
8
21
  export class HostRequestError extends Error {
9
22
  }
@@ -17,6 +30,7 @@ export class HostClient {
17
30
  this.socketPath = socketPath;
18
31
  this.retryDelayMs = options.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS;
19
32
  this.retryAttempts = options.retryAttempts ?? DEFAULT_RETRY_ATTEMPTS;
33
+ this.finalStatusTimeoutMs = options.finalStatusTimeoutMs ?? DEFAULT_FINAL_STATUS_TIMEOUT_MS;
20
34
  }
21
35
  /** An authorization header the node signed for the job address. */
22
36
  async signAuth(signal) {
@@ -26,6 +40,20 @@ export class HostClient {
26
40
  }
27
41
  return body.authorization;
28
42
  }
43
+ /**
44
+ * Hands the node the job's status, which it keeps in the job's directory.
45
+ * One while the job runs is tried a few times, for up to a minute; the last
46
+ * one, carrying the result, for up to 30 minutes. Either bound covers a
47
+ * request the node never answers. Rejects when the node never took it, or
48
+ * refused it.
49
+ */
50
+ async reportStatus(status, signal) {
51
+ const isFinal = status.result !== undefined;
52
+ const timeoutMs = isFinal ? this.finalStatusTimeoutMs : STATUS_TIMEOUT_MS;
53
+ const attempts = isFinal ? Infinity : STATUS_RETRY_ATTEMPTS;
54
+ const bound = AbortSignal.any([AbortSignal.timeout(timeoutMs), ...(signal ? [signal] : [])]);
55
+ await this.retry(() => this.json('PUT', JOB_RUNTIME_HOST_PATHS.status, status, bound), bound, attempts);
56
+ }
29
57
  /**
30
58
  * Resolves with the reason once the node wants the job stopped. Waits out a
31
59
  * node that is down for as long as it is down.
@@ -46,9 +74,9 @@ export class HostClient {
46
74
  }
47
75
  }
48
76
  /** Retries what could not reach the node; a node's own failure is final. */
49
- retry(attempt, signal) {
77
+ retry(attempt, signal, attempts = this.retryAttempts) {
50
78
  return retry(attempt, {
51
- attempts: this.retryAttempts,
79
+ attempts,
52
80
  delayMs: this.retryDelayMs,
53
81
  signal,
54
82
  isFinal: (error) => error instanceof HostRequestError,
@@ -62,6 +90,11 @@ export class HostClient {
62
90
  path,
63
91
  method,
64
92
  signal,
93
+ // A connection of its own, closed after it. A large status can be
94
+ // answered before its last write completes; on a pooled keep-alive
95
+ // socket, a node closing the connection then fails that write where
96
+ // no listener is left (an uncaught EPIPE). Here it reaches `req`.
97
+ agent: false,
65
98
  headers: payload
66
99
  ? {
67
100
  'content-type': 'application/json',
@@ -9,11 +9,12 @@ import type { ResourceCacheSnapshot } from '../resources/records.js';
9
9
  * has bind-mounted:
10
10
  *
11
11
  * - the node writes the {@link JobRuntimeSeed} before the sidecar starts;
12
- * - the sidecar keeps its {@link JobRuntimeStatus} there, the last one
13
- * carrying its result, and what it changed in the cache records
14
- * (ResourceCacheChanges), each as it happens;
15
- * - the node serves a unix socket there for the two things that need it
16
- * live: its signature on the job address, and the job's stop.
12
+ * - the sidecar keeps what it changed in the cache records
13
+ * (ResourceCacheChanges) there, as it happens;
14
+ * - the node serves a unix socket there for what needs it live: its
15
+ * signature on the job address, the job's stop, and the sidecar's
16
+ * {@link JobRuntimeStatus}, the last one carrying its result, which the
17
+ * node keeps in the directory.
17
18
  *
18
19
  * Neither needs the other up to make progress: the files and the sidecar's
19
20
  * container outlive either process. Nothing the sidecar sends can point the
@@ -55,7 +56,11 @@ export declare const JOB_RUNTIME_HOST_SOCKET = "host.sock";
55
56
  export declare const JOB_RUNTIME_FILES: {
56
57
  /** {@link JobRuntimeSeed}, from the node. */
57
58
  readonly seed: "seed.json";
58
- /** {@link JobRuntimeStatus}, from the sidecar. */
59
+ /**
60
+ * {@link JobRuntimeStatus}, written by the node from what the sidecar sent
61
+ * it (JOB_RUNTIME_HOST_PATHS.status). A sidecar of an earlier release wrote
62
+ * it itself, which a node taking it over reads the same.
63
+ */
59
64
  readonly status: "status.json";
60
65
  /** ResourceCacheChanges, from the sidecar. */
61
66
  readonly resources: "resources.json";
@@ -68,7 +73,8 @@ export declare const JOB_RUNTIME_FILES: {
68
73
  * refuses a seed from a node newer than itself rather than misread it.
69
74
  *
70
75
  * The status has none: the node reads only a few of its fields and checks
71
- * their shape instead, a status it cannot read counting as none. A change to
76
+ * their shape instead ({@link isReadableStatus}), as it receives one and as
77
+ * it reads the file, a status it cannot read counting as none. A change to
72
78
  * what a field means would add one, its absence meaning the format of today.
73
79
  */
74
80
  export declare const JOB_RUNTIME_SEED_VERSION = 1;
@@ -97,6 +103,13 @@ export declare const JOB_RUNTIME_HOST_PATHS: {
97
103
  * already does.
98
104
  */
99
105
  readonly stop: "/stop";
106
+ /**
107
+ * PUT {@link JobRuntimeStatus} → 204: the sidecar's status, at most once a
108
+ * second while the job runs, the last one carrying its result. The node
109
+ * checks its shape ({@link isReadableStatus}), answers 400 to one it cannot
110
+ * read, and keeps it in the job's directory (JOB_RUNTIME_FILES.status).
111
+ */
112
+ readonly status: "/status";
100
113
  };
101
114
  /** An inline run: its definition, and who it runs for and on. */
102
115
  export interface InlineJob {
@@ -151,6 +164,13 @@ export interface JobRuntimeStatus {
151
164
  */
152
165
  result?: JobRuntimeResult;
153
166
  }
167
+ /**
168
+ * Whether a status has what the node reads of it in the shape it reads it:
169
+ * the outcome, the ops (the benchmark's progress) and, once there, the
170
+ * result. A status has no version (see JOB_RUNTIME_SEED_VERSION); one an
171
+ * older sidecar wrote reads the same.
172
+ */
173
+ export declare function isReadableStatus(value: unknown): value is JobRuntimeStatus;
154
174
  /**
155
175
  * The one line that best explains a terminal status: the first error of the
156
176
  * first op that recorded one, else the first flow-level error.
@@ -7,11 +7,12 @@ import { describeError } from '../../../common/src/index.js';
7
7
  * has bind-mounted:
8
8
  *
9
9
  * - the node writes the {@link JobRuntimeSeed} before the sidecar starts;
10
- * - the sidecar keeps its {@link JobRuntimeStatus} there, the last one
11
- * carrying its result, and what it changed in the cache records
12
- * (ResourceCacheChanges), each as it happens;
13
- * - the node serves a unix socket there for the two things that need it
14
- * live: its signature on the job address, and the job's stop.
10
+ * - the sidecar keeps what it changed in the cache records
11
+ * (ResourceCacheChanges) there, as it happens;
12
+ * - the node serves a unix socket there for what needs it live: its
13
+ * signature on the job address, the job's stop, and the sidecar's
14
+ * {@link JobRuntimeStatus}, the last one carrying its result, which the
15
+ * node keeps in the directory.
15
16
  *
16
17
  * Neither needs the other up to make progress: the files and the sidecar's
17
18
  * container outlive either process. Nothing the sidecar sends can point the
@@ -38,7 +39,11 @@ export const JOB_RUNTIME_HOST_SOCKET = 'host.sock';
38
39
  export const JOB_RUNTIME_FILES = {
39
40
  /** {@link JobRuntimeSeed}, from the node. */
40
41
  seed: 'seed.json',
41
- /** {@link JobRuntimeStatus}, from the sidecar. */
42
+ /**
43
+ * {@link JobRuntimeStatus}, written by the node from what the sidecar sent
44
+ * it (JOB_RUNTIME_HOST_PATHS.status). A sidecar of an earlier release wrote
45
+ * it itself, which a node taking it over reads the same.
46
+ */
42
47
  status: 'status.json',
43
48
  /** ResourceCacheChanges, from the sidecar. */
44
49
  resources: 'resources.json',
@@ -51,7 +56,8 @@ export const JOB_RUNTIME_FILES = {
51
56
  * refuses a seed from a node newer than itself rather than misread it.
52
57
  *
53
58
  * The status has none: the node reads only a few of its fields and checks
54
- * their shape instead, a status it cannot read counting as none. A change to
59
+ * their shape instead ({@link isReadableStatus}), as it receives one and as
60
+ * it reads the file, a status it cannot read counting as none. A change to
55
61
  * what a field means would add one, its absence meaning the format of today.
56
62
  */
57
63
  export const JOB_RUNTIME_SEED_VERSION = 1;
@@ -74,7 +80,37 @@ export const JOB_RUNTIME_HOST_PATHS = {
74
80
  * already does.
75
81
  */
76
82
  stop: '/stop',
83
+ /**
84
+ * PUT {@link JobRuntimeStatus} → 204: the sidecar's status, at most once a
85
+ * second while the job runs, the last one carrying its result. The node
86
+ * checks its shape ({@link isReadableStatus}), answers 400 to one it cannot
87
+ * read, and keeps it in the job's directory (JOB_RUNTIME_FILES.status).
88
+ */
89
+ status: '/status',
77
90
  };
91
+ /**
92
+ * Whether a status has what the node reads of it in the shape it reads it:
93
+ * the outcome, the ops (the benchmark's progress) and, once there, the
94
+ * result. A status has no version (see JOB_RUNTIME_SEED_VERSION); one an
95
+ * older sidecar wrote reads the same.
96
+ */
97
+ export function isReadableStatus(value) {
98
+ if (typeof value !== 'object' || value === null)
99
+ return false;
100
+ const status = value;
101
+ if (typeof status.status !== 'string' ||
102
+ !Array.isArray(status.errors) ||
103
+ !Array.isArray(status.opStates)) {
104
+ return false;
105
+ }
106
+ if (status.result === undefined)
107
+ return true;
108
+ if (typeof status.result !== 'object' || status.result === null)
109
+ return false;
110
+ const { ipfsHash, error } = status.result;
111
+ return ((ipfsHash === undefined || typeof ipfsHash === 'string') &&
112
+ (error === undefined || typeof error === 'string'));
113
+ }
78
114
  /**
79
115
  * Error records as plain messages. Op errors are `{event, message}` objects;
80
116
  * flow errors are whatever was recorded (a string, an Error, an object).
@@ -1,6 +1,9 @@
1
1
  import type { JobRuntimeServerConfig } from '../config.js';
2
2
  export interface JobRuntime {
3
- /** Resolves once the job is over and its last status, the result, is written. */
3
+ /**
4
+ * Resolves once the job is over and its last status, the result, handed to
5
+ * the node, or given up on (see HostClient.reportStatus).
6
+ */
4
7
  readonly done: Promise<void>;
5
8
  /**
6
9
  * Stops the job (as the node quitting would), closes the API and removes
@@ -18,10 +21,10 @@ export interface JobRuntime {
18
21
  * serves the job API at `<job>.<frp server>` through its own frpc, pulls the
19
22
  * images and downloads the resources, runs the operations, applies the
20
23
  * receive logistics and pins the result. It works on a copy of the node's
21
- * cache records, from the seed, and writes back what it changed; its status
22
- * goes in the job's directory too, ending with the result's hash for the node
23
- * to submit onchain. Only the node's signature on the job address and the
24
- * job's stop come over the job runtime socket.
24
+ * cache records, from the seed, and writes back what it changed in the job's
25
+ * directory. Its status goes to the node over the job runtime socket, ending
26
+ * with the result's hash for the node to submit onchain; the node's signature
27
+ * on the job address and the job's stop come back over it.
25
28
  *
26
29
  * An inline run (the node's market benchmark, `nosana node run`) has no job
27
30
  * onchain and no poster: the definition is in the seed, there is no job API
@@ -32,7 +32,7 @@ import { retrieveJobDefinitionWithRetry } from './retrieveJobDefinition.js';
32
32
  import { RuntimeLog } from './RuntimeLog.js';
33
33
  import { LogStream, StateStream } from './streams.js';
34
34
  import { abortable, retry } from '../utils/abort.js';
35
- import { readJson, writeJsonAtomic } from '../utils/files.js';
35
+ import { readJson } from '../utils/files.js';
36
36
  /**
37
37
  * Retry cadence for resolving the job onchain. The node starts the sidecar as
38
38
  * soon as it claims the job, when an RPC may still lag; bounded so a sidecar
@@ -41,7 +41,7 @@ import { readJson, writeJsonAtomic } from '../utils/files.js';
41
41
  */
42
42
  const RESOLVE_RETRY_DELAY_MS = 5_000;
43
43
  const RESOLVE_RETRY_ATTEMPTS = 30;
44
- /** At most one status written a second while the job runs. */
44
+ /** At most one status sent a second while the job runs. */
45
45
  const STATUS_REPORT_INTERVAL_MS = 1_000;
46
46
  /**
47
47
  * The sidecar's own stop at the job's expiry, for when the node missed it
@@ -67,10 +67,10 @@ const NO_DEFINITION = { ops: [] };
67
67
  * serves the job API at `<job>.<frp server>` through its own frpc, pulls the
68
68
  * images and downloads the resources, runs the operations, applies the
69
69
  * receive logistics and pins the result. It works on a copy of the node's
70
- * cache records, from the seed, and writes back what it changed; its status
71
- * goes in the job's directory too, ending with the result's hash for the node
72
- * to submit onchain. Only the node's signature on the job address and the
73
- * job's stop come over the job runtime socket.
70
+ * cache records, from the seed, and writes back what it changed in the job's
71
+ * directory. Its status goes to the node over the job runtime socket, ending
72
+ * with the result's hash for the node to submit onchain; the node's signature
73
+ * on the job address and the job's stop come back over it.
74
74
  *
75
75
  * An inline run (the node's market benchmark, `nosana node run`) has no job
76
76
  * onchain and no poster: the definition is in the seed, there is no job API
@@ -85,7 +85,7 @@ export async function runJob(config) {
85
85
  if (!seed)
86
86
  throw new Error(`The node left no seed for job ${job} at ${seedFile}`);
87
87
  if (!isKnownVersion(seed.version, JOB_RUNTIME_SEED_VERSION)) {
88
- refuseSeed(config.hostDir, job, seed.version);
88
+ await refuseSeed(host, job, seed.version);
89
89
  }
90
90
  const inline = seed.inline;
91
91
  configureJobRuntime({
@@ -132,12 +132,25 @@ export async function runJob(config) {
132
132
  // send logistics resolve, carries the receive logistics.
133
133
  let project = '';
134
134
  let envelope;
135
- const statusFile = path.join(config.hostDir, JOB_RUNTIME_FILES.status);
135
+ // One status in flight at a time, so none overtakes another; behind it
136
+ // waits only the latest. Nothing but finish() waits for a send.
136
137
  let reportTimer;
138
+ let waiting;
139
+ let sending = Promise.resolve();
137
140
  const reportNow = () => {
138
141
  clearTimeout(reportTimer);
139
142
  reportTimer = undefined;
140
- writeJsonAtomic(statusFile, deriveJobRuntimeStatus(store.getFlowState(job), result));
143
+ const isQueued = waiting !== undefined;
144
+ waiting = deriveJobRuntimeStatus(store.getFlowState(job), result);
145
+ if (!isQueued)
146
+ sending = sending.then(sendWaiting);
147
+ return sending;
148
+ };
149
+ const sendWaiting = async () => {
150
+ const status = waiting;
151
+ waiting = undefined;
152
+ if (status)
153
+ await sendStatus(host, job, status);
141
154
  };
142
155
  const reportSoon = () => {
143
156
  reportTimer ??= setTimeout(() => void reportNow(), STATUS_REPORT_INTERVAL_MS);
@@ -243,7 +256,7 @@ export async function runJob(config) {
243
256
  // An inline run's state is the node's alone: it goes back whole, and
244
257
  // nothing of it is published.
245
258
  result = chain ? await pinResult(resultState) : { state: resultState };
246
- reportNow();
259
+ await reportNow();
247
260
  }
248
261
  /**
249
262
  * Who the job is for and runs on, and what to run: an onchain job from the
@@ -381,7 +394,7 @@ export async function runJob(config) {
381
394
  if (!send?.type)
382
395
  return envelope;
383
396
  store.setflow(job, createInitialFlow(job, project, envelope, [], 'waiting-for-job-definition', Date.now()));
384
- reportNow();
397
+ void reportNow();
385
398
  try {
386
399
  return await abortable(new JobDefinitionStrategySelector(events, hostAuthHeaders(host, stopping.signal))
387
400
  .selectStrategy(send.type)
@@ -430,7 +443,7 @@ export async function runJob(config) {
430
443
  errors: state.errors ?? [],
431
444
  };
432
445
  store.updateflowState(job, { status: 'waiting-for-result' });
433
- reportNow();
446
+ void reportNow();
434
447
  try {
435
448
  // Not the stop's signal: the job has stopped by now, delivery has not.
436
449
  await new ResultReturnStrategySelector(events, hostAuthHeaders(host))
@@ -470,7 +483,7 @@ export async function runJob(config) {
470
483
  if (status.phase === 'failed' && failure)
471
484
  console.log(` ✖ ${failure}`);
472
485
  }
473
- reportNow();
486
+ void reportNow();
474
487
  return {
475
488
  done,
476
489
  async close() {
@@ -488,16 +501,30 @@ export async function runJob(config) {
488
501
  }
489
502
  /**
490
503
  * Refuses a seed this sidecar cannot read, from a node newer than itself. It
491
- * leaves a last status whose result is the reason, so the node does not
492
- * start it again, and pins the outcome with that reason itself.
504
+ * sends a last status whose result is the reason, so the node does not start
505
+ * it again, and pins the outcome with that reason itself.
493
506
  */
494
- function refuseSeed(hostDir, job, version) {
507
+ async function refuseSeed(host, job, version) {
495
508
  const message = `The seed of job ${job} is version ${String(version)}; this job runtime ` +
496
509
  `reads up to version ${JOB_RUNTIME_SEED_VERSION}`;
497
510
  const now = Date.now();
498
- writeJsonAtomic(path.join(hostDir, JOB_RUNTIME_FILES.status), deriveJobRuntimeStatus({ status: 'failed', startTime: now, endTime: now, opStates: [], errors: [] }, { error: message }));
511
+ await host
512
+ .reportStatus(deriveJobRuntimeStatus({ status: 'failed', startTime: now, endTime: now, opStates: [], errors: [] }, { error: message }))
513
+ .catch((error) => console.error(`The node did not take the refusal of job ${job}: ${describeError(error)}`));
499
514
  throw new Error(message);
500
515
  }
516
+ /** Hands the node a status; one it does not take is logged, not thrown. */
517
+ async function sendStatus(host, job, status) {
518
+ try {
519
+ await host.reportStatus(status);
520
+ }
521
+ catch (error) {
522
+ const reason = describeError(error);
523
+ console.error(status.result
524
+ ? `The node did not take the result of job ${job}; exiting all the same: ${reason}`
525
+ : `Could not send the status of job ${job} to the node: ${reason}`);
526
+ }
527
+ }
501
528
  /** A job completed or stopped onchain. */
502
529
  function isOverOnchain(state) {
503
530
  return state === JobState.COMPLETED || state === JobState.STOPPED;
@@ -0,0 +1,67 @@
1
+ /** Where the registry keeps its locks and which CIDs it hands out. */
2
+ export interface CidRegistryConfig {
3
+ /** The shared lock directory (default: the first writable of {@link DEFAULT_LOCK_DIRS}). */
4
+ dir?: string;
5
+ /** Lowest CID handed out (default 3). */
6
+ baseCid?: number;
7
+ }
8
+ /** How the registry probes the host; injectable for tests. */
9
+ export interface CidRegistrySystem {
10
+ /** Is a lock's recorded owner pid alive? */
11
+ isPidAlive: (pid: number) => boolean;
12
+ }
13
+ /**
14
+ * Host-global vsock guest-CID allocator. A guest CID, and the host vsock port
15
+ * derived from it, is a host-scoped resource, but N co-tenant node processes
16
+ * each boot VMs, so reservations live as lockfiles in a directory every node
17
+ * process resolves identically, not in per-process memory.
18
+ *
19
+ * A claim is a file named after the CID recording the owner pid, created
20
+ * atomically (write-to-temp + link(2), which fails EEXIST when the CID is
21
+ * taken). A lock whose recorded pid is dead is a crash leftover and is
22
+ * reclaimed in place; reclaim races are settled by an atomic rename. The
23
+ * kernel stays the ultimate arbiter regardless: QEMU refuses a duplicate
24
+ * guest-cid, which the hypervisor treats as a retriable allocation failure.
25
+ */
26
+ export declare class CidRegistry {
27
+ private readonly config;
28
+ private readonly baseCid;
29
+ private readonly isPidAlive;
30
+ private readonly owned;
31
+ private dir?;
32
+ private seq;
33
+ constructor(config?: CidRegistryConfig, system?: Partial<CidRegistrySystem>);
34
+ /** Claim the lowest free CID, skipping any the caller has blacklisted. */
35
+ claim(skip?: (cid: number) => boolean): Promise<number>;
36
+ /**
37
+ * Hand a claimed CID's lock to the process that holds the CID from now on
38
+ * (the VM's QEMU, which outlives the node process that booted it), so the
39
+ * lock is live exactly as long as the VM. The lock is rewritten in place
40
+ * (temp file + rename), never left absent.
41
+ */
42
+ transfer(cid: number, pid: number): Promise<void>;
43
+ /**
44
+ * Release a CID: one this registry claimed (owner: this process), or, with
45
+ * `owner`, one whose lock was {@link transfer}red to that pid. A no-op for
46
+ * anything else.
47
+ */
48
+ release(cid: number, owner?: number): Promise<void>;
49
+ private resolveDir;
50
+ private tryClaim;
51
+ /**
52
+ * Take over a taken CID whose owner is dead (or whose lock is unreadable): a
53
+ * crash leftover. The stale lock is renamed aside, which exactly one
54
+ * contender wins, then re-verified stale (a fresh claim could have replaced
55
+ * it since it was read) before the slot is taken.
56
+ */
57
+ private reclaimStale;
58
+ /**
59
+ * Create the lockfile atomically-with-content: link(2) either publishes the
60
+ * fully written temp file under the lock name or fails EEXIST, so no reader
61
+ * ever sees a half-written (reclaimable-looking) lock.
62
+ */
63
+ private writeLock;
64
+ private isLiveOwner;
65
+ /** A temp file name in the lock dir, unique to this process and call. */
66
+ private tempPath;
67
+ }