@jini-ai/sidecar 0.6.19 → 0.6.22

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.6.22
4
+
5
+ - Supervision moved to `src/supervision/`; published entry points are unchanged. The supervisor rediscovers a replacement sidecar.
6
+
7
+ ## 0.6.21
8
+
9
+ - Native IPC carries a handler's explicit public `refusalReason` (1–1024 characters) back to the caller instead of a generic "IPC request refused"; raw handler errors still never cross the channel.
10
+
3
11
  ## 0.6.17
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -18,6 +18,6 @@ export { readJsonFile, removeFile, removePointerIfCurrent, writeJsonFile } from
18
18
  export { createJsonIpcServer, requestJsonIpc } from "./json-ipc.js";
19
19
  export type { LocalDaemonRegistryRecord } from "./daemon-registry.js";
20
20
  export { isProcessAlive, readLiveDaemonRegistryRecord, removeDaemonRegistryRecordIfCurrent, resolveDaemonRegistryPath, writeDaemonRegistryRecord, } from "./daemon-registry.js";
21
- export * from "./respawn-policy.js";
22
- export * from "./supervisor.js";
21
+ export * from "./supervision/respawn-policy.js";
22
+ export * from "./supervision/supervisor.js";
23
23
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ export { allocatePort } from "./port.js";
16
16
  export { readJsonFile, removeFile, removePointerIfCurrent, writeJsonFile } from "./json-file.js";
17
17
  export { createJsonIpcServer, requestJsonIpc } from "./json-ipc.js";
18
18
  export { isProcessAlive, readLiveDaemonRegistryRecord, removeDaemonRegistryRecordIfCurrent, resolveDaemonRegistryPath, writeDaemonRegistryRecord, } from "./daemon-registry.js";
19
- export * from "./respawn-policy.js";
20
- export * from "./supervisor.js";
19
+ // Preserve published entries with one implementation in supervision; Node adapters stay isolated.
20
+ export * from "./supervision/respawn-policy.js";
21
+ export * from "./supervision/supervisor.js";
21
22
  //# sourceMappingURL=index.js.map
@@ -2,7 +2,7 @@ import type { Writable } from "node:stream";
2
2
  import type { ChildProcess, SpawnOptions } from "node:child_process";
3
3
  import type { Serializable } from "node:child_process";
4
4
  import { listProcessSnapshots, stopProcesses, waitForProcessExit } from "@jini-ai/platform/process";
5
- import type { LocalDaemonRegistryRecord } from "./daemon-registry.js";
5
+ import type { LocalDaemonRegistryRecord } from "../daemon-registry.js";
6
6
  import type { SpawnedDaemonProcess, SupervisorScheduler } from "./supervisor.js";
