@operad-io/pool 0.1.0 → 0.2.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/package.json +2 -2
- package/src/index.ts +11 -6
- package/src/shared.ts +3 -8
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operad-io/pool",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@operad-io/engine": "0.
|
|
9
|
+
"@operad-io/engine": "0.2.0"
|
|
10
10
|
},
|
|
11
11
|
"description": "operad: the pool plugin, workers shared by runs",
|
|
12
12
|
"repository": {
|
package/src/index.ts
CHANGED
|
@@ -32,6 +32,7 @@ export const POOL_SETTINGS = {
|
|
|
32
32
|
properties: {
|
|
33
33
|
harnesses: {
|
|
34
34
|
type: "object" as const,
|
|
35
|
+
title: "Runs per agent",
|
|
35
36
|
additionalProperties: {
|
|
36
37
|
type: "integer" as const,
|
|
37
38
|
minimum: 1,
|
|
@@ -43,9 +44,6 @@ export const POOL_SETTINGS = {
|
|
|
43
44
|
},
|
|
44
45
|
};
|
|
45
46
|
|
|
46
|
-
/** The settings keys, for the docs test. */
|
|
47
|
-
export const POOL_SETTING_NAMES: readonly string[] = Object.keys(POOL_SETTINGS.properties);
|
|
48
|
-
|
|
49
47
|
function capOf(
|
|
50
48
|
settings: Readonly<Record<string, unknown>>,
|
|
51
49
|
harness: string,
|
|
@@ -210,7 +208,7 @@ export function createPoolPlugin(options: PoolPluginOptions = {}) {
|
|
|
210
208
|
steps: [
|
|
211
209
|
{
|
|
212
210
|
name: "agent",
|
|
213
|
-
results: ["done", "failed", "interrupted"],
|
|
211
|
+
results: ["done", "failed", "interrupted", "waiting"],
|
|
214
212
|
// A run waits for room and then runs an agent: as long as a harness step.
|
|
215
213
|
timeoutSecs: 8 * 3600,
|
|
216
214
|
async run(ctx, params): Promise<PluginStepResult> {
|
|
@@ -275,11 +273,18 @@ export function createPoolPlugin(options: PoolPluginOptions = {}) {
|
|
|
275
273
|
const first = await attempt(ctx, prefix, candidates, params, options);
|
|
276
274
|
if (first.kind === "aborted") return interrupted();
|
|
277
275
|
const name = first.worker.fallback;
|
|
276
|
+
// A throw is not a trigger: the harness reports a process that
|
|
277
|
+
// cannot start as a failed result with reason `missing` or `spawn`,
|
|
278
|
+
// and anything else thrown is the step's own error. It fails the
|
|
279
|
+
// work, as it does when the worker has no fallback. That includes a
|
|
280
|
+
// worker whose harness plugin is not loaded: the step throws
|
|
281
|
+
// StepNotLoadedError before any process exists, and it does not fall
|
|
282
|
+
// back.
|
|
278
283
|
const triggered =
|
|
279
284
|
name !== undefined &&
|
|
280
285
|
!ctx.signal.aborted &&
|
|
281
|
-
|
|
282
|
-
|
|
286
|
+
first.kind === "result" &&
|
|
287
|
+
(modelUnavailable(first.result.data) ||
|
|
283
288
|
(first.result.result === "failed" && harnessDidNotStart(first.result.data)));
|
|
284
289
|
if (!triggered) {
|
|
285
290
|
if (first.kind === "threw") throw first.error;
|
package/src/shared.ts
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* crashed serve) is dropped the next time anyone looks.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { mkdirSync, readFileSync
|
|
10
|
+
import { mkdirSync, readFileSync } from "node:fs";
|
|
11
11
|
import { randomUUID } from "node:crypto";
|
|
12
12
|
import { join } from "node:path";
|
|
13
|
-
import { watchDirectory, withLockFile } from "@operad-io/engine/platform";
|
|
13
|
+
import { watchDirectory, withLockFile, writeJsonAtomicSync } from "@operad-io/engine/platform";
|
|
14
14
|
import type { Claim, ClaimResult, Places } from "./places.ts";
|
|
15
15
|
import { isRecord } from "@operad-io/engine";
|
|
16
16
|
|
|
@@ -86,7 +86,6 @@ function alive(pid: number): boolean {
|
|
|
86
86
|
export class FilePlaces implements Places {
|
|
87
87
|
private readonly file: string;
|
|
88
88
|
private readonly lock: string;
|
|
89
|
-
private counter = 0;
|
|
90
89
|
|
|
91
90
|
private readonly now: () => number;
|
|
92
91
|
private readonly heartbeatMs: number;
|
|
@@ -112,10 +111,7 @@ export class FilePlaces implements Places {
|
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
private write(book: Book): void {
|
|
115
|
-
|
|
116
|
-
const tmp = `${this.file}.${process.pid}.${randomUUID()}.tmp`;
|
|
117
|
-
writeFileSync(tmp, JSON.stringify(book));
|
|
118
|
-
renameSync(tmp, this.file);
|
|
114
|
+
writeJsonAtomicSync(this.file, book, { newline: false });
|
|
119
115
|
}
|
|
120
116
|
|
|
121
117
|
private quiet<T>(work: () => T): Promise<T> {
|
|
@@ -173,7 +169,6 @@ export class FilePlaces implements Places {
|
|
|
173
169
|
full.push("home");
|
|
174
170
|
holders.push(holding(claim.home));
|
|
175
171
|
} else {
|
|
176
|
-
this.counter += 1;
|
|
177
172
|
// Unique across instances: step threads share the pid and may share the millisecond.
|
|
178
173
|
const id = `${process.pid}-${randomUUID()}`;
|
|
179
174
|
this.write({
|