@kelceyp/caw-server 1.0.273 → 1.0.274

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.
@@ -8,9 +8,17 @@
8
8
  * IPC protocol (JSON-lines over stdin/stdout):
9
9
  * Startup: sends { ready: true } after pipeline is loaded
10
10
  * sends { error: "..." } if startup fails
11
- * Request: parent → worker: { texts: ["...", "..."] }\n
12
- * Response: worker → parent: { vectors: [[...], ...] }\n
13
- * or { error: "..." }\n
11
+ * Request: parent → worker: { id, texts: ["...", "..."], maxLength? }\n
12
+ * Response: worker → parent: { id, vectors: [[...], ...] }\n
13
+ * or { id, error: "..." }\n
14
+ *
15
+ * Every request line carries a numeric `id` allocated by the parent; every
16
+ * response echoes the same `id` so the parent can pair responses by id (not
17
+ * by order of arrival). Requests that are unparseable JSON, missing a
18
+ * numeric id, or fail the texts-array validation are dropped rather than
19
+ * answered — without a correlatable id the parent has no way to pair such
20
+ * a response. In-package this path is unreachable (the provider always
21
+ * sends well-formed lines); the drop is defence-in-depth for version skew.
14
22
  *
15
23
  * Vectors are raw (un-normalised) Float32Arrays serialised as plain number arrays.
16
24
  * Normalisation is performed by EmbeddingProvider after receiving the response.
@@ -81,13 +89,18 @@ const run = async () => {
81
89
  try {
82
90
  req = JSON.parse(line);
83
91
  } catch {
84
- sendLine({ error: `Invalid JSON request: ${line}` });
92
+ // Cannot echo an id we could not parse — drop silently.
85
93
  return;
86
94
  }
87
95
 
88
- const { texts, maxLength } = req;
96
+ const { id, texts, maxLength } = req;
97
+ if (typeof id !== 'number') {
98
+ // No correlatable id — drop silently (see IPC protocol note).
99
+ return;
100
+ }
89
101
  if (!Array.isArray(texts)) {
90
- sendLine({ error: 'Request must have a texts array' });
102
+ // Malformed request with a valid id — drop silently rather than
103
+ // answer with an id-less error.
91
104
  return;
92
105
  }
93
106
 
@@ -120,9 +133,9 @@ const run = async () => {
120
133
  const embedRss = Math.round(process.memoryUsage().rss / 1024 / 1024);
121
134
  const shapeStr = maxLength !== undefined ? `[${texts.length}×${maxLength}]` : `[${texts.length}×var]`;
122
135
  logStderr('debug', `Embed #${embedCallCount}: shape=${shapeStr}, RSS: ${embedRss}MB`);
123
- sendLine({ vectors });
136
+ sendLine({ id, vectors });
124
137
  } catch (err) {
125
- sendLine({ error: `Embedding failed: ${err.message}` });
138
+ sendLine({ id, error: `Embedding failed: ${err.message}` });
126
139
  }
127
140
  });
128
141