Skip to content

Commit b715304

Browse files
BrainSlugs83Copilot
andcommitted
fix: proxy auto-relaunches server + keepalive ping
- Proxy retries with ensureServer() on ECONNREFUSED/ECONNRESET - Keepalive ping every 2 minutes prevents idle shutdown during active sessions - Removed session-store.db mtime check (keepalive supersedes it) - Bumped to v1.2.1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent aec1863 commit b715304

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

index.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,33 @@ function callServer(path, body) {
147147
});
148148
}
149149

150+
// Auto-relaunch wrapper: retries once after ensureServer on connection failure
151+
async function callServerWithRetry(path, body) {
152+
try {
153+
return await callServer(path, body);
154+
} catch (err) {
155+
if (err.message && (err.message.includes("ECONNREFUSED") || err.message.includes("ECONNRESET"))) {
156+
startupError = null;
157+
await ensureServer();
158+
return await callServer(path, body);
159+
}
160+
throw err;
161+
}
162+
}
163+
164+
// --- Keepalive: ping server every 2 minutes to prevent idle shutdown ---
165+
const KEEPALIVE_MS = 2 * 60_000;
166+
setInterval(async () => {
167+
try {
168+
const result = await ping();
169+
if (!result) {
170+
// Server died — relaunch it
171+
startupError = null;
172+
await ensureServer();
173+
}
174+
} catch {}
175+
}, KEEPALIVE_MS);
176+
150177
// --- Start: ensure server, then expose MCP tools ---
151178

152179
let startupError = null;
@@ -180,7 +207,7 @@ server.tool(
180207
return { content: [{ type: "text", text: `⚠ vector-memory misconfigured: ${startupError}` }] };
181208
}
182209
try {
183-
const results = await callServer("/search", { query, limit });
210+
const results = await callServerWithRetry("/search", { query, limit });
184211

185212
if (results.error) {
186213
return { content: [{ type: "text", text: `Error: ${results.error}` }] };
@@ -213,7 +240,7 @@ server.tool(
213240
return { content: [{ type: "text", text: `⚠ vector-memory misconfigured: ${startupError}` }] };
214241
}
215242
try {
216-
const result = await callServer("/reindex", {});
243+
const result = await callServerWithRetry("/reindex", {});
217244
if (result.error) {
218245
return { content: [{ type: "text", text: `Error: ${result.error}` }] };
219246
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vector-memory-mcp",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Semantic vector search MCP server for GitHub Copilot CLI session history",
55
"main": "index.js",
66
"type": "module",

vector-memory-server.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as sqliteVec from "sqlite-vec";
33
import { Worker } from "worker_threads";
44
import { join, dirname } from "path";
55
import { homedir } from "os";
6-
import { existsSync, writeFileSync, unlinkSync, readFileSync, statSync } from "fs";
6+
import { existsSync, writeFileSync, unlinkSync, readFileSync } from "fs";
77
import { fileURLToPath } from "url";
88
import { createServer, request as httpReq } from "http";
99
import { execSync } from "child_process";
@@ -341,11 +341,6 @@ setInterval(backgroundIndex, INDEX_INTERVAL_MS);
341341
// --- Idle shutdown ---
342342
if (IDLE_TIMEOUT_MS > 0) {
343343
setInterval(() => {
344-
// If session-store.db was recently modified, count as activity
345-
try {
346-
const mtime = statSync(SESSION_STORE_PATH).mtimeMs;
347-
if (mtime > lastActivity) lastActivity = mtime;
348-
} catch {}
349344
const idle = Date.now() - lastActivity;
350345
if (idle >= IDLE_TIMEOUT_MS) {
351346
process.stderr.write(`[vector-memory] Idle for ${Math.round(idle / 1000)}s — shutting down.\n`);

0 commit comments

Comments
 (0)