@ship.zone/runner 2.1.0 → 4.0.0

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 (200) hide show
  1. package/.smartconfig.json +118 -3
  2. package/changelog.md +101 -0
  3. package/dist_rust/runnerworkspace_linux_amd64_musl +0 -0
  4. package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.json +679 -0
  5. package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.txt +15719 -0
  6. package/dist_rust/runnerworkspace_linux_amd64_musl.tsrust-build.json +5 -5
  7. package/dist_rust/runnerworkspace_linux_arm64_musl +0 -0
  8. package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.json +679 -0
  9. package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.txt +15719 -0
  10. package/dist_rust/runnerworkspace_linux_arm64_musl.tsrust-build.json +5 -5
  11. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  12. package/dist_ts/00_commitinfo_data.js +9 -0
  13. package/dist_ts/api-client.d.ts +47 -0
  14. package/dist_ts/api-client.js +600 -0
  15. package/dist_ts/artifact-manager.d.ts +11 -0
  16. package/dist_ts/artifact-manager.js +140 -0
  17. package/dist_ts/attempt-state.d.ts +18 -0
  18. package/dist_ts/attempt-state.js +151 -0
  19. package/dist_ts/cache-manager.d.ts +13 -0
  20. package/dist_ts/cache-manager.js +300 -0
  21. package/dist_ts/cli-entry.d.ts +2 -0
  22. package/dist_ts/cli-entry.js +18 -0
  23. package/dist_ts/cli.d.ts +14 -0
  24. package/dist_ts/cli.js +243 -0
  25. package/dist_ts/config.d.ts +8 -0
  26. package/dist_ts/config.js +495 -0
  27. package/dist_ts/egress-proxy.d.ts +99 -0
  28. package/dist_ts/egress-proxy.js +607 -0
  29. package/dist_ts/errors.d.ts +41 -0
  30. package/dist_ts/errors.js +90 -0
  31. package/dist_ts/filesystem.d.ts +73 -0
  32. package/dist_ts/filesystem.js +207 -0
  33. package/dist_ts/index.d.ts +20 -0
  34. package/dist_ts/index.js +21 -0
  35. package/dist_ts/interfaces.d.ts +685 -0
  36. package/dist_ts/interfaces.js +3 -0
  37. package/dist_ts/log-sender.d.ts +26 -0
  38. package/dist_ts/log-sender.js +124 -0
  39. package/dist_ts/microvm-executor.d.ts +90 -0
  40. package/dist_ts/microvm-executor.js +1045 -0
  41. package/dist_ts/node-version.d.ts +11 -0
  42. package/dist_ts/node-version.js +43 -0
  43. package/dist_ts/npm-grants.d.ts +9 -0
  44. package/dist_ts/npm-grants.js +44 -0
  45. package/dist_ts/oci-registry.d.ts +73 -0
  46. package/dist_ts/oci-registry.js +508 -0
  47. package/dist_ts/plugins.d.ts +23 -0
  48. package/dist_ts/plugins.js +27 -0
  49. package/dist_ts/protocol-validator.d.ts +39 -0
  50. package/dist_ts/protocol-validator.js +488 -0
  51. package/dist_ts/redactor.d.ts +78 -0
  52. package/dist_ts/redactor.js +235 -0
  53. package/dist_ts/registration-state.d.ts +16 -0
  54. package/dist_ts/registration-state.js +171 -0
  55. package/dist_ts/runner.d.ts +65 -0
  56. package/dist_ts/runner.js +912 -0
  57. package/dist_ts/source-workspace.d.ts +10 -0
  58. package/dist_ts/source-workspace.js +125 -0
  59. package/dist_ts/spec-version.d.ts +11 -0
  60. package/dist_ts/spec-version.js +41 -0
  61. package/dist_ts/staging-scavenger.d.ts +7 -0
  62. package/dist_ts/staging-scavenger.js +63 -0
  63. package/dist_ts/state-owner.d.ts +74 -0
  64. package/dist_ts/state-owner.js +291 -0
  65. package/dist_ts/transfer-archive.d.ts +78 -0
  66. package/dist_ts/transfer-archive.js +1619 -0
  67. package/dist_ts/validation.d.ts +11 -0
  68. package/dist_ts/validation.js +79 -0
  69. package/dist_ts/vsock-protocol.d.ts +130 -0
  70. package/dist_ts/vsock-protocol.js +336 -0
  71. package/dist_ts/wire-schema.d.ts +10 -0
  72. package/dist_ts/wire-schema.js +114 -0
  73. package/native-notices/crates/bitflags-2.13.1/license-apache +201 -0
  74. package/native-notices/crates/bitflags-2.13.1/license-mit +25 -0
  75. package/native-notices/crates/cc-1.8.0/license-apache +201 -0
  76. package/native-notices/crates/cc-1.8.0/license-mit +25 -0
  77. package/native-notices/crates/cfg-if-1.0.4/license-apache +201 -0
  78. package/native-notices/crates/cfg-if-1.0.4/license-mit +25 -0
  79. package/native-notices/crates/cfg_aliases-0.2.2/license +9 -0
  80. package/native-notices/crates/cfg_aliases-0.2.2/notices.md +26 -0
  81. package/native-notices/crates/find-msvc-tools-0.1.14/license-apache +201 -0
  82. package/native-notices/crates/find-msvc-tools-0.1.14/license-mit +25 -0
  83. package/native-notices/crates/itoa-1.0.18/license-apache +176 -0
  84. package/native-notices/crates/itoa-1.0.18/license-mit +23 -0
  85. package/native-notices/crates/libc-0.2.189/license-apache +176 -0
  86. package/native-notices/crates/libc-0.2.189/license-mit +25 -0
  87. package/native-notices/crates/memchr-2.8.3/copying +3 -0
  88. package/native-notices/crates/memchr-2.8.3/license-mit +21 -0
  89. package/native-notices/crates/memchr-2.8.3/unlicense +24 -0
  90. package/native-notices/crates/nix-0.30.1/license +21 -0
  91. package/native-notices/crates/proc-macro2-1.0.107/license-apache +176 -0
  92. package/native-notices/crates/proc-macro2-1.0.107/license-mit +23 -0
  93. package/native-notices/crates/quote-1.0.47/license-apache +176 -0
  94. package/native-notices/crates/quote-1.0.47/license-mit +23 -0
  95. package/native-notices/crates/serde-1.0.229/license-apache +176 -0
  96. package/native-notices/crates/serde-1.0.229/license-mit +23 -0
  97. package/native-notices/crates/serde_core-1.0.229/license-apache +176 -0
  98. package/native-notices/crates/serde_core-1.0.229/license-mit +23 -0
  99. package/native-notices/crates/serde_derive-1.0.229/license-apache +176 -0
  100. package/native-notices/crates/serde_derive-1.0.229/license-mit +23 -0
  101. package/native-notices/crates/serde_json-1.0.151/license-apache +176 -0
  102. package/native-notices/crates/serde_json-1.0.151/license-mit +23 -0
  103. package/native-notices/crates/shlex-2.0.1/license-apache +13 -0
  104. package/native-notices/crates/shlex-2.0.1/license-mit +21 -0
  105. package/native-notices/crates/syn-3.0.3/license-apache +176 -0
  106. package/native-notices/crates/syn-3.0.3/license-mit +23 -0
  107. package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-apache +201 -0
  108. package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-mit +25 -0
  109. package/native-notices/crates/tikv-jemallocator-0.7.0/license-apache +201 -0
  110. package/native-notices/crates/tikv-jemallocator-0.7.0/license-mit +25 -0
  111. package/native-notices/crates/unicode-ident-1.0.24/license-apache +176 -0
  112. package/native-notices/crates/unicode-ident-1.0.24/license-mit +23 -0
  113. package/native-notices/crates/unicode-ident-1.0.24/license-unicode +39 -0
  114. package/native-notices/crates/zmij-1.0.23/license-mit +23 -0
  115. package/native-notices/manifest.json +763 -0
  116. package/native-notices/native/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/jemalloc-5.3.1/jemalloc-copying +27 -0
  117. package/native-notices/readme.md +46 -0
  118. package/native-notices/runtime/gcc/gpl-3.0.txt +674 -0
  119. package/native-notices/runtime/gcc/runtime-library-exception-3.1.txt +73 -0
  120. package/native-notices/runtime/libunwind-22.1.2/license.txt +311 -0
  121. package/native-notices/runtime/musl-1.2.5/copyright +193 -0
  122. package/native-notices/rust/compiler-builtins-license.txt +275 -0
  123. package/native-notices/rust/copyright-library.html +8266 -0
  124. package/native-notices/rust/crates/addr2line-0.25.1/license-apache +201 -0
  125. package/native-notices/rust/crates/addr2line-0.25.1/license-mit +25 -0
  126. package/native-notices/rust/crates/adler2-2.0.1/license-0bsd +12 -0
  127. package/native-notices/rust/crates/adler2-2.0.1/license-apache +201 -0
  128. package/native-notices/rust/crates/adler2-2.0.1/license-mit +23 -0
  129. package/native-notices/rust/crates/memchr-2.7.6/copying +3 -0
  130. package/native-notices/rust/crates/memchr-2.7.6/license-mit +21 -0
  131. package/native-notices/rust/crates/memchr-2.7.6/unlicense +24 -0
  132. package/native-notices/rust/crates/miniz_oxide-0.8.9/license +25 -0
  133. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-apache.md +177 -0
  134. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-mit.md +24 -0
  135. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-zlib.md +14 -0
  136. package/native-notices/rust/crates/object-0.37.3/license-apache +201 -0
  137. package/native-notices/rust/crates/object-0.37.3/license-mit +25 -0
  138. package/native-notices/rust/licenses/apache-2.0.txt +73 -0
  139. package/native-notices/rust/licenses/bsd-2-clause.txt +9 -0
  140. package/native-notices/rust/licenses/cc-by-sa-4.0.txt +427 -0
  141. package/native-notices/rust/licenses/gcc-exception-3.1.txt +30 -0
  142. package/native-notices/rust/licenses/gpl-2.0-only.txt +133 -0
  143. package/native-notices/rust/licenses/gpl-3.0-or-later.txt +202 -0
  144. package/native-notices/rust/licenses/isc.txt +7 -0
  145. package/native-notices/rust/licenses/llvm-exception.txt +15 -0
  146. package/native-notices/rust/licenses/mit.txt +9 -0
  147. package/native-notices/rust/licenses/ncsa.txt +29 -0
  148. package/native-notices/rust/licenses/ofl-1.1.txt +43 -0
  149. package/native-notices/rust/licenses/unicode-3.0.txt +39 -0
  150. package/package.json +31 -26
  151. package/readme.md +157 -95
  152. package/rust/.cargo/config.toml +1 -1
  153. package/rust/Cargo.lock +1 -0
  154. package/rust/Cargo.toml +3 -2
  155. package/rust/src/cpio.rs +147 -0
  156. package/rust/src/extfs.rs +747 -0
  157. package/rust/src/guest.rs +2411 -0
  158. package/rust/src/lib.rs +197 -1
  159. package/rust/src/main.rs +7 -2
  160. package/rust/src/oci_tar.rs +842 -0
  161. package/rust-toolchain.toml +4 -0
  162. package/ts/00_commitinfo_data.ts +2 -2
  163. package/ts/api-client.ts +29 -8
  164. package/ts/artifact-manager.ts +9 -7
  165. package/ts/attempt-state.ts +75 -84
  166. package/ts/cache-manager.ts +22 -28
  167. package/ts/cli-entry.ts +17 -0
  168. package/ts/cli.ts +86 -53
  169. package/ts/config.ts +146 -62
  170. package/ts/egress-proxy.ts +649 -0
  171. package/ts/errors.ts +19 -0
  172. package/ts/filesystem.ts +316 -0
  173. package/ts/index.ts +20 -15
  174. package/ts/interfaces.ts +105 -23
  175. package/ts/log-sender.ts +4 -4
  176. package/ts/microvm-executor.ts +1265 -0
  177. package/ts/node-version.ts +49 -0
  178. package/ts/npm-grants.ts +49 -0
  179. package/ts/oci-registry.ts +649 -0
  180. package/ts/plugins.ts +25 -3
  181. package/ts/protocol-validator.ts +34 -30
  182. package/ts/redactor.ts +2 -2
  183. package/ts/registration-state.ts +82 -90
  184. package/ts/runner.ts +81 -34
  185. package/ts/source-workspace.ts +11 -8
  186. package/ts/spec-version.ts +2 -2
  187. package/ts/staging-scavenger.ts +37 -26
  188. package/ts/state-owner.ts +353 -0
  189. package/ts/transfer-archive.ts +214 -243
  190. package/ts/validation.ts +1 -1
  191. package/ts/vsock-protocol.ts +437 -0
  192. package/ts/wire-schema.ts +3 -3
  193. package/deno.json +0 -56
  194. package/deno.lock +0 -1495
  195. package/dist_npm/mod.d.ts +0 -967
  196. package/dist_npm/mod.js +0 -10058
  197. package/mod.ts +0 -8
  198. package/musl-copyright.md +0 -81
  199. package/third-party-licenses.md +0 -187
  200. package/ts/oci-executor.ts +0 -3137
