hammerkit 2.1.0-next.14 → 2.1.0-next.16
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/dist/executer/runner-commands.js +36 -0
- package/dist/kubernetes/follow-pod-logs.js +8 -5
- package/dist/kubernetes/kept-claims.js +26 -5
- package/dist/kubernetes/sandbox-runner.js +526 -156
- package/dist/optimizer/get-work-cache-stats.js +7 -0
- package/dist/planner/work-item-status.js +12 -2
- package/dist/planner/work-runtime-kubernetes.js +251 -51
- package/dist/server/executor.js +3 -0
- package/dist/server/kubernetes-backend.js +28 -7
- package/dist/server/run-worker.js +118 -30
- package/dist/server/runs.js +163 -6
- package/dist/server/sandbox-files.js +7 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.workerMain = exports.readInput = exports.taskCommands = exports.taskCauses = exports.describeFailures = exports.failedTasks = exports.runTasks = exports.getEndpointTargets = exports.publishEndpoints = exports.getRunNetwork = exports.workerInputSchema = void 0;
|
|
3
|
+
exports.workerMain = exports.readInput = exports.taskCommands = exports.taskCauses = exports.describeFailures = exports.failedTasks = exports.runTasks = exports.relayStatus = exports.removeCommandsOfRun = exports.getRunnerCommands = exports.getLogEvent = exports.getEndpointTargets = exports.publishEndpoints = exports.getRunNetwork = exports.workerInputSchema = void 0;
|
|
4
4
|
const readline_1 = require("readline");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const cli_1 = require("../cli");
|
|
@@ -30,6 +30,8 @@ const kubernetes_instance_1 = require("../kubernetes/kubernetes-instance");
|
|
|
30
30
|
const check_keys_1 = require("../optimizer/check-keys");
|
|
31
31
|
const units_2 = require("../utils/units");
|
|
32
32
|
const keep_artifacts_1 = require("./keep-artifacts");
|
|
33
|
+
const sandbox_runner_1 = require("../kubernetes/sandbox-runner");
|
|
34
|
+
const runner_commands_1 = require("../executer/runner-commands");
|
|
33
35
|
// one log line of a task is cut here, the registry caps how many events a run keeps
|
|
34
36
|
const MAX_LOG_TEXT = 8 * 1024;
|
|
35
37
|
/**
|
|
@@ -90,6 +92,26 @@ exports.workerInputSchema = zod_1.z
|
|
|
90
92
|
.object({ directory: zod_1.z.string().min(1), maxBytes: zod_1.z.number().int().positive() })
|
|
91
93
|
.strict()
|
|
92
94
|
.optional(),
|
|
95
|
+
// the run executed before a restart of the server: how far its log holds the output of
|
|
96
|
+
// each command in a sandbox's runner (RunContext.resumed)
|
|
97
|
+
resumed: zod_1.z
|
|
98
|
+
.object({
|
|
99
|
+
outputs: zod_1.z
|
|
100
|
+
.record(zod_1.z.string().regex(runner_commands_1.COMMAND_ID_PATTERN), zod_1.z
|
|
101
|
+
.object({
|
|
102
|
+
task: zod_1.z.string().max(1024),
|
|
103
|
+
step: zod_1.z.number().int().nonnegative(),
|
|
104
|
+
execution: zod_1.z.number().int().nonnegative(),
|
|
105
|
+
stdout: zod_1.z.number().int().nonnegative(),
|
|
106
|
+
stderr: zod_1.z.number().int().nonnegative(),
|
|
107
|
+
done: zod_1.z.literal(true).optional(),
|
|
108
|
+
cut: zod_1.z.literal(true).optional(),
|
|
109
|
+
})
|
|
110
|
+
.strict())
|
|
111
|
+
.refine((outputs) => Object.keys(outputs).length <= runner_commands_1.MAX_OUTPUT_COMMANDS, 'too many commands'),
|
|
112
|
+
})
|
|
113
|
+
.strict()
|
|
114
|
+
.optional(),
|
|
93
115
|
})
|
|
94
116
|
.strict();
|
|
95
117
|
// The ceiling of the run, combined here and not in the server: the lower of two allow lists
|
|
@@ -153,6 +175,72 @@ function getEndpointTargets(workTree, up, kubernetes) {
|
|
|
153
175
|
return targets;
|
|
154
176
|
}
|
|
155
177
|
exports.getEndpointTargets = getEndpointTargets;
|
|
178
|
+
// What the run says of a message of the engine: the output of its tasks and services, and
|
|
179
|
+
// what went wrong; where the log of a pod got to with a line of it (RunEventData)
|
|
180
|
+
function getLogEvent(message) {
|
|
181
|
+
if (message.type === 'console') {
|
|
182
|
+
return {
|
|
183
|
+
type: 'log',
|
|
184
|
+
task: message.context.name,
|
|
185
|
+
stream: message.console,
|
|
186
|
+
text: message.message.slice(0, MAX_LOG_TEXT),
|
|
187
|
+
...(message.cursor ? { cursor: message.cursor } : {}),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (message.level === 'error' || message.level === 'warn') {
|
|
191
|
+
return { type: 'log', task: message.context.name, stream: 'stderr', text: message.message.slice(0, MAX_LOG_TEXT) };
|
|
192
|
+
}
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
exports.getLogEvent = getLogEvent;
|
|
196
|
+
// What the commands of the run in a sandbox's runner know of it: the ones it started before a
|
|
197
|
+
// restart and how far its log held their output, and the `output` events that say how far it
|
|
198
|
+
// holds it now. They go out through `emit` after the log lines they count, so the registry
|
|
199
|
+
// never keeps an offset ahead of its log.
|
|
200
|
+
function getRunnerCommands(input, emit) {
|
|
201
|
+
return (0, runner_commands_1.createRunnerCommands)({
|
|
202
|
+
...(input.resumed ? { resumed: input.resumed.outputs } : {}),
|
|
203
|
+
reached: (command, record) => emit({ type: 'output', command, ...record }),
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
exports.getRunnerCommands = getRunnerCommands;
|
|
207
|
+
// What the commands of a run that ended left in the sandbox goes: they are killed and their
|
|
208
|
+
// directory removed. Not when the server went (it stops, or died): the run resumes with the
|
|
209
|
+
// next one, which takes its commands up again. A server that stops kills this process before.
|
|
210
|
+
async function removeCommandsOfRun(input, commands, emit) {
|
|
211
|
+
const kubernetes = input.kubernetes;
|
|
212
|
+
const workspace = kubernetes?.server?.workspace;
|
|
213
|
+
if (!kubernetes || !workspace?.runner || commands.executions.size === 0) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
await (0, sandbox_runner_1.removeRunCommands)((0, kubernetes_instance_1.createKubernetesInstances)(kubernetes), kubernetes.namespace, workspace.label, kubernetes.server.run, {
|
|
218
|
+
clean: true,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
emit({
|
|
223
|
+
type: 'log',
|
|
224
|
+
task: 'hammerkit',
|
|
225
|
+
stream: 'stderr',
|
|
226
|
+
text: `what the commands of the run left in the sandbox could not be removed: ${(0, log_1.getErrorMessage)(e)}`,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.removeCommandsOfRun = removeCommandsOfRun;
|
|
231
|
+
// What a task says in the process of a run, as events: the lines it prints (with where the log
|
|
232
|
+
// of its pod got to) and its warnings and errors, in the order they come. The `output` events
|
|
233
|
+
// of the commands in a runner are emitted after the lines they count, on the same way (see
|
|
234
|
+
// getRunnerCommands).
|
|
235
|
+
function relayStatus(status, emit) {
|
|
236
|
+
return status.on((message) => {
|
|
237
|
+
const event = getLogEvent(message);
|
|
238
|
+
if (event) {
|
|
239
|
+
emit(event);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
exports.relayStatus = relayStatus;
|
|
156
244
|
/**
|
|
157
245
|
* Executes the tasks of a run with the engine of `hammerkit run`. The caller says which
|
|
158
246
|
* process this is in: it reports what happens through `emit` and stops when `abortCtrl`
|
|
@@ -162,7 +250,9 @@ async function runTasks(input, cwd, processEnvs, abortCtrl,
|
|
|
162
250
|
// whether the run was stopped from outside; the engine aborts too when a task fails
|
|
163
251
|
cancelled, emit,
|
|
164
252
|
// a service run: its services are ready, at these addresses
|
|
165
|
-
up
|
|
253
|
+
up,
|
|
254
|
+
// its commands in a sandbox's runner
|
|
255
|
+
commands = getRunnerCommands(input, emit)) {
|
|
166
256
|
const secrets = (0, redact_1.createSecretRegistry)();
|
|
167
257
|
const status = (0, work_item_status_1.statusConsole)((0, empty_writable_1.emptyWritable)(), secrets);
|
|
168
258
|
// the process starts in a directory of the server, the tasks work on the run's files
|
|
@@ -176,6 +266,7 @@ up) {
|
|
|
176
266
|
accounts: input.accounts,
|
|
177
267
|
kubernetes: input.kubernetes,
|
|
178
268
|
capabilityRuntime: input.capabilityRuntime,
|
|
269
|
+
runnerCommands: commands,
|
|
179
270
|
},
|
|
180
271
|
abortCtrl,
|
|
181
272
|
cwd: work,
|
|
@@ -187,24 +278,7 @@ up) {
|
|
|
187
278
|
stderr: (0, empty_writable_1.emptyWritable)(),
|
|
188
279
|
stdoutColumns: 120,
|
|
189
280
|
};
|
|
190
|
-
const listener = status
|
|
191
|
-
if (message.type === 'console') {
|
|
192
|
-
emit({
|
|
193
|
-
type: 'log',
|
|
194
|
-
task: message.context.name,
|
|
195
|
-
stream: message.console,
|
|
196
|
-
text: message.message.slice(0, MAX_LOG_TEXT),
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
else if (message.level === 'error' || message.level === 'warn') {
|
|
200
|
-
emit({
|
|
201
|
-
type: 'log',
|
|
202
|
-
task: message.context.name,
|
|
203
|
-
stream: 'stderr',
|
|
204
|
-
text: message.message.slice(0, MAX_LOG_TEXT),
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
});
|
|
281
|
+
const listener = relayStatus(status, emit);
|
|
208
282
|
try {
|
|
209
283
|
const options = input.options;
|
|
210
284
|
const execOptions = {
|
|
@@ -595,17 +669,31 @@ async function workerMain(stdin, stdout, processEnvs, cwd, abortCtrl) {
|
|
|
595
669
|
say({ kind: 'result', ok: false, error: `the run could not be read: ${e instanceof Error ? e.message : e}` });
|
|
596
670
|
return;
|
|
597
671
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
672
|
+
// the input ends before the run does: the server is gone
|
|
673
|
+
let gone = false;
|
|
674
|
+
reader.onEnd(() => {
|
|
675
|
+
gone = true;
|
|
676
|
+
if (input.up) {
|
|
677
|
+
// services stay until they are stopped: without the server that would stop them, at
|
|
678
|
+
// their ttl or on a cancel, nothing would
|
|
679
|
+
stop();
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
const emit = (event) => say({ kind: 'event', event });
|
|
683
|
+
const commands = getRunnerCommands(input, emit);
|
|
603
684
|
try {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
685
|
+
let result;
|
|
686
|
+
try {
|
|
687
|
+
await runTasks(input, cwd, processEnvs, abortCtrl, () => cancelled, emit, (targets) => say({ kind: 'up', targets }), commands);
|
|
688
|
+
result = { kind: 'result', ok: true };
|
|
689
|
+
}
|
|
690
|
+
catch (e) {
|
|
691
|
+
result = { kind: 'result', ok: false, error: e instanceof Error ? e.message : String(e) };
|
|
692
|
+
}
|
|
693
|
+
if (!gone) {
|
|
694
|
+
await removeCommandsOfRun(input, commands, emit);
|
|
695
|
+
}
|
|
696
|
+
say(result);
|
|
609
697
|
}
|
|
610
698
|
finally {
|
|
611
699
|
reader.close();
|
package/dist/server/runs.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unavailableExecutor = exports.RunRegistry = exports.MAX_COMMANDS = exports.MAX_TASK_ERROR = exports.MAX_CAUSES = exports.MAX_RESUMES = exports.CLOSE_TIMEOUT = exports.SANDBOX_ID_PATTERN = exports.RUN_ID_PATTERN = exports.QuotaError = exports.ShuttingDownError = exports.RunError = exports.isDetached = exports.RUN_PHASES = exports.isFinal = void 0;
|
|
3
|
+
exports.unavailableExecutor = exports.RunRegistry = exports.isLogCursor = exports.logCursors = exports.MAX_CURSORS_PER_ITEM = exports.MAX_COMMANDS = exports.MAX_TASK_ERROR = exports.MAX_CAUSES = exports.MAX_RESUMES = exports.CLOSE_TIMEOUT = exports.SANDBOX_ID_PATTERN = exports.RUN_ID_PATTERN = exports.QuotaError = exports.ShuttingDownError = exports.RunError = exports.isDetached = exports.RUN_PHASES = exports.isFinal = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const oauth_1 = require("./oauth");
|
|
6
|
+
const runner_commands_1 = require("../executer/runner-commands");
|
|
6
7
|
const run_logs_1 = require("./run-logs");
|
|
7
8
|
const units_1 = require("../utils/units");
|
|
8
9
|
const FINAL_STATES = ['succeeded', 'failed', 'cancelled', 'rejected'];
|
|
@@ -147,6 +148,70 @@ function eventSize(event) {
|
|
|
147
148
|
}
|
|
148
149
|
return event.type === 'log' ? Buffer.byteLength(event.text) + 64 : event.type === 'task' ? taskEventSize(event) : 64;
|
|
149
150
|
}
|
|
151
|
+
// the instances of the container of a task or service whose cursors a run keeps: the kubelet
|
|
152
|
+
// keeps the log of the one that runs and of the one before it
|
|
153
|
+
exports.MAX_CURSORS_PER_ITEM = 10;
|
|
154
|
+
// lines with the same time of a log, which has nanoseconds
|
|
155
|
+
const MAX_CURSOR_COUNT = 1000000;
|
|
156
|
+
// The cursors of a record, as the registry keeps them: by task, those of a pod's log
|
|
157
|
+
function logCursors(cursors) {
|
|
158
|
+
const kept = new Map();
|
|
159
|
+
if (!cursors || typeof cursors !== 'object' || Array.isArray(cursors)) {
|
|
160
|
+
return kept;
|
|
161
|
+
}
|
|
162
|
+
for (const [item, list] of Object.entries(cursors)) {
|
|
163
|
+
if (kept.size >= MAX_KEYED_TASKS) {
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
const valid = Array.isArray(list) ? list.filter(isLogCursor).slice(-exports.MAX_CURSORS_PER_ITEM) : [];
|
|
167
|
+
if (valid.length > 0) {
|
|
168
|
+
kept.set(item, valid.map(copyCursor));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return kept;
|
|
172
|
+
}
|
|
173
|
+
exports.logCursors = logCursors;
|
|
174
|
+
function isLogCursor(cursor) {
|
|
175
|
+
const value = cursor;
|
|
176
|
+
return (!!value &&
|
|
177
|
+
typeof value === 'object' &&
|
|
178
|
+
typeof value.container === 'string' &&
|
|
179
|
+
value.container.length > 0 &&
|
|
180
|
+
value.container.length <= 256 &&
|
|
181
|
+
typeof value.at === 'string' &&
|
|
182
|
+
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{9}$/.test(value.at) &&
|
|
183
|
+
Number.isSafeInteger(value.count) &&
|
|
184
|
+
value.count >= 0 &&
|
|
185
|
+
value.count <= MAX_CURSOR_COUNT);
|
|
186
|
+
}
|
|
187
|
+
exports.isLogCursor = isLogCursor;
|
|
188
|
+
function copyCursor(cursor) {
|
|
189
|
+
return { container: cursor.container, at: cursor.at, count: cursor.count };
|
|
190
|
+
}
|
|
191
|
+
// Where the log of an instance got to: in place of the cursor it had, the newest last
|
|
192
|
+
function keepCursor(cursors, item, cursor) {
|
|
193
|
+
const list = cursors.get(item);
|
|
194
|
+
if (!list) {
|
|
195
|
+
if (cursors.size < MAX_KEYED_TASKS) {
|
|
196
|
+
cursors.set(item, [copyCursor(cursor)]);
|
|
197
|
+
}
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const index = list.findIndex((kept) => kept.container === cursor.container);
|
|
201
|
+
if (index >= 0) {
|
|
202
|
+
list.splice(index, 1);
|
|
203
|
+
}
|
|
204
|
+
list.push(copyCursor(cursor));
|
|
205
|
+
list.splice(0, Math.max(0, list.length - exports.MAX_CURSORS_PER_ITEM));
|
|
206
|
+
}
|
|
207
|
+
// without a prototype: an item may be named as a property of any object
|
|
208
|
+
function cursorsOf(cursors) {
|
|
209
|
+
const record = Object.create(null);
|
|
210
|
+
for (const [item, list] of cursors) {
|
|
211
|
+
record[item] = list.map(copyCursor);
|
|
212
|
+
}
|
|
213
|
+
return record;
|
|
214
|
+
}
|
|
150
215
|
// The check keys of a record, as the registry keeps them: by task, a key or null
|
|
151
216
|
function checkKeys(keys) {
|
|
152
217
|
if (!keys || typeof keys !== 'object' || Array.isArray(keys)) {
|
|
@@ -156,6 +221,39 @@ function checkKeys(keys) {
|
|
|
156
221
|
.filter(([, key]) => key === null || typeof key === 'string')
|
|
157
222
|
.slice(0, MAX_KEYED_TASKS));
|
|
158
223
|
}
|
|
224
|
+
// The commands of a record, as the registry keeps them (`output` events)
|
|
225
|
+
function commandRecords(outputs) {
|
|
226
|
+
if (!outputs || typeof outputs !== 'object' || Array.isArray(outputs)) {
|
|
227
|
+
return {};
|
|
228
|
+
}
|
|
229
|
+
return Object.fromEntries(Object.entries(outputs)
|
|
230
|
+
.flatMap(([command, record]) => {
|
|
231
|
+
const kept = toCommandRecord({ ...record, command });
|
|
232
|
+
return kept ? [[command, kept]] : [];
|
|
233
|
+
})
|
|
234
|
+
.slice(0, runner_commands_1.MAX_OUTPUT_COMMANDS));
|
|
235
|
+
}
|
|
236
|
+
// What an `output` event says of its command, when it is one
|
|
237
|
+
function toCommandRecord(event) {
|
|
238
|
+
const count = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
239
|
+
if (typeof event?.command !== 'string' ||
|
|
240
|
+
!runner_commands_1.COMMAND_ID_PATTERN.test(event.command) ||
|
|
241
|
+
typeof event.task !== 'string' ||
|
|
242
|
+
event.task.length > 1024 ||
|
|
243
|
+
![event.step, event.execution, event.stdout, event.stderr].every(count)) {
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
const { task, step, execution, stdout, stderr } = event;
|
|
247
|
+
return {
|
|
248
|
+
task,
|
|
249
|
+
step,
|
|
250
|
+
execution,
|
|
251
|
+
stdout,
|
|
252
|
+
stderr,
|
|
253
|
+
...(event.done === true ? { done: true } : {}),
|
|
254
|
+
...(event.cut === true ? { cut: true } : {}),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
159
257
|
// What keeps the run of a record from executing again: what it runs, from where, is not in it
|
|
160
258
|
function unresumable(run) {
|
|
161
259
|
if (typeof run.id !== 'string' || !exports.RUN_ID_PATTERN.test(run.id)) {
|
|
@@ -228,7 +326,7 @@ class RunRegistry {
|
|
|
228
326
|
// the queue as it was: the runs that executed first, then the others as they were queued
|
|
229
327
|
const resuming = [];
|
|
230
328
|
skipped.forEach((name) => this.options.log?.(`skip run record ${name}: it can not be read`));
|
|
231
|
-
for (const { run, events, keys, clean } of records) {
|
|
329
|
+
for (const { run, events, keys, cursors, outputs, clean } of records) {
|
|
232
330
|
// a move that executed went with the server
|
|
233
331
|
delete run.moving;
|
|
234
332
|
const entry = {
|
|
@@ -241,6 +339,8 @@ class RunRegistry {
|
|
|
241
339
|
tails: new Map(Object.entries(run.results ?? {}).map(([task, result]) => [task, result.lastLog])),
|
|
242
340
|
saving: Promise.resolve(),
|
|
243
341
|
keys: checkKeys(keys),
|
|
342
|
+
cursors: logCursors(cursors),
|
|
343
|
+
outputs: commandRecords(outputs),
|
|
244
344
|
};
|
|
245
345
|
this.entries.set(run.id, entry);
|
|
246
346
|
if (run.state === 'awaiting-approval') {
|
|
@@ -398,6 +498,7 @@ class RunRegistry {
|
|
|
398
498
|
tails: new Map(),
|
|
399
499
|
saving: Promise.resolve(),
|
|
400
500
|
keys: {},
|
|
501
|
+
cursors: new Map(),
|
|
401
502
|
};
|
|
402
503
|
this.entries.set(run.id, entry);
|
|
403
504
|
if (waiting) {
|
|
@@ -986,14 +1087,18 @@ class RunRegistry {
|
|
|
986
1087
|
runningOf(owner) {
|
|
987
1088
|
return this.usage(owner).running.length;
|
|
988
1089
|
}
|
|
989
|
-
// The run on the same sandbox that executes: a sandbox runs one at a time.
|
|
1090
|
+
// The run on the same sandbox that executes: a sandbox runs one at a time. One that executed
|
|
1091
|
+
// before a restart and resumes holds it from the queue too: what it runs on in the sandbox's
|
|
1092
|
+
// runner is not another run's to clean up.
|
|
990
1093
|
sandboxBusy(run) {
|
|
991
1094
|
const source = run.source;
|
|
992
1095
|
if (source.type !== 'sandbox') {
|
|
993
1096
|
return undefined;
|
|
994
1097
|
}
|
|
995
|
-
|
|
996
|
-
|
|
1098
|
+
const resuming = this.entries.get(run.id)?.resumed;
|
|
1099
|
+
return [...this.entries.values()].find((entry) => onSandbox(entry.run, source.id) &&
|
|
1100
|
+
(entry.run.state === 'running' ||
|
|
1101
|
+
(entry.run.state === 'queued' && entry.resumed && !resuming && entry.run.id !== run.id)))?.run.id;
|
|
997
1102
|
}
|
|
998
1103
|
// The run that executes and holds what the run would (RunExecutor.excludes)
|
|
999
1104
|
held(run) {
|
|
@@ -1059,7 +1164,8 @@ class RunRegistry {
|
|
|
1059
1164
|
async execute(entry) {
|
|
1060
1165
|
// a run that resumes executes again: what it left is this execution's to remove, and its
|
|
1061
1166
|
// time counts from its first start (a service run that was up gets it again)
|
|
1062
|
-
const
|
|
1167
|
+
const resumed = !!entry.resumed;
|
|
1168
|
+
const continues = resumed && !!entry.run.startedAt && !entry.run.upAt;
|
|
1063
1169
|
entry.resumed = false;
|
|
1064
1170
|
entry.run.state = 'running';
|
|
1065
1171
|
if (!continues) {
|
|
@@ -1089,6 +1195,16 @@ class RunRegistry {
|
|
|
1089
1195
|
emit: (event) => this.record(entry, event),
|
|
1090
1196
|
signal: entry.abort.signal,
|
|
1091
1197
|
detached: () => !!entry.detached,
|
|
1198
|
+
...(resumed
|
|
1199
|
+
? {
|
|
1200
|
+
resumed: {
|
|
1201
|
+
logs: cursorsOf(entry.cursors),
|
|
1202
|
+
// the commands it started in a sandbox's runner, which a run that went on
|
|
1203
|
+
// takes up again
|
|
1204
|
+
...(continues ? { outputs: { ...entry.outputs } } : {}),
|
|
1205
|
+
},
|
|
1206
|
+
}
|
|
1207
|
+
: {}),
|
|
1092
1208
|
...(Object.keys(durations).length > 0 ? { durations } : {}),
|
|
1093
1209
|
...(this.options.artifacts && !entry.run.up
|
|
1094
1210
|
? {
|
|
@@ -1763,6 +1879,18 @@ class RunRegistry {
|
|
|
1763
1879
|
this.keepPhase(entry, recorded);
|
|
1764
1880
|
return;
|
|
1765
1881
|
}
|
|
1882
|
+
if (recorded.type === 'log' && 'cursor' in recorded) {
|
|
1883
|
+
// with the line it came with: a record has the cursor of the last line it has
|
|
1884
|
+
const { cursor, ...line } = recorded;
|
|
1885
|
+
if (isLogCursor(cursor)) {
|
|
1886
|
+
keepCursor(entry.cursors, recorded.task, cursor);
|
|
1887
|
+
}
|
|
1888
|
+
recorded = line;
|
|
1889
|
+
}
|
|
1890
|
+
if (recorded.type === 'output') {
|
|
1891
|
+
this.keepCommand(entry, recorded);
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1766
1894
|
const event = recorded.type === 'task' ? bounded(recorded) : recorded;
|
|
1767
1895
|
if (event.type === 'log') {
|
|
1768
1896
|
this.keepTail(entry, event.task, event.text);
|
|
@@ -1789,6 +1917,29 @@ class RunRegistry {
|
|
|
1789
1917
|
}
|
|
1790
1918
|
this.push(entry, event);
|
|
1791
1919
|
}
|
|
1920
|
+
// the newest of each command; past MAX_OUTPUT_COMMANDS one that ended makes way for a new one,
|
|
1921
|
+
// which a run that resumes would start again
|
|
1922
|
+
keepCommand(entry, event) {
|
|
1923
|
+
const record = toCommandRecord(event);
|
|
1924
|
+
if (!record) {
|
|
1925
|
+
return;
|
|
1926
|
+
}
|
|
1927
|
+
const outputs = (entry.outputs ?? (entry.outputs = {}));
|
|
1928
|
+
const started = !(event.command in outputs);
|
|
1929
|
+
if (started && Object.keys(outputs).length >= runner_commands_1.MAX_OUTPUT_COMMANDS) {
|
|
1930
|
+
const ended = Object.keys(outputs).find((command) => outputs[command].done);
|
|
1931
|
+
if (!ended) {
|
|
1932
|
+
return;
|
|
1933
|
+
}
|
|
1934
|
+
delete outputs[ended];
|
|
1935
|
+
}
|
|
1936
|
+
outputs[event.command] = record;
|
|
1937
|
+
if (started && !this.closed) {
|
|
1938
|
+
// written down at once: a server killed before its next write would have the run resume
|
|
1939
|
+
// without it, start the command again and kill the one that runs
|
|
1940
|
+
this.persist(entry);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1792
1943
|
// once each, from the executor: a phase it reports again (a service run that wakes) is the
|
|
1793
1944
|
// newest
|
|
1794
1945
|
keepPhase(entry, event) {
|
|
@@ -1880,10 +2031,16 @@ class RunRegistry {
|
|
|
1880
2031
|
}
|
|
1881
2032
|
// the check keys of a run that resumes are the ones from before anything of it ran
|
|
1882
2033
|
const keys = isFinal(entry.run.state) || Object.keys(entry.keys).length === 0 ? {} : { keys: { ...entry.keys } };
|
|
2034
|
+
// where the logs of its pods got to, for the next server that resumes it
|
|
2035
|
+
const cursors = isFinal(entry.run.state) || entry.cursors.size === 0 ? {} : { cursors: cursorsOf(entry.cursors) };
|
|
2036
|
+
// what the log of a run that resumes holds of the output of its commands, as far as `events` go
|
|
2037
|
+
const outputs = isFinal(entry.run.state) || Object.keys(entry.outputs ?? {}).length === 0 ? {} : { outputs: { ...entry.outputs } };
|
|
1883
2038
|
const record = {
|
|
1884
2039
|
run: this.copy(entry.run),
|
|
1885
2040
|
events: [...entry.events],
|
|
1886
2041
|
...keys,
|
|
2042
|
+
...cursors,
|
|
2043
|
+
...outputs,
|
|
1887
2044
|
...(clean || this.written ? { clean: true } : {}),
|
|
1888
2045
|
};
|
|
1889
2046
|
entry.saving = entry.saving
|
|
@@ -11,6 +11,7 @@ const path_1 = require("path");
|
|
|
11
11
|
const minimatch_1 = require("minimatch");
|
|
12
12
|
const source_manifest_1 = require("../remote/source-manifest");
|
|
13
13
|
const sandbox_patch_1 = require("./sandbox-patch");
|
|
14
|
+
const runner_commands_1 = require("../executer/runner-commands");
|
|
14
15
|
// The largest file the API reads into memory, edits or writes: the limit of an upload.
|
|
15
16
|
exports.MAX_FILE_BYTES = source_manifest_1.MAX_SOURCE_FILE_BYTES;
|
|
16
17
|
// what one typed read answers at most
|
|
@@ -66,8 +67,13 @@ function checkPath(path) {
|
|
|
66
67
|
}
|
|
67
68
|
exports.checkPath = checkPath;
|
|
68
69
|
// The deny list of uploads, with the last name taken as a directory too, so `.git` itself
|
|
69
|
-
// is as denied as what is in it.
|
|
70
|
+
// is as denied as what is in it. The output of the commands of runs in the sandbox's runner
|
|
71
|
+
// is denied too: it is the runs' to read (their logs), not a file of the sandbox, and a file
|
|
72
|
+
// written there could pass for how a command ended.
|
|
70
73
|
function deniedPath(path) {
|
|
74
|
+
if (path === runner_commands_1.RUNNER_COMMANDS_DIRECTORY || path.startsWith(`${runner_commands_1.RUNNER_COMMANDS_DIRECTORY}/`)) {
|
|
75
|
+
return 'the commands of runs keep their output there';
|
|
76
|
+
}
|
|
71
77
|
return (0, source_manifest_1.deniedSourcePath)(path) ?? (0, source_manifest_1.deniedSourcePath)(`${path}/-`);
|
|
72
78
|
}
|
|
73
79
|
exports.deniedPath = deniedPath;
|
package/package.json
CHANGED