7
7
  export interface SupervisorRegistry {
8
8
  readLive(): Promise<LocalDaemonRegistryRecord | null>;
@@ -80,7 +80,15 @@ export interface NodeIpcPeer {
80
80
  on(event: "message" | "disconnect", listener: (message: unknown) => void): unknown;
81
81
  removeListener(event: "message" | "disconnect", listener: (message: unknown) => void): unknown;
82
82
  }
83
- /** Native request/reply with bounded pending work. Errors never echo a request, payload or handler error.
83
+ /** Only explicitly public, bounded refusal text may cross IPC. Raw handler messages stay private.
84
+ * @complexity O(1); the caller owns choosing a reason that contains no private data.
85
+ */
86
+ export declare function ipcRefusalReason({ value }: {
87
+ value: unknown;
88
+ }, _optional?: {}): string | undefined;
89
+ /** Native request/reply with bounded pending work. Errors never echo a request, payload or raw handler error.
90
+ * Handlers may opt into public diagnostics by throwing an error with a `refusalReason` string
91
+ * (1–1024 characters), e.g. `Object.assign(new Error(), { refusalReason: "This session ended." })`.
84
92
  * @param required The actual spawned child or inherited process channel.
85
93
  * @param optional Handler, deadline and pending-request cap; construction starts no requests.
86
94
  * @returns Request and idempotent disposal; disconnect rejects and clears every pending request.
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
3
3
  import { createCommandInvocation } from "@jini-ai/platform/command";
4
4
  import { omitEnvironmentKeys } from "@jini-ai/platform/child-environment";
5
5
  import { collectProcessTreePids, listProcessSnapshots, stopProcesses, waitForProcessExit } from "@jini-ai/platform/process";
6
- import { readLiveDaemonRegistryRecord, removeDaemonRegistryRecordIfCurrent, writeDaemonRegistryRecord } from "./daemon-registry.js";
6
+ import { readLiveDaemonRegistryRecord, removeDaemonRegistryRecordIfCurrent, writeDaemonRegistryRecord } from "../daemon-registry.js";
7
7
  /**
8
8
  * Reuse the sidecar registry's atomic records, liveness checks and ownership-guarded removal.
9
9
  * The child calls write only after it actually starts listening.
@@ -152,7 +152,20 @@ function isIpcEnvelope(message) {
152
152
  return false;
153
153
  return "jiniIpc" in message && message.jiniIpc === 1 && "id" in message && typeof message.id === "string" && "kind" in message;
154
154
  }
155
- /** Native request/reply with bounded pending work. Errors never echo a request, payload or handler error.
155
+ /** Only explicitly public, bounded refusal text may cross IPC. Raw handler messages stay private.
156
+ * @complexity O(1); the caller owns choosing a reason that contains no private data.
157
+ */
158
+ export function ipcRefusalReason({ value }, _optional = {}) {
159
+ if (typeof value !== "object" || value === null || !("refusalReason" in value))
160
+ return undefined;
161
+ const reason = value.refusalReason;
162
+ if (typeof reason !== "string")
163
+ return undefined;
164
+ return reason.length > 0 && reason.length <= 1024 ? reason : undefined;
165
+ }
166
+ /** Native request/reply with bounded pending work. Errors never echo a request, payload or raw handler error.
167
+ * Handlers may opt into public diagnostics by throwing an error with a `refusalReason` string
168
+ * (1–1024 characters), e.g. `Object.assign(new Error(), { refusalReason: "This session ended." })`.
156
169
  * @param required The actual spawned child or inherited process channel.
157
170
  * @param optional Handler, deadline and pending-request cap; construction starts no requests.
158
171
  * @returns Request and idempotent disposal; disconnect rejects and clears every pending request.
@@ -180,12 +193,18 @@ export function createNodeIpcChannel({ peer }, { handle, timeoutMs = 30_000, max
180
193
  dispose({});
181
194
  } // A departing peer cannot receive a refusal.
182
195
  }
196
+ /** Complete only a matching request, preserving explicit public refusals. O(1) lookup. */
197
+ function receiveReply({ message }, _optional = {}) {
198
+ const refusalReason = ipcRefusalReason({ value: message });
199
+ const error = message.ok === true ? null : Object.assign(new Error(refusalReason ?? "IPC request refused"), refusalReason === undefined ? {} : { refusalReason });
200
+ pending.get(message.id)?.finish(error, message.payload);
201
+ }
183
202
  function receive(message) {
184
203
  if (disposed || !isIpcEnvelope(message) || message.channel !== channel)
185
204
  return;
186
205
  const { id } = message;
187
206
  if (message.kind === "reply") {
188
- pending.get(id)?.finish(message.ok === true ? null : new Error("IPC request refused"), message.payload);
207
+ receiveReply({ message });
189
208
  }
190
209
  else if (message.kind === "request" && handle) {
191
210
  if (handling >= maxPending) {
@@ -193,7 +212,10 @@ export function createNodeIpcChannel({ peer }, { handle, timeoutMs = 30_000, max
193
212
  return;
194
213
  }
195
214
  handling++;
196
- void Promise.resolve().then(() => handle(message.payload)).then(payload => reply({ jiniIpc: 1, kind: "reply", id, ok: true, payload }), () => reply({ jiniIpc: 1, kind: "reply", id, ok: false })).catch(() => { }).finally(() => { handling--; }); // A disconnected peer cannot receive its reply.
215
+ void Promise.resolve().then(() => handle(message.payload)).then(payload => reply({ jiniIpc: 1, kind: "reply", id, ok: true, payload }), error => {
216
+ const refusalReason = ipcRefusalReason({ value: error });
217
+ reply({ jiniIpc: 1, kind: "reply", id, ok: false, ...(refusalReason ? { refusalReason } : {}) });
218
+ }).catch(() => { }).finally(() => { handling--; }); // A disconnected peer cannot receive its reply.
197
219
  }
198
220
  }
199
221
  function dispose(_required, _optional = {}) {
@@ -80,6 +80,18 @@ export function createDaemonSupervisor(deps, options = {}) {
80
80
  void poll();
81
81
  });
82
82
  }
83
+ /** One monitor spans demand and replacement; background shutdown rejection is observed.
84
+ * @complexity O(1) state; one PID probe immediately, then at most once per 250ms until ready.
85
+ */
86
+ function discoverReadiness() {
87
+ if (!discoveryWork) {
88
+ const discovery = waitForReady().finally(() => { if (discoveryWork === discovery)
89
+ discoveryWork = undefined; });
90
+ discoveryWork = discovery;
91
+ void discovery.catch(() => { });
92
+ }
93
+ return discoveryWork;
94
+ }
83
95
  function ensureReady(_required, { signal } = {}) {
84
96
  if (signal?.aborted)
85
97
  return Promise.reject(signal.reason);
@@ -100,12 +112,7 @@ export function createDaemonSupervisor(deps, options = {}) {
100
112
  // A slow healthy child must keep being discovered after an HTTP caller gives up.
101
113
  // Share the monitor across subsequent demands; shutdown or parking cancels polling.
102
114
  // A parked waiter's cleanup must not clear a fresh wake's discovery or request work.
103
- if (!discoveryWork) {
104
- const discovery = waitForReady().finally(() => { if (discoveryWork === discovery)
105
- discoveryWork = undefined; });
106
- discoveryWork = discovery;
107
- }
108
- const ready = readinessDeadline({ work: discoveryWork, scheduler: deps.scheduler }).finally(() => { if (readyWork === ready)
115
+ const ready = readinessDeadline({ work: discoverReadiness(), scheduler: deps.scheduler }).finally(() => { if (readyWork === ready)
109
116
  readyWork = undefined; });
110
117
  readyWork = ready;
111
118
  }
@@ -215,6 +222,10 @@ export function createDaemonSupervisor(deps, options = {}) {
215
222
  if (!state.deliberate)
216
223
  handleUnexpectedExit(code, signal);
217
224
  } });
225
+ // Cold construction and an idle park do no discovery. A replacement must still publish
226
+ // readiness when no caller is waiting; reuse the current monitor if startup is ongoing.
227
+ if (spawnAttempts > 1 && deps.readiness)
228
+ void discoverReadiness();
218
229
  }
219
230
  // Wait for a still-live child to exit before replacement: spawning alongside it would
220
231
  // collide on its listening port and manufacture the bind failure we are recovering from.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/sidecar",
3
- "version": "0.6.19",
3
+ "version": "0.6.22",
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": {
@@ -30,19 +30,19 @@
30
30
  "default": "./dist/index.js"
31
31
  },
32
32
  "./respawn-policy": {
33
- "types": "./dist/respawn-policy.d.ts",
34
- "import": "./dist/respawn-policy.js",
35
- "default": "./dist/respawn-policy.js"
33
+ "types": "./dist/supervision/respawn-policy.d.ts",
34
+ "import": "./dist/supervision/respawn-policy.js",
35
+ "default": "./dist/supervision/respawn-policy.js"
36
36
  },
37
37
  "./supervisor": {
38
- "types": "./dist/supervisor.d.ts",
39
- "import": "./dist/supervisor.js",
40
- "default": "./dist/supervisor.js"
38
+ "types": "./dist/supervision/supervisor.d.ts",
39
+ "import": "./dist/supervision/supervisor.js",
40
+ "default": "./dist/supervision/supervisor.js"
41
41
  },
42
42
  "./supervisor/node": {
43
- "types": "./dist/supervisor-node.d.ts",
44
- "import": "./dist/supervisor-node.js",
45
- "default": "./dist/supervisor-node.js"
43
+ "types": "./dist/supervision/supervisor-node.d.ts",
44
+ "import": "./dist/supervision/supervisor-node.js",
45
+ "default": "./dist/supervision/supervisor-node.js"
46
46
  }
47
47
  },
48
48
  "files": [
@@ -63,12 +63,12 @@
63
63
  },
64
64
  "devDependencies": {
65
65
  "@vitest/coverage-v8": "^2.1.9",
66
- "@jini-ai/core": "0.6.19",
67
- "@jini-ai/platform": "0.6.19"
66
+ "@jini-ai/core": "0.6.22",
67
+ "@jini-ai/platform": "0.6.22"
68
68
  },
69
69
  "dependencies": {
70
- "@jini-ai/core": "^0.6.19",
71
- "@jini-ai/platform": "^0.6.19"
70
+ "@jini-ai/platform": "^0.6.22",
71
+ "@jini-ai/core": "^0.6.22"
72
72
  },
73
73
  "scripts": {
74
74
  "build": "tsc -p tsconfig.json",