@gresearch/marimohub-compute-armada 0.2.0 → 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 -5
- 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 +237 -56
- 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,14 +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
|
+
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
|
|
157
178
|
pick hardware per notebook: when creating it, later through "Change compute profile", or
|
|
158
179
|
for one edit session. The adapter tells marimohub it applies them, and a profile's CPU
|
|
159
180
|
and memory become the kernel container's requests and limits, which Armada requires to
|
|
160
181
|
be equal. So a kernel that outgrows its profile's memory is OOM-killed, and every session
|
|
161
182
|
is charged its full profile against the queue's fair share, idle or not. Offer a short
|
|
162
183
|
list of sizes rather than one large default. Users can only pick when
|
|
163
|
-
`MARIMOHUB_COMPUTE_PROFILE_OVERRIDE=editors`.
|
|
184
|
+
`MARIMOHUB_COMPUTE_PROFILE_OVERRIDE=editors`.
|
|
164
185
|
`MARIMOHUB_COMPUTE_APP_PROFILES` gives apps their own list, in the same syntax; without
|
|
165
186
|
it, apps use the editing list.
|
|
166
187
|
|
|
@@ -348,7 +369,7 @@ binary at it. The agent image is still needed, since it runs in the cluster.
|
|
|
348
369
|
sudo install -D dist/index.js /etc/marimohub/compute.mjs
|
|
349
370
|
|
|
350
371
|
# The binary, at the release the Dockerfile names, checked against its published hash.
|
|
351
|
-
V=0.
|
|
372
|
+
V=0.7.1
|
|
352
373
|
curl -fsSLO "https://github.com/marimo-team/marimohub/releases/download/v$V/marimohub-linux-x64"
|
|
353
374
|
curl -fsSLO "https://github.com/marimo-team/marimohub/releases/download/v$V/marimohub-linux-x64.sha256"
|
|
354
375
|
sha256sum -c marimohub-linux-x64.sha256
|
|
@@ -399,8 +420,9 @@ export ARMADA_AGENT_IMAGE=marimohub-kernel-agent:local
|
|
|
399
420
|
[docs/CONTRIBUTING.md](docs/CONTRIBUTING.md), which also covers the case where
|
|
400
421
|
`kind load` trips over a multi-platform image.
|
|
401
422
|
|
|
402
|
-
|
|
403
|
-
|
|
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.
|
|
404
426
|
|
|
405
427
|
## Documentation
|
|
406
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,14 +179,64 @@ 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;
|
|
239
|
+
var DEFAULT_STATUS_TIMEOUT_MS = 5 * 1000;
|
|
187
240
|
var SANDBOX_MARK = "marimohub/sandbox";
|
|
188
241
|
var ACTIVE_JOB_STATES = ["QUEUED", "LEASED", "PENDING", "RUNNING"];
|
|
189
242
|
var FINISHED_JOB_STATES = new Set([
|
|
@@ -193,12 +246,23 @@ var FINISHED_JOB_STATES = new Set([
|
|
|
193
246
|
JOB_STATE.CANCELLED,
|
|
194
247
|
JOB_STATE.REJECTED
|
|
195
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
|
+
}
|
|
196
258
|
var LIST_ACTIVE_PAGE = 500;
|
|
197
259
|
|
|
198
260
|
class ArmadaClient {
|
|
199
261
|
config;
|
|
200
|
-
|
|
262
|
+
retryDelayMs;
|
|
263
|
+
constructor(config, retryDelayMs = DEFAULT_RETRY_DELAY_MS) {
|
|
201
264
|
this.config = config;
|
|
265
|
+
this.retryDelayMs = retryDelayMs;
|
|
202
266
|
}
|
|
203
267
|
async requestHeaders() {
|
|
204
268
|
const authorization = await authorizationHeader(this.config.auth);
|
|
@@ -250,43 +314,81 @@ class ArmadaClient {
|
|
|
250
314
|
}
|
|
251
315
|
return { jobId: item.jobId, jobSetId: sandboxId, queue };
|
|
252
316
|
}
|
|
253
|
-
async waitForRunning(job, timeoutMs =
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
for await (const value of readNdjson(response.body)) {
|
|
265
|
-
const line = asObject(value, "an event stream line");
|
|
266
|
-
if (line.error !== undefined) {
|
|
267
|
-
throw new Error(`Armada event stream failed: ${line.error.message ?? "unknown error"}`);
|
|
268
|
-
}
|
|
269
|
-
const message = line.result?.message;
|
|
270
|
-
if (message === undefined)
|
|
271
|
-
continue;
|
|
272
|
-
const running = message.running;
|
|
273
|
-
if (running !== undefined && running.jobId === job.jobId) {
|
|
274
|
-
return {
|
|
275
|
-
clusterId: running.clusterId ?? "",
|
|
276
|
-
podName: running.podName ?? "",
|
|
277
|
-
podNamespace: running.podNamespace ?? this.config.namespace,
|
|
278
|
-
...running.nodeName === undefined ? {} : { nodeName: running.nodeName }
|
|
279
|
-
};
|
|
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 });
|
|
280
328
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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;
|
|
284
385
|
}
|
|
285
|
-
|
|
286
|
-
|
|
386
|
+
try {
|
|
387
|
+
await sleep(this.retryDelayMs, undefined, { signal });
|
|
388
|
+
} catch {
|
|
389
|
+
throw lastDrop ?? signal.reason;
|
|
287
390
|
}
|
|
288
391
|
}
|
|
289
|
-
throw new Error(`Armada event stream ended before job ${job.jobId} started`);
|
|
290
392
|
}
|
|
291
393
|
async ingressAddress(job, port, timeoutMs = DEFAULT_INGRESS_TIMEOUT_MS) {
|
|
292
394
|
const request = {
|
|
@@ -346,15 +448,53 @@ class ArmadaClient {
|
|
|
346
448
|
await this.post("/v1/job/cancel", request);
|
|
347
449
|
}
|
|
348
450
|
async findJob(sandboxId, queue) {
|
|
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;
|
|
484
|
+
}
|
|
485
|
+
async isFinished(job, timeoutMs = DEFAULT_STATUS_TIMEOUT_MS) {
|
|
486
|
+
const states = await this.jobStates(job.jobSetId, job.queue, AbortSignal.timeout(timeoutMs));
|
|
487
|
+
const state = states[job.jobId];
|
|
488
|
+
return state !== undefined && FINISHED_JOB_STATES.has(state);
|
|
489
|
+
}
|
|
490
|
+
async jobStates(sandboxId, queue, signal) {
|
|
349
491
|
const request = {
|
|
350
492
|
queue,
|
|
351
493
|
jobset: sandboxId,
|
|
352
494
|
externalJobUri: sandboxId
|
|
353
495
|
};
|
|
354
|
-
const response = await this.postJson("/v1/job/statusUsingExternalJobUri", request);
|
|
355
|
-
|
|
356
|
-
const jobId = live.at(-1);
|
|
357
|
-
return jobId === undefined ? undefined : { jobId, jobSetId: sandboxId, queue };
|
|
496
|
+
const response = await this.postJson("/v1/job/statusUsingExternalJobUri", request, signal);
|
|
497
|
+
return response.jobStates ?? {};
|
|
358
498
|
}
|
|
359
499
|
async findQueue(jobSetId) {
|
|
360
500
|
const lookout = this.config.lookoutUrl;
|
|
@@ -412,12 +552,12 @@ class ArmadaClient {
|
|
|
412
552
|
});
|
|
413
553
|
if (!response.ok) {
|
|
414
554
|
const detail = (await response.text()).trim();
|
|
415
|
-
throw new
|
|
555
|
+
throw new ArmadaHttpError(`Armada ${path} failed (${response.status}): ${detail === "" ? response.statusText : detail}`, response.status);
|
|
416
556
|
}
|
|
417
557
|
return response;
|
|
418
558
|
}
|
|
419
|
-
async postJson(path, body) {
|
|
420
|
-
const response = await this.post(path, body);
|
|
559
|
+
async postJson(path, body, signal) {
|
|
560
|
+
const response = await this.post(path, body, signal);
|
|
421
561
|
return asObject(await response.json(), `a response to ${path}`);
|
|
422
562
|
}
|
|
423
563
|
async postJsonTo(base, path, body) {
|
|
@@ -684,6 +824,7 @@ function profileGpuTypes(profiles) {
|
|
|
684
824
|
}
|
|
685
825
|
var DEFAULT_MAX_LIFETIME_SECONDS = 24 * 60 * 60;
|
|
686
826
|
var DEFAULT_COMMAND_MAX_SECONDS = 6 * 60 * 60;
|
|
827
|
+
var DEFAULT_START_TIMEOUT_SECONDS = 5 * 60;
|
|
687
828
|
var DEFAULT_IMAGE = "ghcr.io/marimo-team/marimo-sandbox:latest";
|
|
688
829
|
function readConfig(env, compute) {
|
|
689
830
|
const image = env.MARIMOHUB_COMPUTE_IMAGE === undefined ? DEFAULT_IMAGE : env.MARIMOHUB_COMPUTE_IMAGE.split(",")[0]?.trim();
|
|
@@ -714,6 +855,7 @@ function readConfig(env, compute) {
|
|
|
714
855
|
lookoutUrl: optionalUrl(env, "ARMADA_LOOKOUT_URL"),
|
|
715
856
|
maxLifetimeSeconds: compute?.sessionMaxLifetimeSeconds ?? optionalSeconds(env, "ARMADA_KERNEL_MAX_LIFETIME_SECONDS", DEFAULT_MAX_LIFETIME_SECONDS),
|
|
716
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),
|
|
717
859
|
auth: readAuth(env)
|
|
718
860
|
};
|
|
719
861
|
if (config.agentPort === config.port) {
|
|
@@ -773,7 +915,7 @@ async function refusalOf(response) {
|
|
|
773
915
|
} catch {}
|
|
774
916
|
return { code, message: `HTTP ${String(response.status)}: ${message}` };
|
|
775
917
|
}
|
|
776
|
-
async function
|
|
918
|
+
async function sleep2(ms) {
|
|
777
919
|
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
778
920
|
}
|
|
779
921
|
function pidOf(value) {
|
|
@@ -849,7 +991,7 @@ class AgentChannel {
|
|
|
849
991
|
}
|
|
850
992
|
if (Date.now() >= deadline)
|
|
851
993
|
break;
|
|
852
|
-
await
|
|
994
|
+
await sleep2(READY_POLL_MS);
|
|
853
995
|
}
|
|
854
996
|
throw new Error(`The agent in ${this.where} at ${this.base} did not answer within ${String(timeoutMs)}ms: ${last}`);
|
|
855
997
|
}
|
|
@@ -1160,6 +1302,7 @@ class QueueDirectory {
|
|
|
1160
1302
|
all;
|
|
1161
1303
|
mapped;
|
|
1162
1304
|
remembered = new Map;
|
|
1305
|
+
guesses = new Set;
|
|
1163
1306
|
constructor(config, lookup) {
|
|
1164
1307
|
this.config = config;
|
|
1165
1308
|
this.lookup = lookup;
|
|
@@ -1178,9 +1321,14 @@ class QueueDirectory {
|
|
|
1178
1321
|
}
|
|
1179
1322
|
remember(id, queue) {
|
|
1180
1323
|
this.remembered.set(id, queue);
|
|
1324
|
+
this.guesses.delete(id);
|
|
1181
1325
|
}
|
|
1182
1326
|
forget(id) {
|
|
1183
1327
|
this.remembered.delete(id);
|
|
1328
|
+
this.guesses.delete(id);
|
|
1329
|
+
}
|
|
1330
|
+
guessed(id) {
|
|
1331
|
+
return this.guesses.has(id);
|
|
1184
1332
|
}
|
|
1185
1333
|
async resolve(id, owner) {
|
|
1186
1334
|
const known = this.remembered.get(id);
|
|
@@ -1202,6 +1350,7 @@ class QueueDirectory {
|
|
|
1202
1350
|
}
|
|
1203
1351
|
const queue = owner === undefined ? this.config.queue : this.forOwner(owner);
|
|
1204
1352
|
this.remembered.set(id, queue);
|
|
1353
|
+
this.guesses.add(id);
|
|
1205
1354
|
return queue;
|
|
1206
1355
|
}
|
|
1207
1356
|
}
|
|
@@ -1255,6 +1404,10 @@ function agentToken(secret, id) {
|
|
|
1255
1404
|
var WRITE_CONCURRENCY = 8;
|
|
1256
1405
|
var AGENT_READY_TIMEOUT_MS = 30000;
|
|
1257
1406
|
var PORT_READY_TIMEOUT_MS = 0;
|
|
1407
|
+
var goneErrors = new WeakSet;
|
|
1408
|
+
function isSandboxGone(error) {
|
|
1409
|
+
return error instanceof Error && goneErrors.has(error);
|
|
1410
|
+
}
|
|
1258
1411
|
function toExecResult(result) {
|
|
1259
1412
|
if (result.exitCode === 0) {
|
|
1260
1413
|
return { success: true, stdout: result.stdout, stderr: result.stderr };
|
|
@@ -1290,6 +1443,7 @@ class ArmadaSandbox {
|
|
|
1290
1443
|
openChannel;
|
|
1291
1444
|
queues;
|
|
1292
1445
|
placements;
|
|
1446
|
+
notFound;
|
|
1293
1447
|
options;
|
|
1294
1448
|
attachOnly;
|
|
1295
1449
|
supportsBucketMount = false;
|
|
@@ -1299,17 +1453,23 @@ class ArmadaSandbox {
|
|
|
1299
1453
|
token;
|
|
1300
1454
|
env = {};
|
|
1301
1455
|
envDefaults = {};
|
|
1302
|
-
constructor(id, config, armada, openChannel, queues, placements, options, attachOnly = false) {
|
|
1456
|
+
constructor(id, config, armada, openChannel, queues, placements, notFound, options, attachOnly = false) {
|
|
1303
1457
|
this.id = id;
|
|
1304
1458
|
this.config = config;
|
|
1305
1459
|
this.armada = armada;
|
|
1306
1460
|
this.openChannel = openChannel;
|
|
1307
1461
|
this.queues = queues;
|
|
1308
1462
|
this.placements = placements;
|
|
1463
|
+
this.notFound = notFound;
|
|
1309
1464
|
this.options = options;
|
|
1310
1465
|
this.attachOnly = attachOnly;
|
|
1311
1466
|
this.token = agentToken(config.agentTokenSecret, id);
|
|
1312
1467
|
}
|
|
1468
|
+
gone(message) {
|
|
1469
|
+
const error = this.notFound(message);
|
|
1470
|
+
goneErrors.add(error);
|
|
1471
|
+
return error;
|
|
1472
|
+
}
|
|
1313
1473
|
async ready() {
|
|
1314
1474
|
if (this.channel !== undefined)
|
|
1315
1475
|
return;
|
|
@@ -1326,6 +1486,10 @@ class ArmadaSandbox {
|
|
|
1326
1486
|
}
|
|
1327
1487
|
}
|
|
1328
1488
|
this.job ??= this.attachOnly ? await this.existingJob() : await this.submit();
|
|
1489
|
+
const finished = !this.attachOnly && await this.armada.isFinished(this.job).catch(() => false);
|
|
1490
|
+
if (finished) {
|
|
1491
|
+
throw this.gone(`Sandbox ${this.id} is gone: its Armada job ${this.job.jobId} has finished, and a finished job is never started again`);
|
|
1492
|
+
}
|
|
1329
1493
|
this.pod = await this.armada.waitForRunning(this.job);
|
|
1330
1494
|
const url = await this.armada.portUrl(this.job, this.config.agentPort);
|
|
1331
1495
|
const channel = this.openChannel({ url, token: this.token, pod: this.pod });
|
|
@@ -1335,15 +1499,20 @@ class ArmadaSandbox {
|
|
|
1335
1499
|
}
|
|
1336
1500
|
async submit() {
|
|
1337
1501
|
const tokenSha256 = createHash("sha256").update(this.token).digest("hex");
|
|
1338
|
-
|
|
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;
|
|
1339
1505
|
}
|
|
1340
1506
|
async existingJob() {
|
|
1341
1507
|
const queue = await this.queue();
|
|
1342
|
-
const
|
|
1343
|
-
if (
|
|
1344
|
-
|
|
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.`);
|
|
1345
1514
|
}
|
|
1346
|
-
|
|
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`);
|
|
1347
1516
|
}
|
|
1348
1517
|
get placement() {
|
|
1349
1518
|
return this.pod;
|
|
@@ -1372,6 +1541,8 @@ class ArmadaSandbox {
|
|
|
1372
1541
|
const result = await channel.run(["sh", "-lc", command], deadline === undefined ? {} : { timeoutMs: deadline });
|
|
1373
1542
|
return toExecResult(result);
|
|
1374
1543
|
} catch (error) {
|
|
1544
|
+
if (isSandboxGone(error))
|
|
1545
|
+
throw error;
|
|
1375
1546
|
const stderr = error instanceof CommandTimeoutError && backstopMs !== undefined ? `Command ran past ARMADA_COMMAND_MAX_SECONDS (${String(this.config.commandMaxSeconds)}s) and was killed: ${cmd}` : reason(error);
|
|
1376
1547
|
return {
|
|
1377
1548
|
success: false,
|
|
@@ -1418,6 +1589,8 @@ class ArmadaSandbox {
|
|
|
1418
1589
|
try {
|
|
1419
1590
|
outcome = await read(await this.open());
|
|
1420
1591
|
} catch (error) {
|
|
1592
|
+
if (isSandboxGone(error))
|
|
1593
|
+
throw error;
|
|
1421
1594
|
return this.readFailed(path, "BACKEND_ERROR", reason(error));
|
|
1422
1595
|
}
|
|
1423
1596
|
if (outcome.outcome === "not-found") {
|
|
@@ -1437,7 +1610,9 @@ class ArmadaSandbox {
|
|
|
1437
1610
|
let listed;
|
|
1438
1611
|
try {
|
|
1439
1612
|
listed = await (await this.open()).listFiles(path, options?.recursive === true);
|
|
1440
|
-
} catch {
|
|
1613
|
+
} catch (error) {
|
|
1614
|
+
if (isSandboxGone(error))
|
|
1615
|
+
throw error;
|
|
1441
1616
|
return { success: false, files: [], error: { code: "BACKEND_ERROR" } };
|
|
1442
1617
|
}
|
|
1443
1618
|
if (listed.outcome === "not-a-directory") {
|
|
@@ -1569,13 +1744,15 @@ ${log}`);
|
|
|
1569
1744
|
// src/provider.ts
|
|
1570
1745
|
class ArmadaCompute {
|
|
1571
1746
|
config;
|
|
1747
|
+
notFound;
|
|
1572
1748
|
armada;
|
|
1573
1749
|
queues;
|
|
1574
1750
|
placements = new Map;
|
|
1575
1751
|
listActive;
|
|
1576
1752
|
capabilities;
|
|
1577
|
-
constructor(config) {
|
|
1753
|
+
constructor(config, notFound) {
|
|
1578
1754
|
this.config = config;
|
|
1755
|
+
this.notFound = notFound;
|
|
1579
1756
|
this.armada = new ArmadaClient(config);
|
|
1580
1757
|
this.capabilities = {
|
|
1581
1758
|
multiPort: config.surfacePorts.length > 0,
|
|
@@ -1593,10 +1770,10 @@ class ArmadaCompute {
|
|
|
1593
1770
|
}
|
|
1594
1771
|
}
|
|
1595
1772
|
create(id, options) {
|
|
1596
|
-
return new ArmadaSandbox(id, this.config, this.armada, openAgent, this.queues, this.placements, options);
|
|
1773
|
+
return new ArmadaSandbox(id, this.config, this.armada, openAgent, this.queues, this.placements, this.notFound, options, false);
|
|
1597
1774
|
}
|
|
1598
1775
|
connectExisting(id, options) {
|
|
1599
|
-
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);
|
|
1600
1777
|
}
|
|
1601
1778
|
async proxy(_request) {
|
|
1602
1779
|
return null;
|
|
@@ -1611,7 +1788,11 @@ var manifest = {
|
|
|
1611
1788
|
apiVersion: 1,
|
|
1612
1789
|
kind: "compute",
|
|
1613
1790
|
create(context) {
|
|
1614
|
-
|
|
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);
|
|
1615
1796
|
}
|
|
1616
1797
|
};
|
|
1617
1798
|
var src_default = manifest;
|
|
@@ -1619,5 +1800,5 @@ export {
|
|
|
1619
1800
|
src_default as default
|
|
1620
1801
|
};
|
|
1621
1802
|
|
|
1622
|
-
//# debugId=
|
|
1803
|
+
//# debugId=4B03CA1D79634B6864756E2164756E21
|
|
1623
1804
|
//# sourceMappingURL=index.js.map
|