@gresearch/marimohub-compute-armada 0.2.1 → 0.3.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.
- package/README.md +27 -11
- package/dist/agent/SHA256SUMS +2 -2
- package/dist/agent/linux-amd64/agent +0 -0
- package/dist/agent/linux-arm64/agent +0 -0
- package/dist/index.js +202 -57
- package/dist/index.js.map +9 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,6 +59,7 @@ in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
|
|
|
59
59
|
| `ARMADA_RUN_AS_GROUP` | no | Pod `securityContext.runAsGroup`, a gid |
|
|
60
60
|
| `ARMADA_FS_GROUP` | no | Pod `securityContext.fsGroup`; owns the agent volume |
|
|
61
61
|
| `ARMADA_COMMAND_MAX_SECONDS` | no | Backstop for one exec (default `21600`, `0` off) |
|
|
62
|
+
| `ARMADA_START_TIMEOUT_SECONDS` | no | Wait for a job to start running (default `300`) |
|
|
62
63
|
| `ARMADA_EXPOSE` | no | `nodeport` (default) or `ingress`, for both ports |
|
|
63
64
|
| `ARMADA_INGRESS_TLS` | no | `true` (default) or `false`; ingress only |
|
|
64
65
|
| `ARMADA_INGRESS_CERT_NAME` | no | TLS secret name prefix (default `<namespace>-`) |
|
|
@@ -153,20 +154,34 @@ Lookout by job set for a sandbox it has never seen, since marimohub addresses sa
|
|
|
153
154
|
id alone on several paths. A queue map therefore requires `ARMADA_LOOKOUT_URL`, and a
|
|
154
155
|
call Lookout cannot answer fails rather than guesses; marimohub retries it.
|
|
155
156
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
Armada queue
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
Two clocks bound a session start. `ARMADA_START_TIMEOUT_SECONDS` (default 300) is the
|
|
158
|
+
adapter's: how long it waits for the job to start running, which covers the time in the
|
|
159
|
+
Armada queue, scheduling, the image pull and the agent's init container. marimohub's
|
|
160
|
+
`MARIMOHUB_SANDBOX_STARTUP_TIMEOUT_SECONDS` (default 120) starts only once the pod
|
|
161
|
+
answers, and covers installing the notebook's dependencies and starting marimo. On a busy
|
|
162
|
+
cluster, raise `ARMADA_START_TIMEOUT_SECONDS` to allow more time for server-side placement.
|
|
163
|
+
A start that runs out of it fails with the last event the job reported, which tells a job
|
|
164
|
+
still in its queue from one whose pod will not start.
|
|
165
|
+
|
|
166
|
+
marimohub adds three limits of its own. The browser tab that initiated the start can still
|
|
167
|
+
time out after 150 seconds while the server continues waiting: marimohub 0.7.1 fixes that
|
|
168
|
+
limit in the browser, it covers marimohub's own startup as well as the queue wait, and no
|
|
169
|
+
setting changes it. A browser tab that picks
|
|
170
|
+
up a session that is already starting (a reload, a second tab) gives up after
|
|
171
|
+
`MARIMOHUB_SANDBOX_STARTUP_TIMEOUT_SECONDS` plus 30 seconds from when it began watching,
|
|
172
|
+
so keep that at least as long as a typical queue wait. And marimohub marks a session that
|
|
173
|
+
is still starting after 15 minutes as failed, so keep `ARMADA_START_TIMEOUT_SECONDS` plus
|
|
174
|
+
`MARIMOHUB_SANDBOX_STARTUP_TIMEOUT_SECONDS` and about 90 seconds of adapter waits (the
|
|
175
|
+
ingress address and the agent's first answer) below that.
|
|
176
|
+
|
|
177
|
+
Compute profiles (`MARIMOHUB_COMPUTE_PROFILES`) let editors
|
|
163
178
|
pick hardware per notebook: when creating it, later through "Change compute profile", or
|
|
164
179
|
for one edit session. The adapter tells marimohub it applies them, and a profile's CPU
|
|
165
180
|
and memory become the kernel container's requests and limits, which Armada requires to
|
|
166
181
|
be equal. So a kernel that outgrows its profile's memory is OOM-killed, and every session
|
|
167
182
|
is charged its full profile against the queue's fair share, idle or not. Offer a short
|
|
168
183
|
list of sizes rather than one large default. Users can only pick when
|
|
169
|
-
`MARIMOHUB_COMPUTE_PROFILE_OVERRIDE=editors`.
|
|
184
|
+
`MARIMOHUB_COMPUTE_PROFILE_OVERRIDE=editors`.
|
|
170
185
|
`MARIMOHUB_COMPUTE_APP_PROFILES` gives apps their own list, in the same syntax; without
|
|
171
186
|
it, apps use the editing list.
|
|
172
187
|
|
|
@@ -354,7 +369,7 @@ binary at it. The agent image is still needed, since it runs in the cluster.
|
|
|
354
369
|
sudo install -D dist/index.js /etc/marimohub/compute.mjs
|
|
355
370
|
|
|
356
371
|
# The binary, at the release the Dockerfile names, checked against its published hash.
|
|
357
|
-
V=0.
|
|
372
|
+
V=0.7.1
|
|
358
373
|
curl -fsSLO "https://github.com/marimo-team/marimohub/releases/download/v$V/marimohub-linux-x64"
|
|
359
374
|
curl -fsSLO "https://github.com/marimo-team/marimohub/releases/download/v$V/marimohub-linux-x64.sha256"
|
|
360
375
|
sha256sum -c marimohub-linux-x64.sha256
|
|
@@ -405,8 +420,9 @@ export ARMADA_AGENT_IMAGE=marimohub-kernel-agent:local
|
|
|
405
420
|
[docs/CONTRIBUTING.md](docs/CONTRIBUTING.md), which also covers the case where
|
|
406
421
|
`kind load` trips over a multi-platform image.
|
|
407
422
|
|
|
408
|
-
|
|
409
|
-
|
|
423
|
+
Needs marimohub 0.7.1 or later, and is built and tested against the release in the
|
|
424
|
+
`Dockerfile`. An older marimohub gives library adapters no `errors.notFound`, which the
|
|
425
|
+
adapter reports a lost pod with, so the adapter refuses to load there.
|
|
410
426
|
|
|
411
427
|
## Documentation
|
|
412
428
|
|
package/dist/agent/SHA256SUMS
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
607e91a18881348cb21078fe9948e6c3afdbdf60a5470803daa317e7750ad22d linux-amd64/agent
|
|
2
|
+
2a8fff0d1e2ea18125f5ece55eac9f7ee9a9f2ca1ba13ed7be74e1f06241ac60 linux-arm64/agent
|
|
Binary file
|
|
Binary file
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// src/config.ts
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
|
|
4
|
+
// src/armada.ts
|
|
5
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
6
|
+
|
|
4
7
|
// src/armada-types.ts
|
|
5
8
|
var JOB_STATE = {
|
|
6
9
|
QUEUED: 0,
|
|
@@ -176,13 +179,62 @@ function exposedPorts(spec) {
|
|
|
176
179
|
}
|
|
177
180
|
|
|
178
181
|
// src/armada.ts
|
|
182
|
+
class ArmadaHttpError extends Error {
|
|
183
|
+
status;
|
|
184
|
+
constructor(message, status) {
|
|
185
|
+
super(message);
|
|
186
|
+
this.status = status;
|
|
187
|
+
this.name = "ArmadaHttpError";
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
var UNREACHABLE_STATUSES = new Set([502, 503, 504]);
|
|
191
|
+
function isUnreachable(error) {
|
|
192
|
+
return error instanceof TypeError || error instanceof ArmadaHttpError && UNREACHABLE_STATUSES.has(error.status);
|
|
193
|
+
}
|
|
179
194
|
function asObject(value, what) {
|
|
180
195
|
if (typeof value !== "object" || value === null) {
|
|
181
196
|
throw new Error(`Armada returned ${what} that is not a JSON object: ${JSON.stringify(value)}`);
|
|
182
197
|
}
|
|
183
198
|
return value;
|
|
184
199
|
}
|
|
185
|
-
|
|
200
|
+
function eventKind(message, jobId) {
|
|
201
|
+
for (const [kind, event] of Object.entries(message)) {
|
|
202
|
+
if (typeof event === "object" && event !== null && "jobId" in event && event.jobId === jobId) {
|
|
203
|
+
return kind;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
var STAGE_NEUTRAL_EVENTS = new Set(["reprioritizing", "reprioritized"]);
|
|
209
|
+
function stuckAt(stage, queue) {
|
|
210
|
+
switch (stage) {
|
|
211
|
+
case undefined:
|
|
212
|
+
return "Armada reported no event for it, or did not answer";
|
|
213
|
+
case "submitted":
|
|
214
|
+
case "queued":
|
|
215
|
+
return `it is still waiting in queue ${queue}`;
|
|
216
|
+
case "leased":
|
|
217
|
+
return "it was scheduled, but the executor has not created its pod";
|
|
218
|
+
case "pending":
|
|
219
|
+
return "its pod exists but is not running; look for a slow or failing image pull or init container";
|
|
220
|
+
case "failed":
|
|
221
|
+
return `its last run failed, and Armada retries it from queue ${queue}`;
|
|
222
|
+
case "leaseReturned":
|
|
223
|
+
case "leaseExpired":
|
|
224
|
+
case "preempted":
|
|
225
|
+
return `its last run ended (${stage}) and it is back in queue ${queue}`;
|
|
226
|
+
default:
|
|
227
|
+
return `its last event was ${stage}`;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
var DEFAULT_RETRY_DELAY_MS = 1000;
|
|
231
|
+
var JOB_SEARCH_ATTEMPTS = 3;
|
|
232
|
+
var SEARCH_READ_TIMEOUT_MS = 30 * 1000;
|
|
233
|
+
function endsJob(kind, event) {
|
|
234
|
+
if (kind === "succeeded" || kind === "cancelled")
|
|
235
|
+
return true;
|
|
236
|
+
return kind === "failed" && !(("retryable" in event) && event.retryable === true);
|
|
237
|
+
}
|
|
186
238
|
var DEFAULT_INGRESS_TIMEOUT_MS = 60 * 1000;
|
|
187
239
|
var DEFAULT_STATUS_TIMEOUT_MS = 5 * 1000;
|
|
188
240
|
var SANDBOX_MARK = "marimohub/sandbox";
|
|
@@ -194,12 +246,23 @@ var FINISHED_JOB_STATES = new Set([
|
|
|
194
246
|
JOB_STATE.CANCELLED,
|
|
195
247
|
JOB_STATE.REJECTED
|
|
196
248
|
]);
|
|
249
|
+
function newestJob(jobs, finished, sandboxId, queue) {
|
|
250
|
+
const entries = Object.entries(jobs).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
251
|
+
const live = entries.findLast(([, value]) => !finished(value))?.[0];
|
|
252
|
+
if (live !== undefined) {
|
|
253
|
+
return { found: "live", job: { jobId: live, jobSetId: sandboxId, queue } };
|
|
254
|
+
}
|
|
255
|
+
const last = entries.at(-1)?.[0];
|
|
256
|
+
return last === undefined ? undefined : { found: "finished", jobId: last };
|
|
257
|
+
}
|
|
197
258
|
var LIST_ACTIVE_PAGE = 500;
|
|
198
259
|
|
|
199
260
|
class ArmadaClient {
|
|
200
261
|
config;
|
|
201
|
-
|
|
262
|
+
retryDelayMs;
|
|
263
|
+
constructor(config, retryDelayMs = DEFAULT_RETRY_DELAY_MS) {
|
|
202
264
|
this.config = config;
|
|
265
|
+
this.retryDelayMs = retryDelayMs;
|
|
203
266
|
}
|
|
204
267
|
async requestHeaders() {
|
|
205
268
|
const authorization = await authorizationHeader(this.config.auth);
|
|
@@ -251,43 +314,81 @@ class ArmadaClient {
|
|
|
251
314
|
}
|
|
252
315
|
return { jobId: item.jobId, jobSetId: sandboxId, queue };
|
|
253
316
|
}
|
|
254
|
-
async waitForRunning(job, timeoutMs =
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
for await (const value of readNdjson(response.body)) {
|
|
266
|
-
const line = asObject(value, "an event stream line");
|
|
267
|
-
if (line.error !== undefined) {
|
|
268
|
-
throw new Error(`Armada event stream failed: ${line.error.message ?? "unknown error"}`);
|
|
269
|
-
}
|
|
270
|
-
const message = line.result?.message;
|
|
271
|
-
if (message === undefined)
|
|
272
|
-
continue;
|
|
273
|
-
const running = message.running;
|
|
274
|
-
if (running !== undefined && running.jobId === job.jobId) {
|
|
275
|
-
return {
|
|
276
|
-
clusterId: running.clusterId ?? "",
|
|
277
|
-
podName: running.podName ?? "",
|
|
278
|
-
podNamespace: running.podNamespace ?? this.config.namespace,
|
|
279
|
-
...running.nodeName === undefined ? {} : { nodeName: running.nodeName }
|
|
280
|
-
};
|
|
317
|
+
async waitForRunning(job, timeoutMs = this.config.startTimeoutSeconds * 1000) {
|
|
318
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
319
|
+
let stage;
|
|
320
|
+
try {
|
|
321
|
+
return await this.followUntilRunning(job, signal, (kind) => {
|
|
322
|
+
if (!STAGE_NEUTRAL_EVENTS.has(kind))
|
|
323
|
+
stage = kind;
|
|
324
|
+
});
|
|
325
|
+
} catch (error) {
|
|
326
|
+
if (signal.aborted) {
|
|
327
|
+
throw new Error(`Armada job ${job.jobId} did not start running within ${String(timeoutMs / 1000)}s (ARMADA_START_TIMEOUT_SECONDS): ${stuckAt(stage, job.queue)}`, { cause: error });
|
|
281
328
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
async followUntilRunning(job, signal, onEvent) {
|
|
333
|
+
const path = `/v1/job-set/${encodeURIComponent(job.queue)}/${encodeURIComponent(job.jobSetId)}`;
|
|
334
|
+
let cursor;
|
|
335
|
+
let lastDrop;
|
|
336
|
+
for (;; ) {
|
|
337
|
+
const request = {
|
|
338
|
+
queue: job.queue,
|
|
339
|
+
id: job.jobSetId,
|
|
340
|
+
watch: true,
|
|
341
|
+
errorIfMissing: false,
|
|
342
|
+
...cursor === undefined ? {} : { fromMessageId: cursor }
|
|
343
|
+
};
|
|
344
|
+
try {
|
|
345
|
+
const response = await this.post(path, request, signal);
|
|
346
|
+
lastDrop = undefined;
|
|
347
|
+
if (response.body === null)
|
|
348
|
+
throw new Error(`Armada returned no event stream for ${path}`);
|
|
349
|
+
for await (const value of readNdjson(response.body)) {
|
|
350
|
+
const line = asObject(value, "an event stream line");
|
|
351
|
+
if (line.error !== undefined) {
|
|
352
|
+
throw new Error(`Armada event stream failed: ${line.error.message ?? "unknown error"}`);
|
|
353
|
+
}
|
|
354
|
+
if (line.result?.id !== undefined)
|
|
355
|
+
cursor = line.result.id;
|
|
356
|
+
const message = line.result?.message;
|
|
357
|
+
if (message === undefined)
|
|
358
|
+
continue;
|
|
359
|
+
const kind = eventKind(message, job.jobId);
|
|
360
|
+
if (kind !== undefined)
|
|
361
|
+
onEvent(kind);
|
|
362
|
+
const running = message.running;
|
|
363
|
+
if (running !== undefined && running.jobId === job.jobId) {
|
|
364
|
+
return {
|
|
365
|
+
clusterId: running.clusterId ?? "",
|
|
366
|
+
podName: running.podName ?? "",
|
|
367
|
+
podNamespace: running.podNamespace ?? this.config.namespace,
|
|
368
|
+
...running.nodeName === undefined ? {} : { nodeName: running.nodeName }
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
const failed = message.failed;
|
|
372
|
+
if (failed !== undefined && failed.jobId === job.jobId && failed.retryable !== true) {
|
|
373
|
+
throw new Error(`Armada job ${job.jobId} failed: ${failed.reason ?? "no reason given"}`);
|
|
374
|
+
}
|
|
375
|
+
if (message.cancelled !== undefined && message.cancelled.jobId === job.jobId) {
|
|
376
|
+
throw new Error(`Armada job ${job.jobId} was cancelled before it started`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
} catch (error) {
|
|
380
|
+
if (signal.aborted)
|
|
381
|
+
throw lastDrop ?? error;
|
|
382
|
+
if (!isUnreachable(error))
|
|
383
|
+
throw error;
|
|
384
|
+
lastDrop = error;
|
|
285
385
|
}
|
|
286
|
-
|
|
287
|
-
|
|
386
|
+
try {
|
|
387
|
+
await sleep(this.retryDelayMs, undefined, { signal });
|
|
388
|
+
} catch {
|
|
389
|
+
throw lastDrop ?? signal.reason;
|
|
288
390
|
}
|
|
289
391
|
}
|
|
290
|
-
throw new Error(`Armada event stream ended before job ${job.jobId} started`);
|
|
291
392
|
}
|
|
292
393
|
async ingressAddress(job, port, timeoutMs = DEFAULT_INGRESS_TIMEOUT_MS) {
|
|
293
394
|
const request = {
|
|
@@ -347,9 +448,39 @@ class ArmadaClient {
|
|
|
347
448
|
await this.post("/v1/job/cancel", request);
|
|
348
449
|
}
|
|
349
450
|
async findJob(sandboxId, queue) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
451
|
+
for (let attempt = 1;; attempt++) {
|
|
452
|
+
const listed = newestJob(await this.jobStates(sandboxId, queue, AbortSignal.timeout(SEARCH_READ_TIMEOUT_MS)), (state) => FINISHED_JOB_STATES.has(state), sandboxId, queue);
|
|
453
|
+
if (listed !== undefined)
|
|
454
|
+
return listed;
|
|
455
|
+
const seen = newestJob(await this.lastEvents(sandboxId, queue), (finished) => finished, sandboxId, queue);
|
|
456
|
+
if (seen !== undefined)
|
|
457
|
+
return seen;
|
|
458
|
+
if (attempt === JOB_SEARCH_ATTEMPTS)
|
|
459
|
+
return { found: "nothing" };
|
|
460
|
+
await sleep(this.retryDelayMs);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
async lastEvents(sandboxId, queue) {
|
|
464
|
+
const request = { queue, id: sandboxId, watch: false, errorIfMissing: false };
|
|
465
|
+
const path = `/v1/job-set/${encodeURIComponent(queue)}/${encodeURIComponent(sandboxId)}`;
|
|
466
|
+
const response = await this.post(path, request, AbortSignal.timeout(SEARCH_READ_TIMEOUT_MS));
|
|
467
|
+
if (response.body === null)
|
|
468
|
+
throw new Error(`Armada returned no event stream for ${path}`);
|
|
469
|
+
const ended = {};
|
|
470
|
+
for await (const value of readNdjson(response.body)) {
|
|
471
|
+
const line = asObject(value, "an event stream line");
|
|
472
|
+
if (line.error !== undefined) {
|
|
473
|
+
throw new Error(`Armada event stream failed: ${line.error.message ?? "unknown error"}`);
|
|
474
|
+
}
|
|
475
|
+
for (const [kind, event] of Object.entries(line.result?.message ?? {})) {
|
|
476
|
+
if (typeof event !== "object" || event === null)
|
|
477
|
+
continue;
|
|
478
|
+
if (!("jobId" in event) || typeof event.jobId !== "string")
|
|
479
|
+
continue;
|
|
480
|
+
ended[event.jobId] = ended[event.jobId] === true || endsJob(kind, event);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return ended;
|
|
353
484
|
}
|
|
354
485
|
async isFinished(job, timeoutMs = DEFAULT_STATUS_TIMEOUT_MS) {
|
|
355
486
|
const states = await this.jobStates(job.jobSetId, job.queue, AbortSignal.timeout(timeoutMs));
|
|
@@ -421,7 +552,7 @@ class ArmadaClient {
|
|
|
421
552
|
});
|
|
422
553
|
if (!response.ok) {
|
|
423
554
|
const detail = (await response.text()).trim();
|
|
424
|
-
throw new
|
|
555
|
+
throw new ArmadaHttpError(`Armada ${path} failed (${response.status}): ${detail === "" ? response.statusText : detail}`, response.status);
|
|
425
556
|
}
|
|
426
557
|
return response;
|
|
427
558
|
}
|
|
@@ -693,6 +824,7 @@ function profileGpuTypes(profiles) {
|
|
|
693
824
|
}
|
|
694
825
|
var DEFAULT_MAX_LIFETIME_SECONDS = 24 * 60 * 60;
|
|
695
826
|
var DEFAULT_COMMAND_MAX_SECONDS = 6 * 60 * 60;
|
|
827
|
+
var DEFAULT_START_TIMEOUT_SECONDS = 5 * 60;
|
|
696
828
|
var DEFAULT_IMAGE = "ghcr.io/marimo-team/marimo-sandbox:latest";
|
|
697
829
|
function readConfig(env, compute) {
|
|
698
830
|
const image = env.MARIMOHUB_COMPUTE_IMAGE === undefined ? DEFAULT_IMAGE : env.MARIMOHUB_COMPUTE_IMAGE.split(",")[0]?.trim();
|
|
@@ -723,6 +855,7 @@ function readConfig(env, compute) {
|
|
|
723
855
|
lookoutUrl: optionalUrl(env, "ARMADA_LOOKOUT_URL"),
|
|
724
856
|
maxLifetimeSeconds: compute?.sessionMaxLifetimeSeconds ?? optionalSeconds(env, "ARMADA_KERNEL_MAX_LIFETIME_SECONDS", DEFAULT_MAX_LIFETIME_SECONDS),
|
|
725
857
|
commandMaxSeconds: optionalSeconds(env, "ARMADA_COMMAND_MAX_SECONDS", DEFAULT_COMMAND_MAX_SECONDS, 0),
|
|
858
|
+
startTimeoutSeconds: optionalSeconds(env, "ARMADA_START_TIMEOUT_SECONDS", DEFAULT_START_TIMEOUT_SECONDS),
|
|
726
859
|
auth: readAuth(env)
|
|
727
860
|
};
|
|
728
861
|
if (config.agentPort === config.port) {
|
|
@@ -782,7 +915,7 @@ async function refusalOf(response) {
|
|
|
782
915
|
} catch {}
|
|
783
916
|
return { code, message: `HTTP ${String(response.status)}: ${message}` };
|
|
784
917
|
}
|
|
785
|
-
async function
|
|
918
|
+
async function sleep2(ms) {
|
|
786
919
|
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
787
920
|
}
|
|
788
921
|
function pidOf(value) {
|
|
@@ -858,7 +991,7 @@ class AgentChannel {
|
|
|
858
991
|
}
|
|
859
992
|
if (Date.now() >= deadline)
|
|
860
993
|
break;
|
|
861
|
-
await
|
|
994
|
+
await sleep2(READY_POLL_MS);
|
|
862
995
|
}
|
|
863
996
|
throw new Error(`The agent in ${this.where} at ${this.base} did not answer within ${String(timeoutMs)}ms: ${last}`);
|
|
864
997
|
}
|
|
@@ -1169,6 +1302,7 @@ class QueueDirectory {
|
|
|
1169
1302
|
all;
|
|
1170
1303
|
mapped;
|
|
1171
1304
|
remembered = new Map;
|
|
1305
|
+
guesses = new Set;
|
|
1172
1306
|
constructor(config, lookup) {
|
|
1173
1307
|
this.config = config;
|
|
1174
1308
|
this.lookup = lookup;
|
|
@@ -1187,9 +1321,14 @@ class QueueDirectory {
|
|
|
1187
1321
|
}
|
|
1188
1322
|
remember(id, queue) {
|
|
1189
1323
|
this.remembered.set(id, queue);
|
|
1324
|
+
this.guesses.delete(id);
|
|
1190
1325
|
}
|
|
1191
1326
|
forget(id) {
|
|
1192
1327
|
this.remembered.delete(id);
|
|
1328
|
+
this.guesses.delete(id);
|
|
1329
|
+
}
|
|
1330
|
+
guessed(id) {
|
|
1331
|
+
return this.guesses.has(id);
|
|
1193
1332
|
}
|
|
1194
1333
|
async resolve(id, owner) {
|
|
1195
1334
|
const known = this.remembered.get(id);
|
|
@@ -1211,6 +1350,7 @@ class QueueDirectory {
|
|
|
1211
1350
|
}
|
|
1212
1351
|
const queue = owner === undefined ? this.config.queue : this.forOwner(owner);
|
|
1213
1352
|
this.remembered.set(id, queue);
|
|
1353
|
+
this.guesses.add(id);
|
|
1214
1354
|
return queue;
|
|
1215
1355
|
}
|
|
1216
1356
|
}
|
|
@@ -1264,10 +1404,6 @@ function agentToken(secret, id) {
|
|
|
1264
1404
|
var WRITE_CONCURRENCY = 8;
|
|
1265
1405
|
var AGENT_READY_TIMEOUT_MS = 30000;
|
|
1266
1406
|
var PORT_READY_TIMEOUT_MS = 0;
|
|
1267
|
-
|
|
1268
|
-
class SandboxGoneError extends Error {
|
|
1269
|
-
name = "SandboxGoneError";
|
|
1270
|
-
}
|
|
1271
1407
|
var goneErrors = new WeakSet;
|
|
1272
1408
|
function isSandboxGone(error) {
|
|
1273
1409
|
return error instanceof Error && goneErrors.has(error);
|
|
@@ -1307,9 +1443,9 @@ class ArmadaSandbox {
|
|
|
1307
1443
|
openChannel;
|
|
1308
1444
|
queues;
|
|
1309
1445
|
placements;
|
|
1446
|
+
notFound;
|
|
1310
1447
|
options;
|
|
1311
1448
|
attachOnly;
|
|
1312
|
-
notFound;
|
|
1313
1449
|
supportsBucketMount = false;
|
|
1314
1450
|
job;
|
|
1315
1451
|
pod;
|
|
@@ -1317,16 +1453,16 @@ class ArmadaSandbox {
|
|
|
1317
1453
|
token;
|
|
1318
1454
|
env = {};
|
|
1319
1455
|
envDefaults = {};
|
|
1320
|
-
constructor(id, config, armada, openChannel, queues, placements, options, attachOnly = false
|
|
1456
|
+
constructor(id, config, armada, openChannel, queues, placements, notFound, options, attachOnly = false) {
|
|
1321
1457
|
this.id = id;
|
|
1322
1458
|
this.config = config;
|
|
1323
1459
|
this.armada = armada;
|
|
1324
1460
|
this.openChannel = openChannel;
|
|
1325
1461
|
this.queues = queues;
|
|
1326
1462
|
this.placements = placements;
|
|
1463
|
+
this.notFound = notFound;
|
|
1327
1464
|
this.options = options;
|
|
1328
1465
|
this.attachOnly = attachOnly;
|
|
1329
|
-
this.notFound = notFound;
|
|
1330
1466
|
this.token = agentToken(config.agentTokenSecret, id);
|
|
1331
1467
|
}
|
|
1332
1468
|
gone(message) {
|
|
@@ -1363,15 +1499,20 @@ class ArmadaSandbox {
|
|
|
1363
1499
|
}
|
|
1364
1500
|
async submit() {
|
|
1365
1501
|
const tokenSha256 = createHash("sha256").update(this.token).digest("hex");
|
|
1366
|
-
|
|
1502
|
+
const job = await this.armada.submit(this.id, buildPodSpec(this.config, { tokenSha256 }, this.options), await this.queue());
|
|
1503
|
+
this.queues.remember(this.id, job.queue);
|
|
1504
|
+
return job;
|
|
1367
1505
|
}
|
|
1368
1506
|
async existingJob() {
|
|
1369
1507
|
const queue = await this.queue();
|
|
1370
|
-
const
|
|
1371
|
-
if (
|
|
1372
|
-
|
|
1508
|
+
const lookup = await this.armada.findJob(this.id, queue);
|
|
1509
|
+
if (lookup.found === "live")
|
|
1510
|
+
return lookup.job;
|
|
1511
|
+
if (lookup.found === "nothing" && this.queues.guessed(this.id)) {
|
|
1512
|
+
const others = this.queues.all.filter((q) => q !== queue).join(", ");
|
|
1513
|
+
console.warn(`marimohub-compute-armada: sandbox ${this.id} is reported gone, but its queue "${queue}" is only the owner map's answer of today: neither this process nor Lookout has seen its job. If the job sits in another queue (${others}), for a map changed since its submit or an attach that named no owner, the sandbox is live and marimohub drops its unsaved edits.`);
|
|
1373
1514
|
}
|
|
1374
|
-
|
|
1515
|
+
throw this.gone(lookup.found === "finished" ? `Sandbox ${this.id} is gone: its Armada job ${lookup.jobId} has finished, and attaching never submits a new one` : `Sandbox ${this.id} has no job in queue "${queue}" to attach to, and attaching never submits one`);
|
|
1375
1516
|
}
|
|
1376
1517
|
get placement() {
|
|
1377
1518
|
return this.pod;
|
|
@@ -1629,10 +1770,10 @@ class ArmadaCompute {
|
|
|
1629
1770
|
}
|
|
1630
1771
|
}
|
|
1631
1772
|
create(id, options) {
|
|
1632
|
-
return new ArmadaSandbox(id, this.config, this.armada, openAgent, this.queues, this.placements, options, false
|
|
1773
|
+
return new ArmadaSandbox(id, this.config, this.armada, openAgent, this.queues, this.placements, this.notFound, options, false);
|
|
1633
1774
|
}
|
|
1634
1775
|
connectExisting(id, options) {
|
|
1635
|
-
return new ArmadaSandbox(id, this.config, this.armada, openAgent, this.queues, this.placements, options, true
|
|
1776
|
+
return new ArmadaSandbox(id, this.config, this.armada, openAgent, this.queues, this.placements, this.notFound, options, true);
|
|
1636
1777
|
}
|
|
1637
1778
|
async proxy(_request) {
|
|
1638
1779
|
return null;
|
|
@@ -1647,7 +1788,11 @@ var manifest = {
|
|
|
1647
1788
|
apiVersion: 1,
|
|
1648
1789
|
kind: "compute",
|
|
1649
1790
|
create(context) {
|
|
1650
|
-
|
|
1791
|
+
const errors = context.errors;
|
|
1792
|
+
if (errors.notFound === undefined) {
|
|
1793
|
+
throw new Error("The Armada compute adapter needs marimohub 0.7.1 or later: older releases give library adapters no errors.notFound, so a lost pod would keep its notebook locked");
|
|
1794
|
+
}
|
|
1795
|
+
return new ArmadaCompute(readConfig(context.env, context.compute), errors.notFound);
|
|
1651
1796
|
}
|
|
1652
1797
|
};
|
|
1653
1798
|
var src_default = manifest;
|
|
@@ -1655,5 +1800,5 @@ export {
|
|
|
1655
1800
|
src_default as default
|
|
1656
1801
|
};
|
|
1657
1802
|
|
|
1658
|
-
//# debugId=
|
|
1803
|
+
//# debugId=4B03CA1D79634B6864756E2164756E21
|
|
1659
1804
|
//# sourceMappingURL=index.js.map
|