vexp-mcp 3.2.0 → 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 +62 -6
- package/package.json +1 -1
package/dist/daemon-client.js
CHANGED
|
@@ -184,9 +184,27 @@ export class DaemonClient {
|
|
|
184
184
|
return resolveDaemonSocket() ?? getDefaultSocketPath();
|
|
185
185
|
}
|
|
186
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;
|
|
187
194
|
const msg = err.message;
|
|
188
195
|
return DaemonClient.RETRYABLE_CODES.some((code) => msg.includes(code));
|
|
189
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
|
+
}
|
|
190
208
|
/**
|
|
191
209
|
* Invia una richiesta al daemon con retry per errori di connessione transienti.
|
|
192
210
|
*/
|
|
@@ -224,10 +242,32 @@ export class DaemonClient {
|
|
|
224
242
|
}
|
|
225
243
|
throw this.augmentDaemonError(lastError);
|
|
226
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
|
+
}
|
|
227
264
|
/** Append the daemon log tail to a connection error so a failure that
|
|
228
265
|
* survived auto-spawn + retries is actionable instead of opaque. */
|
|
229
266
|
augmentDaemonError(err) {
|
|
230
|
-
|
|
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))
|
|
231
271
|
return err;
|
|
232
272
|
const tail = this.daemonLogTail();
|
|
233
273
|
if (tail && !err.message.includes("--- daemon.log") && !err.message.includes("--- vexp.log")) {
|
|
@@ -236,8 +276,10 @@ export class DaemonClient {
|
|
|
236
276
|
// Targeting diagnostics apply only to the stdio path that RESOLVES the target
|
|
237
277
|
// (env/cwd/registry). The HTTP supervisor (spawnWorkspaceRoot) and explicit-
|
|
238
278
|
// socket callers (tests, one-shot CLI) already know their target, so leave
|
|
239
|
-
// those error paths byte-for-byte unchanged.
|
|
240
|
-
|
|
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 &&
|
|
241
283
|
!this.spawnWorkspaceRoot &&
|
|
242
284
|
!err.message.includes("--- vexp targeting diagnostics ---")) {
|
|
243
285
|
err.message += targetingDiagnostic();
|
|
@@ -376,6 +418,7 @@ export class DaemonClient {
|
|
|
376
418
|
let client;
|
|
377
419
|
let responseBuffer = "";
|
|
378
420
|
let settled = false;
|
|
421
|
+
let requestWritten = false;
|
|
379
422
|
const budgetMs = DaemonClient.callBudgetMs(tool);
|
|
380
423
|
const timeout = setTimeout(() => {
|
|
381
424
|
if (!settled) {
|
|
@@ -398,7 +441,18 @@ export class DaemonClient {
|
|
|
398
441
|
client = net.createConnection({ path: this.socketPath });
|
|
399
442
|
}
|
|
400
443
|
client.on("connect", () => {
|
|
401
|
-
|
|
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
|
+
});
|
|
402
456
|
});
|
|
403
457
|
client.on("data", (chunk) => {
|
|
404
458
|
responseBuffer += chunk.toString();
|
|
@@ -421,10 +475,12 @@ export class DaemonClient {
|
|
|
421
475
|
}
|
|
422
476
|
});
|
|
423
477
|
client.on("error", (err) => {
|
|
424
|
-
settle(() => reject(
|
|
478
|
+
settle(() => reject(requestWritten
|
|
479
|
+
? DaemonClient.daemonGoneError(tool, err.message)
|
|
480
|
+
: new Error(`Daemon connection error: ${err.message}. ${daemonRunHint()}`)));
|
|
425
481
|
});
|
|
426
482
|
client.on("close", () => {
|
|
427
|
-
settle(() => reject(
|
|
483
|
+
settle(() => reject(DaemonClient.daemonGoneError(tool)));
|
|
428
484
|
});
|
|
429
485
|
});
|
|
430
486
|
}
|