@foldrun/core 17.3.0 → 18.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/approvals.js +3 -3
- package/dist/src/blob-cache.d.ts +58 -0
- package/dist/src/blob-cache.js +312 -0
- package/dist/src/blob-pins.d.ts +44 -0
- package/dist/src/blob-pins.js +61 -0
- package/dist/src/blob-store.d.ts +47 -0
- package/dist/src/blob-store.js +362 -0
- package/dist/src/blob-sweeper.d.ts +70 -0
- package/dist/src/blob-sweeper.js +282 -0
- package/dist/src/blob-types.d.ts +145 -0
- package/dist/src/blob-types.js +115 -0
- package/dist/src/evals.js +1 -1
- package/dist/src/history.d.ts +92 -9
- package/dist/src/history.js +168 -20
- package/dist/src/journal-store.d.ts +58 -0
- package/dist/src/journal-store.js +117 -0
- package/dist/src/manifest.d.ts +92 -0
- package/dist/src/manifest.js +239 -0
- package/dist/src/ops-log.js +26 -3
- package/dist/src/platform.d.ts +7 -0
- package/dist/src/platform.js +1 -0
- package/dist/src/publish.d.ts +134 -0
- package/dist/src/publish.js +434 -0
- package/dist/src/records.d.ts +72 -0
- package/dist/src/records.js +24 -0
- package/dist/src/revision-store.d.ts +161 -0
- package/dist/src/revision-store.js +378 -0
- package/dist/src/run-container.d.ts +20 -0
- package/dist/src/run-container.js +61 -0
- package/dist/src/runner.js +1 -1
- package/dist/src/s3-blob-store.d.ts +29 -0
- package/dist/src/s3-blob-store.js +531 -0
- package/dist/src/state-retention.d.ts +15 -0
- package/dist/src/state-retention.js +65 -0
- package/dist/src/storage.d.ts +29 -1
- package/dist/src/storage.js +331 -81
- package/dist/src/store.d.ts +41 -0
- package/dist/src/store.js +188 -5
- package/dist/src/trigger-log.js +17 -0
- package/dist/src/workspace-revisions.d.ts +269 -0
- package/dist/src/workspace-revisions.js +1382 -0
- package/package.json +1 -1
- package/src/approvals.ts +3 -3
- package/src/blob-cache.ts +357 -0
- package/src/blob-pins.ts +99 -0
- package/src/blob-store.ts +389 -0
- package/src/blob-sweeper.ts +336 -0
- package/src/blob-types.ts +216 -0
- package/src/evals.ts +1 -1
- package/src/history.ts +226 -19
- package/src/journal-store.ts +152 -0
- package/src/manifest.ts +274 -0
- package/src/ops-log.ts +25 -3
- package/src/platform.ts +8 -0
- package/src/publish.ts +520 -0
- package/src/records.ts +105 -0
- package/src/revision-store.ts +513 -0
- package/src/run-container.ts +62 -0
- package/src/runner.ts +1 -1
- package/src/s3-blob-store.ts +560 -0
- package/src/state-retention.ts +83 -0
- package/src/storage.ts +335 -81
- package/src/store.ts +178 -5
- package/src/trigger-log.ts +15 -0
- package/src/workspace-revisions.ts +1423 -0
|
@@ -26,6 +26,7 @@ import crypto from "node:crypto";
|
|
|
26
26
|
import { spawn, spawnSync } from "node:child_process";
|
|
27
27
|
import { CAPTURE_CAP, isPlatformPath } from "./store.js";
|
|
28
28
|
import { divertedSummary, isDivertedPath, overlayTestWrites } from "./test-mode.js";
|
|
29
|
+
import { recordStepOutputs, pinRunBase } from "./workspace-revisions.js";
|
|
29
30
|
import { refusedBack, refusedLine, keptLine } from "./copy-back.js";
|
|
30
31
|
import { isFileValue, fileContent, installKeyMaterial } from "./secrets.js";
|
|
31
32
|
import { safeTenantSegment, systemInstallSh, SYSTEM_FROM_INPUT_SH, INSTALL_SOCKET, ROOT_ENV_RESET_SH, ROOT_SHELL_GUARD_SH, ROOT_ENV_FILE, STEP_ENV_FILE, stepEnvShell, rootEnvShell, SNAPSHOT_KEY_FILE } from "./runtime.js";
|
|
@@ -201,6 +202,39 @@ export function dropHandedIn(workspaceRoot, runId, ref) {
|
|
|
201
202
|
const file = handedInPath(workspaceRoot, runId, ref);
|
|
202
203
|
if (file)
|
|
203
204
|
fs.rmSync(file, { force: true });
|
|
205
|
+
const base = baseRevisionPath(workspaceRoot, runId, ref);
|
|
206
|
+
if (base)
|
|
207
|
+
fs.rmSync(base, { force: true });
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The revisions a step's stage-in started from (FOL-126 fixes), kept on the host
|
|
211
|
+
* beside what it was handed, for the same reason: a driver that inherits the
|
|
212
|
+
* step publishes its copy-back against the SAME base, not against whatever the
|
|
213
|
+
* heads hold by then. Platform-owned, never staged, erased with the run.
|
|
214
|
+
*/
|
|
215
|
+
export function baseRevisionPath(workspaceRoot, runId, ref) {
|
|
216
|
+
const file = handedInPath(workspaceRoot, runId, ref);
|
|
217
|
+
return file ? file.replace(/\.json$/, ".base.json") : null;
|
|
218
|
+
}
|
|
219
|
+
export function writeBaseRevision(workspaceRoot, runId, ref, base) {
|
|
220
|
+
const file = baseRevisionPath(workspaceRoot, runId, ref);
|
|
221
|
+
if (!file)
|
|
222
|
+
return;
|
|
223
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
224
|
+
fs.writeFileSync(file, JSON.stringify(base));
|
|
225
|
+
}
|
|
226
|
+
export function readBaseRevision(workspaceRoot, runId, ref) {
|
|
227
|
+
const file = baseRevisionPath(workspaceRoot, runId, ref);
|
|
228
|
+
if (!file)
|
|
229
|
+
return undefined;
|
|
230
|
+
try {
|
|
231
|
+
const m = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
232
|
+
const ok = (v) => v === null || typeof v === "string";
|
|
233
|
+
return m && ok(m.workspace) && ok(m.state) ? { workspace: m.workspace ?? null, state: m.state ?? null } : undefined;
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
204
238
|
}
|
|
205
239
|
/**
|
|
206
240
|
* Every file's mtime under `dir`, relative path to milliseconds — so a copy
|
|
@@ -286,6 +320,7 @@ export function mergeAppends(was, host, next) {
|
|
|
286
320
|
}
|
|
287
321
|
export function applyContainerChanges(hostWs, containerWs, baseline, note, divert, opts = {}) {
|
|
288
322
|
const applied = [];
|
|
323
|
+
const written = [];
|
|
289
324
|
// Files a sandbox: own job's reply copied into this sandbox mid-step
|
|
290
325
|
// (delegate-tools.ts copyBackFiles), path → sha256 of what was written: for
|
|
291
326
|
// those, that is what the step started from. The job's change is already on
|
|
@@ -377,10 +412,16 @@ export function applyContainerChanges(hostWs, containerWs, baseline, note, diver
|
|
|
377
412
|
// other run's ledger rows on 2026-09-14. Merge appends; keep both
|
|
378
413
|
// sides of anything else.
|
|
379
414
|
const hostMoved = was !== undefined && hostNow !== null && !same(hostNow);
|
|
415
|
+
// What the step was handed, as a sha (null: no such file; undefined: not
|
|
416
|
+
// known). It is the base the head is held to — unless the folder was
|
|
417
|
+
// merged, which already folded the other writer's change in.
|
|
418
|
+
const handed = was === undefined ? undefined : was === null ? null : typeof was === "string" ? was : sha(was);
|
|
419
|
+
let foldedIn = false;
|
|
380
420
|
if (hostMoved) {
|
|
381
421
|
const merged = mergeAppends(was ?? null, hostNow, next);
|
|
382
422
|
if (merged) {
|
|
383
423
|
next = merged;
|
|
424
|
+
foldedIn = true;
|
|
384
425
|
}
|
|
385
426
|
else {
|
|
386
427
|
const ext = path.extname(rel);
|
|
@@ -390,6 +431,7 @@ export function applyContainerChanges(hostWs, containerWs, baseline, note, diver
|
|
|
390
431
|
fs.mkdirSync(path.dirname(conflictAbs), { recursive: true });
|
|
391
432
|
fs.writeFileSync(conflictAbs, next);
|
|
392
433
|
applied.push(conflictRel);
|
|
434
|
+
written.push({ path: conflictRel.replaceAll("\\", "/"), base: null, after: next });
|
|
393
435
|
note?.(`write-back conflict on ${rel.replaceAll("\\", "/")}: it changed on the workspace while this step ran, ` +
|
|
394
436
|
`and not only by appending — kept the workspace's version; this step's version is ${conflictRel.replaceAll("\\", "/")}`);
|
|
395
437
|
continue;
|
|
@@ -410,9 +452,22 @@ export function applyContainerChanges(hostWs, containerWs, baseline, note, diver
|
|
|
410
452
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
411
453
|
fs.writeFileSync(target, next);
|
|
412
454
|
applied.push(rel);
|
|
455
|
+
// The pinned base is what the folder held before this write (null: a new
|
|
456
|
+
// file) — for an untouched path that is what the step was handed.
|
|
457
|
+
written.push({ path: rel.replaceAll("\\", "/"), base: hostNow ? sha(hostNow) : null, after: next, handed: foldedIn ? undefined : handed });
|
|
413
458
|
}
|
|
414
459
|
};
|
|
415
460
|
walk(containerWs);
|
|
461
|
+
// The step's outputs as one revision (all its paths, or none). Never allowed
|
|
462
|
+
// to fail the copy-back: the folder is written already.
|
|
463
|
+
if (opts.revision && written.length) {
|
|
464
|
+
try {
|
|
465
|
+
recordStepOutputs(opts.revision.tenant, path.basename(hostWs), written, { runId: opts.revision.runId, step: opts.revision.step, base: opts.revision.base });
|
|
466
|
+
}
|
|
467
|
+
catch (err) {
|
|
468
|
+
note?.(`the step's files were written to the workspace but not recorded as a revision yet: ${err instanceof Error ? err.message : String(err)}`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
416
471
|
return applied;
|
|
417
472
|
}
|
|
418
473
|
// ---------- the dependency cache ----------
|
|
@@ -1751,7 +1806,11 @@ export async function runStepInContainer(args) {
|
|
|
1751
1806
|
args.emit("info", line);
|
|
1752
1807
|
const staging = fs.mkdtempSync(path.join(os.tmpdir(), "foldrun-run-"));
|
|
1753
1808
|
let containerId = "";
|
|
1809
|
+
// The revisions this step starts from (FOL-126 fixes): taken before the
|
|
1810
|
+
// folder is copied, held until the copy-back is done.
|
|
1811
|
+
let pinned = null;
|
|
1754
1812
|
try {
|
|
1813
|
+
pinned = args.tenant ? await pinRunBase(args.tenant, path.basename(args.workspaceRoot), `${args.runId ?? "step"}:${crypto.randomBytes(4).toString("hex")}`) : null;
|
|
1755
1814
|
// Stage the workspace copy minus what the platform owns — the vault,
|
|
1756
1815
|
// hook state, run history. The container gets the trust boundary, not
|
|
1757
1816
|
// the bookkeeping. One definition of "platform-owned" for this filter,
|
|
@@ -1940,6 +1999,7 @@ export async function runStepInContainer(args) {
|
|
|
1940
1999
|
onRefused: (r) => refused.push(r),
|
|
1941
2000
|
allowConfig: args.configWrites === true,
|
|
1942
2001
|
onKept: (r) => kept.push(r),
|
|
2002
|
+
revision: args.tenant ? { tenant: args.tenant, runId: args.runId, step: containerId, base: pinned?.base ?? null } : undefined,
|
|
1943
2003
|
});
|
|
1944
2004
|
if (refused.length)
|
|
1945
2005
|
args.emit("info", refusedLine(refused));
|
|
@@ -1965,5 +2025,6 @@ export async function runStepInContainer(args) {
|
|
|
1965
2025
|
if (containerId)
|
|
1966
2026
|
spawnSync(cli(), ["rm", "-f", containerId], { stdio: "ignore" });
|
|
1967
2027
|
fs.rmSync(staging, { recursive: true, force: true });
|
|
2028
|
+
await pinned?.release();
|
|
1968
2029
|
}
|
|
1969
2030
|
}
|
package/dist/src/runner.js
CHANGED
|
@@ -4604,7 +4604,7 @@ function driveRunInner(tenant, workspace, run, modelOverride, tags, opts) {
|
|
|
4604
4604
|
// /source makes one too. A re-run comes through here as well.
|
|
4605
4605
|
run.drivenAt ??= new Date().toISOString();
|
|
4606
4606
|
if (run.revision === undefined)
|
|
4607
|
-
run.revision = latestRevisionId(tenant, workspace);
|
|
4607
|
+
run.revision = await latestRevisionId(tenant, workspace);
|
|
4608
4608
|
if (run.status !== "running") {
|
|
4609
4609
|
run.status = "running";
|
|
4610
4610
|
run.parkedAt = null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type S3Config } from "./storage.ts";
|
|
2
|
+
import { bufferSource, type BlobStore, type BlobSweeper } from "./blob-types.ts";
|
|
3
|
+
/** S3's floor for every part but the last. R2 and MinIO enforce the same. */
|
|
4
|
+
export declare const MIN_PART_BYTES: number;
|
|
5
|
+
/** S3's ceiling on the number of parts. */
|
|
6
|
+
export declare const MAX_PARTS = 10000;
|
|
7
|
+
export interface S3BlobOptions {
|
|
8
|
+
/** Objects at or above this many bytes go up as multipart. */
|
|
9
|
+
multipartThresholdBytes: number;
|
|
10
|
+
/** Size of every part but the last. Raised if the object would need more
|
|
11
|
+
* than MAX_PARTS; never below MIN_PART_BYTES. */
|
|
12
|
+
partBytes: number;
|
|
13
|
+
/** Parts in flight at once for ONE upload. */
|
|
14
|
+
partConcurrency: number;
|
|
15
|
+
/** Per-part (and per single request) deadline floor and the throughput the
|
|
16
|
+
* deadline assumes on top of it. */
|
|
17
|
+
requestDeadlineMs: number;
|
|
18
|
+
minBytesPerSec: number;
|
|
19
|
+
}
|
|
20
|
+
export declare const DEFAULT_S3_OPTIONS: S3BlobOptions;
|
|
21
|
+
export declare function s3OptionsFromEnv(env?: NodeJS.ProcessEnv): S3BlobOptions;
|
|
22
|
+
/** The part size for an object: the configured one, raised until the object
|
|
23
|
+
* fits in MAX_PARTS parts. Every part but the last is exactly this size —
|
|
24
|
+
* R2 requires uniform parts, S3 and MinIO do not mind. */
|
|
25
|
+
export declare function planPartBytes(size: number, configured: number): number;
|
|
26
|
+
export declare function s3BlobStore(cfg: S3Config, given?: Partial<S3BlobOptions>): BlobStore & BlobSweeper & {
|
|
27
|
+
checkBucket(signal?: AbortSignal): Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
export { bufferSource };
|