@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
|
@@ -30,14 +30,27 @@ import type {
|
|
|
30
30
|
MachineSpec,
|
|
31
31
|
MachineState,
|
|
32
32
|
} from "./machine-provider";
|
|
33
|
+
import {
|
|
34
|
+
noApprovedImageMessage,
|
|
35
|
+
PAYLOAD_AMI_OWNER,
|
|
36
|
+
payloadImageFilters,
|
|
37
|
+
PRODUCTION_PAYLOAD_SELECTOR,
|
|
38
|
+
selectStationPayloadImage,
|
|
39
|
+
STALE_MAX_MS,
|
|
40
|
+
type PayloadImageSelector,
|
|
41
|
+
} from "./machine-payload-image";
|
|
33
42
|
|
|
34
43
|
export const AWS_MACHINE_TAG = "com.uai.machine";
|
|
44
|
+
/** Station payload validation state, carried ON the instance so it survives
|
|
45
|
+
* retries, Station restarts and moves with the machine. `pending` is set
|
|
46
|
+
* atomically in run-instances for an auto-selected image; `ok` once the
|
|
47
|
+
* payload marker was confirmed over ssh (task-environment/machine.ts). */
|
|
48
|
+
export const PAYLOAD_VALIDATION_TAG = "com.uai.payload-validation";
|
|
35
49
|
|
|
36
|
-
/** ADR-125 BYO-AWS:
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
export
|
|
40
|
-
export const PAYLOAD_AMI_NAME_PREFIX = "uai-machine-payload";
|
|
50
|
+
/** ADR-125 BYO-AWS: a host with no UAI_MACHINE_IMAGE resolves the newest
|
|
51
|
+
* APPROVED Station payload in its region; the gate is
|
|
52
|
+
* PRODUCTION_PAYLOAD_SELECTOR (machine-payload-image.ts). */
|
|
53
|
+
export { PAYLOAD_AMI_OWNER };
|
|
41
54
|
/** Regions the payload AMI is published to (build-ami.sh bakes in the first
|
|
42
55
|
* and copies to the rest). A BYO-AWS runner elsewhere would find no image
|
|
43
56
|
* and fail every launch, so setup refuses other regions up front (owner,
|
|
@@ -220,6 +233,7 @@ type LiveInstance = {
|
|
|
220
233
|
state: string;
|
|
221
234
|
privateIp: string | null;
|
|
222
235
|
taskLabel: string | null;
|
|
236
|
+
payloadValidation: "pending" | "ok" | null;
|
|
223
237
|
};
|
|
224
238
|
|
|
225
239
|
/** Strict reservations parse. Any malformed instance voids the answer. */
|
|
@@ -249,6 +263,7 @@ function parseReservations(stdout: string): LiveInstance[] | null {
|
|
|
249
263
|
const state = record.State?.Name;
|
|
250
264
|
if (typeof state !== "string") return null;
|
|
251
265
|
let taskLabel: string | null = null;
|
|
266
|
+
let payloadValidation: "pending" | "ok" | null = null;
|
|
252
267
|
if (record.Tags !== undefined) {
|
|
253
268
|
if (!Array.isArray(record.Tags)) return null;
|
|
254
269
|
for (const tag of record.Tags) {
|
|
@@ -256,6 +271,11 @@ function parseReservations(stdout: string): LiveInstance[] | null {
|
|
|
256
271
|
if (typeof tag.Value !== "string") return null;
|
|
257
272
|
taskLabel = tag.Value;
|
|
258
273
|
}
|
|
274
|
+
if (tag?.Key === PAYLOAD_VALIDATION_TAG) {
|
|
275
|
+
if (typeof tag.Value !== "string") return null;
|
|
276
|
+
// Anything but `ok` is still unvalidated: fail closed (probe).
|
|
277
|
+
payloadValidation = tag.Value === "ok" ? "ok" : "pending";
|
|
278
|
+
}
|
|
259
279
|
}
|
|
260
280
|
}
|
|
261
281
|
instances.push({
|
|
@@ -272,6 +292,7 @@ function parseReservations(stdout: string): LiveInstance[] | null {
|
|
|
272
292
|
? record.PrivateIpAddress
|
|
273
293
|
: null,
|
|
274
294
|
taskLabel,
|
|
295
|
+
payloadValidation,
|
|
275
296
|
});
|
|
276
297
|
}
|
|
277
298
|
}
|
|
@@ -323,19 +344,25 @@ async function hostEgressIp(): Promise<string> {
|
|
|
323
344
|
);
|
|
324
345
|
}
|
|
325
346
|
|
|
326
|
-
/** How long a resolved payload AMI is trusted before the newest
|
|
347
|
+
/** How long a resolved payload AMI is trusted before the newest approved
|
|
327
348
|
* image is looked up again. Long enough that a burst of launches shares one
|
|
328
|
-
* describe-images; short enough that a
|
|
329
|
-
* RUNNING host
|
|
330
|
-
* (before 0.9.106 the answer was kept for the process lifetime). */
|
|
349
|
+
* describe-images; short enough that a promotion or demotion reaches every
|
|
350
|
+
* RUNNING host on its next task without a restart. */
|
|
331
351
|
export const PAYLOAD_AMI_TTL_MS = 5 * 60_000;
|
|
332
352
|
|
|
333
353
|
export function createAwsMachineProvider(
|
|
334
354
|
config: AwsMachineConfig,
|
|
335
355
|
runner: Runner = defaultRunner(config.region),
|
|
336
|
-
deps: {
|
|
356
|
+
deps: {
|
|
357
|
+
now?: () => number;
|
|
358
|
+
/** ONLY the non-packaged canary driver passes one. Production
|
|
359
|
+
* construction (task-environment/index.ts) never does, and no env var or
|
|
360
|
+
* config reads one. */
|
|
361
|
+
selector?: PayloadImageSelector;
|
|
362
|
+
} = {},
|
|
337
363
|
): MachineProvider {
|
|
338
364
|
const now = deps.now ?? (() => Date.now());
|
|
365
|
+
const selector = deps.selector ?? PRODUCTION_PAYLOAD_SELECTOR;
|
|
339
366
|
const taskIdOf = (machineId: string): string => {
|
|
340
367
|
if (!machineId.startsWith("uai-machine-")) {
|
|
341
368
|
throw new Error(`not a uai machine id: ${machineId}`);
|
|
@@ -385,51 +412,87 @@ export function createAwsMachineProvider(
|
|
|
385
412
|
// orchestrator can never reach.
|
|
386
413
|
// -------------------------------------------------------------------------
|
|
387
414
|
|
|
388
|
-
|
|
415
|
+
// The last SUCCESSFUL lookup's answer. Only a successful lookup sets
|
|
416
|
+
// lastOkAt; a failed one never advances it.
|
|
417
|
+
let payloadMemo: {
|
|
418
|
+
id: string;
|
|
419
|
+
name: string;
|
|
420
|
+
lastOkAt: number;
|
|
421
|
+
deprecationTime: number | null;
|
|
422
|
+
} | null = null;
|
|
423
|
+
/** Guards applied before EVERY cached return (the TTL fast path and the
|
|
424
|
+
* failed-lookup fallback alike): at most STALE_MAX_MS after the last
|
|
425
|
+
* successful lookup, and never at or past the image's deprecation time. */
|
|
426
|
+
const memoReturnable = (at: number): boolean =>
|
|
427
|
+
payloadMemo !== null &&
|
|
428
|
+
at < payloadMemo.lastOkAt + STALE_MAX_MS &&
|
|
429
|
+
(payloadMemo.deprecationTime === null || at < payloadMemo.deprecationTime);
|
|
430
|
+
|
|
389
431
|
async function resolveImage(specImage: string): Promise<string> {
|
|
432
|
+
// An explicit AMI (UAI_MACHINE_IMAGE=ami-…) bypasses the lookup.
|
|
390
433
|
if (specImage.startsWith("ami-")) return specImage;
|
|
391
|
-
|
|
392
|
-
|
|
434
|
+
const started = now();
|
|
435
|
+
if (payloadMemo && started - payloadMemo.lastOkAt < PAYLOAD_AMI_TTL_MS && memoReturnable(started)) {
|
|
436
|
+
return payloadMemo.id;
|
|
393
437
|
}
|
|
394
438
|
const res = await runner([
|
|
395
439
|
"ec2",
|
|
396
440
|
"describe-images",
|
|
397
441
|
"--owners",
|
|
398
|
-
|
|
442
|
+
selector.owner,
|
|
399
443
|
"--filters",
|
|
400
|
-
|
|
401
|
-
"Name=state,Values=available",
|
|
444
|
+
...payloadImageFilters(selector),
|
|
402
445
|
"--query",
|
|
403
|
-
"
|
|
446
|
+
"Images[].{ImageId: ImageId, Name: Name, CreationDate: CreationDate, OwnerId: OwnerId, " +
|
|
447
|
+
"Architecture: Architecture, State: State, Public: Public, DeprecationTime: DeprecationTime, Tags: Tags}",
|
|
404
448
|
]);
|
|
405
|
-
let
|
|
449
|
+
let images: unknown = null;
|
|
406
450
|
if (res.status === 0) {
|
|
407
451
|
try {
|
|
408
|
-
|
|
452
|
+
images = JSON.parse(res.stdout);
|
|
409
453
|
} catch {
|
|
410
|
-
|
|
454
|
+
images = null;
|
|
411
455
|
}
|
|
412
456
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
//
|
|
416
|
-
|
|
457
|
+
const at = now();
|
|
458
|
+
if (!Array.isArray(images)) {
|
|
459
|
+
// A failed lookup proves nothing: keep launching the last approved
|
|
460
|
+
// image only while its guards hold, otherwise fail closed.
|
|
461
|
+
if (payloadMemo && memoReturnable(at)) {
|
|
462
|
+
console.warn(
|
|
463
|
+
`[machine-aws] payload image lookup failed in ${config.region}; keeping ${payloadMemo.id} ` +
|
|
464
|
+
`(last confirmed ${Math.round((at - payloadMemo.lastOkAt) / 1000)}s ago)`,
|
|
465
|
+
);
|
|
466
|
+
return payloadMemo.id;
|
|
467
|
+
}
|
|
417
468
|
throw new Error(
|
|
418
|
-
`
|
|
419
|
-
|
|
469
|
+
`could not look up the Moondeck Station machine image in ${config.region}: ${
|
|
470
|
+
res.stderr.trim() || `exit ${res.status ?? "killed"}`
|
|
471
|
+
} — set UAI_MACHINE_IMAGE to an AMI id to launch without the lookup`,
|
|
420
472
|
);
|
|
421
473
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
//
|
|
425
|
-
|
|
474
|
+
const { selected, rejected } = selectStationPayloadImage(images, selector, at);
|
|
475
|
+
if (!selected) {
|
|
476
|
+
// A successful empty answer is authoritative: forget the cached image.
|
|
477
|
+
payloadMemo = null;
|
|
478
|
+
if (rejected.length > 0) {
|
|
479
|
+
console.warn(
|
|
480
|
+
`[machine-aws] payload images rejected in ${config.region}: ${rejected
|
|
481
|
+
.map((r) => `${r.id} (${r.reason})`)
|
|
482
|
+
.join(", ")}`,
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
throw new Error(noApprovedImageMessage(selector, config.region));
|
|
486
|
+
}
|
|
487
|
+
if (payloadMemo?.id !== selected.id) {
|
|
488
|
+
// The journal line that tells an operator which payload a task got.
|
|
426
489
|
console.log(
|
|
427
|
-
`[machine-aws] payload image for ${config.region}: ${
|
|
428
|
-
(
|
|
490
|
+
`[machine-aws] payload image for ${config.region}: ${selected.id} (${selected.name})` +
|
|
491
|
+
(payloadMemo ? ` (was ${payloadMemo.id})` : ""),
|
|
429
492
|
);
|
|
430
493
|
}
|
|
431
|
-
|
|
432
|
-
return
|
|
494
|
+
payloadMemo = { ...selected, lastOkAt: at };
|
|
495
|
+
return selected.id;
|
|
433
496
|
}
|
|
434
497
|
|
|
435
498
|
let resolvedSubnet: string | null = null;
|
|
@@ -647,6 +710,8 @@ export function createAwsMachineProvider(
|
|
|
647
710
|
return {
|
|
648
711
|
id: machineId,
|
|
649
712
|
taskLabel: instance.taskLabel,
|
|
713
|
+
payloadValidation: instance.payloadValidation,
|
|
714
|
+
instanceId: instance.instanceId,
|
|
650
715
|
state,
|
|
651
716
|
// Still stopping: its processes run until the instance is stopped.
|
|
652
717
|
...(instance.state === "stopping" ? { frozen: true as const } : {}),
|
|
@@ -674,7 +739,9 @@ export function createAwsMachineProvider(
|
|
|
674
739
|
// volume while the root stays small — so resolve it per image.
|
|
675
740
|
const diskGiB = config.diskGiB ?? DEFAULT_DISK_GIB;
|
|
676
741
|
// ADR-125 BYO-AWS: explicit config wins; otherwise resolve the newest
|
|
677
|
-
//
|
|
742
|
+
// approved payload AMI and the default-VPC network per process.
|
|
743
|
+
// Only an auto-selected image is subject to the payload-marker probe.
|
|
744
|
+
const autoSelected = !spec.image.startsWith("ami-");
|
|
678
745
|
const image = await resolveImage(spec.image);
|
|
679
746
|
const subnetId = await resolveSubnet();
|
|
680
747
|
const securityGroupId = await resolveSecurityGroup(subnetId);
|
|
@@ -690,6 +757,13 @@ export function createAwsMachineProvider(
|
|
|
690
757
|
securityGroupId,
|
|
691
758
|
config.iamInstanceProfileArn ?? null,
|
|
692
759
|
diskGiB,
|
|
760
|
+
// The tag spec depends on the validation mode (an auto-selected
|
|
761
|
+
// image gets the `pending` tag, a pinned one none), so the mode
|
|
762
|
+
// is part of the token: the same AMI pinned and auto-selected
|
|
763
|
+
// must never share one (IdempotentParameterMismatch). The "v1"
|
|
764
|
+
// also keeps the tokens of 1.0.4 and earlier from meeting the new tag spec.
|
|
765
|
+
// describe-first above still prevents a double launch.
|
|
766
|
+
["payload-validation-v1", autoSelected ? "pending" : null],
|
|
693
767
|
]),
|
|
694
768
|
)
|
|
695
769
|
.digest("hex")
|
|
@@ -708,7 +782,9 @@ export function createAwsMachineProvider(
|
|
|
708
782
|
"--client-token",
|
|
709
783
|
`${machineId}-${launchFingerprint}`.slice(0, 64),
|
|
710
784
|
"--tag-specifications",
|
|
711
|
-
`ResourceType=instance,Tags=[{Key=${AWS_MACHINE_TAG},Value=${spec.taskId}},{Key=Name,Value=${machineId}}
|
|
785
|
+
`ResourceType=instance,Tags=[{Key=${AWS_MACHINE_TAG},Value=${spec.taskId}},{Key=Name,Value=${machineId}}${
|
|
786
|
+
autoSelected ? `,{Key=${PAYLOAD_VALIDATION_TAG},Value=pending}` : ""
|
|
787
|
+
}]`,
|
|
712
788
|
"--block-device-mappings",
|
|
713
789
|
JSON.stringify([
|
|
714
790
|
{
|
|
@@ -760,7 +836,67 @@ export function createAwsMachineProvider(
|
|
|
760
836
|
})`,
|
|
761
837
|
);
|
|
762
838
|
}
|
|
763
|
-
|
|
839
|
+
// What was launched decides the probe, not a possibly stale describe.
|
|
840
|
+
return { ...info, payloadValidation: autoSelected ? "pending" : null };
|
|
841
|
+
},
|
|
842
|
+
|
|
843
|
+
async terminateInstance(machineId: string, instanceId: string): Promise<void> {
|
|
844
|
+
if (!/^i-[0-9a-f]+$/.test(instanceId)) {
|
|
845
|
+
throw new Error(`machine ${machineId}: refusing to terminate bad instance id ${instanceId}`);
|
|
846
|
+
}
|
|
847
|
+
const res = await runner(["ec2", "terminate-instances", "--instance-ids", instanceId]);
|
|
848
|
+
if (res.status !== 0) {
|
|
849
|
+
throw new Error(
|
|
850
|
+
`machine terminate failed for ${machineId} (${instanceId}): ${
|
|
851
|
+
res.stderr.trim() || `exit ${res.status ?? "killed"}`
|
|
852
|
+
}`,
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
// Proven by THIS instance id, never by the tag (which may now name a
|
|
856
|
+
// replacement): shutting-down/terminated, or EC2's exact not-found.
|
|
857
|
+
const deadline = Date.now() + 120_000;
|
|
858
|
+
for (;;) {
|
|
859
|
+
const raw = await runner([
|
|
860
|
+
"ec2",
|
|
861
|
+
"describe-instances",
|
|
862
|
+
"--instance-ids",
|
|
863
|
+
instanceId,
|
|
864
|
+
"--query",
|
|
865
|
+
"Reservations[].Instances[].State.Name",
|
|
866
|
+
"--output",
|
|
867
|
+
"text",
|
|
868
|
+
]);
|
|
869
|
+
const state = raw.status === 0 ? raw.stdout.trim() : "";
|
|
870
|
+
if (state === "shutting-down" || state === "terminated") return;
|
|
871
|
+
if (raw.status !== 0 && /InvalidInstanceID\.NotFound/.test(raw.stderr)) return;
|
|
872
|
+
if (Date.now() >= deadline) {
|
|
873
|
+
throw new Error(`instance ${instanceId} of ${machineId} could not be proven terminated (${state || "unknown"})`);
|
|
874
|
+
}
|
|
875
|
+
await new Promise<void>((resolve) => setTimeout(resolve, 5_000));
|
|
876
|
+
}
|
|
877
|
+
},
|
|
878
|
+
|
|
879
|
+
async markPayloadValidated(machineId: string, instanceId: string): Promise<void> {
|
|
880
|
+
if (!/^i-[0-9a-f]+$/.test(instanceId)) {
|
|
881
|
+
throw new Error(`could not record payload validation on ${machineId}: bad instance id ${instanceId}`);
|
|
882
|
+
}
|
|
883
|
+
// The probed instance itself — never re-resolved by tag, so a
|
|
884
|
+
// replacement under the same logical id can never inherit `ok`.
|
|
885
|
+
const res = await runner([
|
|
886
|
+
"ec2",
|
|
887
|
+
"create-tags",
|
|
888
|
+
"--resources",
|
|
889
|
+
instanceId,
|
|
890
|
+
"--tags",
|
|
891
|
+
`Key=${PAYLOAD_VALIDATION_TAG},Value=ok`,
|
|
892
|
+
]);
|
|
893
|
+
if (res.status !== 0) {
|
|
894
|
+
throw new Error(
|
|
895
|
+
`could not record payload validation on ${machineId}: ${
|
|
896
|
+
res.stderr.trim() || `exit ${res.status ?? "killed"}`
|
|
897
|
+
}`,
|
|
898
|
+
);
|
|
899
|
+
}
|
|
764
900
|
},
|
|
765
901
|
|
|
766
902
|
async stop(machineId: string): Promise<void> {
|
|
@@ -900,6 +1036,8 @@ export function createAwsMachineProvider(
|
|
|
900
1036
|
? awsMachineName(instance.taskLabel)
|
|
901
1037
|
: instance.instanceId,
|
|
902
1038
|
taskLabel: instance.taskLabel,
|
|
1039
|
+
payloadValidation: instance.payloadValidation,
|
|
1040
|
+
instanceId: instance.instanceId,
|
|
903
1041
|
state,
|
|
904
1042
|
...(instance.state === "stopping" ? { frozen: true as const } : {}),
|
|
905
1043
|
address: state === "running" ? instance.privateIp : null,
|
package/lib/machine-provider.ts
CHANGED
|
@@ -66,6 +66,17 @@ export interface MachineInfo {
|
|
|
66
66
|
sshPort?: number;
|
|
67
67
|
/** Present only alongside `unknown` — what the backend actually said. */
|
|
68
68
|
detail?: string;
|
|
69
|
+
/** Station payload validation recorded ON the machine (aws: the
|
|
70
|
+
* `com.uai.payload-validation` tag, set to `pending` atomically at launch
|
|
71
|
+
* of an auto-selected image). `pending` = the payload marker has not been
|
|
72
|
+
* confirmed yet, so it is probed before any workspace prep; `ok` = it was;
|
|
73
|
+
* null/absent = never subject to the probe (pinned image, pre-1.0.5
|
|
74
|
+
* machine, or a backend without the concept). */
|
|
75
|
+
payloadValidation?: "pending" | "ok" | null;
|
|
76
|
+
/** The PHYSICAL instance behind the logical id (aws: the EC2 instance id).
|
|
77
|
+
* Payload validation is bound to it: a replacement under the same logical
|
|
78
|
+
* id is a different machine and is validated afresh. */
|
|
79
|
+
instanceId?: string;
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
export interface MachineProvider {
|
|
@@ -87,4 +98,15 @@ export interface MachineProvider {
|
|
|
87
98
|
* rows reject the whole listing (they could hide exactly the labeled
|
|
88
99
|
* machine a proof needs to see). */
|
|
89
100
|
list(): Promise<MachineInfo[]>;
|
|
101
|
+
/** Record that the payload marker was confirmed ON exactly `instanceId`
|
|
102
|
+
* (the physical instance that was probed), never on whatever the logical
|
|
103
|
+
* id resolves to now. Backends without validation state omit it. Throws
|
|
104
|
+
* when the write fails; the instance then stays `pending`. */
|
|
105
|
+
markPayloadValidated?(id: string, instanceId: string): Promise<void>;
|
|
106
|
+
/** Terminate exactly ONE physical instance (the one a payload probe
|
|
107
|
+
* rejected), never re-resolving the logical id: a replacement under the
|
|
108
|
+
* same id is never touched. Resolves once that instance is proven
|
|
109
|
+
* shutting down or gone; throws otherwise. Ordinary teardown keeps using
|
|
110
|
+
* `terminate(id)`. */
|
|
111
|
+
terminateInstance?(id: string, instanceId: string): Promise<void>;
|
|
90
112
|
}
|
package/lib/managed-runtime.ts
CHANGED
|
@@ -37,6 +37,8 @@ import {
|
|
|
37
37
|
BUNDLED_RUNTIME_ROOT,
|
|
38
38
|
MANAGED_RUNTIME_CAPABILITY,
|
|
39
39
|
MANAGED_RUNTIME_CREDENTIALS,
|
|
40
|
+
AGENT_FILES_SINCE_1_0_5,
|
|
41
|
+
agentFilesRequiredFor,
|
|
40
42
|
MANAGED_RUNTIME_CREDENTIALS_VERSION,
|
|
41
43
|
extractVerifiedRuntimeArchive,
|
|
42
44
|
readVerifiedArtifactFile,
|
|
@@ -2165,6 +2167,29 @@ export async function validateInstalledRuntime(
|
|
|
2165
2167
|
throw new Error(`managed runtime file escapes its version directory: ${relative}`);
|
|
2166
2168
|
}
|
|
2167
2169
|
}
|
|
2170
|
+
for (const [relative, executable] of AGENT_FILES_SINCE_1_0_5) {
|
|
2171
|
+
const absolute = path.join(root, ...relative.split("/"));
|
|
2172
|
+
const stat = await lstat(absolute).catch((error: NodeJS.ErrnoException) => {
|
|
2173
|
+
if (error.code === "ENOENT") return null;
|
|
2174
|
+
throw error;
|
|
2175
|
+
});
|
|
2176
|
+
// Absent in every generation before 1.0.5, a rollback target included;
|
|
2177
|
+
// required from 1.0.5 on.
|
|
2178
|
+
if (stat === null) {
|
|
2179
|
+
if (agentFilesRequiredFor(descriptor.hostVersion)) {
|
|
2180
|
+
throw new Error(`managed runtime is missing regular file ${relative}`);
|
|
2181
|
+
}
|
|
2182
|
+
continue;
|
|
2183
|
+
}
|
|
2184
|
+
if (!stat.isFile()) throw new Error(`managed runtime is missing regular file ${relative}`);
|
|
2185
|
+
if (executable && (stat.mode & 0o111) === 0) {
|
|
2186
|
+
throw new Error(`managed runtime file is not executable: ${relative}`);
|
|
2187
|
+
}
|
|
2188
|
+
const resolved = await realpath(absolute);
|
|
2189
|
+
if (!isInside(root, resolved)) {
|
|
2190
|
+
throw new Error(`managed runtime file escapes its version directory: ${relative}`);
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2168
2193
|
if (capabilities.capabilitySchemaVersion === 3) {
|
|
2169
2194
|
await validateInstalledRuntimeAssets(root, capabilities);
|
|
2170
2195
|
}
|
package/lib/orchestrator.ts
CHANGED
|
@@ -1665,6 +1665,14 @@ export class Orchestrator {
|
|
|
1665
1665
|
) {
|
|
1666
1666
|
return false;
|
|
1667
1667
|
}
|
|
1668
|
+
// A healthy initial start stays memoized, so binds and the start-loop tail
|
|
1669
|
+
// do not run on a re-attach ensure. Reassert the actual roster state to
|
|
1670
|
+
// heal a ready event lost by the cloud's former stage-write race. An ensure
|
|
1671
|
+
// acknowledgement alone is not readiness: every roster member must have
|
|
1672
|
+
// bound (including one-shot engines that have since exited).
|
|
1673
|
+
if (ready && this.rosterReady(channel)) {
|
|
1674
|
+
this.emitTaskStage(channel.taskId, "ready");
|
|
1675
|
+
}
|
|
1668
1676
|
return ready;
|
|
1669
1677
|
}
|
|
1670
1678
|
|
|
@@ -7880,6 +7888,9 @@ export function buildSystemPreamble(
|
|
|
7880
7888
|
...handoffBrief,
|
|
7881
7889
|
"",
|
|
7882
7890
|
...workspaceBrief,
|
|
7891
|
+
`Read \`${workspacePath}/.moondeck/init/runtime-notes\` if present for skipped tools and installation guidance.`,
|
|
7892
|
+
"If dependencies seem missing, inspect deps-status and deps.log in that directory.",
|
|
7893
|
+
"",
|
|
7883
7894
|
// ADR-062: shared files — only when this container actually carries the
|
|
7884
7895
|
// mounts (task-up drops a marker; pre-feature containers have none).
|
|
7885
7896
|
...(sharedFiles &&
|
|
@@ -11251,6 +11262,8 @@ async function recoverOneDockerTask(
|
|
|
11251
11262
|
"-e",
|
|
11252
11263
|
"ASDF_RUST_VERSION=",
|
|
11253
11264
|
"-e",
|
|
11265
|
+
"ASDF_BUN_VERSION=",
|
|
11266
|
+
"-e",
|
|
11254
11267
|
"COREPACK_HOME=/opt/asdf-data/corepack",
|
|
11255
11268
|
"-e",
|
|
11256
11269
|
"COREPACK_DEFAULT_TO_LATEST=0",
|
package/lib/runtime-archive.ts
CHANGED
|
@@ -459,6 +459,41 @@ function validateEntryGraph(
|
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Agent scripts added in Station 1.0.5: the dependency list _common.sh
|
|
465
|
+
* sources, and the Station's report of it. The build requires them
|
|
466
|
+
* (scripts/host-runtime/archive.mjs). Validation here and of an installed
|
|
467
|
+
* generation (managed-runtime.ts) requires them for a generation at or above
|
|
468
|
+
* 1.0.5, and for an older one checks them only if present: both validators
|
|
469
|
+
* also judge OLDER generations (a rollback target, a pinned earlier
|
|
470
|
+
* release), which never had them, and refusing those would block every way
|
|
471
|
+
* back. Main is still 1.0.4 while these land; #790's bump to 1.0.5 is what
|
|
472
|
+
* makes them required, with no further change here.
|
|
473
|
+
*/
|
|
474
|
+
export const AGENT_FILES_SINCE_1_0_5: ReadonlyArray<readonly [string, boolean]> = Object.freeze([
|
|
475
|
+
Object.freeze(["agent/scripts/agent/_deps.sh", false] as const),
|
|
476
|
+
Object.freeze(["agent/scripts/agent/check-deps.sh", true] as const),
|
|
477
|
+
]);
|
|
478
|
+
const AGENT_FILES_REQUIRED_FROM = Object.freeze([1, 0, 5] as const);
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Whether a generation of `version` must carry AGENT_FILES_SINCE_1_0_5.
|
|
482
|
+
* Compares the numeric major.minor.patch core, so 1.0.5 and every later
|
|
483
|
+
* release (1.0.10, 1.1.0, 2.0.0) require them, and a prerelease of 1.0.5 is
|
|
484
|
+
* built from code that has them. A version that does not parse is held to
|
|
485
|
+
* the stricter rule.
|
|
486
|
+
*/
|
|
487
|
+
export function agentFilesRequiredFor(version: string): boolean {
|
|
488
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(version);
|
|
489
|
+
if (!match) return true;
|
|
490
|
+
const core = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
491
|
+
for (let i = 0; i < 3; i++) {
|
|
492
|
+
if (core[i]! !== AGENT_FILES_REQUIRED_FROM[i]) return core[i]! > AGENT_FILES_REQUIRED_FROM[i]!;
|
|
493
|
+
}
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
|
|
462
497
|
function validateEntryLayout(
|
|
463
498
|
entries: readonly ArchiveEntry[],
|
|
464
499
|
byPath: ReadonlyMap<string, ArchiveEntry>,
|
|
@@ -555,6 +590,18 @@ function validateEntryLayout(
|
|
|
555
590
|
throw new Error(`runtime archive executable mode is invalid: ${executable}`);
|
|
556
591
|
}
|
|
557
592
|
}
|
|
593
|
+
const agentFilesRequired = agentFilesRequiredFor(descriptor.hostVersion);
|
|
594
|
+
for (const [file, executable] of AGENT_FILES_SINCE_1_0_5) {
|
|
595
|
+
const entry = byPath.get(file);
|
|
596
|
+
if (entry === undefined) {
|
|
597
|
+
if (agentFilesRequired) throw new Error(`runtime archive is missing regular file ${file}`);
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
if (entry.type !== "0") throw new Error(`runtime archive is missing regular file ${file}`);
|
|
601
|
+
if (executable && entry.mode !== 0o755) {
|
|
602
|
+
throw new Error(`runtime archive executable mode is invalid: ${file}`);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
558
605
|
return {
|
|
559
606
|
...platformCapabilities,
|
|
560
607
|
runtimeCapabilityVersion,
|
package/lib/runtime-authority.ts
CHANGED
|
@@ -30,6 +30,7 @@ export const RUNTIME_AUTHORITY_ENV: Readonly<Record<string, string>> =
|
|
|
30
30
|
ASDF_GOLANG_VERSION: "",
|
|
31
31
|
ASDF_RUBY_VERSION: "",
|
|
32
32
|
ASDF_RUST_VERSION: "",
|
|
33
|
+
ASDF_BUN_VERSION: "",
|
|
33
34
|
// asdf-nodejs wraps global npm installs with an automatic reshim. Task
|
|
34
35
|
// mounts are intentionally read-only and private bins are already on PATH;
|
|
35
36
|
// only host maintenance may mutate shared shims.
|
package/lib/skills.ts
CHANGED
|
@@ -258,19 +258,19 @@ const SKILL_EXEC_TIMEOUT_MS = 180_000; // clones / npx installs can be slow
|
|
|
258
258
|
* In-container git-skill installer. Shallow-clones a repo, then works out where
|
|
259
259
|
* the actual skill(s) live and copies each into `~/.claude/skills/<name>/`:
|
|
260
260
|
*
|
|
261
|
-
* - `$
|
|
261
|
+
* - `$3` (subpath) given → that folder is the skill.
|
|
262
262
|
* - else repo root has a SKILL.md → the whole repo is the skill.
|
|
263
263
|
* - else search the clone for SKILL.md files → install every skill folder it
|
|
264
264
|
* finds (a "collection" repo), each under its own folder name.
|
|
265
265
|
* - else exit 3 → the repo isn't a ready skill (needs a build; use cli mode).
|
|
266
266
|
*
|
|
267
|
-
* Params are positional argv ($1=url, $2=
|
|
267
|
+
* Params are positional argv ($1=url, $2=name, $3=optional subpath) — never interpolated
|
|
268
268
|
* into this text — so a repo URL / subpath can't shell-inject. `.git` is
|
|
269
269
|
* stripped and the temp clone removed; existing skill dirs are left untouched.
|
|
270
270
|
*/
|
|
271
271
|
const GIT_INSTALL_SCRIPT = `
|
|
272
272
|
set -eu
|
|
273
|
-
url="$1";
|
|
273
|
+
url="$1"; name="$2"; sub="\${3:-}"
|
|
274
274
|
skills="$HOME/.claude/skills"
|
|
275
275
|
mkdir -p "$skills"
|
|
276
276
|
tmp="$(mktemp -d)"
|
|
@@ -317,7 +317,9 @@ export function collectPackageSkills(agents: RosterAgent[]): RosterSkill[] {
|
|
|
317
317
|
for (const a of agents) {
|
|
318
318
|
if (a.kind !== "claude") continue;
|
|
319
319
|
for (const s of a.skills ?? []) {
|
|
320
|
-
|
|
320
|
+
// Draft entries must not claim a slug ahead of another agent's valid
|
|
321
|
+
// skill, or warn on every resume while their install details are unset.
|
|
322
|
+
if (s.type !== "package" || !s.value.trim() || s.source == null) continue;
|
|
321
323
|
const key = skillSlug(s.name);
|
|
322
324
|
if (seen.has(key)) continue;
|
|
323
325
|
seen.add(key);
|
|
@@ -425,7 +427,28 @@ export async function installPackageSkills(
|
|
|
425
427
|
for (const s of pkgs) {
|
|
426
428
|
const slug = skillSlug(s.name);
|
|
427
429
|
try {
|
|
430
|
+
// Validate author-supplied fields before invoking the provider so errors
|
|
431
|
+
// name the skill and field instead of surfacing a generic argv failure.
|
|
432
|
+
for (const [field, value] of [["name", s.name], ["value", s.value]] as const) {
|
|
433
|
+
if (!value.trim() || value.includes("\0")) {
|
|
434
|
+
throw new Error(`${field} must be a nonempty NUL-free string`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (s.source !== "git" && s.source !== "cli") {
|
|
438
|
+
throw new Error("source must be git or cli");
|
|
439
|
+
}
|
|
440
|
+
if (s.source === "git" && s.subpath?.includes("\0")) {
|
|
441
|
+
throw new Error("subpath must be NUL-free");
|
|
442
|
+
}
|
|
428
443
|
if (s.source === "git") {
|
|
444
|
+
// subpath is de-fanged against traversal; url/subpath/name reach the
|
|
445
|
+
// installer as positional argv (never interpolated) — no shell inject.
|
|
446
|
+
const sub = (s.subpath ?? "").replace(/^[/.]+/, "").replace(/\.\.+/g, "");
|
|
447
|
+
// Single-dot/slash spellings mean the repo root. Only traversal that
|
|
448
|
+
// erases the whole path is an error, even if a done marker exists.
|
|
449
|
+
if (!sub && s.subpath?.includes("..")) {
|
|
450
|
+
throw new Error("subpath must name a folder after removing traversal");
|
|
451
|
+
}
|
|
429
452
|
// Idempotent across ensureSessions re-runs: a marker records that the
|
|
430
453
|
// clone+install already ran, so reconnects don't re-clone.
|
|
431
454
|
const marker = `/home/node/.claude/skills/.uai-git-${slug}.done`;
|
|
@@ -433,17 +456,16 @@ export async function installPackageSkills(
|
|
|
433
456
|
done.push(installedSkillPath(s));
|
|
434
457
|
continue;
|
|
435
458
|
}
|
|
436
|
-
// subpath is de-fanged against traversal; url/subpath/name reach the
|
|
437
|
-
// installer as positional argv (never interpolated) — no shell inject.
|
|
438
|
-
const sub = (s.subpath ?? "").replace(/^[/.]+/, "").replace(/\.\.+/g, "");
|
|
439
459
|
const r = await exec(container, [
|
|
440
460
|
"bash",
|
|
441
461
|
"-lc",
|
|
442
462
|
GIT_INSTALL_SCRIPT,
|
|
443
463
|
"uai-skill", // $0
|
|
444
464
|
s.value, // $1 url
|
|
445
|
-
|
|
446
|
-
|
|
465
|
+
slug, // $2 name
|
|
466
|
+
// Environment exec forbids empty argv entries. Omit the optional
|
|
467
|
+
// subpath; the installer defaults it to empty inside the shell.
|
|
468
|
+
...(sub ? [sub] : []), // $3 subpath
|
|
447
469
|
]);
|
|
448
470
|
if (r.status !== 0) {
|
|
449
471
|
const why =
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The owned-host hourly standard-image maintenance schedule.
|
|
3
|
+
*
|
|
4
|
+
* A pass is Docker (or Apple container) work end to end; against an
|
|
5
|
+
* unavailable runtime every call waits out its own timeout (live 2026-11-06:
|
|
6
|
+
* a 1.0.4 station reported "no runtime" for 14 h while each hourly pass spent
|
|
7
|
+
* 15 min timing out against a hung OrbStack). So the schedule only runs a
|
|
8
|
+
* pass while the runtime is operational (the public state is `ready`), and
|
|
9
|
+
* otherwise skips with one log line. A detected-but-fenced runtime counts as
|
|
10
|
+
* not ready: activation has not yet proved the persisted environments'
|
|
11
|
+
* identity or quarantined writable containers (Codex review, 2026-11-06).
|
|
12
|
+
* Readiness brings its own maintenance: activation runs a pass on every ready
|
|
13
|
+
* edge, so a skipped hour is not lost.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export interface StandardImageScheduleDeps {
|
|
17
|
+
intervalMs: number;
|
|
18
|
+
/** The PUBLIC runtime status (containerRuntimeCapabilityState): `checking`
|
|
19
|
+
* while a detected runtime is still fenced. Activation's own pass does not
|
|
20
|
+
* go through this schedule. */
|
|
21
|
+
runtimeStatus: () => string;
|
|
22
|
+
run: () => Promise<unknown>;
|
|
23
|
+
log?: (line: string) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** One scheduled tick: run the pass, or skip it while the runtime is not ready. */
|
|
27
|
+
export async function runScheduledStandardImageMaintenance(
|
|
28
|
+
deps: Omit<StandardImageScheduleDeps, "intervalMs">,
|
|
29
|
+
): Promise<"ran" | "skipped"> {
|
|
30
|
+
const status = deps.runtimeStatus();
|
|
31
|
+
if (status !== "ready") {
|
|
32
|
+
(deps.log ?? ((line: string) => console.log(line)))(
|
|
33
|
+
`[host-agent] standard-image maintenance skipped: container runtime is ${status}`,
|
|
34
|
+
);
|
|
35
|
+
return "skipped";
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
await deps.run();
|
|
39
|
+
} catch {
|
|
40
|
+
// ensureStandardImage reports its own failures; a schedule tick never throws.
|
|
41
|
+
}
|
|
42
|
+
return "ran";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function startStandardImageMaintenanceSchedule(
|
|
46
|
+
deps: StandardImageScheduleDeps,
|
|
47
|
+
): () => void {
|
|
48
|
+
const timer = setInterval(() => {
|
|
49
|
+
void runScheduledStandardImageMaintenance(deps);
|
|
50
|
+
}, deps.intervalMs);
|
|
51
|
+
timer.unref?.();
|
|
52
|
+
return () => clearInterval(timer);
|
|
53
|
+
}
|