@remnic/plugin-claude-code 10.0.164 → 10.0.165

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "remnic",
3
3
  "description": "Universal memory for AI agents — automatic recall, observation, and cross-agent knowledge sharing",
4
- "version": "10.0.164",
4
+ "version": "10.0.165",
5
5
  "author": {
6
6
  "name": "Joshua Warren"
7
7
  },
@@ -372,6 +372,20 @@ function run(config) {
372
372
  // observations land on the default key while a namespaced flush drains a
373
373
  // different (empty) queue, and most in-session memory never flushes before
374
374
  // compaction. An explicit bodyObj.namespace still takes precedence.
375
+ // One deadline for the whole request: connect, response headers, and body.
376
+ // req.setTimeout() is an idle timer that does not arm until the socket
377
+ // connects and restarts on every byte, so a daemon address that drops
378
+ // packets, or a front that accepts and then trickles, held the hook far
379
+ // past its budget. On expiry the request is destroyed and `onTimeout`
380
+ // reports the same failure the caller already handles for a dead daemon.
381
+ function armRequestDeadline(req, timeoutMs, onTimeout) {
382
+ const timer = setTimeout(() => {
383
+ req.destroy();
384
+ onTimeout();
385
+ }, timeoutMs);
386
+ req.on("close", () => clearTimeout(timer));
387
+ }
388
+
375
389
  function httpPost(urlPath, token, bodyObj, timeoutMs) {
376
390
  if (DAEMON_URL === null) {
377
391
  // Explicit-but-invalid REMNIC_DAEMON_URL — disabled, fail open (see
@@ -422,10 +436,7 @@ function run(config) {
422
436
  },
423
437
  );
424
438
  req.on("error", () => resolve({ ok: false, status: 0, body: "" }));
425
- req.setTimeout(timeoutMs, () => {
426
- req.destroy();
427
- resolve({ ok: false, status: 0, body: "" });
428
- });
439
+ armRequestDeadline(req, timeoutMs, () => resolve({ ok: false, status: 0, body: "" }));
429
440
  req.write(data);
430
441
  req.end();
431
442
  });
@@ -468,10 +479,7 @@ function run(config) {
468
479
  },
469
480
  );
470
481
  req.on("error", () => resolve(0));
471
- req.setTimeout(budget, () => {
472
- req.destroy();
473
- resolve(0);
474
- });
482
+ armRequestDeadline(req, budget, () => resolve(0));
475
483
  req.end();
476
484
  });
477
485
  return probe("/engram/v1/live", timeoutMs).then((status) => {
@@ -211,6 +211,16 @@ function forward(msg, isNotification) {
211
211
  params: msg.params ?? {},
212
212
  });
213
213
  return new Promise((resolve) => {
214
+ // One-shot completion guard: req.destroy() can surface the same failure
215
+ // on both the request and response error channels (and a late socket
216
+ // error can follow a completed response). Only the first terminal event
217
+ // may write a JSON-RPC reply.
218
+ let answered = false;
219
+ const firstAnswer = () => {
220
+ if (answered) return false;
221
+ answered = true;
222
+ return true;
223
+ };
214
224
  const req = transport.request(
215
225
  {
216
226
  method: "POST",
@@ -238,6 +248,7 @@ function forward(msg, isNotification) {
238
248
  chunks += c;
239
249
  });
240
250
  res.on("end", () => {
251
+ if (!firstAnswer()) return;
241
252
  try {
242
253
  if (isNotification) {
243
254
  // No reply expected. Either 2xx success or non-2xx-with-no-body
@@ -327,6 +338,7 @@ function forward(msg, isNotification) {
327
338
  }
328
339
  });
329
340
  res.on("error", (err) => {
341
+ if (!firstAnswer()) return;
330
342
  if (isNotification) {
331
343
  process.stderr.write(
332
344
  `remnic-mcp-proxy: notification ${msg.method} response stream error: ${sanitizeMessage(err.message)}\n`
@@ -343,10 +355,16 @@ function forward(msg, isNotification) {
343
355
  });
344
356
  }
345
357
  );
346
- req.setTimeout(REQUEST_TIMEOUT_MS, () => {
358
+ // One deadline for connect plus the full response. req.setTimeout() is an
359
+ // idle timer: it does not arm until the socket connects and restarts on
360
+ // every byte, so a daemon front that drops packets or trickles a reply
361
+ // held the tool call open far past REQUEST_TIMEOUT_MS.
362
+ const deadline = setTimeout(() => {
347
363
  req.destroy(new Error(`request timed out after ${REQUEST_TIMEOUT_MS}ms`));
348
- });
364
+ }, REQUEST_TIMEOUT_MS);
365
+ req.on("close", () => clearTimeout(deadline));
349
366
  req.on("error", (err) => {
367
+ if (!firstAnswer()) return;
350
368
  if (isNotification) {
351
369
  process.stderr.write(
352
370
  `remnic-mcp-proxy: notification ${msg.method} transport error: ${sanitizeMessage(err.message)}\n`
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ // Spawn test for the stdio->HTTP MCP proxy's request deadline. A daemon front
4
+ // that accepts and then never finishes the response must not hold an MCP tool
5
+ // call past REQUEST_TIMEOUT_MS (30s): the proxy answers with a timeout error
6
+ // instead of waiting on an idle timer the trickle keeps alive.
7
+
8
+ const assert = require("node:assert/strict");
9
+ const test = require("node:test");
10
+ const path = require("node:path");
11
+
12
+ const { startTricklingDaemon, callMcpProxy } = require("../../../tests/helpers/stalled-daemon.cjs");
13
+
14
+ const SERVER = path.join(__dirname, "server.js");
15
+
16
+ test("trickling daemon front: the request fails at its 30s deadline", async () => {
17
+ const front = await startTricklingDaemon();
18
+ try {
19
+ const { reply, signal, lines, elapsedMs } = await callMcpProxy(SERVER, front.url, { killAfterMs: 45000 });
20
+ assert.ok(reply, `proxy never answered (signal=${signal}, ${elapsedMs}ms)`);
21
+ assert.ok(reply.elapsedMs < 37000, `proxy answered after ${reply.elapsedMs}ms against a 30s deadline`);
22
+ assert.equal(reply.message.id, 1);
23
+ assert.match(reply.message.error.message, /request timed out after 30000ms/);
24
+ assert.equal(lines.length, 1, `expected one reply, got:\n${lines.join("\n")}`);
25
+ } finally {
26
+ front.close();
27
+ }
28
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/plugin-claude-code",
3
- "version": "10.0.164",
3
+ "version": "10.0.165",
4
4
  "description": "Remnic memory plugin for Claude Code — hooks, skills, MCP integration",
5
5
  "type": "module",
6
6
  "license": "MIT",