@smoothbricks/nx-plugin 0.6.0 → 0.6.2
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/README.md +68 -56
- package/dist/.build-inputs.json +16 -13
- package/dist/cargo-retention-hook.d.ts +8 -1
- package/dist/cargo-retention-hook.d.ts.map +1 -1
- package/dist/cargo-retention-hook.js +12 -1
- package/dist/ensure-built-receipt.d.ts +9 -0
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +42 -1
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +28 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.js +20 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts +4 -4
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +7 -6
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +20 -2
- package/dist/executors/bounded-exec/gateway-lease.d.ts +3 -2
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
- package/dist/executors/bounded-exec/gateway-lease.js +23 -3
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
- package/dist/executors/bounded-exec/hang-diagnostics.js +25 -1
- package/dist/executors/bounded-exec/lease-wait.d.ts +23 -2
- package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -1
- package/dist/executors/bounded-exec/lease-wait.js +15 -11
- package/dist/executors/bounded-exec/mbx-pool.d.ts +31 -0
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -0
- package/dist/executors/bounded-exec/mbx-pool.js +24 -0
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts +9 -3
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/run-cpu-pool.js +109 -12
- package/dist/executors/bounded-exec/verdict.d.ts +8 -0
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +1 -1
- package/dist/executors/typescript-emit/emit-overrides.d.ts +14 -0
- package/dist/executors/typescript-emit/emit-overrides.d.ts.map +1 -0
- package/dist/executors/typescript-emit/emit-overrides.js +24 -0
- package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
- package/dist/executors/typescript-emit/executor.js +1 -19
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +6 -0
- package/dist/managed-files/publish-workflow.js +14 -11
- package/dist/producer-receipts.d.ts.map +1 -1
- package/dist/producer-receipts.js +441 -1
- package/managed/raw/envrc +15 -0
- package/managed/raw/tooling/direnv/developer-links.ts +12 -1
- package/managed/raw/tooling/direnv/devenv.smoo.nix +21 -8
- package/managed/raw/tooling/direnv/linked-snapshots.ts +50 -13
- package/managed/raw/tooling/direnv/setup-environment.ts +23 -11
- package/managed/raw/tooling/git-hooks/pre-push.sh +4 -1
- package/managed/raw/tooling/git-reword-commit +151 -0
- package/package.json +22 -5
- package/src/cargo-retention-hook.ts +12 -1
- package/src/ensure-built-receipt.ts +41 -0
- package/src/executors/bounded-exec/cpu-pool-thread.ts +43 -0
- package/src/executors/bounded-exec/cpu-pool.ts +7 -6
- package/src/executors/bounded-exec/executor.ts +20 -2
- package/src/executors/bounded-exec/gateway-lease.ts +17 -7
- package/src/executors/bounded-exec/hang-diagnostics.ts +28 -1
- package/src/executors/bounded-exec/lease-wait.ts +39 -12
- package/src/executors/bounded-exec/mbx-pool.ts +48 -0
- package/src/executors/bounded-exec/run-cpu-pool.ts +117 -15
- package/src/executors/bounded-exec/verdict.ts +8 -1
- package/src/executors/typescript-emit/emit-overrides.ts +24 -0
- package/src/executors/typescript-emit/executor.ts +1 -20
- package/src/managed-files/files.ts +6 -0
- package/src/managed-files/publish-workflow.ts +20 -15
- package/src/producer-receipts.ts +28 -0
- package/test-timings.json +120 -118
|
@@ -11,6 +11,7 @@ import { earliestBound, stepBounds, UNARMED } from './bounds.js';
|
|
|
11
11
|
import { CPU_POOL_ENV, createCpuPool, readInheritedCpuPool, takeParentCpuTokens, } from './cpu-pool.js';
|
|
12
12
|
import { GATEWAY_SOCKET } from './gateway-lease.js';
|
|
13
13
|
import { captureHangDiagnostics, HANG_CAPTURE_MS } from './hang-diagnostics.js';
|
|
14
|
+
import { mbxLeaf, mbxPool, withMbxLeaf } from './mbx-pool.js';
|
|
14
15
|
import { createNoSpaceWatch } from './no-space.js';
|
|
15
16
|
import { COWSHED_EXECUTABLE_ENV, cowshedSubtreeOwner, HANDLE_FD, readAdmission, SUPERVISOR_SOCKET_ENV, } from './owned-subtree.js';
|
|
16
17
|
import { createRunProgress, withProgressReport } from './progress.js';
|
|
@@ -354,6 +355,7 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
|
|
|
354
355
|
// instead. A pool whose endpoint is gone (its holder exited) lends nothing, and the run goes on as asked.
|
|
355
356
|
let grant = null;
|
|
356
357
|
let parentRefusal = null;
|
|
358
|
+
let parentWait;
|
|
357
359
|
if (inherited !== null) {
|
|
358
360
|
const fromParent = await takeParentCpuTokens(inherited, demand.want);
|
|
359
361
|
if (fromParent.granted) {
|
|
@@ -364,16 +366,25 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
|
|
|
364
366
|
}
|
|
365
367
|
else {
|
|
366
368
|
parentRefusal = fromParent.reason;
|
|
369
|
+
parentWait = fromParent.wait;
|
|
367
370
|
}
|
|
368
371
|
}
|
|
369
372
|
const waitedMs = Date.now() - asked;
|
|
370
373
|
let cpu;
|
|
371
374
|
let sized = { command: requested, env: {} };
|
|
375
|
+
// With mbx the leaf's admission is mbx's one pool, not a parent's tokens: its runner is sized to the job's count,
|
|
376
|
+
// and a non-Cargo leaf holds that much of the pool for its run (specs/cowshed/05_gateway.md, "Parallelism inside a
|
|
377
|
+
// job"). No grant and no sub-pool beside it.
|
|
378
|
+
const mbx = mbxPool(process.env);
|
|
379
|
+
const leaf = mbx === null ? null : mbxLeaf(mbx, demand.kind, demand.want);
|
|
372
380
|
if (grant !== null) {
|
|
373
381
|
sized = sizeRunner(demand, requested, grant.tokens);
|
|
374
382
|
cpu = { tokens: grant.tokens, want: demand.want, waitedMs };
|
|
375
383
|
appendStderr(`cowshed: cpu-pool wait done elapsed=${waitedMs}ms status=ok tokens=${grant.tokens}/${demand.want} runner=${demand.kind}\n`);
|
|
376
384
|
}
|
|
385
|
+
else if (leaf !== null) {
|
|
386
|
+
sized = sizeRunner(demand, requested, demand.want);
|
|
387
|
+
}
|
|
377
388
|
// The run's sub-pool and grant are given back exactly once, however the run ends. The sub-pool closes first, so no
|
|
378
389
|
// descendant still draws on tokens the grant has returned.
|
|
379
390
|
let pool = null;
|
|
@@ -408,7 +419,13 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
|
|
|
408
419
|
if (verdict.outcome === 'bound' && verdict.bound === 'test') {
|
|
409
420
|
appendStderr(`Every failing test failed only on its per-test timeout: ${verdict.tests.join(', ')}\n`);
|
|
410
421
|
}
|
|
411
|
-
await writeRecord(recordDirectory, {
|
|
422
|
+
await writeRecord(recordDirectory, {
|
|
423
|
+
task: task.id,
|
|
424
|
+
hash: task.hash,
|
|
425
|
+
verdict,
|
|
426
|
+
...(cpu ? { cpu } : {}),
|
|
427
|
+
...(parentWait ? { cpuWait: parentWait } : {}),
|
|
428
|
+
});
|
|
412
429
|
};
|
|
413
430
|
// A run refused before its command starts says why, gives back its grant and RAM, and records the failure.
|
|
414
431
|
const refuse = async (message) => {
|
|
@@ -457,7 +474,8 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
|
|
|
457
474
|
const startedAt = Date.now();
|
|
458
475
|
// With a supervisor, `cowshed subtree-root` asks it for a handle on itself, writes the answer to the handle
|
|
459
476
|
// descriptor, and execs `/bin/sh -c command` in the same process: the command's pid, group and life are unchanged.
|
|
460
|
-
const
|
|
477
|
+
const unadmitted = hooked?.command ?? (fixture === null ? command : `${fixture.command} && ${command}`);
|
|
478
|
+
const shellCommand = leaf === null ? unadmitted : withMbxLeaf(unadmitted, leaf);
|
|
461
479
|
const root = owner?.rootArgv(shellCommand);
|
|
462
480
|
let child;
|
|
463
481
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CpuLeaseWait } from './lease-wait.js';
|
|
1
|
+
import { CpuLeaseWait, type CpuWaitRow } from './lease-wait.js';
|
|
2
2
|
/**
|
|
3
3
|
* The client half of a lease held on a unix socket: the gateway's host disk-lifecycle lease
|
|
4
4
|
* (`disk-lease.ts`) and a parent's CPU pool (`cpu-pool.ts`) speak the same protocol
|
|
@@ -26,12 +26,13 @@ export interface LeaseBounds {
|
|
|
26
26
|
* other refusal, silence or breakage.
|
|
27
27
|
*/
|
|
28
28
|
export type UnleasedCause = 'absent' | 'predates' | 'predates-field' | 'other';
|
|
29
|
-
/** A refusal: the lease is not held, and why. */
|
|
29
|
+
/** A refusal: the lease is not held, and why. A CPU wait that expired carries its typed row. */
|
|
30
30
|
export type Unleased = {
|
|
31
31
|
granted: false;
|
|
32
32
|
cause: UnleasedCause;
|
|
33
33
|
reason: string;
|
|
34
34
|
code?: string;
|
|
35
|
+
wait?: CpuWaitRow;
|
|
35
36
|
};
|
|
36
37
|
/**
|
|
37
38
|
* A granted lease with its `granted` answer, held until released, or why there is none. `closed`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway-lease.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/gateway-lease.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"gateway-lease.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/gateway-lease.ts"],"names":[],"mappings":"AAEA,OAAO,EAA8C,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK5G;;;;;;;;;;GAUG;AAEH,oFAAoF;AACpF,eAAO,MAAM,cAAc,wCAAwC,CAAC;AAEpE,MAAM,WAAW,WAAW;IAC1B,wEAAwE;IACxE,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,YAAY,EAAE,MAAM,CAAC;IACrB,2FAA2F;IAC3F,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,UAAU,GAAG,gBAAgB,GAAG,OAAO,CAAC;AAE/E,gGAAgG;AAChG,MAAM,MAAM,QAAQ,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAAE,CAAC;AAElH;;;;GAIG;AACH,MAAM,MAAM,SAAS,GACjB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,GACxG,QAAQ,CAAC;AAEb;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC1C,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,GAAG,YAAY,EAClC,QAAQ,CAAC,EAAE,MAAM,IAAI,GACpB,OAAO,CAAC,SAAS,CAAC,CA2KpB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _isTypeUint32_1 from "typia/lib/internal/_isTypeUint32";
|
|
1
2
|
import { connect } from 'node:net';
|
|
2
3
|
import typia from 'typia';
|
|
3
4
|
import { CpuLeaseWait } from './lease-wait.js';
|
|
@@ -12,6 +13,17 @@ const isCpuProgress = (() => {
|
|
|
12
13
|
}));
|
|
13
14
|
return (input, _exceptionable = true) => "object" === typeof input && null !== input && _io0(input, true);
|
|
14
15
|
})();
|
|
16
|
+
const isCpuQueued = (() => {
|
|
17
|
+
const _io0 = (input, _exceptionable = true) => true === input.ok && "queued" === input.lease && ("number" === typeof input.server && _isTypeUint32_1._isTypeUint32(input.server)) && (3 === Object.keys(input).length || Object.keys(input).every(key => {
|
|
18
|
+
if (["ok", "lease", "server"].some(prop => key === prop))
|
|
19
|
+
return true;
|
|
20
|
+
const value = input[key];
|
|
21
|
+
if (undefined === value)
|
|
22
|
+
return true;
|
|
23
|
+
return false;
|
|
24
|
+
}));
|
|
25
|
+
return (input, _exceptionable = true) => "object" === typeof input && null !== input && _io0(input, true);
|
|
26
|
+
})();
|
|
15
27
|
/**
|
|
16
28
|
* The client half of a lease held on a unix socket: the gateway's host disk-lifecycle lease
|
|
17
29
|
* (`disk-lease.ts`) and a parent's CPU pool (`cpu-pool.ts`) speak the same protocol
|
|
@@ -61,7 +73,13 @@ export function holdLease(socket, request, what, bounds, onQueued) {
|
|
|
61
73
|
}
|
|
62
74
|
resolve(outcome);
|
|
63
75
|
};
|
|
64
|
-
const unleased = (reason, cause = 'other', code) => settle({
|
|
76
|
+
const unleased = (reason, cause = 'other', code, wait) => settle({
|
|
77
|
+
granted: false,
|
|
78
|
+
cause,
|
|
79
|
+
reason,
|
|
80
|
+
...(code === undefined ? {} : { code }),
|
|
81
|
+
...(wait === undefined ? {} : { wait }),
|
|
82
|
+
});
|
|
65
83
|
const wait = (ms, onExpiry) => {
|
|
66
84
|
clearTimeout(timer);
|
|
67
85
|
timer = setTimeout(onExpiry, ms);
|
|
@@ -76,7 +94,8 @@ export function holdLease(socket, request, what, bounds, onQueued) {
|
|
|
76
94
|
armCpu();
|
|
77
95
|
return;
|
|
78
96
|
}
|
|
79
|
-
|
|
97
|
+
const peer = failure.server === null ? socket : `${socket} (pid ${failure.server})`;
|
|
98
|
+
unleased(`${failure.code}: cpu-pool: the lease endpoint ${peer} exceeded ${failure.boundMs} ms (waited ${failure.elapsedMs} ms; last progress: ${failure.last})`, 'other', failure.code, { ...failure, socket });
|
|
80
99
|
});
|
|
81
100
|
};
|
|
82
101
|
armCpu();
|
|
@@ -126,7 +145,8 @@ export function holdLease(socket, request, what, bounds, onQueued) {
|
|
|
126
145
|
state = 'queued';
|
|
127
146
|
onQueued?.();
|
|
128
147
|
if (bounds instanceof CpuLeaseWait) {
|
|
129
|
-
|
|
148
|
+
// A pool from before its acknowledgement named its process names none.
|
|
149
|
+
bounds.queued(isCpuQueued(parsed) ? parsed.server : null);
|
|
130
150
|
armCpu();
|
|
131
151
|
}
|
|
132
152
|
else if (bounds.grantMs === null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hang-diagnostics.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/hang-diagnostics.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,QAAQ,EAKd,MAAM,gBAAgB,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"hang-diagnostics.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/hang-diagnostics.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,QAAQ,EAKd,MAAM,gBAAgB,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAS,CAAC;AAoCtC,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,SAAS,GAAG,MAAM,GAAG,YAAY,CAAC;IAC3C,0HAA0H;IAC1H,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClE;IAAE,MAAM,EAAE,aAAa,GAAG,WAAW,GAAG,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvG,qGAAqG;AACrG,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAChH;AAUD,0FAA0F;AAC1F,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,kBAAkB,EAC3B,MAAM,GAAE,kBAAyB,GAChC,OAAO,CAAC,eAAe,CAAC,CAgR1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAM5D"}
|
|
@@ -17,6 +17,8 @@ const PS_FIELDS = 'pid=,ppid=,pgid=,stat=,%cpu=,etime=,lstart=,command=';
|
|
|
17
17
|
*/
|
|
18
18
|
const MAX_SAMPLED_LEAVES = 4;
|
|
19
19
|
const SAMPLE_SECONDS = 1;
|
|
20
|
+
/** How long a process in an uninterruptible kernel wait has its file-system calls traced. */
|
|
21
|
+
const FS_USAGE_SECONDS = 5;
|
|
20
22
|
/**
|
|
21
23
|
* A process census's limit. The stack samples run until the closing census is this far from the window's end.
|
|
22
24
|
*/
|
|
@@ -173,6 +175,28 @@ export function captureHangDiagnostics(request, source = host) {
|
|
|
173
175
|
lines.push(`${name}: no stack; sudo -n sample did not answer, so the call this process waits in is not observed.`);
|
|
174
176
|
}));
|
|
175
177
|
};
|
|
178
|
+
/**
|
|
179
|
+
* A process in an uninterruptible kernel wait (state U) is in a file-system or device call no signal ends, and its
|
|
180
|
+
* stack stops at the system call. Its file-system calls over a few seconds (fs_usage) name the volume and files it
|
|
181
|
+
* waits on, which tells a fixture doing its I/O on a contended shared volume from one serialised behind one APFS
|
|
182
|
+
* operation. Bounded like the stack samples; one fs_usage sudo refuses is named as no trace.
|
|
183
|
+
*/
|
|
184
|
+
const kernelWaits = async (tree) => {
|
|
185
|
+
const waiting = tree.filter((entry) => entry.stat.startsWith('U')).slice(0, MAX_SAMPLED_LEAVES);
|
|
186
|
+
const limitMs = endsAtMs - Date.now() - CENSUS_LIMIT_MS;
|
|
187
|
+
await Promise.all(waiting.map(async ({ pid }) => {
|
|
188
|
+
const name = `fs_usage pid ${pid}`;
|
|
189
|
+
const args = ['-n', 'fs_usage', '-w', '-t', String(FS_USAGE_SECONDS), '-f', 'filesys', String(pid)];
|
|
190
|
+
const result = await probe(name, 'sudo', args, limitMs);
|
|
191
|
+
if (finished)
|
|
192
|
+
return;
|
|
193
|
+
if (result.stdout.trim() !== '') {
|
|
194
|
+
lines.push(`${name} (${FS_USAGE_SECONDS}s of file-system calls):\n${result.stdout.trimEnd()}`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
lines.push(`${name}: no trace; sudo -n fs_usage gave none, so the files this process waits on are not observed.`);
|
|
198
|
+
}));
|
|
199
|
+
};
|
|
176
200
|
const collect = async () => {
|
|
177
201
|
const before = await census('ps before');
|
|
178
202
|
if (finished)
|
|
@@ -227,7 +251,7 @@ export function captureHangDiagnostics(request, source = host) {
|
|
|
227
251
|
}
|
|
228
252
|
}
|
|
229
253
|
};
|
|
230
|
-
await Promise.all([openFiles(), stackSamples(before)]);
|
|
254
|
+
await Promise.all([openFiles(), stackSamples(before), kernelWaits(before)]);
|
|
231
255
|
if (finished)
|
|
232
256
|
return;
|
|
233
257
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { tags } from 'typia';
|
|
1
2
|
/** Peer wait classes from specs/cowshed/05_gateway.md, "Deadlines". */
|
|
2
3
|
export declare const CONTROL_MS = 5000;
|
|
3
4
|
export declare const HEARTBEAT_MS = 5000;
|
|
@@ -7,12 +8,29 @@ export interface CpuLeaseProgress {
|
|
|
7
8
|
ok: true;
|
|
8
9
|
progress: number;
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* The CPU pool's queue acknowledgement, shared by its server and lease client. `server` is the pid of the process the
|
|
13
|
+
* pool runs in, so a wait that falls silent names the process to look at.
|
|
14
|
+
*/
|
|
15
|
+
export interface CpuLeaseQueued {
|
|
16
|
+
ok: true;
|
|
17
|
+
lease: 'queued';
|
|
18
|
+
server: number & tags.Type<'uint32'>;
|
|
19
|
+
}
|
|
10
20
|
/** A failed wait, not a failed command: expiry ends this client's admission only. */
|
|
11
21
|
export interface CpuWaitFailure {
|
|
12
22
|
code: 'TIMEOUT' | 'SILENT';
|
|
13
23
|
boundMs: number;
|
|
14
24
|
elapsedMs: number;
|
|
15
25
|
last: string;
|
|
26
|
+
/** The last advancing heartbeat sequence the client read; 0 before the first. */
|
|
27
|
+
sequence: number;
|
|
28
|
+
/** The pool's pid as its queue acknowledgement named it; null before one, or from a pool that names none. */
|
|
29
|
+
server: number | null;
|
|
30
|
+
}
|
|
31
|
+
/** An expired CPU wait as its client keeps it: the failure, and the socket of the pool it waited on. */
|
|
32
|
+
export interface CpuWaitRow extends CpuWaitFailure {
|
|
33
|
+
socket: string;
|
|
16
34
|
}
|
|
17
35
|
/** Pure CPU admission policy; its injected monotonic clock performs no I/O or scheduling. */
|
|
18
36
|
export declare class CpuLeaseWait {
|
|
@@ -24,8 +42,11 @@ export declare class CpuLeaseWait {
|
|
|
24
42
|
constructor(now?: () => number);
|
|
25
43
|
/** The kernel took the complete request; only peer silence bounds the answer from here. */
|
|
26
44
|
sent(): void;
|
|
27
|
-
/**
|
|
28
|
-
|
|
45
|
+
/**
|
|
46
|
+
* A queue entry proves actor progress, not a deadline for returning a token. It names the pool's pid when the pool
|
|
47
|
+
* says it.
|
|
48
|
+
*/
|
|
49
|
+
queued(server: number | null): void;
|
|
29
50
|
/** Only an advancing actor sequence renews silence; duplicate or invalid progress proves nothing. */
|
|
30
51
|
heartbeat(sequence: number): boolean;
|
|
31
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lease-wait.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/lease-wait.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,eAAO,MAAM,UAAU,OAAQ,CAAC;AAChC,eAAO,MAAM,YAAY,OAAQ,CAAC;AAClC,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAE3C,qFAAqF;AACrF,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,IAAI,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;CAClB;
|
|
1
|
+
{"version":3,"file":"lease-wait.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/lease-wait.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAElC,uEAAuE;AACvE,eAAO,MAAM,UAAU,OAAQ,CAAC;AAChC,eAAO,MAAM,YAAY,OAAQ,CAAC;AAClC,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAE3C,qFAAqF;AACrF,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,IAAI,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,QAAQ,CAAC;IAChB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;CACtC;AAMD,qFAAqF;AACrF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,QAAQ,EAAE,MAAM,CAAC;IACjB,6GAA6G;IAC7G,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,wGAAwG;AACxG,MAAM,WAAW,UAAW,SAAQ,cAAc;IAChD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,6FAA6F;AAC7F,qBAAa,YAAY;IAMX,OAAO,CAAC,QAAQ,CAAC,GAAG;IALhC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,KAAK,CAAqC;IAClD,qEAAqE;IACrE,OAAO,CAAC,MAAM,CAAS;IAEvB,YAA6B,GAAG,GAAE,MAAM,MAAgC,EAGvE;IAED,2FAA2F;IAC3F,IAAI,IAAI,IAAI,CAKX;IAED;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAKlC;IAED,qGAAqG;IACrG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAMnC;IAED;;;;;OAKG;IACH,IAAI,IAAI,IAAI,CAMX;IAED,qEAAqE;IACrE,WAAW,IAAI,MAAM,CAGpB;IAED,2FAA2F;IAC3F,OAAO,IAAI,cAAc,GAAG,IAAI,CAS/B;CACF"}
|
|
@@ -18,14 +18,17 @@ export class CpuLeaseWait {
|
|
|
18
18
|
sent() {
|
|
19
19
|
this.looked = this.now();
|
|
20
20
|
if (this.state.kind === 'sending') {
|
|
21
|
-
this.state = { kind: 'waiting', at: this.now(), last: 'request sent', sequence: 0 };
|
|
21
|
+
this.state = { kind: 'waiting', at: this.now(), last: 'request sent', sequence: 0, server: null };
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* A queue entry proves actor progress, not a deadline for returning a token. It names the pool's pid when the pool
|
|
26
|
+
* says it.
|
|
27
|
+
*/
|
|
28
|
+
queued(server) {
|
|
26
29
|
this.sent();
|
|
27
30
|
if (this.state.kind === 'waiting') {
|
|
28
|
-
this.state = { ...this.state, at: this.now(), last: 'queued' };
|
|
31
|
+
this.state = { ...this.state, at: this.now(), last: 'queued', server };
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
/** Only an advancing actor sequence renews silence; duplicate or invalid progress proves nothing. */
|
|
@@ -33,7 +36,7 @@ export class CpuLeaseWait {
|
|
|
33
36
|
this.sent();
|
|
34
37
|
if (this.state.kind !== 'waiting' || !Number.isSafeInteger(sequence) || sequence <= this.state.sequence)
|
|
35
38
|
return false;
|
|
36
|
-
this.state = {
|
|
39
|
+
this.state = { ...this.state, at: this.now(), last: `heartbeat ${sequence}`, sequence };
|
|
37
40
|
return true;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
@@ -58,11 +61,12 @@ export class CpuLeaseWait {
|
|
|
58
61
|
expired() {
|
|
59
62
|
if (this.remainingMs() > 0)
|
|
60
63
|
return null;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
elapsedMs:
|
|
65
|
-
|
|
66
|
-
};
|
|
64
|
+
const elapsedMs = this.now() - this.started;
|
|
65
|
+
if (this.state.kind === 'sending') {
|
|
66
|
+
const last = 'connecting or sending request';
|
|
67
|
+
return { code: 'TIMEOUT', boundMs: CONTROL_MS, elapsedMs, last, sequence: 0, server: null };
|
|
68
|
+
}
|
|
69
|
+
const { last, sequence, server } = this.state;
|
|
70
|
+
return { code: 'SILENT', boundMs: HEARTBEAT_SILENCE_MS, elapsedMs, last, sequence, server };
|
|
67
71
|
}
|
|
68
72
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RunnerKind } from './runner-sizing.js';
|
|
2
|
+
/**
|
|
3
|
+
* mbx's machine-wide pool as a leaf runner meets it (specs/cowshed/05_gateway.md, "Host scheduling", "Parallelism inside
|
|
4
|
+
* a job"). With the mbx capability the canonical environment names the one pool (`MBX_SCHEDULER=1` beside the shared
|
|
5
|
+
* `MBX_CACHE_DIR`) and the job's priority in it; that pool is the host's CPU and memory ledger, so no Nx run or leaf
|
|
6
|
+
* serves a pool of its own beside it.
|
|
7
|
+
*/
|
|
8
|
+
export interface MbxPool {
|
|
9
|
+
readonly priority: 'normal' | 'low';
|
|
10
|
+
}
|
|
11
|
+
/** The pool the environment names, or `null` where the project has no mbx and cowshed's own pools apply unchanged. */
|
|
12
|
+
export declare function mbxPool(environment: Readonly<NodeJS.ProcessEnv>): MbxPool | null;
|
|
13
|
+
/**
|
|
14
|
+
* How a leaf enters the pool once: a Cargo leaf runs through mbx, which admits its compiler and supported test work
|
|
15
|
+
* itself, so wrapping it would charge it twice; any other leaf holds `cpus` of the pool for its whole run through
|
|
16
|
+
* `mbx reserve`, `cpus` being the job's own count.
|
|
17
|
+
*/
|
|
18
|
+
export type MbxLeaf = {
|
|
19
|
+
readonly kind: 'cargo';
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'reserve';
|
|
22
|
+
readonly cpus: number;
|
|
23
|
+
readonly priority: 'normal' | 'low';
|
|
24
|
+
};
|
|
25
|
+
export declare function mbxLeaf(pool: MbxPool, kind: RunnerKind, want: number): MbxLeaf;
|
|
26
|
+
/**
|
|
27
|
+
* `command` as the shell runs it under its leaf's admission. `mbx` is the canonical environment's, whose realpath
|
|
28
|
+
* cowshed's admission proved to be the host's pinned mbx.
|
|
29
|
+
*/
|
|
30
|
+
export declare function withMbxLeaf(command: string, leaf: MbxLeaf): string;
|
|
31
|
+
//# sourceMappingURL=mbx-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mbx-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/mbx-pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,KAAK,CAAC;CACrC;AAED,sHAAsH;AACtH,wBAAgB,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,OAAO,GAAG,IAAI,CAKhF;AAED;;;;GAIG;AACH,MAAM,MAAM,OAAO,GACf;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,KAAK,CAAA;CAAE,CAAC;AAI7F,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAI9E;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAKlE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { shellQuote } from './verdict.js';
|
|
2
|
+
/** The pool the environment names, or `null` where the project has no mbx and cowshed's own pools apply unchanged. */
|
|
3
|
+
export function mbxPool(environment) {
|
|
4
|
+
if (environment.MBX_SCHEDULER !== '1' || !environment.MBX_CACHE_DIR) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return { priority: environment.MBX_SCHEDULER_PRIORITY === 'normal' ? 'normal' : 'low' };
|
|
8
|
+
}
|
|
9
|
+
const CARGO_LEAVES = new Set(['cargo', 'cargo-mutants', 'nextest']);
|
|
10
|
+
export function mbxLeaf(pool, kind, want) {
|
|
11
|
+
return CARGO_LEAVES.has(kind)
|
|
12
|
+
? { kind: 'cargo' }
|
|
13
|
+
: { kind: 'reserve', cpus: Math.max(1, want), priority: pool.priority };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `command` as the shell runs it under its leaf's admission. `mbx` is the canonical environment's, whose realpath
|
|
17
|
+
* cowshed's admission proved to be the host's pinned mbx.
|
|
18
|
+
*/
|
|
19
|
+
export function withMbxLeaf(command, leaf) {
|
|
20
|
+
if (leaf.kind === 'cargo') {
|
|
21
|
+
return command;
|
|
22
|
+
}
|
|
23
|
+
return `mbx reserve --cpus ${leaf.cpus} --priority ${leaf.priority} -- /bin/sh -c ${shellQuote(command)}`;
|
|
24
|
+
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { PostTasksExecutionContext, PreTasksExecutionContext } from 'nx/src/project-graph/plugins/public-api.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* The count of the pool a run is served, or null when it is served none. A run that inherits a pool (an enclosing
|
|
4
|
+
* executor's) takes from that one; with mbx, its pool is the host's one ledger, and a run pool beside it would count
|
|
5
|
+
* every leaf twice. Otherwise one token per core, or the inherited positive count when that is fewer.
|
|
6
|
+
*/
|
|
7
|
+
export declare function runPoolTokens(env: Readonly<NodeJS.ProcessEnv>, cores: number): number | null;
|
|
8
|
+
/**
|
|
9
|
+
* Serve `context`'s run a pool of `runPoolTokens` and publish it in `env`, which every task inherits, unless the run
|
|
10
|
+
* is served none. A pool that cannot be made is said, and the run's tasks are then sized only by the ceilings they
|
|
11
|
+
* inherit.
|
|
6
12
|
*/
|
|
7
13
|
export declare function serveRunCpuPool(context: Pick<PreTasksExecutionContext, 'id'>, env?: NodeJS.ProcessEnv, cores?: number): Promise<void>;
|
|
8
14
|
/** Close the pool `context`'s run was served, if it was served one. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-cpu-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/run-cpu-pool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-cpu-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/run-cpu-pool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAmDtH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM5F;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,IAAI,CAAC,EAC7C,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,KAAK,GAAE,MAA+B,GACrC,OAAO,CAAC,IAAI,CAAC,CAgBf;AAiED,uEAAuE;AACvE,wBAAsB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,yBAAyB,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnG"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { availableParallelism } from 'node:os';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { Worker } from 'node:worker_threads';
|
|
2
4
|
import { logger } from 'nx/src/devkit-exports.js';
|
|
3
|
-
import {
|
|
5
|
+
import { readInheritedCpuPool } from './cpu-pool.js';
|
|
6
|
+
import { mbxPool } from './mbx-pool.js';
|
|
4
7
|
import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
|
|
5
8
|
/**
|
|
6
9
|
* The CPU pool of an Nx run (specs/cowshed/05_gateway.md, "Host scheduling", "Parallelism inside a job", "Every Nx run
|
|
@@ -16,30 +19,124 @@ import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
|
|
|
16
19
|
* A run that inherits a pool (an enclosing executor's) takes from that one and serves none. Otherwise its pool holds
|
|
17
20
|
* one token per core, or the inherited positive `BOUNDED_EXEC_CPU_TOKENS` when that is fewer: inside a cowshed job
|
|
18
21
|
* that count is the job's own, so the job's `--want` bounds the run.
|
|
22
|
+
*
|
|
23
|
+
* The pool runs on a thread of its own (`cpu-pool-thread.ts`). The process that serves it, the Nx daemon when installed
|
|
24
|
+
* plugins load in it or the Nx CLI without one, hashes the run's tasks and builds its project graph in synchronous calls
|
|
25
|
+
* on its main thread. In a gate on 2026-10-28 one `hashPlans` ran for 14.2 s, and sixteen runners queued on a pool on
|
|
26
|
+
* that thread failed `SILENT` together while it was alive (05_gateway.md, "Deadlines"). The thread's event loop runs the
|
|
27
|
+
* pool alone; this module starts it, publishes the environment it reports and closes it.
|
|
19
28
|
*/
|
|
20
29
|
/** The pools this process serves, by Nx run id, until that run's `postTasksExecution`. */
|
|
21
30
|
const pools = new Map();
|
|
22
31
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
32
|
+
* The pool thread's module, in the form this one was loaded in: compiled JavaScript when Nx loads the plugin, its
|
|
33
|
+
* TypeScript source under Bun. A Bun worker starts without its parent's preloads, so from source the thread takes the
|
|
34
|
+
* transform preload this package's source needs, the one its bunfig names; compiled, it needs none.
|
|
35
|
+
*/
|
|
36
|
+
const FROM_SOURCE = import.meta.url.endsWith('.ts');
|
|
37
|
+
const THREAD_ENTRY = new URL(FROM_SOURCE ? './cpu-pool-thread.ts' : './cpu-pool-thread.js', import.meta.url);
|
|
38
|
+
const THREAD_PRELOAD = FROM_SOURCE
|
|
39
|
+
? { preload: [fileURLToPath(import.meta.resolve('@smoothbricks/validation/bun/preload'))] }
|
|
40
|
+
: {};
|
|
41
|
+
/**
|
|
42
|
+
* The count of the pool a run is served, or null when it is served none. A run that inherits a pool (an enclosing
|
|
43
|
+
* executor's) takes from that one; with mbx, its pool is the host's one ledger, and a run pool beside it would count
|
|
44
|
+
* every leaf twice. Otherwise one token per core, or the inherited positive count when that is fewer.
|
|
45
|
+
*/
|
|
46
|
+
export function runPoolTokens(env, cores) {
|
|
47
|
+
if (readInheritedCpuPool(env) !== null || mbxPool(env) !== null) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const inherited = parseInheritedTokens(env[CPU_TOKENS_ENV]);
|
|
51
|
+
return inherited === null ? cores : Math.min(inherited, cores);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Serve `context`'s run a pool of `runPoolTokens` and publish it in `env`, which every task inherits, unless the run
|
|
55
|
+
* is served none. A pool that cannot be made is said, and the run's tasks are then sized only by the ceilings they
|
|
56
|
+
* inherit.
|
|
26
57
|
*/
|
|
27
58
|
export async function serveRunCpuPool(context, env = process.env, cores = availableParallelism()) {
|
|
28
|
-
|
|
59
|
+
const tokens = runPoolTokens(env, cores);
|
|
60
|
+
if (tokens === null) {
|
|
29
61
|
return;
|
|
30
62
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (!made.ok) {
|
|
35
|
-
logger.warn(`bounded-exec: this run's CPU pool failed (${made.error}); its tasks are sized only by the ceilings they inherit`);
|
|
63
|
+
const served = await servePoolThread(tokens);
|
|
64
|
+
if (!served.ok) {
|
|
65
|
+
logger.warn(`bounded-exec: this run's CPU pool failed (${served.error}); its tasks are sized only by the ceilings they inherit`);
|
|
36
66
|
return;
|
|
37
67
|
}
|
|
38
|
-
pools.set(context.id,
|
|
39
|
-
for (const [name, value] of Object.entries(
|
|
68
|
+
pools.set(context.id, served.pool);
|
|
69
|
+
for (const [name, value] of Object.entries(served.pool.environment)) {
|
|
40
70
|
env[name] = value;
|
|
41
71
|
}
|
|
42
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Start a pool of `tokens` on a thread of its own, and wait until it serves or says why it cannot. The first `close()`
|
|
75
|
+
* closes the pool and ends the thread; every call returns that close's outcome. A thread that throws or exits before it
|
|
76
|
+
* has said how its pool closed fails whichever wait is open, a later close returns that failure, and a thread lost while
|
|
77
|
+
* its pool serves is said at once.
|
|
78
|
+
*/
|
|
79
|
+
function servePoolThread(tokens) {
|
|
80
|
+
const thread = new Worker(THREAD_ENTRY, { workerData: { tokens }, ...THREAD_PRELOAD });
|
|
81
|
+
return new Promise((served) => {
|
|
82
|
+
let state = { kind: 'starting', served };
|
|
83
|
+
let closing;
|
|
84
|
+
// The pool is done with its thread once it has said how it ended: nothing of the pool's is left to run there.
|
|
85
|
+
const finish = (outcome) => {
|
|
86
|
+
const was = state;
|
|
87
|
+
state = { kind: 'ended', outcome };
|
|
88
|
+
void thread.terminate();
|
|
89
|
+
return was;
|
|
90
|
+
};
|
|
91
|
+
const lose = (why) => {
|
|
92
|
+
if (state.kind === 'ended') {
|
|
93
|
+
// The exit that finishing the thread caused.
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const error = `the CPU pool's thread ${why}`;
|
|
97
|
+
const was = finish({ ok: false, error });
|
|
98
|
+
if (was.kind === 'starting') {
|
|
99
|
+
was.served({ ok: false, error });
|
|
100
|
+
}
|
|
101
|
+
else if (was.kind === 'closing') {
|
|
102
|
+
was.closed({ ok: false, error });
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
logger.warn(`bounded-exec: this run's CPU pool stopped serving: ${error}`);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const close = () => {
|
|
109
|
+
closing ??=
|
|
110
|
+
state.kind === 'ended'
|
|
111
|
+
? Promise.resolve(state.outcome)
|
|
112
|
+
: new Promise((closed) => {
|
|
113
|
+
state = { kind: 'closing', closed };
|
|
114
|
+
thread.postMessage(null);
|
|
115
|
+
});
|
|
116
|
+
return closing;
|
|
117
|
+
};
|
|
118
|
+
thread.on('message', (report) => {
|
|
119
|
+
const now = state;
|
|
120
|
+
if (now.kind === 'starting' && report.kind === 'serving') {
|
|
121
|
+
state = { kind: 'serving' };
|
|
122
|
+
now.served({ ok: true, pool: { environment: report.environment, close } });
|
|
123
|
+
}
|
|
124
|
+
else if (now.kind === 'starting' && report.kind === 'failed') {
|
|
125
|
+
finish({ ok: false, error: report.error });
|
|
126
|
+
now.served({ ok: false, error: report.error });
|
|
127
|
+
}
|
|
128
|
+
else if (now.kind === 'closing' && report.kind === 'closed') {
|
|
129
|
+
finish(report.outcome);
|
|
130
|
+
now.closed(report.outcome);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
lose(`said ${report.kind} while ${now.kind}`);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
thread.on('error', (error) => lose(`failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
137
|
+
thread.on('exit', (code) => lose(`exited with code ${code}`));
|
|
138
|
+
});
|
|
139
|
+
}
|
|
43
140
|
/** Close the pool `context`'s run was served, if it was served one. */
|
|
44
141
|
export async function closeRunCpuPool(context) {
|
|
45
142
|
const pool = pools.get(context.id);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CpuWaitRow } from './lease-wait.js';
|
|
1
2
|
import { type LockWait } from './lock-wait.js';
|
|
2
3
|
/**
|
|
3
4
|
* Why one bounded run ended, recorded per Nx task so a caller can tell a load-sensitive bound
|
|
@@ -84,6 +85,12 @@ export interface BoundedExecRecord {
|
|
|
84
85
|
readonly want: number;
|
|
85
86
|
readonly waitedMs: number;
|
|
86
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* The parent CPU pool's wait that expired and refused the run: its code, bound and elapsed time, the last heartbeat
|
|
90
|
+
* sequence it read, and the pool's socket and pid (specs/cowshed/05_gateway.md, "Deadlines"). Absent when no wait
|
|
91
|
+
* expired; written for the reader of a refused run, never read back.
|
|
92
|
+
*/
|
|
93
|
+
readonly cpuWait?: CpuWaitRow;
|
|
87
94
|
}
|
|
88
95
|
/** The Nx task a run executes as. Nx gives an executor no task id, only its parts. */
|
|
89
96
|
export interface BoundedExecTask {
|
|
@@ -187,6 +194,7 @@ export declare const GO_TEST: RegExp;
|
|
|
187
194
|
* that already chose bun's reporter, is returned unchanged and judged by its exit alone.
|
|
188
195
|
*/
|
|
189
196
|
export declare function withJunitReport(command: string, directory: string): Promise<string>;
|
|
197
|
+
export declare function shellQuote(value: string): string;
|
|
190
198
|
/** Remove a previous run's verdict and report, so neither can be read as this run's. */
|
|
191
199
|
export declare function clearTaskDirectory(directory: string): Promise<void>;
|
|
192
200
|
export declare function writeRecord(directory: string, record: BoundedExecRecord): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verdict.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/verdict.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,QAAQ,EAAe,MAAM,gBAAgB,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,GAC9B;IACE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,GACD;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GACxF;IACE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,8FAA8F;IAC9F,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;CACzC,GACD,CAAC;IAAE,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;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0F;AAC1F,wBAAsB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAWrF;AAED,uFAAuF;AACvF,wBAAsB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAStF;AA8HD,0FAA0F;AAC1F,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,kBAAkB,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;CAAE,GACpH;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9E;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CA6BrG;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAyBnE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAgBjE"}
|
|
@@ -199,7 +199,7 @@ export async function withJunitReport(command, directory) {
|
|
|
199
199
|
await writeFile(config, `[profile.default.junit]\npath = ${JSON.stringify(report)}\n`);
|
|
200
200
|
return command.replace(NEXTEST_RUN, () => `nextest run --tool-config-file ${shellQuote(`smoo-report:${config}`)}`);
|
|
201
201
|
}
|
|
202
|
-
function shellQuote(value) {
|
|
202
|
+
export function shellQuote(value) {
|
|
203
203
|
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
204
204
|
}
|
|
205
205
|
/** Remove a previous run's verdict and report, so neither can be read as this run's. */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the emit changes about the project's own options: JavaScript and declarations from one non-incremental program.
|
|
3
|
+
* They ride the command line onto the project's tsconfig. A synthesized config would have to sit beside that tsconfig,
|
|
4
|
+
* because `${configDir}` and `paths` anchor to the directory of the config that consumes them, and a transient file there
|
|
5
|
+
* changes the directory listing a concurrent ttsc transform of another project proves while it compiles; that
|
|
6
|
+
* transform then refuses with `graph/accessible-entries-changed`.
|
|
7
|
+
*
|
|
8
|
+
* The one definition of how a package's TypeScript dist is emitted: the typescript-emit executor passes these, and so
|
|
9
|
+
* does every bootstrap that emits a dist before Nx can run (tooling/ttsc-emit.ts, the shell entry). A bootstrap that
|
|
10
|
+
* emitted incrementally wrote the tsconfig's tsBuildInfoFile into dist, a file no Nx output produces, and a release
|
|
11
|
+
* refused the verified dist at its merge boundary for it.
|
|
12
|
+
*/
|
|
13
|
+
export declare const EMIT_OVERRIDES: readonly string[];
|
|
14
|
+
//# sourceMappingURL=emit-overrides.d.ts.map
|