@@ -1,4 +1,4 @@
1
- import { ProtocolError } from './errors.ts';
1
+ import { ProtocolError } from './errors.js';
2
2
  import type {
3
3
  ICompiledStep,
4
4
  IJobLease,
@@ -11,10 +11,10 @@ import type {
11
11
  TJsonObject,
12
12
  TJsonValue,
13
13
  TLeaseFeature,
14
- } from './interfaces.ts';
15
- import { acceptSpecVersion, runnerSpecVersion } from './spec-version.ts';
16
- import { isRecord } from './validation.ts';
17
- import { validateCompiledJobSchema, validateWireMessage } from './wire-schema.ts';
14
+ } from './interfaces.js';
15
+ import { acceptSpecVersion, runnerSpecVersion } from './spec-version.js';
16
+ import { isRecord } from './validation.js';
17
+ import { validateCompiledJobSchema, validateWireMessage } from './wire-schema.js';
18
18
 
19
19
  const sha256Pattern = /^[a-f0-9]{64}$/;
20
20
  const reservedEnvironmentNames = ['SHIPZONE_CI_INPUTS_JSON', 'SHIPZONE_CI_MATRIX_JSON'] as const;
@@ -464,34 +464,37 @@ const requireLeaseCoherence = (lease: IJobLease): void => {
464
464
  };
