@arnilo/prism-hosts 0.14.2 → 0.14.3
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/CHANGELOG.md +3 -1
- package/driver-process/README.md +3 -1
- package/driver-process/src/abort.ts +59 -5
- package/driver-process/src/driver.ts +8 -2
- package/host-builder/data/api.json +5 -5
- package/host-builder/data/errors.json +1 -1
- package/host-builder/data/examples.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
-
## [0.14.
|
|
5
|
+
## [0.14.3] - 2026-11-28
|
|
6
|
+
|
|
7
|
+
- `./driver-process`: **Fixed:** an aborted run left the vendor's descendants running. A coding CLI runs its shell tools as children (Claude Code `Bash`, Codex `commandExecution`, agy `command`); the driver signalled the vendor pid only, so a `sleep 600` or a dev server outlived the abort, reparented to init. The vendor is now spawned `detached` (POSIX), so it leads its own process group, with stdio still piped and the child not `unref`ed. Every signal step of the adapter's abort ladder, the fallback signal ladder and the hard SIGKILL go to the group (`process.kill(-pid, signal)`), falling back to the vendor alone when the group is gone. When the vendor exits, on any path (turn end, graceful shutdown, abort, crash), the driver sends SIGKILL to the group once, so descendants that ignored the earlier signals do not outlive the run. Unchanged: the `closeStdin` and `rpc` steps, the `graceMs` default, the `aborted` status, the no-archive-on-abort rule, and the `endRun` interrupt, which signals the vendor only so it can end its turn and the next run resumes. On Windows there are no process groups: signals reach the vendor alone, as before. A terminal Ctrl-C no longer reaches the vendor directly; the host's abort stops it. Docs: `docs/agent-adapters.md` "The abort ladder". Tests: `src/__tests__/process-group.test.ts`.
|
|
6
8
|
|
|
7
9
|
- `./driver-process`: **Fixed:** an aborted driver run resolved `completed` with no `abortReason`. A run whose `run.signal` aborts before the vendor's `turnEnd` (including one aborted before the process starts) now ends `aborted` with the signal's reason, as a native run does. The abort ladder, the `graceMs` and SIGKILL deadlines and the no-archive-on-abort rule are unchanged, and a turn that reached `turnEnd` before the abort still completes. `adapterConformance`'s `abort_within_grace` leg now also asserts `status: "aborted"` and the reason.
|
|
8
10
|
- `./driver-process`: a Prism-served tool (`prismTools` over MCP, or a json-rpc request handler's `bridge`) that returns an accepted `endRun` ends the vendor's turn: after 200 ms for the vendor to read the result, the driver runs its abort ladder's first step once (Claude Code SIGINT, Codex `turn/interrupt`, closing stdin), treats `turnEnd` or the process exit as the end of the turn, archives the resume state, and the run ends `stopped` with `stopReason: "tool_end_run"`. Requires `@arnilo/prism` 0.14.2.
|
package/driver-process/README.md
CHANGED
|
@@ -62,7 +62,9 @@ Archived strings and object keys are checked against all declared protected cred
|
|
|
62
62
|
|
|
63
63
|
## Abort
|
|
64
64
|
|
|
65
|
-
A run abort executes the adapter's declared steps in order. RPC steps send JSON-RPC notifications, stdin steps close the input, and signal steps signal the child. Each step receives a slice of `graceMs`, with two slices reserved for the fallback signal ladder; a hard SIGKILL deadline covers the whole abort budget. Failed interrupt writes do not prevent escalation. RPC steps require `json-rpc`.
|
|
65
|
+
A run abort executes the adapter's declared steps in order. RPC steps send JSON-RPC notifications, stdin steps close the input, and signal steps signal the child's process group. Each step receives a slice of `graceMs`, with two slices reserved for the fallback signal ladder; a hard SIGKILL deadline covers the whole abort budget. Failed interrupt writes do not prevent escalation. RPC steps require `json-rpc`.
|
|
66
|
+
|
|
67
|
+
The vendor is spawned `detached`, so it leads its own process group, and every signal step, the fallback ladder and the hard SIGKILL go to that group (falling back to the vendor alone if the group is gone). Shell tools the vendor runs as children, such as a `sleep` or a dev server, stop with it. Once the vendor exits, on any path, the driver sends SIGKILL to the group once, so descendants that ignored the earlier signals do not outlive the run. The interrupt a Prism tool's `endRun` triggers signals the vendor only. On Windows there are no process groups: signals reach the vendor process alone. Because the vendor is no longer in the host's group, a terminal Ctrl-C reaches the host, not the vendor; the host's abort stops it.
|
|
66
68
|
|
|
67
69
|
Normal completion closes stdin and waits up to `graceMs` for flushing before using the fallback signal ladder. It can therefore take roughly twice the grace budget if escalation is needed. An abort during this final flush still executes the abort steps. Classified vendor limits also use the abort ladder, without retry.
|
|
68
70
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ChildProcessWithoutNullStreams } from "node:child_process";
|
|
2
|
-
import { signalLadder } from "@arnilo/prism/driver-kit";
|
|
3
2
|
import type { AgentAdapter, EncodeContext } from "./adapter.js";
|
|
4
3
|
import type { Transport } from "./transports/types.js";
|
|
5
4
|
|
|
@@ -14,6 +13,32 @@ function wait(exited: Promise<void>, ms: number): Promise<void> {
|
|
|
14
13
|
});
|
|
15
14
|
}
|
|
16
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Whether vendor processes run in their own process group. POSIX only: on Windows the driver signals the
|
|
18
|
+
* vendor process alone, so descendants it started are not stopped by an abort.
|
|
19
|
+
*/
|
|
20
|
+
export const PROCESS_GROUPS = process.platform !== "win32";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Signals the vendor's process group (the vendor is its leader, spawned `detached`), so shell tools and
|
|
24
|
+
* other descendants stop with it. Falls back to the leader alone when the group is gone or groups are off.
|
|
25
|
+
*/
|
|
26
|
+
function signalGroup(child: ChildProcessWithoutNullStreams, signal: NodeJS.Signals): void {
|
|
27
|
+
if (PROCESS_GROUPS && child.pid !== undefined) {
|
|
28
|
+
try {
|
|
29
|
+
process.kill(-child.pid, signal);
|
|
30
|
+
return;
|
|
31
|
+
} catch {
|
|
32
|
+
// ESRCH: no live member left in the group; the leader itself may still be signalled below.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
child.kill(signal);
|
|
37
|
+
} catch {
|
|
38
|
+
// Already reaped.
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
17
42
|
export function processShutdown(
|
|
18
43
|
child: ChildProcessWithoutNullStreams,
|
|
19
44
|
exited: Promise<void>,
|
|
@@ -26,6 +51,34 @@ export function processShutdown(
|
|
|
26
51
|
void exited.then(() => {
|
|
27
52
|
stopped = true;
|
|
28
53
|
});
|
|
54
|
+
// The leader's exit, which can precede `close` while a descendant still holds its stdio.
|
|
55
|
+
let leaderExited = child.exitCode !== null || child.signalCode !== null;
|
|
56
|
+
const leaderExit = new Promise<void>((resolve) => {
|
|
57
|
+
if (leaderExited) resolve();
|
|
58
|
+
else
|
|
59
|
+
child.once("exit", () => {
|
|
60
|
+
leaderExited = true;
|
|
61
|
+
resolve();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
// Reap after exit: once the leader is gone, SIGKILL whatever is left in its group, once. Runs on every
|
|
65
|
+
// path (turn end, graceful shutdown, abort, crash), so no descendant outlives the run.
|
|
66
|
+
void leaderExit.then(() => {
|
|
67
|
+
if (PROCESS_GROUPS && child.pid !== undefined)
|
|
68
|
+
try {
|
|
69
|
+
process.kill(-child.pid, "SIGKILL");
|
|
70
|
+
} catch {
|
|
71
|
+
// ESRCH: the group is already empty.
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
/** SIGINT, then SIGTERM after `graceMs`, then SIGKILL after another `graceMs`, each to the whole group. */
|
|
75
|
+
const ladder = async (graceMs: number) => {
|
|
76
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGKILL"] as const) {
|
|
77
|
+
if (leaderExited) return;
|
|
78
|
+
signalGroup(child, signal);
|
|
79
|
+
if (signal !== "SIGKILL") await wait(leaderExit, graceMs);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
29
82
|
let stopping: Promise<void> | undefined;
|
|
30
83
|
let aborting: Promise<void> | undefined;
|
|
31
84
|
const abort = () =>
|
|
@@ -35,7 +88,7 @@ export function processShutdown(
|
|
|
35
88
|
return;
|
|
36
89
|
}
|
|
37
90
|
const deadline = Date.now() + graceMs;
|
|
38
|
-
const hardKill = setTimeout(() => child
|
|
91
|
+
const hardKill = setTimeout(() => signalGroup(child, "SIGKILL"), graceMs);
|
|
39
92
|
try {
|
|
40
93
|
const slice = graceMs / (adapter.abort.length + 2);
|
|
41
94
|
for (const step of adapter.abort) {
|
|
@@ -43,14 +96,14 @@ export function processShutdown(
|
|
|
43
96
|
const action = async () => {
|
|
44
97
|
if ("rpc" in step) await transport.send({ method: step.rpc, params: step.params?.(encoding), notify: true });
|
|
45
98
|
else if ("closeStdin" in step) child.stdin.end();
|
|
46
|
-
else child
|
|
99
|
+
else signalGroup(child, step.signal);
|
|
47
100
|
};
|
|
48
101
|
const pause = wait(exited, Math.min(slice, Math.max(0, deadline - Date.now())));
|
|
49
102
|
// A broken interrupt channel must not prevent later signals or the hard kill.
|
|
50
103
|
await Promise.race([action().catch(() => undefined), pause]);
|
|
51
104
|
await pause;
|
|
52
105
|
}
|
|
53
|
-
if (!stopped && Date.now() < deadline) await
|
|
106
|
+
if (!stopped && Date.now() < deadline) await ladder(Math.max(1, Math.floor((deadline - Date.now()) / 2)));
|
|
54
107
|
await exited;
|
|
55
108
|
} finally {
|
|
56
109
|
clearTimeout(hardKill);
|
|
@@ -67,13 +120,14 @@ export function processShutdown(
|
|
|
67
120
|
await wait(exited, graceMs);
|
|
68
121
|
}
|
|
69
122
|
if (aborting) await aborting;
|
|
70
|
-
else if (!stopped) await
|
|
123
|
+
else if (!stopped) await ladder(Math.max(1, Math.floor(graceMs / 2)));
|
|
71
124
|
await exited;
|
|
72
125
|
})());
|
|
73
126
|
let interrupting: Promise<void> | undefined;
|
|
74
127
|
/**
|
|
75
128
|
* Ends the vendor's current turn without aborting the run: only the ladder's first step (an interrupt
|
|
76
129
|
* signal, an interrupt request, or closing stdin), once. The turn then ends with `turnEnd` or the process exits.
|
|
130
|
+
* A signal goes to the leader only: the vendor must survive to end its turn.
|
|
77
131
|
*/
|
|
78
132
|
const interrupt = () =>
|
|
79
133
|
(interrupting ??= (async () => {
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
redactedStderr,
|
|
22
22
|
relayCommand,
|
|
23
23
|
} from "@arnilo/prism/driver-kit";
|
|
24
|
-
import { processShutdown } from "./abort.js";
|
|
24
|
+
import { PROCESS_GROUPS, processShutdown } from "./abort.js";
|
|
25
25
|
import { type AgentAdapter, assertAdapter, type ProcessDriverConfig, quoteCommand } from "./adapter.js";
|
|
26
26
|
import { ProcessDriverError } from "./errors.js";
|
|
27
27
|
import { inspectDriver } from "./inspect.js";
|
|
@@ -262,7 +262,13 @@ async function converse(
|
|
|
262
262
|
): Promise<boolean> {
|
|
263
263
|
const { run, binary, config, tools, spec } = ctx;
|
|
264
264
|
if (run.signal.aborted) return false;
|
|
265
|
-
|
|
265
|
+
// Its own process group (POSIX), so an abort also stops the shell tools it runs; not `unref`ed.
|
|
266
|
+
const child: ChildProcessWithoutNullStreams = spawn(binary.path, args, {
|
|
267
|
+
cwd,
|
|
268
|
+
env,
|
|
269
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
270
|
+
detached: PROCESS_GROUPS,
|
|
271
|
+
});
|
|
266
272
|
child.stdin.on("error", () => undefined);
|
|
267
273
|
let spawnError: Error | undefined;
|
|
268
274
|
child.on("error", (error) => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"prismVersion": "0.14.
|
|
4
|
-
"contentHash": "
|
|
3
|
+
"prismVersion": "0.14.3",
|
|
4
|
+
"contentHash": "03a53d042903f70080e861f5fb0141961dd46770cdc2397fcc34cc7c5f350def",
|
|
5
5
|
"packages": [
|
|
6
6
|
{
|
|
7
7
|
"name": "@arnilo/prism",
|
|
8
|
-
"version": "0.14.
|
|
8
|
+
"version": "0.14.3",
|
|
9
9
|
"path": ".",
|
|
10
10
|
"experimental": false,
|
|
11
11
|
"entries": [
|
|
@@ -756,7 +756,7 @@
|
|
|
756
756
|
{"name":"validateJsonSchema","kind":"function","signature":"export declare function validateJsonSchema(schema: JsonSchema, value: unknown): SchemaResult","summary":"Validates `value` against `schema` and returns it with defaults applied.","examples":["examples/secure-agent.ts","examples/web-research.ts"]},
|
|
757
757
|
{"name":"validateLoadedSkillBodies","kind":"function","signature":"export declare function validateLoadedSkillBodies(value: unknown, bounds?: SkillBodyBounds): asserts value is readonly LoadedSkillBodiesEntry[]","summary":"Fail-closed shape/cap validation for a persisted bodies payload (load and save sides)."},
|
|
758
758
|
{"name":"validateSessionAppendBatch","kind":"function","signature":"export declare function validateSessionAppendBatch(entries: readonly SessionEntry[]): SessionAppendBatch | undefined","summary":"The store-independent part of `SessionStore.appendMany` validation (plan 230 Task 5): one session, no id twice, and the parents the batch does not carry itself.","docs":["node_modules/@arnilo/prism/docs/slots.md"]},
|
|
759
|
-
{"name":"version","kind":"const","signature":"export declare const version = \"0.14.
|
|
759
|
+
{"name":"version","kind":"const","signature":"export declare const version = \"0.14.3\"","docs":["node_modules/@arnilo/prism/docs/agent-adapters.md","node_modules/@arnilo/prism/docs/events.md","node_modules/@arnilo/prism/docs/limits.md","node_modules/@arnilo/prism/docs/live-testing.md","node_modules/@arnilo/prism/docs/long-running.md","node_modules/@arnilo/prism/docs/manifest.md"]},
|
|
760
760
|
{"name":"waitForRetry","kind":"function","signature":"export declare function waitForRetry(decision: RetryDecision, signal?: AbortSignal): Promise<void>"},
|
|
761
761
|
{"name":"withContextBlocks","kind":"function","signature":"export declare function withContextBlocks(draft: ContextDraft, blocks: readonly ContextBlock[]): ContextDraft | undefined","summary":"Append `blocks` to a draft's context, or return `undefined` when there is nothing to add — the transform's way of saying \"no change\", so the controller skips re-deriving the request.","examples":["examples/context.ts","examples/custom-builders.ts","examples/instruction-injection.ts","examples/rag.ts"]}
|
|
762
762
|
]
|
|
@@ -3127,7 +3127,7 @@
|
|
|
3127
3127
|
},
|
|
3128
3128
|
{
|
|
3129
3129
|
"name": "@arnilo/prism-hosts",
|
|
3130
|
-
"version": "0.14.
|
|
3130
|
+
"version": "0.14.3",
|
|
3131
3131
|
"path": "packages/hosts",
|
|
3132
3132
|
"experimental": false,
|
|
3133
3133
|
"entries": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"prismVersion": "0.14.
|
|
3
|
+
"prismVersion": "0.14.3",
|
|
4
4
|
"contentHash": "5c71012ee5433cc8e041667101be81e71a9e97b864a6734ee737a49e722a53ed",
|
|
5
5
|
"codes": [
|
|
6
6
|
{"code":"ERR_PRISM_A2A_CONFIG","namespace":"ERR_PRISM","package":"@arnilo/prism-hosts","file":"packages/hosts/a2a/src/errors.ts","line":41,"errorClass":"A2AConfigError","meaning":"Invalid `serveA2A` / `connectA2A` options, thrown at construction.","sampleMessage":null,"docs":[]},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"prismVersion": "0.14.
|
|
3
|
+
"prismVersion": "0.14.3",
|
|
4
4
|
"contentHash": "75fc16968d39788d3d4456f0868c2220580fa4537621501d37e2a473142ee766",
|
|
5
5
|
"examples": [
|
|
6
6
|
{"path":"examples/a2a-client.ts","title":"Bun-only demo (the examples tsconfig is Node-typed): the one Bun global this file uses.","gate":"executed","imports":["@arnilo/prism","@arnilo/prism-hosts/a2a","@arnilo/prism/provider-kit"],"requiresEnv":["DEMO_A2A_TOKEN"],"needsCredentials":true},
|
package/package.json
CHANGED