@jini-ai/sidecar 0.4.1 → 0.4.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @jini-ai/sidecar
2
2
 
3
+ ## 0.4.3 — 2026-10-13
4
+
5
+ - Windows: the Node supervisor stops its daemon gracefully by closing a stdin pipe (launch env `JINI_STOP_ON_STDIN_EOF=1`), waits 5s, then falls back to `taskkill /T /F`. POSIX is unchanged. Hosts opt in by running their disposal on stdin `end` when the flag is set.
6
+
7
+ ## 0.4.2 — 2026-10-13
8
+
9
+ - The Node supervisor imports `@jini-ai/platform/command` and `/process` instead of the platform root; peer `@jini-ai/platform` floor is now `^0.5.5`.
10
+
3
11
  ## 0.4.1
4
12
 
5
13
  ### Patch Changes
@@ -1,5 +1,6 @@
1
1
  import type { Writable } from "node:stream";
2
2
  import type { ChildProcess, SpawnOptions } from "node:child_process";
3
+ import { listProcessSnapshots, stopProcesses, waitForProcessExit } from "@jini-ai/platform/process";
3
4
  import type { LocalDaemonRegistryRecord } from "./daemon-registry.js";
4
5
  import type { SpawnedDaemonProcess, SupervisorScheduler } from "./supervisor.js";
5
6
  export interface SupervisorRegistry {
@@ -38,6 +39,14 @@ export interface NodeDaemonProcessOptions {
38
39
  args: string[];
39
40
  options: SpawnOptions;
40
41
  }, optional?: Record<string, never>) => ChildProcess;
42
+ /** Native effect ports retain their platform ABI so tests can supply DI fakes. */
43
+ listProcessSnapshots?: typeof listProcessSnapshots;
44
+ waitForProcessExit?: typeof waitForProcessExit;
45
+ stopProcesses?: typeof stopProcesses;
46
+ signalProcess?: typeof process.kill;
47
+ execFileSync?: (file: string, args: readonly string[], options: {
48
+ stdio: "ignore";
49
+ }) => unknown;
41
50
  }
42
51
  /**
43
52
  * Node launch/tree-stop adapter using platform command quoting, snapshots and signal escalation.
@@ -1,5 +1,6 @@
1
1
  import { execFileSync, spawn } from "node:child_process";
2
- import { collectProcessTreePids, createCommandInvocation, listProcessSnapshots, stopProcesses } from "@jini-ai/platform";
2
+ import { createCommandInvocation } from "@jini-ai/platform/command";
3
+ import { collectProcessTreePids, listProcessSnapshots, stopProcesses, waitForProcessExit } from "@jini-ai/platform/process";
3
4
  import { readLiveDaemonRegistryRecord, removeDaemonRegistryRecordIfCurrent, writeDaemonRegistryRecord } from "./daemon-registry.js";
4
5
  /**
5
6
  * Reuse the sidecar registry's atomic records, liveness checks and ownership-guarded removal.
@@ -25,14 +26,15 @@ export function createSupervisorRegistry({ registryPath }) {
25
26
  export function createNodeDaemonProcessAdapter(required, options = {}) {
26
27
  return {
27
28
  spawnDaemonProcess() {
29
+ const win32 = (options.platform ?? process.platform) === "win32";
28
30
  const invocation = createCommandInvocation({ command: required.command, args: [...required.args], env: required.env });
29
31
  // detached creates a POSIX process group so teardown reaches the daemon below a
30
32
  // launcher hop; windowsHide avoids an otherwise visible detached Windows console.
31
33
  // Pipe output through the parent instead of inheriting its descriptors: an orphan
32
34
  // retaining those descriptors previously kept parent/test teardown waiting forever.
33
35
  const spawnOptions = {
34
- cwd: required.cwd, env: { ...required.env }, detached: true, windowsHide: true,
35
- stdio: ["ignore", "pipe", "pipe"],
36
+ cwd: required.cwd, env: { ...required.env, ...(win32 ? { JINI_STOP_ON_STDIN_EOF: "1" } : {}) }, detached: true, windowsHide: true,
37
+ stdio: [win32 ? "pipe" : "ignore", "pipe", "pipe"],
36
38
  ...(invocation.windowsVerbatimArguments === undefined ? {} : { windowsVerbatimArguments: invocation.windowsVerbatimArguments }),
37
39
  };
38
40
  const child = options.spawn
@@ -55,31 +57,51 @@ export function createNodeDaemonProcessAdapter(required, options = {}) {
55
57
  child.on("error", (error) => input.listener({ error }));
56
58
  },
57
59
  kill(_required, { signal } = {}) { return child.kill(signal); },
60
+ ...(win32 && child.stdin ? { closeStdin(_required) {
61
+ // EPIPE when the daemon exits first must not become an unhandled stream error.
62
+ child.stdin.once("error", () => undefined).end();
63
+ } } : {}),
58
64
  };
59
65
  },
60
66
  async terminateProcess({ child }) {
61
67
  if (child.pid === undefined)
62
68
  return;
63
69
  const pid = child.pid;
64
- const snapshotRequest = listProcessSnapshots();
65
- // Signal before the first await: even a parent exiting immediately after shutdown reaps its tree.
66
- // Windows has no group signal, so taskkill supplies the synchronous tree-stop equivalent.
70
+ const snapshotRequest = (options.listProcessSnapshots ?? listProcessSnapshots)();
71
+ // Request stop before the first await: even a parent exiting immediately starts tree teardown.
72
+ // Windows has no group signal, so taskkill supplies the tree-stop escalation.
67
73
  // Windows has no POSIX group signal. Killing only the immediate launcher would
68
74
  // orphan its daemon; taskkill /T walks the entire descendant tree instead.
69
- try {
70
- if ((options.platform ?? process.platform) === "win32") {
71
- execFileSync("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore" });
75
+ if ((options.platform ?? process.platform) === "win32") {
76
+ let exited = false;
77
+ if (child.closeStdin !== undefined) {
78
+ try {
79
+ child.closeStdin({});
80
+ // Reuse platform's existing 5s grace before any forced Windows termination.
81
+ exited = await (options.waitForProcessExit ?? waitForProcessExit)(pid);
82
+ }
83
+ catch { /* A broken pipe cannot request shutdown; escalate to the whole tree. */ }
72
84
  }
