@moondeck/station 1.0.4 → 1.0.6
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/lib/agent-dependencies.ts +246 -0
- package/lib/agent.ts +9 -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-exec.ts +6 -2
- package/lib/machine-payload-image.ts +192 -0
- package/lib/machine-provider-aws.ts +429 -113
- package/lib/machine-provider.ts +65 -0
- package/lib/managed-runtime.ts +25 -0
- package/lib/orchestrator.ts +70 -1
- package/lib/runtime-archive.ts +47 -0
- package/lib/skills.ts +31 -9
- package/lib/standard-image-schedule.ts +53 -0
- package/lib/task-credential-cleanup.ts +62 -5
- package/lib/task-env-forwarder.ts +123 -17
- package/lib/task-environment/machine-task-up.ts +4 -0
- package/lib/task-environment/machine.ts +576 -23
- package/lib/task-environment/types.ts +28 -0
- 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/src/cli.ts +1 -1
- package/src/event-outbox.ts +50 -1
- package/src/index.ts +138 -1
- package/src/main.ts +127 -15
- package/src/process-wake.ts +36 -0
- package/src/protocol.ts +120 -1
- package/src/task-note-publisher.ts +65 -0
package/lib/machine-exec.ts
CHANGED
|
@@ -22,6 +22,10 @@ import { spawn } from "node:child_process";
|
|
|
22
22
|
import type { DockerResult } from "./docker-exec";
|
|
23
23
|
|
|
24
24
|
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
25
|
+
/** ssh's ConnectTimeout for every machine exec: it bounds the TCP connect
|
|
26
|
+
* and the SSH handshake and key exchange (ssh_config(5)). Exec budgets that
|
|
27
|
+
* must leave room for a slow connect count it in (task-env-forwarder.ts). */
|
|
28
|
+
export const MACHINE_SSH_CONNECT_TIMEOUT_SECONDS = 10;
|
|
25
29
|
const DEFAULT_MAX_OUTPUT_BYTES = 4 * 1024 * 1024;
|
|
26
30
|
/** SIGKILLed ssh normally closes at once; an unreapable child must not hold
|
|
27
31
|
* the promise open past the caller's own deadline. */
|
|
@@ -123,7 +127,7 @@ export function machineSshArgs(
|
|
|
123
127
|
"-o",
|
|
124
128
|
"StrictHostKeyChecking=accept-new",
|
|
125
129
|
"-o",
|
|
126
|
-
|
|
130
|
+
`ConnectTimeout=${MACHINE_SSH_CONNECT_TIMEOUT_SECONDS}`,
|
|
127
131
|
"-i",
|
|
128
132
|
target.keyPath,
|
|
129
133
|
"-p",
|
|
@@ -166,7 +170,7 @@ export function machineEnvironmentSshArgs(
|
|
|
166
170
|
"-o",
|
|
167
171
|
"StrictHostKeyChecking=accept-new",
|
|
168
172
|
"-o",
|
|
169
|
-
|
|
173
|
+
`ConnectTimeout=${MACHINE_SSH_CONNECT_TIMEOUT_SECONDS}`,
|
|
170
174
|
"-i",
|
|
171
175
|
target.keyPath,
|
|
172
176
|
"-p",
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Moondeck Station machine payload image: its identity, and the ONE place
|
|
3
|
+
* the AWS-host lookup's eligibility gate is defined (plan "AWS hosts on
|
|
4
|
+
* Moondeck Station" rev 3, §1).
|
|
5
|
+
*
|
|
6
|
+
* Gate: decision D1, branch T (the shared-tag channel). An image is eligible
|
|
7
|
+
* only when it is owned by the Moondeck account, named
|
|
8
|
+
* `moondeck-station-machine-payload-v1-YYYYMMDD-HHMM`, arm64, available,
|
|
9
|
+
* PUBLIC, carries the shared tags `ec2:SharedTag/io.moondeck.payload=station-v1`
|
|
10
|
+
* and `ec2:SharedTag/io.moondeck.channel=stable` (visible to every account
|
|
11
|
+
* that can see the image; only the owner can set them), is not deprecated,
|
|
12
|
+
* and its name sorts at or above the floor. Publishing alone selects nothing;
|
|
13
|
+
* `promote` (the channel tag) does.
|
|
14
|
+
*
|
|
15
|
+
* Every requirement is a compile-time constant of the frozen
|
|
16
|
+
* PRODUCTION_PAYLOAD_SELECTOR. No env var, config field or runtime fallback
|
|
17
|
+
* can drop or relax one; a requirement that cannot be read fails closed. The
|
|
18
|
+
* only other selector is the non-packaged canary driver's
|
|
19
|
+
* (scripts/machine-canary-aws.mjs), passed explicitly to
|
|
20
|
+
* createAwsMachineProvider; production construction (task-environment/
|
|
21
|
+
* index.ts) passes none, and a test asserts it.
|
|
22
|
+
*
|
|
23
|
+
* Imported by the cloud too (lib/machines/runtime.ts, lib/machines/aws.ts),
|
|
24
|
+
* so it must stay dependency-free.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** The Moondeck account that bakes and publishes the payload images. */
|
|
28
|
+
export const PAYLOAD_AMI_OWNER = "277057415208";
|
|
29
|
+
|
|
30
|
+
export const STATION_MACHINE_AMI_PREFIX = "moondeck-station-machine-payload-v1";
|
|
31
|
+
/** Ordinary (owner-only) tag the cloud's pinned check reads. */
|
|
32
|
+
export const STATION_MACHINE_AMI_TAG = "io.moondeck.payload";
|
|
33
|
+
export const STATION_MACHINE_AMI_TAG_VALUE = "station-v1";
|
|
34
|
+
/** Written by payload-bootstrap.sh for the Station cohort only; probed on
|
|
35
|
+
* every auto-selected machine before any workspace prep (task-environment/
|
|
36
|
+
* machine.ts). */
|
|
37
|
+
export const STATION_MACHINE_PAYLOAD_MARKER = "/var/lib/moondeck/station-payload-v1";
|
|
38
|
+
|
|
39
|
+
/** Shared tags (`ec2:SharedTag/` prefix): visible to every account that can
|
|
40
|
+
* see the image, public included, and writable only by its owner. */
|
|
41
|
+
export const SHARED_PAYLOAD_TAG = "ec2:SharedTag/io.moondeck.payload";
|
|
42
|
+
export const SHARED_CHANNEL_TAG = "ec2:SharedTag/io.moondeck.channel";
|
|
43
|
+
export const STABLE_CHANNEL = "stable";
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The floor: the oldest image name a Station release will still select.
|
|
47
|
+
* Names are fixed-width (`…-YYYYMMDD-HHMM`), so string order is time order.
|
|
48
|
+
*
|
|
49
|
+
* N1, the first Station payload image (us-west-2 ami-019703ad02ec97b40, its
|
|
50
|
+
* us-east-1 copy ami-012d87cec8aacd5dd). Recorded by the owner on 2026-11-06
|
|
51
|
+
* with D1 = T, after test 6.1. It moves only in a Station release, and never
|
|
52
|
+
* above N-1 (plan §4: rollback needs N-1 to stay eligible).
|
|
53
|
+
*/
|
|
54
|
+
export const STATION_PAYLOAD_MIN_NAME = "moondeck-station-machine-payload-v1-20261106-0051";
|
|
55
|
+
|
|
56
|
+
/** How long a successful lookup's image may still be launched while later
|
|
57
|
+
* lookups keep FAILING. Not a bound from a demotion: a successful but stale
|
|
58
|
+
* DescribeImages answer refreshes it (AWS gives no propagation SLA). */
|
|
59
|
+
export const STALE_MAX_MS = 30 * 60_000;
|
|
60
|
+
|
|
61
|
+
export interface PayloadImageSelector {
|
|
62
|
+
readonly owner: string;
|
|
63
|
+
/** Names must match `^<namePrefix>-\d{8}-\d{4}$`. */
|
|
64
|
+
readonly namePrefix: string;
|
|
65
|
+
/** Lowest eligible name (inclusive); a well-formed name of this prefix. */
|
|
66
|
+
readonly minName: string;
|
|
67
|
+
/** Applied to BOTH the server-side `is-public` filter and the client-side
|
|
68
|
+
* `Public` check. */
|
|
69
|
+
readonly requirePublic: boolean;
|
|
70
|
+
/** Exact key=value tags, filtered server-side and re-checked client-side. */
|
|
71
|
+
readonly requiredTags: readonly { readonly key: string; readonly value: string }[];
|
|
72
|
+
/** For the error text: what "approved" means under this gate. */
|
|
73
|
+
readonly gateDescription: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const PRODUCTION_PAYLOAD_SELECTOR: PayloadImageSelector = Object.freeze({
|
|
77
|
+
owner: PAYLOAD_AMI_OWNER,
|
|
78
|
+
namePrefix: STATION_MACHINE_AMI_PREFIX,
|
|
79
|
+
minName: STATION_PAYLOAD_MIN_NAME,
|
|
80
|
+
requirePublic: true,
|
|
81
|
+
requiredTags: Object.freeze([
|
|
82
|
+
Object.freeze({ key: SHARED_PAYLOAD_TAG, value: STATION_MACHINE_AMI_TAG_VALUE }),
|
|
83
|
+
Object.freeze({ key: SHARED_CHANNEL_TAG, value: STABLE_CHANNEL }),
|
|
84
|
+
]),
|
|
85
|
+
gateDescription: "public, stable channel",
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
/** One image as DescribeImages reports it (the fields the gate reads). */
|
|
89
|
+
export interface DescribedImage {
|
|
90
|
+
ImageId?: unknown;
|
|
91
|
+
Name?: unknown;
|
|
92
|
+
OwnerId?: unknown;
|
|
93
|
+
Architecture?: unknown;
|
|
94
|
+
State?: unknown;
|
|
95
|
+
Public?: unknown;
|
|
96
|
+
DeprecationTime?: unknown;
|
|
97
|
+
Tags?: unknown;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface SelectedPayloadImage {
|
|
101
|
+
id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
/** Epoch ms, or null when the image has no deprecation time. */
|
|
104
|
+
deprecationTime: number | null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface PayloadImageSelection {
|
|
108
|
+
selected: SelectedPayloadImage | null;
|
|
109
|
+
rejected: { id: string; reason: string }[];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const NAME_SUFFIX = /^-\d{8}-\d{4}$/;
|
|
113
|
+
|
|
114
|
+
export function nameMatches(selector: PayloadImageSelector, name: string): boolean {
|
|
115
|
+
return (
|
|
116
|
+
name.startsWith(selector.namePrefix) &&
|
|
117
|
+
NAME_SUFFIX.test(name.slice(selector.namePrefix.length))
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The `describe-images` filters for this selector. The client re-checks
|
|
122
|
+
* every one of them; the filters only keep the answer small. */
|
|
123
|
+
export function payloadImageFilters(selector: PayloadImageSelector): string[] {
|
|
124
|
+
return [
|
|
125
|
+
`Name=name,Values=${selector.namePrefix}-*`,
|
|
126
|
+
"Name=state,Values=available",
|
|
127
|
+
"Name=architecture,Values=arm64",
|
|
128
|
+
...(selector.requirePublic ? ["Name=is-public,Values=true"] : []),
|
|
129
|
+
...selector.requiredTags.map((tag) => `Name=tag:${tag.key},Values=${tag.value}`),
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function noApprovedImageMessage(selector: PayloadImageSelector, region: string): string {
|
|
134
|
+
return (
|
|
135
|
+
`no approved Moondeck Station machine image (${selector.namePrefix}-*, ` +
|
|
136
|
+
`${selector.gateDescription}, ≥ ${selector.minName}) in ${region} — set ` +
|
|
137
|
+
"UAI_MACHINE_IMAGE to an AMI id, or ask Moondeck to publish this region"
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function rejection(image: DescribedImage, selector: PayloadImageSelector, nowMs: number): string | null {
|
|
142
|
+
if (typeof image.ImageId !== "string" || !image.ImageId.startsWith("ami-")) return "no image id";
|
|
143
|
+
if (image.OwnerId !== selector.owner) return `owner ${String(image.OwnerId)}`;
|
|
144
|
+
if (typeof image.Name !== "string" || !nameMatches(selector, image.Name)) return `name ${String(image.Name)}`;
|
|
145
|
+
if (image.Architecture !== "arm64") return `architecture ${String(image.Architecture)}`;
|
|
146
|
+
if (image.State !== "available") return `state ${String(image.State)}`;
|
|
147
|
+
if (selector.requirePublic && image.Public !== true) return "not public";
|
|
148
|
+
if (selector.requiredTags.length > 0) {
|
|
149
|
+
if (!Array.isArray(image.Tags)) return "tags unreadable";
|
|
150
|
+
for (const required of selector.requiredTags) {
|
|
151
|
+
const found = image.Tags.some(
|
|
152
|
+
(tag: unknown) =>
|
|
153
|
+
typeof tag === "object" && tag !== null &&
|
|
154
|
+
(tag as { Key?: unknown }).Key === required.key &&
|
|
155
|
+
(tag as { Value?: unknown }).Value === required.value,
|
|
156
|
+
);
|
|
157
|
+
if (!found) return `missing ${required.key}=${required.value}`;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (image.DeprecationTime !== undefined && image.DeprecationTime !== null) {
|
|
161
|
+
if (typeof image.DeprecationTime !== "string") return "deprecation time unreadable";
|
|
162
|
+
const at = Date.parse(image.DeprecationTime);
|
|
163
|
+
if (!Number.isFinite(at)) return "deprecation time unreadable";
|
|
164
|
+
if (!(nowMs < at)) return "deprecated";
|
|
165
|
+
}
|
|
166
|
+
if (image.Name < selector.minName) return `below the floor ${selector.minName}`;
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Pure: the newest (by name) image meeting every requirement, plus why each
|
|
171
|
+
* other image was rejected. */
|
|
172
|
+
export function selectStationPayloadImage(
|
|
173
|
+
images: readonly DescribedImage[],
|
|
174
|
+
selector: PayloadImageSelector,
|
|
175
|
+
nowMs: number,
|
|
176
|
+
): PayloadImageSelection {
|
|
177
|
+
const rejected: { id: string; reason: string }[] = [];
|
|
178
|
+
let best: SelectedPayloadImage | null = null;
|
|
179
|
+
for (const image of images) {
|
|
180
|
+
const reason = rejection(image, selector, nowMs);
|
|
181
|
+
if (reason !== null) {
|
|
182
|
+
rejected.push({ id: typeof image.ImageId === "string" ? image.ImageId : "?", reason });
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const name = image.Name as string;
|
|
186
|
+
if (best === null || name > best.name) {
|
|
187
|
+
const deprecation = typeof image.DeprecationTime === "string" ? Date.parse(image.DeprecationTime) : null;
|
|
188
|
+
best = { id: image.ImageId as string, name, deprecationTime: deprecation };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return { selected: best, rejected };
|
|
192
|
+
}
|