vexp-mcp 3.1.3 → 3.2.1
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/dist/daemon-client.js +68 -6
- package/package.json +1 -1
package/dist/daemon-client.js
CHANGED
|
@@ -131,6 +131,12 @@ export class DaemonClient {
|
|
|
131
131
|
// unrelated cwd / a stripped env (e.g. the detached HTTP supervisor).
|
|
132
132
|
const env = binaryEnvFor(binary);
|
|
133
133
|
env.VEXP_WORKSPACE = workspaceRoot;
|
|
134
|
+
// `detached` stays (DETACHED_PROCESS on Windows): a non-detached child
|
|
135
|
+
// would sit in libuv's kill-on-close job object and go down with this
|
|
136
|
+
// server. The daemon this starts has no console either; its git
|
|
137
|
+
// children carry CREATE_NO_WINDOW themselves (vexp-core proc.rs), so
|
|
138
|
+
// nothing here opens a terminal window. `windowsHide` is ignored next
|
|
139
|
+
// to DETACHED_PROCESS and is deliberately absent.
|
|
134
140
|
const child = spawn(binary, ["daemon-cmd", "start"], {
|
|
135
141
|
cwd: workspaceRoot,
|
|
136
142
|
stdio: "ignore",
|
|
@@ -178,9 +184,27 @@ export class DaemonClient {
|
|
|
178
184
|
return resolveDaemonSocket() ?? getDefaultSocketPath();
|
|
179
185
|
}
|
|
180
186
|
static isRetryableError(err) {
|
|
187
|
+
// A daemon that died holding the request is never retryable, whatever the
|
|
188
|
+
// OS called it. The classification is by SUBSTRING, and the io error we
|
|
189
|
+
// carry for support ("read ECONNRESET") contains one of these codes — so
|
|
190
|
+
// without the mark, the message that exists to stop a crash loop would
|
|
191
|
+
// start one: respawn the daemon, hand it the same input, three times.
|
|
192
|
+
if (DaemonClient.wasHandlingRequest(err))
|
|
193
|
+
return false;
|
|
181
194
|
const msg = err.message;
|
|
182
195
|
return DaemonClient.RETRYABLE_CODES.some((code) => msg.includes(code));
|
|
183
196
|
}
|
|
197
|
+
/** True for an error raised after the daemon already had the request. */
|
|
198
|
+
static wasHandlingRequest(err) {
|
|
199
|
+
return err.vexpDaemonGone === true;
|
|
200
|
+
}
|
|
201
|
+
/** The error `daemonGoneMessage` describes, marked so no retry path can
|
|
202
|
+
* mistake it for a transient connection failure. */
|
|
203
|
+
static daemonGoneError(tool, ioError) {
|
|
204
|
+
const err = new Error(DaemonClient.daemonGoneMessage(tool, ioError));
|
|
205
|
+
err.vexpDaemonGone = true;
|
|
206
|
+
return err;
|
|
207
|
+
}
|
|
184
208
|
/**
|
|
185
209
|
* Invia una richiesta al daemon con retry per errori di connessione transienti.
|
|
186
210
|
*/
|
|
@@ -218,10 +242,32 @@ export class DaemonClient {
|
|
|
218
242
|
}
|
|
219
243
|
throw this.augmentDaemonError(lastError);
|
|
220
244
|
}
|
|
245
|
+
/** What we say when the daemon took the request and then went away.
|
|
246
|
+
*
|
|
247
|
+
* The lockstep twin of `daemon_gone_message` in
|
|
248
|
+
* packages/vexp-core/src/mcp_stdio.rs. The agent used to be told "Daemon
|
|
249
|
+
* connection closed unexpectedly", which names neither the tool, nor where
|
|
250
|
+
* the reason is, nor what to do — and this is the DEFAULT MCP server, so
|
|
251
|
+
* it is what most agents actually see.
|
|
252
|
+
*
|
|
253
|
+
* It carries no retryable error code on purpose: `isRetryableError` keys
|
|
254
|
+
* on the text, and a daemon that died holding this request must not be
|
|
255
|
+
* respawned and handed the same input again. */
|
|
256
|
+
static daemonGoneMessage(tool, ioError) {
|
|
257
|
+
const because = ioError ? ` (${ioError})` : "";
|
|
258
|
+
return (`The vexp daemon closed the connection before answering '${tool}': it stopped or was ` +
|
|
259
|
+
`restarted while handling the request${because}. If it crashed, the reason is in the last ` +
|
|
260
|
+
`lines of daemon.log (daemon.log.1 once a new daemon has started; vexp.log when VS Code ` +
|
|
261
|
+
`runs it) in the .vexp folder of the workspace it serves. AGENT INSTRUCTION: retry this ` +
|
|
262
|
+
`call once; if it fails the same way, continue with your own tools and tell the user.`);
|
|
263
|
+
}
|
|
221
264
|
/** Append the daemon log tail to a connection error so a failure that
|
|
222
265
|
* survived auto-spawn + retries is actionable instead of opaque. */
|
|
223
266
|
augmentDaemonError(err) {
|
|
224
|
-
|
|
267
|
+
// A daemon that died holding the request is the case the tail was written
|
|
268
|
+
// for — the reason is in the last lines of its log — even though it is
|
|
269
|
+
// deliberately not retryable.
|
|
270
|
+
if (!DaemonClient.isRetryableError(err) && !DaemonClient.wasHandlingRequest(err))
|
|
225
271
|
return err;
|
|
226
272
|
const tail = this.daemonLogTail();
|
|
227
273
|
if (tail && !err.message.includes("--- daemon.log") && !err.message.includes("--- vexp.log")) {
|
|
@@ -230,8 +276,10 @@ export class DaemonClient {
|
|
|
230
276
|
// Targeting diagnostics apply only to the stdio path that RESOLVES the target
|
|
231
277
|
// (env/cwd/registry). The HTTP supervisor (spawnWorkspaceRoot) and explicit-
|
|
232
278
|
// socket callers (tests, one-shot CLI) already know their target, so leave
|
|
233
|
-
// those error paths byte-for-byte unchanged.
|
|
234
|
-
|
|
279
|
+
// those error paths byte-for-byte unchanged. A daemon that answered the
|
|
280
|
+
// connect and then died is not a targeting problem either: we found it.
|
|
281
|
+
if (!DaemonClient.wasHandlingRequest(err) &&
|
|
282
|
+
!this.explicitSocketPath &&
|
|
235
283
|
!this.spawnWorkspaceRoot &&
|
|
236
284
|
!err.message.includes("--- vexp targeting diagnostics ---")) {
|
|
237
285
|
err.message += targetingDiagnostic();
|
|
@@ -370,6 +418,7 @@ export class DaemonClient {
|
|
|
370
418
|
let client;
|
|
371
419
|
let responseBuffer = "";
|
|
372
420
|
let settled = false;
|
|
421
|
+
let requestWritten = false;
|
|
373
422
|
const budgetMs = DaemonClient.callBudgetMs(tool);
|
|
374
423
|
const timeout = setTimeout(() => {
|
|
375
424
|
if (!settled) {
|
|
@@ -392,7 +441,18 @@ export class DaemonClient {
|
|
|
392
441
|
client = net.createConnection({ path: this.socketPath });
|
|
393
442
|
}
|
|
394
443
|
client.on("connect", () => {
|
|
395
|
-
|
|
444
|
+
// The flag is set when the KERNEL accepted the bytes, not when we
|
|
445
|
+
// handed them over: a connect that lands on a pipe the daemon is
|
|
446
|
+
// closing (restart, reload, the Windows re-arm race) fails the write,
|
|
447
|
+
// and that request never reached anyone — it is the ordinary
|
|
448
|
+
// transient failure, and it must still be retried and respawned.
|
|
449
|
+
// Once the bytes are gone, a failure is a daemon that went away WHILE
|
|
450
|
+
// WORKING, and retrying means handing a fresh daemon the same input
|
|
451
|
+
// again: a crash loop, if that input is what ended the last one.
|
|
452
|
+
client.write(requestLine, (err) => {
|
|
453
|
+
if (!err)
|
|
454
|
+
requestWritten = true;
|
|
455
|
+
});
|
|
396
456
|
});
|
|
397
457
|
client.on("data", (chunk) => {
|
|
398
458
|
responseBuffer += chunk.toString();
|
|
@@ -415,10 +475,12 @@ export class DaemonClient {
|
|
|
415
475
|
}
|
|
416
476
|
});
|
|
417
477
|
client.on("error", (err) => {
|
|
418
|
-
settle(() => reject(
|
|
478
|
+
settle(() => reject(requestWritten
|
|
479
|
+
? DaemonClient.daemonGoneError(tool, err.message)
|
|
480
|
+
: new Error(`Daemon connection error: ${err.message}. ${daemonRunHint()}`)));
|
|
419
481
|
});
|
|
420
482
|
client.on("close", () => {
|
|
421
|
-
settle(() => reject(
|
|
483
|
+
settle(() => reject(DaemonClient.daemonGoneError(tool)));
|
|
422
484
|
});
|
|
423
485
|
});
|
|
424
486
|
}
|