73
- else {
74
- process.kill(-pid, "SIGTERM");
85
+ if (!exited) {
86
+ try {
87
+ (options.execFileSync ?? execFileSync)("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore" });
88
+ }
89
+ catch {
90
+ child.kill({}, { signal: "SIGTERM" });
91
+ }
75
92
  }
76
93
  }
77
- catch {
78
- child.kill({}, { signal: "SIGTERM" });
94
+ else {
95
+ try {
96
+ (options.signalProcess ?? process.kill)(-pid, "SIGTERM");
97
+ }
98
+ catch {
99
+ child.kill({}, { signal: "SIGTERM" });
100
+ }
79
101
  }
80
102
  const snapshots = await snapshotRequest;
81
103
  const pids = collectProcessTreePids(snapshots, [pid]);
82
- const result = await stopProcesses(pids);
104
+ const result = await (options.stopProcesses ?? stopProcesses)(pids);
83
105
  if (result.remainingPids.length > 0)
84
106
  throw new Error(`daemon processes still running: ${result.remainingPids.join(", ")}`);
85
107
  await required.registry.removeIfCurrent({ pid });
@@ -23,6 +23,8 @@ export interface SpawnedDaemonProcess {
23
23
  kill(requiredArgs: Record<string, never>, optionalArgs?: {
24
24
  signal?: NodeJS.Signals;
25
25
  }): boolean;
26
+ /** Close the host-owned stdin pipe to request graceful shutdown on Windows. */
27
+ closeStdin?(requiredArgs: Record<string, never>, optionalArgs?: Record<string, never>): void;
26
28
  }
27
29
  /** Scheduling must defer run until after schedule returns; the returned function cancels it. */
28
30
  export interface SupervisorScheduler {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/sidecar",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Sidecar process runtime: JSON-IPC server and client, IPC path validation, namespace/runtime path resolution, port allocation, launch bootstrap, and a local daemon registry.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -63,14 +63,14 @@
63
63
  },
64
64
  "devDependencies": {
65
65
  "@vitest/coverage-v8": "^2.1.9",
66
- "@jini-ai/core": "0.4.2",
67
- "@jini-ai/platform": "0.5.2"
66
+ "@jini-ai/platform": "0.5.5",
67
+ "@jini-ai/core": "0.4.4"
68
68
  },
69
69
  "dependencies": {
70
- "@jini-ai/core": "^0.4.2"
70
+ "@jini-ai/core": "^0.4.4"
71
71
  },
72
72
  "peerDependencies": {
73
- "@jini-ai/platform": "^0.5.1"
73
+ "@jini-ai/platform": "^0.5.5"
74
74
  },
75
75
  "peerDependenciesMeta": {
76
76
  "@jini-ai/platform": {