465
465
 
466
466
  /**
467
- * Narrows a coherent lease to the one shape this runner executes and refuses every other shape:
468
- * the `vm` and `oci-image` profiles, `microvm` isolation, egress networking, candidate images and
469
- * image grants, and npm read grants.
467
+ * Narrows a coherent lease to an executable Firecracker `microvm` lease (`oci`, `vm`, or
468
+ * `oci-image`). Refuses `container` isolation unconditionally because this runner uses
469
+ * Firecracker microVMs exclusively.
470
470
  */
471
471
  export const requireExecutableLease = (lease: IJobLease): IOciJobLease => {
472
472
  const job = lease.job;
473
- if (job.requirements.executionProfile !== 'oci' || !hasSteps(job)) {
473
+ if (job.requirements.isolation !== 'microvm') {
474
+ throw new UnsupportedJobError('container isolation is not supported by this runner');
475
+ }
476
+ if (job.requirements.platform && !job.requirements.platform.startsWith('linux/')) {
474
477
  throw new UnsupportedJobError(
475
- `Execution profile ${job.requirements.executionProfile} is not supported by this runner`,
478
+ `Platform ${job.requirements.platform} is not supported by this Linux Firecracker runner`,
476
479
  );
477
480
  }
478
- if (job.execution.profile !== 'oci') {
479
- throw new UnsupportedJobError('Job execution does not match the oci profile');
480
- }
481
- if (job.requirements.isolation !== 'container') {
482
- throw new UnsupportedJobError('microvm isolation is not supported by this runner');
483
- }
484
- if (job.network.mode !== 'none') {
485
- throw new UnsupportedJobError('egress networking is not enforced by this runner');
486
- }
487
- if (typeof job.execution.image !== 'string' || lease.bindings.length > 0) {
488
- throw new UnsupportedJobError('Candidate image bindings are not supported by this runner');
489
- }
490
- if (lease.grants.length > 0) {
491
- throw new UnsupportedJobError('Image grants are not supported by this runner');
492
- }
493
- if (job.npmRead !== undefined || lease.npmGrants !== undefined) {
494
- throw new UnsupportedJobError('npm read grants are not delivered by this runner');
481
+ const profile = job.requirements.executionProfile;
482
+ if (profile === 'oci') {
483
+ if (!hasSteps(job) || job.execution.profile !== 'oci') {
484
+ throw new UnsupportedJobError('Job execution does not match the oci profile');
485
+ }
486
+ } else if (profile === 'vm') {
487
+ if (!hasSteps(job) || job.execution.profile !== 'vm') {
488
+ throw new UnsupportedJobError('Job execution does not match the vm profile');
489
+ }
490
+ } else if (profile === 'oci-image') {
491
+ if (!('build' in job)) {
492
+ throw new UnsupportedJobError('Job does not match the oci-image build profile');
493
+ }
494
+ } else {
495
+ throw new UnsupportedJobError(
496
+ `Execution profile ${String(profile)} is not supported by this runner`,
497
+ );
495
498
  }
496
499
  return {
497
500
  jobId: lease.jobId,
@@ -499,9 +502,10 @@ export const requireExecutableLease = (lease: IJobLease): IOciJobLease => {
499
502
  leaseId: lease.leaseId,
500
503
  fencingToken: lease.fencingToken,
501
504
  leaseExpiresAt: lease.leaseExpiresAt,
502
- job: job as IOciRunnerJob,
503
- grants: [],
504
- bindings: [],
505
+ job: job as IOciJobLease['job'],
506
+ grants: lease.grants,
507
+ bindings: lease.bindings,
508
+ ...(lease.npmGrants !== undefined ? { npmGrants: lease.npmGrants } : {}),
505
509
  };
506
510
  };
507
511
 
package/ts/redactor.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ISecretContentMatcher, ISecretRedactionSet, TLogStream } from './interfaces.ts';
2
- import { utf8Length } from './validation.ts';
1
+ import type { ISecretContentMatcher, ISecretRedactionSet, TLogStream } from './interfaces.js';
2
+ import { utf8Length } from './validation.js';
3
3
 
4
4
  /** Redaction set members shorter than this many UTF-8 bytes are left out by the protocol. */
5
5
  export const minimumRedactionMemberBytes = 8;
@@ -1,8 +1,21 @@
1
- import { join } from '@std/path';
2
- import { ConfigurationError, RunnerError } from './errors.ts';
3
- import type { IRegisterRunnerRequest } from './interfaces.ts';
4
- import { canonicalizeJson, createRunnerCapabilitySnapshot } from './protocol-validator.ts';
5
- import { validateWireMessage } from './wire-schema.ts';
1
+ import * as plugins from './plugins.js';
2
+ import { ConfigurationError, RunnerError } from './errors.js';
3
+ import {
4
+ createNewWriteFlags,
5
+ isNotFound,
6
+ readInto,
7
+ removePath,
8
+ sameFileIdentity,
9
+ syncDirectory,
10
+ withOpenFile,
11
+ writeAll,
12
+ } from './filesystem.js';
13
+ import { ensurePrivateStateDirectory, type RunnerStateOwner } from './state-owner.js';
14
+ import type { IRegisterRunnerRequest } from './interfaces.js';
15
+ import { canonicalizeJson, createRunnerCapabilitySnapshot } from './protocol-validator.js';
16
+ import { validateWireMessage } from './wire-schema.js';
17
+
18
+ const { join } = plugins.path;
6
19
 
7
20
  const journalName = 'pending-registration.json';
8
21
  const maximumJournalBytes = 64 * 1024;
@@ -35,27 +48,18 @@ const withoutRequestId = (request: IRegisterRunnerRequest): TRegistrationRequest
35
48
  capabilities: request.capabilities,
36
49
  });
