@moondeck/station 1.0.3 → 1.0.5
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/images/standard/Dockerfile +29 -1
- package/images/standard/README.md +7 -2
- package/images/standard/container/uai-init +45 -0
- package/images/standard/container/uai-materialize-runtimes +109 -6
- package/lib/agent-cli.ts +2 -2
- package/lib/agent-dependencies.ts +246 -0
- package/lib/agent.ts +6 -1
- package/lib/cloud-credential-host.ts +31 -4
- package/lib/cloud-credential-leases.ts +35 -4
- package/lib/cloud-credential-runtime.ts +10 -3
- package/lib/container-runtime.ts +168 -31
- package/lib/machine-payload-image.ts +192 -0
- package/lib/machine-provider-aws.ts +175 -37
- package/lib/machine-provider.ts +22 -0
- package/lib/managed-runtime.ts +25 -0
- package/lib/orchestrator.ts +13 -0
- package/lib/runtime-archive.ts +47 -0
- package/lib/runtime-authority.ts +1 -0
- package/lib/skills.ts +31 -9
- package/lib/standard-image-schedule.ts +53 -0
- package/lib/standard-image.ts +3 -2
- package/lib/task-credential-cleanup.ts +62 -5
- package/lib/task-environment/machine.ts +211 -15
- package/lib/task-project-ops.ts +28 -6
- package/lib/vnode-pressure.ts +31 -8
- package/package.json +1 -1
- package/scripts/agent/_common.sh +36 -29
- package/scripts/agent/_deps.sh +47 -0
- package/scripts/agent/check-deps.sh +59 -0
- package/scripts/agent/task-up.sh +4 -0
- package/src/cli.ts +1 -1
- package/src/index.ts +4 -0
- package/src/main.ts +59 -13
- package/src/process-wake.ts +36 -0
- package/src/protocol.ts +53 -0
package/lib/standard-image.ts
CHANGED
|
@@ -75,8 +75,8 @@ export const STANDARD_CODEX_CLI_VERSION = "0.164.0";
|
|
|
75
75
|
* Runtimes the standard image's asdf plugins can satisfy, with a sensible set
|
|
76
76
|
* of advertised versions per kind (ADR-021 `runtimes`). These are the
|
|
77
77
|
* versions the cloud's task-creation picker hints; asdf will lazily install
|
|
78
|
-
* any of them on first use (docs/runtime.md).
|
|
79
|
-
*
|
|
78
|
+
* any of them on first use (docs/runtime.md). Where the image bakes a root
|
|
79
|
+
* `/home/node/.tool-versions` default, it is the first entry in that list.
|
|
80
80
|
*
|
|
81
81
|
* KEEP IN SYNC with host-agent/images/standard/ (the asdf plugins and the
|
|
82
82
|
* root tool-versions). Treat that directory as authoritative for the numbers;
|
|
@@ -98,6 +98,7 @@ export const STANDARD_RUNTIMES: ReadonlyArray<{
|
|
|
98
98
|
{ kind: "go", availableVersions: ["1.23.2", "1.22.8"] },
|
|
99
99
|
{ kind: "ruby", availableVersions: ["3.3.5", "3.2.5"] },
|
|
100
100
|
{ kind: "rust", availableVersions: ["1.81.0"] },
|
|
101
|
+
{ kind: "bun", availableVersions: ["1.3.1"] },
|
|
101
102
|
];
|
|
102
103
|
|
|
103
104
|
/** A fresh, mutable copy of the advertised runtimes for the capability frame. */
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
forgetCredentialCleanupRestop,
|
|
16
16
|
listCredentialCleanupRecoveryTasks,
|
|
17
17
|
listCredentialCleanupPaths,
|
|
18
|
+
listCredentialCleanupPending,
|
|
18
19
|
listCredentialCleanupRestops,
|
|
19
20
|
rememberCredentialCleanupPending,
|
|
20
21
|
rememberCredentialCleanupRestop,
|
|
@@ -274,6 +275,10 @@ async function reconstructCleanupRuntime(
|
|
|
274
275
|
* - `absent`, exactly: the runtime, its writable layer with it, is gone, and
|
|
275
276
|
* so is every path in it. Any other answer, `unknown` above all, is no
|
|
276
277
|
* proof (a failed call never proves absence, 2026-10-20).
|
|
278
|
+
* - `stopped` with no instance (the container gone, its worktree not) is
|
|
279
|
+
* no proof: a project's Dockerfile `VOLUME` under /home/node leaves an
|
|
280
|
+
* anonymous volume behind a container removed without `-v`, and nothing
|
|
281
|
+
* recorded names the image it was made from (2026-11-09 review).
|
|
277
282
|
* - `stopped`, inside the boot sweep only: `docker exec` cannot reach a
|
|
278
283
|
* stopped container, and after a reboot every one is, so the sweep failed
|
|
279
284
|
* for good and the runner stayed in `checking` (2026-10-30). The runtime
|
|
@@ -400,6 +405,9 @@ export class TaskCredentialCleanupCoordinator {
|
|
|
400
405
|
Promise<{ failedEpoch: number; clearThroughEpoch: number }>
|
|
401
406
|
>();
|
|
402
407
|
readonly #deps: TaskCredentialCleanupDeps;
|
|
408
|
+
/** Tasks whose boot cleanup failed and was isolated (`recoverAll`), until
|
|
409
|
+
* a full cleanup of them succeeds. */
|
|
410
|
+
readonly #isolated = new Set<string>();
|
|
403
411
|
|
|
404
412
|
constructor(deps: TaskCredentialCleanupDeps) {
|
|
405
413
|
this.#deps = deps;
|
|
@@ -485,6 +493,7 @@ export class TaskCredentialCleanupCoordinator {
|
|
|
485
493
|
this.#tails.get(request.taskId) === tail &&
|
|
486
494
|
result.state.failedEpoch === 0
|
|
487
495
|
) {
|
|
496
|
+
this.#isolated.delete(request.taskId);
|
|
488
497
|
forgetCredentialCleanupPending(
|
|
489
498
|
request.taskId,
|
|
490
499
|
result.state.clearThroughEpoch,
|
|
@@ -691,6 +700,23 @@ export class TaskCredentialCleanupCoordinator {
|
|
|
691
700
|
this.#deps.hooks.dropMemory(request);
|
|
692
701
|
}
|
|
693
702
|
|
|
703
|
+
/** Whether this process's boot sweep isolated the task's failed cleanup
|
|
704
|
+
* (`recoverAll`) and it still has durable cleanup left (a pending
|
|
705
|
+
* witness, a path row of any run, an owed re-stop): a start of it must
|
|
706
|
+
* run its full cleanup, and prove it, before its gate may open (the
|
|
707
|
+
* registry's startup fence). Only an isolated task: any other task with
|
|
708
|
+
* rows held the sweep, or got them in this process, and starts as before.
|
|
709
|
+
* Each process's sweep isolates afresh. */
|
|
710
|
+
isolatedCleanupOwed(taskId: string): boolean {
|
|
711
|
+
if (!this.#isolated.has(taskId)) return false;
|
|
712
|
+
const owed =
|
|
713
|
+
listCredentialCleanupPending(this.#deps.db).some((row) => row.taskId === taskId) ||
|
|
714
|
+
listCredentialCleanupPaths(taskId, this.#deps.db).length > 0 ||
|
|
715
|
+
listCredentialCleanupRestops(taskId, this.#deps.db).length > 0;
|
|
716
|
+
if (!owed) this.#isolated.delete(taskId);
|
|
717
|
+
return owed;
|
|
718
|
+
}
|
|
719
|
+
|
|
694
720
|
/** Every re-stop the task is owed, tried; each proven retired. Only proof
|
|
695
721
|
* that the exact container is stopped or gone retires one: a removed
|
|
696
722
|
* credential path never does. */
|
|
@@ -729,9 +755,18 @@ export class TaskCredentialCleanupCoordinator {
|
|
|
729
755
|
}
|
|
730
756
|
|
|
731
757
|
/** Boot recovery sweeps every durable task before any grant may be asked.
|
|
732
|
-
* Every task is attempted, one failing never leaving the next unswept
|
|
733
|
-
*
|
|
734
|
-
|
|
758
|
+
* Every task is attempted, one failing never leaving the next unswept.
|
|
759
|
+
* A failure is that task's alone when `isolatable` says the task has no
|
|
760
|
+
* run left (decisions.md "One bad task never blocks the fleet"): its
|
|
761
|
+
* rows, pending witness and closed gate stay, host.log names it, and the
|
|
762
|
+
* next sweep tries it again; the sweep goes on. Any other failure fails
|
|
763
|
+
* the sweep, all of them listed: a task that may still run would have
|
|
764
|
+
* its surviving agents reattached, or a start's gate opened, before its
|
|
765
|
+
* credential paths were proven gone. Absent `isolatable`, none is. */
|
|
766
|
+
async recoverAll(
|
|
767
|
+
runEpochForTask: (taskId: string) => number,
|
|
768
|
+
isolatable: (taskId: string) => boolean = () => false,
|
|
769
|
+
): Promise<void> {
|
|
735
770
|
const tasks = listCredentialCleanupRecoveryTasks(this.#deps.db);
|
|
736
771
|
const failures: unknown[] = [];
|
|
737
772
|
for (const task of tasks) {
|
|
@@ -742,11 +777,33 @@ export class TaskCredentialCleanupCoordinator {
|
|
|
742
777
|
reason: "restart",
|
|
743
778
|
}, true);
|
|
744
779
|
} catch (error) {
|
|
745
|
-
|
|
780
|
+
let isolated = false;
|
|
781
|
+
try {
|
|
782
|
+
isolated = isolatable(task.taskId);
|
|
783
|
+
} catch {
|
|
784
|
+
// Unknown is not isolated: the failure holds the sweep.
|
|
785
|
+
}
|
|
786
|
+
if (!isolated) {
|
|
787
|
+
failures.push(error);
|
|
788
|
+
continue;
|
|
789
|
+
}
|
|
790
|
+
this.#isolated.add(task.taskId);
|
|
791
|
+
console.warn(
|
|
792
|
+
`[credentials] boot recovery: task ${task.taskId} has no run left and its credential cleanup failed; ` +
|
|
793
|
+
`its rows and gate stay closed, the next sweep tries it again, and the station proceeds: ${
|
|
794
|
+
(error instanceof Error ? error.message : String(error)).slice(0, 500)
|
|
795
|
+
}`,
|
|
796
|
+
);
|
|
746
797
|
}
|
|
747
798
|
}
|
|
748
799
|
if (failures.length > 0) {
|
|
749
|
-
|
|
800
|
+
const detail = failures
|
|
801
|
+
.map((error) => (error instanceof Error ? error.message : String(error)).slice(0, 300))
|
|
802
|
+
.join("; ");
|
|
803
|
+
throw new AggregateError(
|
|
804
|
+
failures,
|
|
805
|
+
`credential recovery failed for ${String(failures.length)} task(s): ${detail}`.slice(0, 2_000),
|
|
806
|
+
);
|
|
750
807
|
}
|
|
751
808
|
}
|
|
752
809
|
}
|
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
MachineProvider,
|
|
24
24
|
} from "../machine-provider";
|
|
25
25
|
import { machineEnvironmentSshArgs } from "../machine-exec";
|
|
26
|
+
import { STATION_MACHINE_PAYLOAD_MARKER } from "../machine-payload-image";
|
|
26
27
|
import { applyProjectEnvProfile } from "../runtime-authority";
|
|
27
28
|
import { rootAnchoredRequest } from "./anchor";
|
|
28
29
|
import {
|
|
@@ -217,6 +218,16 @@ class MachineTaskEnvironmentHandle implements TaskEnvironmentHandle {
|
|
|
217
218
|
MachineTaskEnvironmentDeps;
|
|
218
219
|
/** The machine's own /etc/environment, read once (see #anchoredBaseline). */
|
|
219
220
|
#machineWide: Promise<Record<string, string>> | null = null;
|
|
221
|
+
/** Station payload validation (plan §1 item 3), enforced IN the handle so
|
|
222
|
+
* that every path to this machine runs the same rule first: provision,
|
|
223
|
+
* recovery, and any reconstructed handle's exec/spawn/session/copy/file
|
|
224
|
+
* op/gateway tunnel (all dial through #target) plus route inspection. An
|
|
225
|
+
* AWS machine still tagged `pending` is probed for the marker before
|
|
226
|
+
* anything else reaches it. A pass is remembered PER PHYSICAL INSTANCE
|
|
227
|
+
* (the EC2 instance id): a replacement under the same logical id is a
|
|
228
|
+
* different machine and the rule applies to it afresh. */
|
|
229
|
+
#validatedInstance: string | null = null;
|
|
230
|
+
#payloadProbe: { instanceId: string; done: Promise<void> } | null = null;
|
|
220
231
|
|
|
221
232
|
constructor(
|
|
222
233
|
locator: TaskEnvironmentLocator,
|
|
@@ -242,7 +253,7 @@ class MachineTaskEnvironmentHandle implements TaskEnvironmentHandle {
|
|
|
242
253
|
/** Resolve the CURRENT dial target. Cloud machines change address across
|
|
243
254
|
* stop/start, so the locator never stores one — describe is the only
|
|
244
255
|
* source of truth, and a non-running machine has no target at all. */
|
|
245
|
-
async #target(): Promise<{
|
|
256
|
+
async #target(options: { validate?: boolean } = {}): Promise<{
|
|
246
257
|
address: string;
|
|
247
258
|
keyPath: string;
|
|
248
259
|
port?: number;
|
|
@@ -253,6 +264,17 @@ class MachineTaskEnvironmentHandle implements TaskEnvironmentHandle {
|
|
|
253
264
|
`machine ${this.#value.machineId} is not reachable (${info.state})`,
|
|
254
265
|
);
|
|
255
266
|
}
|
|
267
|
+
// Only readiness checks and the probe itself dial an unvalidated machine.
|
|
268
|
+
// The gate and the dial use the SAME describe answer, so the instance
|
|
269
|
+
// validated is the instance dialed.
|
|
270
|
+
if (options.validate !== false) await this.#gate(info);
|
|
271
|
+
return this.#dialTarget(info);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
#dialTarget(info: MachineInfo): { address: string; keyPath: string; port?: number } {
|
|
275
|
+
if (info.state !== "running" || info.address === null) {
|
|
276
|
+
throw new Error(`machine ${this.#value.machineId} is not reachable (${info.state})`);
|
|
277
|
+
}
|
|
256
278
|
return {
|
|
257
279
|
address: info.address,
|
|
258
280
|
keyPath: this.#value.privateKeyPath,
|
|
@@ -260,6 +282,146 @@ class MachineTaskEnvironmentHandle implements TaskEnvironmentHandle {
|
|
|
260
282
|
};
|
|
261
283
|
}
|
|
262
284
|
|
|
285
|
+
/** Validate before use. `validation` is what the caller knows (provision:
|
|
286
|
+
* what it launched or found); otherwise the machine's own tag is read. */
|
|
287
|
+
async ensurePayloadValidated(validation?: MachineInfo["payloadValidation"]): Promise<void> {
|
|
288
|
+
const info = await this.#describeOwn();
|
|
289
|
+
await this.#gate(validation === undefined ? info : { ...info, payloadValidation: validation });
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async #gate(info: MachineInfo): Promise<void> {
|
|
293
|
+
if (this.#deps.machines.kind !== "aws") return;
|
|
294
|
+
const instanceId = info.instanceId ?? null;
|
|
295
|
+
// A different physical instance than the one validated: forget the pass
|
|
296
|
+
// and apply the rule to this one (pending → probe; ok/null → no probe).
|
|
297
|
+
if (this.#validatedInstance !== null && this.#validatedInstance !== instanceId) {
|
|
298
|
+
this.#validatedInstance = null;
|
|
299
|
+
}
|
|
300
|
+
if (info.payloadValidation !== "pending") return;
|
|
301
|
+
if (instanceId === null) {
|
|
302
|
+
throw new PayloadValidationError(
|
|
303
|
+
`machine ${this.#value.machineId} is pending payload validation but its instance id is unknown (left pending; the next attempt probes again)`,
|
|
304
|
+
true,
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
if (this.#validatedInstance === instanceId) return;
|
|
308
|
+
// Join an in-flight probe only when it is for THIS instance: one started
|
|
309
|
+
// for a replaced instance must never stand in for its successor.
|
|
310
|
+
let probe = this.#payloadProbe;
|
|
311
|
+
if (!probe || probe.instanceId !== instanceId) {
|
|
312
|
+
const started: { instanceId: string; done: Promise<void> } = {
|
|
313
|
+
instanceId,
|
|
314
|
+
done: this.#probePayloadMarker(info, instanceId).then(() => {
|
|
315
|
+
// Remember the instance that was PROBED, nothing else.
|
|
316
|
+
this.#validatedInstance = instanceId;
|
|
317
|
+
}),
|
|
318
|
+
};
|
|
319
|
+
started.done.catch(() => {
|
|
320
|
+
// A failed probe proves nothing: the next use probes again.
|
|
321
|
+
if (this.#payloadProbe === started) this.#payloadProbe = null;
|
|
322
|
+
});
|
|
323
|
+
this.#payloadProbe = started;
|
|
324
|
+
probe = started;
|
|
325
|
+
}
|
|
326
|
+
await probe.done;
|
|
327
|
+
// A replacement raced the probe: this caller's instance is no longer
|
|
328
|
+
// the one remembered, so the caller's answer is not validated.
|
|
329
|
+
if (this.#validatedInstance !== instanceId) {
|
|
330
|
+
throw new PayloadValidationError(
|
|
331
|
+
`machine ${this.#value.machineId} changed instance during payload validation (left pending; the next attempt probes again)`,
|
|
332
|
+
true,
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** One ssh round trip that bypasses the payload gate (readiness, probe).
|
|
338
|
+
* `info` pins the dial to one describe answer (the probe's instance). */
|
|
339
|
+
async #ungatedSsh(argv: readonly [string, ...string[]], timeoutMs: number, info?: MachineInfo): Promise<{ exitCode: number | null; stderr: string }> {
|
|
340
|
+
const target = info ? this.#dialTarget(info) : await this.#target({ validate: false });
|
|
341
|
+
const result = await capturedCliExec(
|
|
342
|
+
this.#deps.spawn,
|
|
343
|
+
"ssh",
|
|
344
|
+
machineEnvironmentSshArgs(target, this.#maintenanceRequest({ argv }), "interactive"),
|
|
345
|
+
{ argv: [argv[0]], projectEnvProfile: "maintenance", timeoutMs, maxOutputBytes: 4 * 1024 },
|
|
346
|
+
);
|
|
347
|
+
return { exitCode: result.exitCode, stderr: Buffer.from(result.stderr).toString("utf8").trim() };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** ssh readiness without the payload gate (provision's wait). */
|
|
351
|
+
async sshReady(): Promise<{ ready: boolean; detail: string }> {
|
|
352
|
+
try {
|
|
353
|
+
const probe = await this.#ungatedSsh(["/bin/true"], 10_000);
|
|
354
|
+
return { ready: probe.exitCode === 0, detail: probe.stderr || `probe exited ${probe.exitCode ?? "killed"}` };
|
|
355
|
+
} catch (error) {
|
|
356
|
+
return { ready: false, detail: error instanceof Error ? error.message : String(error) };
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Marker present: record `ok` (a failed write throws, retryable; the
|
|
361
|
+
* machine stays `pending`). Marker DEFINITELY missing (exit 1): terminate,
|
|
362
|
+
* then throw (fatal); a failed terminate leaves it `pending`, so every
|
|
363
|
+
* later use probes and terminates again and nothing reaches it. Anything
|
|
364
|
+
* else (ssh error, timeout): throw, retryable, machine alive and `pending`
|
|
365
|
+
* — a slow boot is not evidence of a wrong image. */
|
|
366
|
+
async #probePayloadMarker(info: MachineInfo, instanceId: string): Promise<void> {
|
|
367
|
+
const machineId = this.#value.machineId;
|
|
368
|
+
const machines = this.#deps.machines;
|
|
369
|
+
let probe: { exitCode: number | null; stderr: string };
|
|
370
|
+
try {
|
|
371
|
+
probe = await this.#ungatedSsh(
|
|
372
|
+
["/bin/sh", "-c", 'test -f "$1"', "payload-probe", STATION_MACHINE_PAYLOAD_MARKER],
|
|
373
|
+
30_000,
|
|
374
|
+
info,
|
|
375
|
+
);
|
|
376
|
+
} catch (error) {
|
|
377
|
+
throw new PayloadValidationError(
|
|
378
|
+
`payload marker probe on ${machineId} could not run (left pending; the next attempt probes again): ${
|
|
379
|
+
error instanceof Error ? error.message : String(error)
|
|
380
|
+
}`,
|
|
381
|
+
true,
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
if (probe.exitCode === 0) {
|
|
385
|
+
if (!machines.markPayloadValidated) {
|
|
386
|
+
throw new PayloadValidationError(`machine backend ${machines.kind} cannot record payload validation`, false);
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
await machines.markPayloadValidated(machineId, instanceId);
|
|
390
|
+
} catch (error) {
|
|
391
|
+
throw new PayloadValidationError(
|
|
392
|
+
`${error instanceof Error ? error.message : String(error)} (left pending; the next attempt probes again)`,
|
|
393
|
+
true,
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (probe.exitCode === 1) {
|
|
399
|
+
try {
|
|
400
|
+
// Exactly the probed instance: never the logical id, which may
|
|
401
|
+
// already name a replacement that must not be touched.
|
|
402
|
+
if (!machines.terminateInstance) {
|
|
403
|
+
throw new Error(`machine backend ${machines.kind} cannot terminate one instance`);
|
|
404
|
+
}
|
|
405
|
+
await machines.terminateInstance(machineId, instanceId);
|
|
406
|
+
} catch (error) {
|
|
407
|
+
throw new PayloadValidationError(
|
|
408
|
+
`machine ${machineId} lacks the Station payload marker ${STATION_MACHINE_PAYLOAD_MARKER} and could not be terminated (left pending; the next attempt probes and terminates again): ${
|
|
409
|
+
error instanceof Error ? error.message : String(error)
|
|
410
|
+
}`,
|
|
411
|
+
false,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
throw new PayloadValidationError(
|
|
415
|
+
`machine ${machineId} was launched from an image without the Station payload marker ${STATION_MACHINE_PAYLOAD_MARKER}; it was terminated. Set UAI_MACHINE_IMAGE to an approved Station AMI, or ask Moondeck to check this region's image`,
|
|
416
|
+
false,
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
throw new PayloadValidationError(
|
|
420
|
+
`payload marker probe on ${machineId} did not answer (exit ${probe.exitCode ?? "killed"}${probe.stderr ? `: ${probe.stderr}` : ""}); left pending, the next attempt probes again`,
|
|
421
|
+
true,
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
263
425
|
/** Describe with the ownership check every mutation rides on: a machine
|
|
264
426
|
* that does not carry OUR task label is a foreign occupant of the id and
|
|
265
427
|
* is treated as unknown — never dialed, never stopped, never terminated. */
|
|
@@ -621,6 +783,12 @@ class MachineTaskEnvironmentHandle implements TaskEnvironmentHandle {
|
|
|
621
783
|
> {
|
|
622
784
|
const info = await this.#describeOwn();
|
|
623
785
|
if (info.state === "running" && info.address !== null) {
|
|
786
|
+
// The editor and previews dial the machine directly: same gate.
|
|
787
|
+
try {
|
|
788
|
+
await this.#gate(info);
|
|
789
|
+
} catch (error) {
|
|
790
|
+
return { kind: "unknown", detail: error instanceof Error ? error.message : String(error) };
|
|
791
|
+
}
|
|
624
792
|
return { kind: "running", ipv4Address: info.address };
|
|
625
793
|
}
|
|
626
794
|
if (info.state === "stopped" || info.state === "absent") {
|
|
@@ -752,6 +920,21 @@ class MachineTaskEnvironmentHandle implements TaskEnvironmentHandle {
|
|
|
752
920
|
if (!context.isCurrent()) {
|
|
753
921
|
return { outcome: "deferred", detail: "runtime generation superseded" };
|
|
754
922
|
}
|
|
923
|
+
// A Station that died between launch and probe left the machine
|
|
924
|
+
// `pending`: probe it before any consumer is prepared or admitted. A
|
|
925
|
+
// retryable failure defers (the machine stays pending); a missing
|
|
926
|
+
// marker terminated it, which throws like provision does.
|
|
927
|
+
try {
|
|
928
|
+
await this.#gate(info);
|
|
929
|
+
} catch (error) {
|
|
930
|
+
if (error instanceof PayloadValidationError && error.retryable) {
|
|
931
|
+
return { outcome: "deferred", detail: error.message };
|
|
932
|
+
}
|
|
933
|
+
throw error;
|
|
934
|
+
}
|
|
935
|
+
if (!context.isCurrent()) {
|
|
936
|
+
return { outcome: "deferred", detail: "runtime generation superseded" };
|
|
937
|
+
}
|
|
755
938
|
await context.prepareConsumers?.();
|
|
756
939
|
context.allowConsumers?.();
|
|
757
940
|
await context.ensureConsumersStarted?.();
|
|
@@ -764,7 +947,7 @@ class MachineTaskEnvironmentHandle implements TaskEnvironmentHandle {
|
|
|
764
947
|
|
|
765
948
|
async #sshAnswers(): Promise<boolean> {
|
|
766
949
|
try {
|
|
767
|
-
const target = await this.#target();
|
|
950
|
+
const target = await this.#target({ validate: false });
|
|
768
951
|
const result = await capturedCliExec(
|
|
769
952
|
this.#deps.spawn,
|
|
770
953
|
"ssh",
|
|
@@ -863,6 +1046,10 @@ export function createMachineTaskEnvironmentProvider(
|
|
|
863
1046
|
);
|
|
864
1047
|
}
|
|
865
1048
|
const reused = existing.state !== "absent";
|
|
1049
|
+
// Validation state lives ON the machine (set at launch), so a retry
|
|
1050
|
+
// or a restarted Station sees the same answer: an unconfirmed machine
|
|
1051
|
+
// is probed whether it is fresh or reused.
|
|
1052
|
+
let payloadValidation = existing.payloadValidation ?? null;
|
|
866
1053
|
if (existing.state === "absent") {
|
|
867
1054
|
const launched = await deps.machines.launch({
|
|
868
1055
|
taskId,
|
|
@@ -881,6 +1068,7 @@ export function createMachineTaskEnvironmentProvider(
|
|
|
881
1068
|
`machine backend named ${launched.id}, locator promised ${machineId}`,
|
|
882
1069
|
);
|
|
883
1070
|
}
|
|
1071
|
+
payloadValidation = launched.payloadValidation ?? null;
|
|
884
1072
|
} else if (existing.state === "stopped") {
|
|
885
1073
|
await deps.machines.start(machineId);
|
|
886
1074
|
}
|
|
@@ -893,6 +1081,13 @@ export function createMachineTaskEnvironmentProvider(
|
|
|
893
1081
|
);
|
|
894
1082
|
await waitForSsh(handle, deps.readyTimeoutMs ?? 120_000);
|
|
895
1083
|
|
|
1084
|
+
// Before ANY workspace prep, clone or credential delivery: an AWS
|
|
1085
|
+
// machine launched from an auto-selected image must carry the Station
|
|
1086
|
+
// payload marker. `ok` / null (validated before, pre-1.0.5, or pinned)
|
|
1087
|
+
// is preserved and never terminated from here. (The handle enforces
|
|
1088
|
+
// the same rule on every later dial.)
|
|
1089
|
+
await handle.ensurePayloadValidated(payloadValidation);
|
|
1090
|
+
|
|
896
1091
|
// Workspace + optional in-env clone (ADR-121: the clone happens in the
|
|
897
1092
|
// task's world; the host never materializes task code).
|
|
898
1093
|
// As root: the workspace root is typically directly under a
|
|
@@ -948,6 +1143,16 @@ export function createMachineTaskEnvironmentProvider(
|
|
|
948
1143
|
};
|
|
949
1144
|
}
|
|
950
1145
|
|
|
1146
|
+
/** A payload validation failure. `retryable`: the machine is alive and
|
|
1147
|
+
* still `pending`, and a later attempt probes again. Otherwise the image is
|
|
1148
|
+
* wrong (marker missing; terminated, or termination itself failed). */
|
|
1149
|
+
export class PayloadValidationError extends Error {
|
|
1150
|
+
override name = "PayloadValidationError";
|
|
1151
|
+
constructor(message: string, readonly retryable: boolean) {
|
|
1152
|
+
super(message);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
|
|
951
1156
|
async function waitForSsh(
|
|
952
1157
|
handle: MachineTaskEnvironmentHandle,
|
|
953
1158
|
budgetMs: number,
|
|
@@ -955,19 +1160,10 @@ async function waitForSsh(
|
|
|
955
1160
|
const deadline = Date.now() + budgetMs;
|
|
956
1161
|
let lastDetail = "ssh never answered";
|
|
957
1162
|
while (Date.now() < deadline) {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
timeoutMs: 10_000,
|
|
963
|
-
maxOutputBytes: 4 * 1024,
|
|
964
|
-
});
|
|
965
|
-
if (probe.exitCode === 0) return;
|
|
966
|
-
lastDetail = Buffer.from(probe.stderr).toString("utf8").trim() ||
|
|
967
|
-
`probe exited ${probe.exitCode ?? "killed"}`;
|
|
968
|
-
} catch (error) {
|
|
969
|
-
lastDetail = error instanceof Error ? error.message : String(error);
|
|
970
|
-
}
|
|
1163
|
+
// Readiness only: the payload gate runs after it, not inside it.
|
|
1164
|
+
const probe = await handle.sshReady();
|
|
1165
|
+
if (probe.ready) return;
|
|
1166
|
+
lastDetail = probe.detail;
|
|
971
1167
|
await new Promise<void>((resolve) => setTimeout(resolve, 2_000));
|
|
972
1168
|
}
|
|
973
1169
|
throw new Error(`machine never became reachable over ssh: ${lastDetail}`);
|
package/lib/task-project-ops.ts
CHANGED
|
@@ -373,7 +373,7 @@ git rev-parse --show-toplevel
|
|
|
373
373
|
export const SETUP_SCRIPT = `set -u
|
|
374
374
|
IFS= read -r nonce || nonce=""
|
|
375
375
|
case "$nonce" in *[!0-9a-f]*|"") echo "uai: setup needs its nonce" >&2; exit 64 ;; esac
|
|
376
|
-
mark() { printf 'uai-setup-%s %s %s\\n' "$nonce" "$1" "$2"; }
|
|
376
|
+
mark() { [ "$1" != invalid-runtime ] || runtime_invalid=1; printf 'uai-setup-%s %s %s\\n' "$nonce" "$1" "$2"; }
|
|
377
377
|
quiet() { "$@" </dev/null 1>&2; }
|
|
378
378
|
# The effective requirements: this folder's .tool-versions (the repository's,
|
|
379
379
|
# or the project's fallback Prepare seeded, as at start), parsed and checked
|
|
@@ -411,6 +411,7 @@ check_runtime() {
|
|
|
411
411
|
;;
|
|
412
412
|
esac
|
|
413
413
|
case "/$version/" in *"/../"*|*"/./"*|*"//"*) mark invalid-runtime "$tool $version (unsafe version path)"; return 0 ;; esac
|
|
414
|
+
case "$tool" in nodejs|python|golang|ruby|rust|bun) ;; *) return 0 ;; esac
|
|
414
415
|
if ! command -v asdf >/dev/null 2>&1; then
|
|
415
416
|
mark missing-runtime "$tool $version (no asdf to check it)"
|
|
416
417
|
elif ! asdf where "$tool" "$version" </dev/null >/dev/null 2>&1; then
|
|
@@ -423,17 +424,24 @@ elif [ -f .tool-versions ]; then
|
|
|
423
424
|
if LC_ALL=C grep -q '[[:cntrl:]]' .tool-versions; then
|
|
424
425
|
mark invalid-runtime ".tool-versions (control characters; a start would refuse it)"
|
|
425
426
|
else
|
|
427
|
+
declare -A seen_tools=()
|
|
426
428
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
427
429
|
line=\${line%%#*}
|
|
428
430
|
read -r -a fields <<< "$line" || true
|
|
429
431
|
[ "\${#fields[@]}" -gt 0 ] || continue
|
|
430
432
|
tool=\${fields[0]}
|
|
433
|
+
runtime_invalid=0
|
|
431
434
|
if [ "\${#fields[@]}" -lt 2 ] || [[ ! "$tool" =~ ^[a-z0-9][a-z0-9_-]*$ ]]; then
|
|
432
435
|
mark invalid-runtime "$line (a start would refuse this line)"
|
|
433
436
|
continue
|
|
434
437
|
fi
|
|
438
|
+
if [ -n "\${seen_tools[$tool]:-}" ]; then
|
|
439
|
+
mark invalid-runtime "$tool (duplicate tool)"
|
|
440
|
+
continue
|
|
441
|
+
fi
|
|
442
|
+
seen_tools[$tool]=1
|
|
435
443
|
case "$tool" in
|
|
436
|
-
nodejs|python|golang|ruby|rust)
|
|
444
|
+
nodejs|python|golang|ruby|rust|bun)
|
|
437
445
|
for version in "\${fields[@]:1}"; do check_runtime "$tool" "$version"; done
|
|
438
446
|
;;
|
|
439
447
|
pnpm|yarn)
|
|
@@ -442,7 +450,16 @@ elif [ -f .tool-versions ]; then
|
|
|
442
450
|
mark invalid-runtime "$tool \${fields[*]:1} (must pin one exact version)"
|
|
443
451
|
fi
|
|
444
452
|
;;
|
|
445
|
-
*)
|
|
453
|
+
*)
|
|
454
|
+
for version in "\${fields[@]:1}"; do check_runtime "$tool" "$version"; done
|
|
455
|
+
if [ "$runtime_invalid" -eq 0 ]; then
|
|
456
|
+
case "$tool" in
|
|
457
|
+
node) mark skipped-runtime "$tool (did you mean nodejs?)" ;;
|
|
458
|
+
go) mark skipped-runtime "$tool (did you mean golang?)" ;;
|
|
459
|
+
*) mark skipped-runtime "$tool" ;;
|
|
460
|
+
esac
|
|
461
|
+
fi
|
|
462
|
+
;;
|
|
446
463
|
esac
|
|
447
464
|
done < .tool-versions
|
|
448
465
|
fi
|
|
@@ -495,10 +512,11 @@ export function boundWarning(value: string): string {
|
|
|
495
512
|
export function parseSetupResult(
|
|
496
513
|
stdout: string,
|
|
497
514
|
nonce: string,
|
|
498
|
-
): { missing: string[]; invalid: string[]; failed: string[] } {
|
|
515
|
+
): { missing: string[]; invalid: string[]; failed: string[]; skipped: string[] } {
|
|
499
516
|
const missing: string[] = [];
|
|
500
517
|
const invalid: string[] = [];
|
|
501
518
|
const failed: string[] = [];
|
|
519
|
+
const skipped: string[] = [];
|
|
502
520
|
const prefix = `uai-setup-${nonce} `;
|
|
503
521
|
for (const raw of stdout.split("\n")) {
|
|
504
522
|
if (!raw.startsWith(prefix)) continue;
|
|
@@ -510,9 +528,10 @@ export function parseSetupResult(
|
|
|
510
528
|
if (!item) continue;
|
|
511
529
|
if (kind === "missing-runtime" && missing.length < 20) missing.push(item);
|
|
512
530
|
if (kind === "invalid-runtime" && invalid.length < 20) invalid.push(item);
|
|
531
|
+
if (kind === "skipped-runtime" && skipped.length < 20) skipped.push(item);
|
|
513
532
|
if (kind === "failed-step" && failed.length < 20) failed.push(item);
|
|
514
533
|
}
|
|
515
|
-
return { missing, invalid, failed };
|
|
534
|
+
return { missing, invalid, failed, skipped };
|
|
516
535
|
}
|
|
517
536
|
|
|
518
537
|
export type TaskProjectEnvironment = Pick<TaskEnvironmentHandle, "exec" | "descriptor">;
|
|
@@ -955,12 +974,15 @@ export class TaskProjectOps {
|
|
|
955
974
|
if ("error" in setup) {
|
|
956
975
|
warnings.push(`dependency setup could not run: ${String((setup as { error: unknown }).error)}`);
|
|
957
976
|
} else {
|
|
958
|
-
const { missing, invalid, failed } = parseSetupResult(text(setup.stdout), nonce);
|
|
977
|
+
const { missing, invalid, failed, skipped } = parseSetupResult(text(setup.stdout), nonce);
|
|
959
978
|
if (invalid.length > 0) {
|
|
960
979
|
warnings.push(
|
|
961
980
|
`the repository's .tool-versions has entries a task start would refuse (${invalid.join(", ")}); fix them before the task restarts`,
|
|
962
981
|
);
|
|
963
982
|
}
|
|
983
|
+
if (skipped.length > 0) warnings.push(
|
|
984
|
+
`unsupported tools skipped (${skipped.join(", ")}); use mise install <tool>@<version>, then mise exec -- <cmd> (or their vendor installers)`,
|
|
985
|
+
);
|
|
964
986
|
if (missing.length > 0) {
|
|
965
987
|
warnings.push(
|
|
966
988
|
`runtimes this repository asks for are not installed in this task (${missing.join(", ")}). ` +
|
package/lib/vnode-pressure.ts
CHANGED
|
@@ -42,6 +42,15 @@ const WARN_THRESHOLD = 0.8;
|
|
|
42
42
|
* requires the vnode ratio AND genuine file-table pressure together.
|
|
43
43
|
*/
|
|
44
44
|
const FILE_TABLE_CORROBORATION_THRESHOLD = 0.5;
|
|
45
|
+
/**
|
|
46
|
+
* The warn band needs the same corroboration, scaled to the warn band. A
|
|
47
|
+
* vnode ratio alone warned at every boot on a normal Mac (MacBook Air,
|
|
48
|
+
* 2026-11-06: `vnodes 263168/263168 (100%)`): macOS caches vnodes until the
|
|
49
|
+
* table reaches kern.maxvnodes, so a full table is the steady state there,
|
|
50
|
+
* not pressure. The sysctls are the right ones; the band was wrong.
|
|
51
|
+
*/
|
|
52
|
+
const FILE_TABLE_WARN_CORROBORATION_THRESHOLD =
|
|
53
|
+
FILE_TABLE_CORROBORATION_THRESHOLD * WARN_THRESHOLD;
|
|
45
54
|
const CACHE_MS = 15_000;
|
|
46
55
|
|
|
47
56
|
export interface VnodePressure {
|
|
@@ -112,19 +121,33 @@ export async function vnodeAdmissionProblem(): Promise<string | null> {
|
|
|
112
121
|
|
|
113
122
|
let lastLoggedBand: "ok" | "warn" | "critical" = "ok";
|
|
114
123
|
|
|
124
|
+
/** The log band for one reading: a full vnode table counts only when the
|
|
125
|
+
* file table corroborates it (see FILE_TABLE_WARN_CORROBORATION_THRESHOLD). */
|
|
126
|
+
export function vnodePressureBand(
|
|
127
|
+
pressure: VnodePressure,
|
|
128
|
+
): "ok" | "warn" | "critical" {
|
|
129
|
+
if (
|
|
130
|
+
pressure.ratio >= ADMISSION_THRESHOLD &&
|
|
131
|
+
pressure.filesRatio >= FILE_TABLE_CORROBORATION_THRESHOLD
|
|
132
|
+
) {
|
|
133
|
+
return "critical";
|
|
134
|
+
}
|
|
135
|
+
if (pressure.filesRatio >= WARN_THRESHOLD) return "warn";
|
|
136
|
+
if (
|
|
137
|
+
pressure.ratio >= WARN_THRESHOLD &&
|
|
138
|
+
pressure.filesRatio >= FILE_TABLE_WARN_CORROBORATION_THRESHOLD
|
|
139
|
+
) {
|
|
140
|
+
return "warn";
|
|
141
|
+
}
|
|
142
|
+
return "ok";
|
|
143
|
+
}
|
|
144
|
+
|
|
115
145
|
/** Log on band TRANSITIONS only, so a host sitting near the ceiling does not
|
|
116
146
|
* spam its own log every interval. */
|
|
117
147
|
export async function logVnodePressure(): Promise<void> {
|
|
118
148
|
const pressure = await readVnodePressure();
|
|
119
149
|
if (!pressure) return;
|
|
120
|
-
const
|
|
121
|
-
pressure.ratio >= ADMISSION_THRESHOLD &&
|
|
122
|
-
pressure.filesRatio >= FILE_TABLE_CORROBORATION_THRESHOLD;
|
|
123
|
-
const band = refusing
|
|
124
|
-
? "critical"
|
|
125
|
-
: pressure.filesRatio >= WARN_THRESHOLD || pressure.ratio >= WARN_THRESHOLD
|
|
126
|
-
? "warn"
|
|
127
|
-
: "ok";
|
|
150
|
+
const band = vnodePressureBand(pressure);
|
|
128
151
|
if (band === lastLoggedBand) return;
|
|
129
152
|
lastLoggedBand = band;
|
|
130
153
|
const detail =
|