37
50
 
38
- const writeAll = async (file: Deno.FsFile, bytes: Uint8Array): Promise<void> => {
39
- let offset = 0;
40
- while (offset < bytes.byteLength) {
41
- const written = await file.write(bytes.subarray(offset));
42
- if (written <= 0) throw new RunnerError('Registration journal write made no progress');
43
- offset += written;
44
- }
45
- };
46
-
47
- const isNotFound = (error: unknown): boolean => error instanceof Deno.errors.NotFound;
48
-
49
51
  export class RegistrationStateStore {
50
52
  readonly path: string;
53
+ private readonly stateDirectory: string;
51
54
 
52
- constructor(private readonly stateDirectory: string) {
53
- this.path = join(stateDirectory, journalName);
55
+ constructor(private readonly owner: RunnerStateOwner) {
56
+ this.stateDirectory = owner.stateDirectory;
57
+ this.path = join(this.stateDirectory, journalName);
54
58
  }
55
59
 
56
60
  async loadOrCreate(
57
61
  template: TRegistrationRequestTemplate,
58
- createRequestId: () => string = () => crypto.randomUUID(),
62
+ createRequestId: () => string = () => plugins.crypto.randomUUID(),
59
63
  ): Promise<IRegisterRunnerRequest> {
60
64
  const candidate = validateRegistrationRequest({
61
65
  registrationRequestId: 'pending-validation',
@@ -83,9 +87,9 @@ export class RegistrationStateStore {
83
87
 
84
88
  async load(): Promise<IRegisterRunnerRequest | undefined> {
85
89
  await this.ensureDirectory();
86
- let pathStat: Deno.FileInfo;
90
+ let pathStat: plugins.Stats;
87
91
  try {
88
- pathStat = await Deno.lstat(this.path);
92
+ pathStat = await plugins.fs.lstat(this.path);
89
93
  } catch (error) {
90
94
  if (isNotFound(error)) return undefined;
91
95
  throw error;
@@ -94,75 +98,74 @@ export class RegistrationStateStore {
94
98
  if (pathStat.size > maximumJournalBytes) {
95
99
  throw new RunnerError('Registration journal exceeds its size limit');
96
100
  }
97
- const file = await Deno.open(this.path, { read: true });
98
- try {
99
- const openStat = await file.stat();
100
- this.assertSafeJournalFile(openStat);
101
- if (
102
- (pathStat.dev !== null && openStat.dev !== pathStat.dev) ||
103
- (pathStat.ino !== null && openStat.ino !== pathStat.ino)
104
- ) {
105
- throw new RunnerError('Registration journal changed while it was opened');
106
- }
107
- const bytes = new Uint8Array(pathStat.size + 1);
108
- let offset = 0;
109
- while (offset < bytes.byteLength) {
110
- const read = await file.read(bytes.subarray(offset));
111
- if (read === null) break;
112
- offset += read;
113
- }
114
- if (offset !== pathStat.size) {
115
- throw new RunnerError('Registration journal changed while it was read');
116
- }
117
- let parsed: unknown;
118
- try {
119
- parsed = JSON.parse(
120
- new TextDecoder('utf-8', { fatal: true }).decode(bytes.subarray(0, offset)),
121
- );
122
- } catch (error) {
123
- throw new RunnerError('Registration journal is not valid UTF-8 JSON', { cause: error });
124
- }
125
- return validateRegistrationRequest(parsed);
126
- } finally {
127
- file.close();
128
- }
101
+ return await withOpenFile(
102
+ this.path,
103
+ 'r',
104
+ undefined,
105
+ async (file) => {
106
+ const openStat = await file.stat();
107
+ this.assertSafeJournalFile(openStat);
108
+ if (!sameFileIdentity(pathStat, openStat)) {
109
+ throw new RunnerError('Registration journal changed while it was opened');
110
+ }
111
+ const bytes = new Uint8Array(pathStat.size + 1);
112
+ let offset = 0;
113
+ while (offset < bytes.byteLength) {
114
+ const read = await readInto(file, bytes.subarray(offset));
115
+ if (read === null) break;
116
+ offset += read;
117
+ }
118
+ if (offset !== pathStat.size) {
119
+ throw new RunnerError('Registration journal changed while it was read');
120
+ }
121
+ let parsed: unknown;
122
+ try {
123
+ parsed = JSON.parse(
124
+ new TextDecoder('utf-8', { fatal: true }).decode(bytes.subarray(0, offset)),
125
+ );
126
+ } catch (error) {
127
+ throw new RunnerError('Registration journal is not valid UTF-8 JSON', { cause: error });
128
+ }
129
+ return validateRegistrationRequest(parsed);
130
+ },
131
+ 'Registration journal read and close failed',
132
+ );
129
133
  }
130
134
 
131
135
  async save(request: IRegisterRunnerRequest): Promise<void> {
132
136
  const validated = validateRegistrationRequest(request);
133
137
  await this.ensureDirectory();
134
138
  try {
135
- this.assertSafeJournalFile(await Deno.lstat(this.path));
139
+ this.assertSafeJournalFile(await plugins.fs.lstat(this.path));
136
140
  } catch (error) {
137
141
  if (!isNotFound(error)) throw error;
138
142
  }
139
143
  const temporaryPath = join(
140
144
  this.stateDirectory,
141
- `.${crypto.randomUUID()}.registration-journal.tmp`,
145
+ `.${plugins.crypto.randomUUID()}.registration-journal.tmp`,
142
146
  );
143
147
  const bytes = new TextEncoder().encode(`${JSON.stringify(validated)}\n`);
144
148
  if (bytes.byteLength > maximumJournalBytes) {
145
149
  throw new RunnerError('Registration journal exceeds its size limit');
146
150
  }
147
- let file: Deno.FsFile | undefined;
148
151
  try {
149
- file = await Deno.open(temporaryPath, {
150
- write: true,
151
- createNew: true,
152
- mode: 0o600,
153
- });
154
- await writeAll(file, bytes);
155
- await file.sync();
156
- file.close();
157
- file = undefined;
158
- await Deno.chmod(temporaryPath, 0o600);
159
- await Deno.rename(temporaryPath, this.path);
160
- await Deno.chmod(this.path, 0o600);
152
+ await withOpenFile(
153
+ temporaryPath,
154
+ createNewWriteFlags,
155
+ 0o600,
156
+ async (file) => {
157
+ await writeAll(file, bytes, 'Registration journal write made no progress');
158
+ await file.sync();
159
+ },
160
+ 'Registration journal write and close failed',
161
+ );
162
+ await plugins.fs.chmod(temporaryPath, 0o600);
163
+ await plugins.fs.rename(temporaryPath, this.path);
164
+ await plugins.fs.chmod(this.path, 0o600);
161
165
  await this.syncDirectory();
162
166
  } catch (error) {
163
- file?.close();
164
167
  try {
165
- await Deno.remove(temporaryPath);
168
+ await removePath(temporaryPath);
166
169
  } catch (cleanupError) {
167
170
  if (!isNotFound(cleanupError)) {
168
171
  throw new AggregateError(
@@ -177,44 +180,33 @@ export class RegistrationStateStore {
177
180
 
178
181
  async clear(): Promise<void> {
179
182
  await this.ensureDirectory();
180
- let stat: Deno.FileInfo;
183
+ let stat: plugins.Stats;
181
184
  try {
182
- stat = await Deno.lstat(this.path);
185
+ stat = await plugins.fs.lstat(this.path);
183
186
  } catch (error) {
184
187
  if (isNotFound(error)) return;
185
188
  throw error;
186
189
  }
187
190
  this.assertSafeJournalFile(stat);
188
- await Deno.remove(this.path);
191
+ await removePath(this.path);
189
192
  await this.syncDirectory();
190
193
  }
191
194
 
192
195
  private async ensureDirectory(): Promise<void> {
193
- await Deno.mkdir(this.stateDirectory, { recursive: true, mode: 0o700 });
194
- const stat = await Deno.lstat(this.stateDirectory);
195
- if (!stat.isDirectory || stat.isSymlink) {
196
- throw new RunnerError('Runner state directory must be a real directory');
197
- }
198
- if (Deno.build.os !== 'windows' && stat.mode !== null && (stat.mode & 0o077) !== 0) {
199
- throw new RunnerError('Runner state directory permissions are not private');
200
- }
196
+ this.owner.assertHeld();
197
+ await ensurePrivateStateDirectory(this.stateDirectory);
201
198
  }
202
199
 
203
- private assertSafeJournalFile(stat: Deno.FileInfo): void {
204
- if (!stat.isFile || stat.isSymlink) {
200
+ private assertSafeJournalFile(stat: plugins.Stats): void {
201
+ if (!stat.isFile() || stat.isSymbolicLink()) {
205
202
  throw new RunnerError('Registration journal must be a regular file');
206
203
  }
207
- if (Deno.build.os !== 'windows' && stat.mode !== null && (stat.mode & 0o777) !== 0o600) {
204
+ if ((stat.mode & 0o777) !== 0o600) {
208
205
  throw new RunnerError('Registration journal permissions must be 0600');
209
206
  }
210
207
  }
211
208
 
212
209
  private async syncDirectory(): Promise<void> {
213
- const directory = await Deno.open(this.stateDirectory, { read: true });
214
- try {
215
- await directory.sync();
216
- } finally {
217
- directory.close();
218
- }
210
+ await syncDirectory(this.stateDirectory, 'Runner state directory sync and close failed');
219
211
  }
220
212
  }
package/ts/runner.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { AttemptStateStore } from './attempt-state.ts';
1
+ import * as plugins from './plugins.js';
2
+ import { AttemptStateStore } from './attempt-state.js';
2
3
  import {
3
4
  AuthenticationError,
5
+ ConfigurationError,
4
6
  CoordinatorError,
5
7
  LeaseLostError,
6
8
  ProtocolError,
7
9
  ResourceCleanupError,
8
10
  RunnerError,
9
- } from './errors.ts';
11
+ } from './errors.js';
10
12
  import type {
11
13
  IAbandonJobRequest,
12
14
  IAcceptJobRequest,
@@ -17,6 +19,7 @@ import type {
17
19
  ICompleteJobRequest,
18
20
  ICompleteJobResponse,
19
21
  IDiscoveryResponse,
22
+ IImageRecord,
20
23
  IJobExecutor,
21
24
  IJobHeartbeatRequest,
22
25
  IJobHeartbeatResponse,
@@ -28,6 +31,7 @@ import type {
28
31
  IPreparedOciLease,
29
32
  IPreparedWorkspace,
30
33
  IProtocolLimits,
34
+ IRecordImageRequest,
31
35
  IRecoverAttemptRequest,
32
36
  IRunnerCapabilities,
33
37
  IRunnerConfig,
@@ -40,13 +44,14 @@ import type {
40
44
  IStartSessionResponse,
41
45
  TExecutionStopReason,
42
46
  TJobCompletionStatus,
43
- } from './interfaces.ts';
44
- import { runnerVersion } from './interfaces.ts';
45
- import { LogSender } from './log-sender.ts';
46
- import { createRunnerCapabilitySnapshot, RunnerProtocolValidator } from './protocol-validator.ts';
47
- import { SecretRedactionSet } from './redactor.ts';
48
- import { runnerSpecVersion, specMajorVersionsMatch } from './spec-version.ts';
49
- import { scavengeRunnerStaging } from './staging-scavenger.ts';
47
+ } from './interfaces.js';
48
+ import { runnerVersion } from './interfaces.js';
49
+ import { LogSender } from './log-sender.js';
50
+ import { createRunnerCapabilitySnapshot, RunnerProtocolValidator } from './protocol-validator.js';
51
+ import { SecretRedactionSet } from './redactor.js';
52
+ import { runnerSpecVersion, specMajorVersionsMatch } from './spec-version.js';
53
+ import { scavengeRunnerStaging } from './staging-scavenger.js';
54
+ import type { RunnerStateOwner } from './state-owner.js';
50
55
 
51
56
  export interface IRunnerCoordinatorClient {
52
57
  discover(signal?: AbortSignal): Promise<IDiscoveryResponse>;
@@ -63,6 +68,7 @@ export interface IRunnerCoordinatorClient {
63
68
  signal?: AbortSignal,
64
69
  ): Promise<IJobHeartbeatResponse>;
65
70
  appendLog(chunk: ILogChunk, signal?: AbortSignal): Promise<ILogAcknowledgement>;
71
+ recordImage?(request: IRecordImageRequest, signal?: AbortSignal): Promise<IImageRecord>;
66
72
  completeJob(request: ICompleteJobRequest, signal?: AbortSignal): Promise<ICompleteJobResponse>;
67
73
  abandonJob(request: IAbandonJobRequest, signal?: AbortSignal): Promise<void>;
68
74
  recoverAttempt(request: IRecoverAttemptRequest, signal?: AbortSignal): Promise<void>;
@@ -73,6 +79,8 @@ export interface IRunnerWorkspaceManager {
73
79
  }
74
80
 
75
81
  export interface IRunnerDependencies {
82
+ /** Ownership of `config.stateDirectory`; the runner stops when it is lost. */
83
+ stateOwner: RunnerStateOwner;
76
84
  api: IRunnerCoordinatorClient;
77
85
  executor: IJobExecutor;
78
86
  workspaceManager: IRunnerWorkspaceManager;
@@ -205,22 +213,24 @@ class LeaseGuard {
205
213
  }
206
214
 
207
215
  /**
208
- * The capabilities this runner advertises: the `oci` profile in `container` isolation on the
209
- * native linux platform of its verified OCI engine, the `none` network mode, the configured
210
- * transfer limits, the resource ceilings it enforces per attempt, no lease features (it uses no
211
- * image grants, candidate bindings, or npm read grants), and its configured longest job timeout.
216
+ * The capabilities this Firecracker runner advertises:
217
+ * - `runnerProfile: 'workload'` → `['oci', 'vm']` in `microvm` isolation (never `oci-image`).
218
+ * - `runnerProfile: 'builder'` → `['oci-image']` exclusively in `microvm` isolation (dedicated builder).
219
+ * Both advertise `image-pull-grants`, `candidate-bindings`, and `npm-read-grants`.
212
220
  */
213
221
  export const runnerCapabilities = (
214
222
  config: IRunnerConfig,
215
223
  runtime: Pick<IOciRuntimeFacts, 'os' | 'architecture'>,
216
224
  ): IRunnerCapabilities => {
217
- const artifactEnabled = config.maximumArtifacts > 0 && config.maximumArtifactBytes > 0 &&
218
- config.maximumArtifactExtractedBytes > 0 && config.maximumArtifactEntries > 0;
225
+ const isBuilder = config.oci.runnerProfile === 'builder';
226
+ const artifactEnabled = !isBuilder && config.maximumArtifacts > 0 &&
227
+ config.maximumArtifactBytes > 0 && config.maximumArtifactExtractedBytes > 0 &&
228
+ config.maximumArtifactEntries > 0;
219
229
  const cacheEnabled = config.maximumCaches > 0 && config.maximumCacheArchiveBytes > 0 &&
220
230
  config.maximumCacheExtractedBytes > 0 && config.maximumCacheEntries > 0;
221
231
  return createRunnerCapabilitySnapshot({
222
- executionProfiles: ['oci'],
223
- isolation: ['container'],
232
+ executionProfiles: isBuilder ? ['oci-image'] : ['oci', 'vm'],
233
+ isolation: ['microvm'],
224
234
  platforms: [`${runtime.os}/${runtime.architecture}`],
225
235
  labels: [...config.labels],
226
236
  features: [
@@ -253,7 +263,7 @@ export const runnerCapabilities = (
253
263
  maximumPids: config.oci.maximumPids,
254
264
  maximumSharedMemoryBytes: config.oci.maximumSharedMemoryBytes,
255
265
  },
256
- leaseFeatures: [],
266
+ leaseFeatures: ['image-pull-grants', 'candidate-bindings', 'npm-read-grants'],
257
267
  maximumTimeoutMs: config.oci.maximumTimeoutMs,
258
268
  });
259
269
  };
@@ -318,15 +328,20 @@ export class ShipRunner {
318
328
  }
319
329
  this.drainRequested = false;
320
330
  this.sessionInvalid = false;
331
+ const stateOwner = this.dependencies.stateOwner;
332
+ if (plugins.path.resolve(this.config.stateDirectory) !== stateOwner.stateDirectory) {
333
+ throw new ConfigurationError('Runner state owner does not own the configured state');
334
+ }
321
335
  this.dependencies.api.setRunnerToken(this.config.runnerToken);
322
336
 
337
+ await scavengeRunnerStaging(stateOwner);
323
338
  const runtime = await this.dependencies.executor.verifyRuntime();
324
339
  const discovery = await this.dependencies.api.discover(options.signal);
325
340
  const capabilities = runnerCapabilities(this.config, runtime);
326
341
  reconcileProtocolLimits(this.config, discovery, capabilities);
327
342
  const validator = new RunnerProtocolValidator(capabilities);
328
343
  const session = await this.dependencies.api.startSession({
329
- sessionRequestId: crypto.randomUUID(),
344
+ sessionRequestId: plugins.crypto.randomUUID(),
330
345
  runnerId,
331
346
  spec: runnerSpecVersion,
332
347
  runnerVersion,
@@ -334,11 +349,13 @@ export class ShipRunner {
334
349
  }, options.signal);
335
350
  if (session.credential) await this.applyCredential(session.credential);
336
351
 
337
- const journal = new AttemptStateStore(this.config.stateDirectory);
352
+ const journal = new AttemptStateStore(stateOwner);
338
353
  const sessionLifecycle = new AbortController();
339
354
  const externalAbort = (): void => sessionLifecycle.abort('runner_shutdown');
340
355
  options.signal?.addEventListener('abort', externalAbort, { once: true });
341
356
  if (options.signal?.aborted) externalAbort();
357
+ stateOwner.lost.addEventListener('abort', externalAbort, { once: true });
358
+ if (stateOwner.lost.aborted) externalAbort();
342
359
  let heartbeatError: unknown;
343
360
  const runnerHeartbeat = this.runnerHeartbeatLoop(
344
361
  runnerId,
@@ -352,7 +369,6 @@ export class ShipRunner {
352
369
  let lastResult: IRunnerRunResult = { claimed: false };
353
370
  try {
354
371
  await this.dependencies.executor.reconcileOrphans(runnerId, session.sessionId);
355
- await scavengeRunnerStaging(this.config.stateDirectory);
356
372
  await this.recoverInterruptedAttempt(
357
373
  journal,
358
374
  runnerId,
@@ -382,8 +398,10 @@ export class ShipRunner {
382
398
  } finally {
383
399
  if (!sessionLifecycle.signal.aborted) sessionLifecycle.abort('runner_shutdown');
384
400
  options.signal?.removeEventListener('abort', externalAbort);
401
+ stateOwner.lost.removeEventListener('abort', externalAbort);
385
402
  await runnerHeartbeat;
386
403
  }
404
+ if (stateOwner.lost.aborted) throw stateOwner.lost.reason;
387
405
  if (operationError instanceof ResourceCleanupError) throw operationError;
388
406
  if (heartbeatError !== undefined) throw heartbeatError;
389
407
  if (
@@ -406,7 +424,7 @@ export class ShipRunner {
406
424
  if (!interrupted) return;
407
425
  try {
408
426
  await this.dependencies.api.recoverAttempt({
409
- recoveryRequestId: crypto.randomUUID(),
427
+ recoveryRequestId: plugins.crypto.randomUUID(),
410
428
  runnerId,
411
429
  currentSessionId: sessionId,
412
430
  previousSessionId: interrupted.previousSessionId,
@@ -431,7 +449,7 @@ export class ShipRunner {
431
449
  ): Promise<IRunnerRunResult> {
432
450
  const claimStartedAt = this.now();
433
451
  const claim = await this.dependencies.api.claimJob({
434
- claimRequestId: crypto.randomUUID(),
452
+ claimRequestId: plugins.crypto.randomUUID(),
435
453
  runnerId,
436
454
  sessionId,
437
455
  capabilities,
@@ -565,7 +583,7 @@ export class ShipRunner {
565
583
  }
566
584
  try {
567
585
  await this.dependencies.api.acceptJob({
568
- acceptRequestId: crypto.randomUUID(),
586
+ acceptRequestId: plugins.crypto.randomUUID(),
569
587
  identity,
570
588
  }, guard.controller.signal);
571
589
  } catch (error) {
@@ -699,14 +717,18 @@ export class ShipRunner {
699
717
  recordFailure(error);
700
718
  };
701
719
 
720
+ const isImageBuild = lease.job.requirements.executionProfile === 'oci-image';
721
+ const hasArtifacts = !isImageBuild && 'artifacts' in lease.job && lease.job.artifacts.length > 0;
722
+ const hasStepCaches = !isImageBuild && lease.job.caches.length > 0;
723
+
702
724
  const deadlineTimer = setTimeout(() => {
703
725
  if (!executionAbort.signal.aborted) executionAbort.abort('job_timeout');
704
726
  }, Math.max(0, lease.job.timeoutMs - (this.monotonicNow() - acceptedAt)));
705
727
  try {
706
- if (lease.job.artifacts.length > 0 && !this.dependencies.artifactManager) {
728
+ if (hasArtifacts && !this.dependencies.artifactManager) {
707
729
  throw new RunnerError('Artifact manager is not configured');
708
730
  }
709
- if (lease.job.caches.length > 0 && !this.dependencies.cacheManager) {
731
+ if (hasStepCaches && !this.dependencies.cacheManager) {
710
732
  throw new RunnerError('Cache manager is not configured');
711
733
  }
712
734
  stagingWorkspace = await this.dependencies.workspaceManager.prepare({
@@ -714,7 +736,7 @@ export class ShipRunner {
714
736
  job: lease.job,
715
737
  signal: executionSignal,
716
738
  });
717
- if (lease.job.caches.length > 0) {
739
+ if (hasStepCaches && 'steps' in lease.job) {
718
740
  await this.dependencies.cacheManager!.restore({
719
741
  workspacePath: stagingWorkspace.path,
720
742
  workspaceEntryCount: stagingWorkspace.materializedEntryCount,
@@ -738,9 +760,34 @@ export class ShipRunner {
738
760
  onLog: (stream, data) => logs.write(stream, data),
739
761
  });
740
762
  runtimeWorkspace = result.workspace;
741
- exitCode = result.exitCode;
742
- status = this.completionStatus(result.stopReason, result.exitCode, heartbeatState);
743
- if (status !== 'succeeded' && status !== 'failed') exitCode = null;
763
+ if (isImageBuild) {
764
+ exitCode = null;
765
+ if (result.stopReason) {
766
+ status = this.completionStatus(result.stopReason, null, heartbeatState);
767
+ } else if (result.producedImage) {
768
+ if (!this.dependencies.api.recordImage) {
769
+ throw new RunnerError('Coordinator API client does not implement recordImage');
770
+ }
771
+ await this.dependencies.api.recordImage(
772
+ {
773
+ recordRequestId: plugins.crypto.randomUUID(),
774
+ identity,
775
+ manifestDigest: result.producedImage.manifestDigest,
776
+ mediaType: result.producedImage.mediaType,
777
+ sizeBytes: result.producedImage.sizeBytes,
778
+ platform: result.producedImage.platform,
779
+ },
780
+ executionSignal,
781
+ );
782
+ status = 'succeeded';
783
+ } else {
784
+ status = 'failed';
785
+ }
786
+ } else {
787
+ exitCode = result.exitCode;
788
+ status = this.completionStatus(result.stopReason, result.exitCode, heartbeatState);
789
+ if (status !== 'succeeded' && status !== 'failed') exitCode = null;
790
+ }
744
791
  } catch (error) {
745
792
  if (error instanceof ResourceCleanupError) recordCleanupFailure(error);
746
793
  else if (
@@ -785,7 +832,7 @@ export class ShipRunner {
785
832
  }
786
833
 
787
834
  if (runtimeWorkspace && !cleanupFailure && !transferSignal.aborted) {
788
- if (lease.job.caches.length > 0) {
835
+ if (hasStepCaches && 'steps' in lease.job) {
789
836
  try {
790
837
  await this.dependencies.cacheManager!.save({
791
838
  workspace: runtimeWorkspace,
@@ -801,7 +848,7 @@ export class ShipRunner {
801
848
  }
802
849
  }
803
850
  if (
804
- lease.job.artifacts.length > 0 && !cleanupFailure &&
851
+ hasArtifacts && 'steps' in lease.job && !cleanupFailure &&
805
852
  !transferSignal.aborted
806
853
  ) {
807
854
  try {
@@ -896,7 +943,7 @@ export class ShipRunner {
896
943
  }
897
944
 
898
945
  const completion: ICompleteJobRequest = {
899
- completionRequestId: crypto.randomUUID(),
946
+ completionRequestId: plugins.crypto.randomUUID(),
900
947
  identity,
901
948
  status,
902
949
  exitCode,
@@ -1068,7 +1115,7 @@ export class ShipRunner {
1068
1115
  ): Promise<void> {
1069
1116
  try {
1070
1117
  await this.dependencies.api.abandonJob({
1071
- abandonRequestId: crypto.randomUUID(),
1118
+ abandonRequestId: plugins.crypto.randomUUID(),
1072
1119
  identity,
1073
1120
  reason,
1074
1121
  });