@mcpmesh/sdk 2.3.0 → 2.5.0
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/__tests__/agent-single-instance.spec.d.ts +2 -0
- package/dist/__tests__/agent-single-instance.spec.d.ts.map +1 -0
- package/dist/__tests__/agent-single-instance.spec.js +80 -0
- package/dist/__tests__/agent-single-instance.spec.js.map +1 -0
- package/dist/__tests__/event-loop-resilience.spec.d.ts +2 -0
- package/dist/__tests__/event-loop-resilience.spec.d.ts.map +1 -0
- package/dist/__tests__/event-loop-resilience.spec.js +321 -0
- package/dist/__tests__/event-loop-resilience.spec.js.map +1 -0
- package/dist/__tests__/llm-agent-model-params.test.js +83 -0
- package/dist/__tests__/llm-agent-model-params.test.js.map +1 -1
- package/dist/__tests__/llm-max-iterations.test.d.ts +20 -0
- package/dist/__tests__/llm-max-iterations.test.d.ts.map +1 -0
- package/dist/__tests__/llm-max-iterations.test.js +252 -0
- package/dist/__tests__/llm-max-iterations.test.js.map +1 -0
- package/dist/__tests__/llm-mesh-error-mapping.test.d.ts +16 -0
- package/dist/__tests__/llm-mesh-error-mapping.test.d.ts.map +1 -0
- package/dist/__tests__/llm-mesh-error-mapping.test.js +135 -0
- package/dist/__tests__/llm-mesh-error-mapping.test.js.map +1 -0
- package/dist/__tests__/llm-provider-multistep.test.d.ts +20 -0
- package/dist/__tests__/llm-provider-multistep.test.d.ts.map +1 -0
- package/dist/__tests__/llm-provider-multistep.test.js +138 -0
- package/dist/__tests__/llm-provider-multistep.test.js.map +1 -0
- package/dist/__tests__/llm-provider-output-mode.test.d.ts +21 -0
- package/dist/__tests__/llm-provider-output-mode.test.d.ts.map +1 -0
- package/dist/__tests__/llm-provider-output-mode.test.js +116 -0
- package/dist/__tests__/llm-provider-output-mode.test.js.map +1 -0
- package/dist/__tests__/llm-provider-stopwhen.test.d.ts +22 -0
- package/dist/__tests__/llm-provider-stopwhen.test.d.ts.map +1 -0
- package/dist/__tests__/llm-provider-stopwhen.test.js +127 -0
- package/dist/__tests__/llm-provider-stopwhen.test.js.map +1 -0
- package/dist/__tests__/llm-provider-system-synthesis.test.d.ts +20 -0
- package/dist/__tests__/llm-provider-system-synthesis.test.d.ts.map +1 -0
- package/dist/__tests__/llm-provider-system-synthesis.test.js +168 -0
- package/dist/__tests__/llm-provider-system-synthesis.test.js.map +1 -0
- package/dist/__tests__/llm-provider-vertex-settings.test.d.ts +18 -0
- package/dist/__tests__/llm-provider-vertex-settings.test.d.ts.map +1 -0
- package/dist/__tests__/llm-provider-vertex-settings.test.js +128 -0
- package/dist/__tests__/llm-provider-vertex-settings.test.js.map +1 -0
- package/dist/__tests__/llm-response-model.test.d.ts +10 -0
- package/dist/__tests__/llm-response-model.test.d.ts.map +1 -0
- package/dist/__tests__/llm-response-model.test.js +92 -0
- package/dist/__tests__/llm-response-model.test.js.map +1 -0
- package/dist/__tests__/port-conflict-fallback.spec.d.ts +2 -0
- package/dist/__tests__/port-conflict-fallback.spec.d.ts.map +1 -0
- package/dist/__tests__/port-conflict-fallback.spec.js +123 -0
- package/dist/__tests__/port-conflict-fallback.spec.js.map +1 -0
- package/dist/__tests__/port-probe-errors.spec.d.ts +2 -0
- package/dist/__tests__/port-probe-errors.spec.d.ts.map +1 -0
- package/dist/__tests__/port-probe-errors.spec.js +100 -0
- package/dist/__tests__/port-probe-errors.spec.js.map +1 -0
- package/dist/__tests__/provider-handler-registry.test.d.ts +0 -1
- package/dist/__tests__/provider-handler-registry.test.d.ts.map +1 -1
- package/dist/__tests__/provider-handler-registry.test.js +23 -1
- package/dist/__tests__/provider-handler-registry.test.js.map +1 -1
- package/dist/__tests__/proxy-sse-no-data.test.d.ts +13 -0
- package/dist/__tests__/proxy-sse-no-data.test.d.ts.map +1 -0
- package/dist/__tests__/proxy-sse-no-data.test.js +147 -0
- package/dist/__tests__/proxy-sse-no-data.test.js.map +1 -0
- package/dist/__tests__/proxy-stream.test.js +26 -0
- package/dist/__tests__/proxy-stream.test.js.map +1 -1
- package/dist/__tests__/proxy-timeout-guard.test.d.ts +12 -0
- package/dist/__tests__/proxy-timeout-guard.test.d.ts.map +1 -0
- package/dist/__tests__/proxy-timeout-guard.test.js +85 -0
- package/dist/__tests__/proxy-timeout-guard.test.js.map +1 -0
- package/dist/__tests__/proxy-timer-leak.test.d.ts +16 -0
- package/dist/__tests__/proxy-timer-leak.test.d.ts.map +1 -0
- package/dist/__tests__/proxy-timer-leak.test.js +97 -0
- package/dist/__tests__/proxy-timer-leak.test.js.map +1 -0
- package/dist/__tests__/proxy-tool-error.test.d.ts +13 -0
- package/dist/__tests__/proxy-tool-error.test.d.ts.map +1 -0
- package/dist/__tests__/proxy-tool-error.test.js +313 -0
- package/dist/__tests__/proxy-tool-error.test.js.map +1 -0
- package/dist/__tests__/registry-disconnect-retains-deps.spec.d.ts +2 -0
- package/dist/__tests__/registry-disconnect-retains-deps.spec.d.ts.map +1 -0
- package/dist/__tests__/registry-disconnect-retains-deps.spec.js +101 -0
- package/dist/__tests__/registry-disconnect-retains-deps.spec.js.map +1 -0
- package/dist/__tests__/response-parser.test.js +29 -0
- package/dist/__tests__/response-parser.test.js.map +1 -1
- package/dist/__tests__/route.test.js +21 -1
- package/dist/__tests__/route.test.js.map +1 -1
- package/dist/__tests__/settle-window.spec.d.ts +2 -0
- package/dist/__tests__/settle-window.spec.d.ts.map +1 -0
- package/dist/__tests__/settle-window.spec.js +324 -0
- package/dist/__tests__/settle-window.spec.js.map +1 -0
- package/dist/__tests__/sse.test.js +12 -0
- package/dist/__tests__/sse.test.js.map +1 -1
- package/dist/__tests__/stop-dispatchers.spec.d.ts +2 -0
- package/dist/__tests__/stop-dispatchers.spec.d.ts.map +1 -0
- package/dist/__tests__/stop-dispatchers.spec.js +227 -0
- package/dist/__tests__/stop-dispatchers.spec.js.map +1 -0
- package/dist/agent.d.ts +65 -5
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +317 -78
- package/dist/agent.js.map +1 -1
- package/dist/api-runtime.d.ts +33 -3
- package/dist/api-runtime.d.ts.map +1 -1
- package/dist/api-runtime.js +133 -33
- package/dist/api-runtime.js.map +1 -1
- package/dist/claim-dispatcher.d.ts +25 -0
- package/dist/claim-dispatcher.d.ts.map +1 -1
- package/dist/claim-dispatcher.js +59 -1
- package/dist/claim-dispatcher.js.map +1 -1
- package/dist/config.d.ts +73 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +108 -2
- package/dist/config.js.map +1 -1
- package/dist/debug.d.ts +1 -1
- package/dist/debug.d.ts.map +1 -1
- package/dist/express.d.ts +33 -0
- package/dist/express.d.ts.map +1 -1
- package/dist/express.js +157 -32
- package/dist/express.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/llm-agent.d.ts +34 -0
- package/dist/llm-agent.d.ts.map +1 -1
- package/dist/llm-agent.js +239 -434
- package/dist/llm-agent.js.map +1 -1
- package/dist/llm-provider.d.ts +51 -4
- package/dist/llm-provider.d.ts.map +1 -1
- package/dist/llm-provider.js +175 -36
- package/dist/llm-provider.js.map +1 -1
- package/dist/llm.d.ts +1 -1
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +8 -5
- package/dist/llm.js.map +1 -1
- package/dist/provider-handlers/gemini-handler.d.ts.map +1 -1
- package/dist/provider-handlers/gemini-handler.js +8 -14
- package/dist/provider-handlers/gemini-handler.js.map +1 -1
- package/dist/provider-handlers/openai-handler.d.ts.map +1 -1
- package/dist/provider-handlers/openai-handler.js +2 -15
- package/dist/provider-handlers/openai-handler.js.map +1 -1
- package/dist/provider-handlers/provider-handler-registry.d.ts +10 -1
- package/dist/provider-handlers/provider-handler-registry.d.ts.map +1 -1
- package/dist/provider-handlers/provider-handler-registry.js +4 -1
- package/dist/provider-handlers/provider-handler-registry.js.map +1 -1
- package/dist/provider-handlers/provider-handler.d.ts +12 -0
- package/dist/provider-handlers/provider-handler.d.ts.map +1 -1
- package/dist/provider-handlers/provider-handler.js +24 -0
- package/dist/provider-handlers/provider-handler.js.map +1 -1
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +360 -287
- package/dist/proxy.js.map +1 -1
- package/dist/response-parser.d.ts +10 -0
- package/dist/response-parser.d.ts.map +1 -1
- package/dist/response-parser.js +55 -0
- package/dist/response-parser.js.map +1 -1
- package/dist/route.d.ts.map +1 -1
- package/dist/route.js +38 -0
- package/dist/route.js.map +1 -1
- package/dist/settle.d.ts +129 -0
- package/dist/settle.d.ts.map +1 -0
- package/dist/settle.js +284 -0
- package/dist/settle.js.map +1 -0
- package/dist/sse.d.ts.map +1 -1
- package/dist/sse.js +5 -2
- package/dist/sse.js.map +1 -1
- package/dist/tracing.d.ts +13 -0
- package/dist/tracing.d.ts.map +1 -1
- package/dist/tracing.js +40 -0
- package/dist/tracing.js.map +1 -1
- package/dist/types.d.ts +10 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for #1173 — concurrent claim-dispatcher shutdown under one
|
|
3
|
+
* shared drain budget, and #1163 MED-2 — `MeshAgent.shutdown()` reaching
|
|
4
|
+
* the registry unregister (`handle.shutdown()`) regardless of drain
|
|
5
|
+
* outcome.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the Python fix in PR #1172
|
|
8
|
+
* (`_mcp_mesh/engine/claim_dispatcher.py::stop_dispatchers`):
|
|
9
|
+
* - N dispatchers drain CONCURRENTLY against the SAME window (one
|
|
10
|
+
* drain window of wall time, not N stacked 30s windows);
|
|
11
|
+
* - the whole phase is hard-capped at drain + grace, after which the
|
|
12
|
+
* remaining drains are abandoned with a warning;
|
|
13
|
+
* - never rejects — a wedged dispatcher must not prevent the registry
|
|
14
|
+
* cleanup callers sequence afterwards.
|
|
15
|
+
*/
|
|
16
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
17
|
+
import { stopDispatchers } from "../claim-dispatcher.js";
|
|
18
|
+
import { MeshAgent } from "../agent.js";
|
|
19
|
+
import { ApiRuntime } from "../api-runtime.js";
|
|
20
|
+
import { MeshExpress } from "../express.js";
|
|
21
|
+
function sleep(ms) {
|
|
22
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
23
|
+
}
|
|
24
|
+
/** Build a stub dispatcher whose stop() runs the given impl. */
|
|
25
|
+
function fakeDispatcher(capability, stopImpl) {
|
|
26
|
+
return {
|
|
27
|
+
capability,
|
|
28
|
+
stop: vi.fn(stopImpl),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
describe("stopDispatchers (#1173)", () => {
|
|
32
|
+
let warnSpy;
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
warnSpy = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
35
|
+
vi.spyOn(console, "log").mockImplementation(() => { });
|
|
36
|
+
});
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
vi.restoreAllMocks();
|
|
39
|
+
});
|
|
40
|
+
it("stops dispatchers concurrently — wall time is one drain window, not N", async () => {
|
|
41
|
+
const d1 = fakeDispatcher("cap-a", () => sleep(200));
|
|
42
|
+
const d2 = fakeDispatcher("cap-b", () => sleep(200));
|
|
43
|
+
const d3 = fakeDispatcher("cap-c", () => sleep(200));
|
|
44
|
+
const t0 = Date.now();
|
|
45
|
+
await stopDispatchers([d1, d2, d3], 2000, 2000);
|
|
46
|
+
const elapsed = Date.now() - t0;
|
|
47
|
+
// Sequential would be >= 600ms; concurrent is ~200ms. The 500ms
|
|
48
|
+
// bound leaves ~300ms of CI scheduling-jitter headroom while still
|
|
49
|
+
// failing a sequential drain.
|
|
50
|
+
expect(elapsed).toBeLessThan(500);
|
|
51
|
+
expect(d1.stop).toHaveBeenCalledWith(2000);
|
|
52
|
+
expect(d2.stop).toHaveBeenCalledWith(2000);
|
|
53
|
+
expect(d3.stop).toHaveBeenCalledWith(2000);
|
|
54
|
+
});
|
|
55
|
+
it("passes the SHARED drain window to every dispatcher", async () => {
|
|
56
|
+
const ds = [
|
|
57
|
+
fakeDispatcher("cap-a", async () => { }),
|
|
58
|
+
fakeDispatcher("cap-b", async () => { }),
|
|
59
|
+
fakeDispatcher("cap-c", async () => { }),
|
|
60
|
+
];
|
|
61
|
+
await stopDispatchers(ds, 250, 100);
|
|
62
|
+
for (const d of ds) {
|
|
63
|
+
expect(d.stop).toHaveBeenCalledWith(250);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
it("abandons a hanging drain at the hard cap (drain + grace) with a warning", async () => {
|
|
67
|
+
const hanging = fakeDispatcher("cap-stuck", () => new Promise(() => { }));
|
|
68
|
+
const t0 = Date.now();
|
|
69
|
+
await stopDispatchers([hanging], 50, 50);
|
|
70
|
+
const elapsed = Date.now() - t0;
|
|
71
|
+
// Returned at ~100ms (50 drain + 50 grace), not hung forever.
|
|
72
|
+
expect(elapsed).toBeGreaterThanOrEqual(90);
|
|
73
|
+
expect(elapsed).toBeLessThan(1000);
|
|
74
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("exceeded the shared budget"));
|
|
75
|
+
});
|
|
76
|
+
it("a rejecting stop() does not skip its peers and does not reject", async () => {
|
|
77
|
+
const bad = fakeDispatcher("cap-bad", async () => {
|
|
78
|
+
throw new Error("stop blew up");
|
|
79
|
+
});
|
|
80
|
+
const good = fakeDispatcher("cap-good", () => sleep(20));
|
|
81
|
+
await expect(stopDispatchers([bad, good], 500, 100)).resolves.toBeUndefined();
|
|
82
|
+
expect(good.stop).toHaveBeenCalledTimes(1);
|
|
83
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("error stopping dispatcher capability=cap-bad"), expect.any(Error));
|
|
84
|
+
});
|
|
85
|
+
it("is a no-op for an empty dispatcher list", async () => {
|
|
86
|
+
await expect(stopDispatchers([], 50, 50)).resolves.toBeUndefined();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe("MeshAgent.shutdown() — unregister runs regardless of drain outcome (#1163 MED-2 / #1173)", () => {
|
|
90
|
+
beforeEach(() => {
|
|
91
|
+
vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
92
|
+
vi.spyOn(console, "log").mockImplementation(() => { });
|
|
93
|
+
});
|
|
94
|
+
afterEach(() => {
|
|
95
|
+
vi.restoreAllMocks();
|
|
96
|
+
});
|
|
97
|
+
/**
|
|
98
|
+
* Drive the REAL `shutdown()` against a stub `this` (same pattern as
|
|
99
|
+
* the event-loop specs) so we don't have to bind a full agent to the
|
|
100
|
+
* napi runtime. Only the fields shutdown() reads are provided.
|
|
101
|
+
*/
|
|
102
|
+
function stubAgentThis(dispatchers) {
|
|
103
|
+
return {
|
|
104
|
+
_claimDispatchers: dispatchers,
|
|
105
|
+
_a2aClients: new Map(),
|
|
106
|
+
httpsProxy: undefined,
|
|
107
|
+
handle: { shutdown: vi.fn(async () => { }) },
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
it("calls handle.shutdown() even when a dispatcher drain hangs", async () => {
|
|
111
|
+
const hanging = fakeDispatcher("cap-stuck", () => new Promise(() => { }));
|
|
112
|
+
const stubThis = stubAgentThis([hanging]);
|
|
113
|
+
const handle = stubThis.handle; // shutdown() nulls this.handle
|
|
114
|
+
const shutdown = MeshAgent.prototype.shutdown;
|
|
115
|
+
await shutdown.call(stubThis, {
|
|
116
|
+
drainTimeoutMs: 30,
|
|
117
|
+
drainGraceMs: 30,
|
|
118
|
+
});
|
|
119
|
+
expect(handle.shutdown).toHaveBeenCalledTimes(1);
|
|
120
|
+
// Handle nulled + dispatcher list cleared after a successful unregister.
|
|
121
|
+
expect(stubThis.handle).toBeNull();
|
|
122
|
+
expect(stubThis._claimDispatchers).toEqual([]);
|
|
123
|
+
});
|
|
124
|
+
it("calls handle.shutdown() even when a dispatcher stop() throws", async () => {
|
|
125
|
+
const bad = fakeDispatcher("cap-bad", async () => {
|
|
126
|
+
throw new Error("drain blew up");
|
|
127
|
+
});
|
|
128
|
+
const stubThis = stubAgentThis([bad]);
|
|
129
|
+
const handle = stubThis.handle;
|
|
130
|
+
const shutdown = MeshAgent.prototype.shutdown;
|
|
131
|
+
await shutdown.call(stubThis, {
|
|
132
|
+
drainTimeoutMs: 30,
|
|
133
|
+
drainGraceMs: 30,
|
|
134
|
+
});
|
|
135
|
+
expect(handle.shutdown).toHaveBeenCalledTimes(1);
|
|
136
|
+
});
|
|
137
|
+
it("drains slow dispatchers concurrently within one budget", async () => {
|
|
138
|
+
const d1 = fakeDispatcher("cap-a", () => sleep(200));
|
|
139
|
+
const d2 = fakeDispatcher("cap-b", () => sleep(200));
|
|
140
|
+
const d3 = fakeDispatcher("cap-c", () => sleep(200));
|
|
141
|
+
const stubThis = stubAgentThis([d1, d2, d3]);
|
|
142
|
+
const handle = stubThis.handle;
|
|
143
|
+
const shutdown = MeshAgent.prototype.shutdown;
|
|
144
|
+
const t0 = Date.now();
|
|
145
|
+
await shutdown.call(stubThis, {
|
|
146
|
+
drainTimeoutMs: 2000,
|
|
147
|
+
drainGraceMs: 2000,
|
|
148
|
+
});
|
|
149
|
+
const elapsed = Date.now() - t0;
|
|
150
|
+
// Sequential would be >= 600ms; concurrent is ~200ms. 500ms bound
|
|
151
|
+
// leaves ~300ms of CI scheduling-jitter headroom.
|
|
152
|
+
expect(elapsed).toBeLessThan(500);
|
|
153
|
+
expect(handle.shutdown).toHaveBeenCalledTimes(1);
|
|
154
|
+
});
|
|
155
|
+
it("shutdown() is idempotent — repeat calls return the SAME promise and never re-run the teardown", async () => {
|
|
156
|
+
const d = fakeDispatcher("cap-a", () => sleep(50));
|
|
157
|
+
const stubThis = stubAgentThis([d]);
|
|
158
|
+
const handle = stubThis.handle;
|
|
159
|
+
const shutdown = MeshAgent.prototype.shutdown;
|
|
160
|
+
const p1 = shutdown.call(stubThis, {
|
|
161
|
+
drainTimeoutMs: 1000,
|
|
162
|
+
drainGraceMs: 1000,
|
|
163
|
+
});
|
|
164
|
+
// Re-entrant call while the first teardown is mid-drain — the
|
|
165
|
+
// user-code-shutdown() + signal-during-drain race. Must NOT start
|
|
166
|
+
// a second concurrent teardown (double dispatcher stop, double
|
|
167
|
+
// napi handle.shutdown()).
|
|
168
|
+
const p2 = shutdown.call(stubThis, {
|
|
169
|
+
drainTimeoutMs: 1000,
|
|
170
|
+
drainGraceMs: 1000,
|
|
171
|
+
});
|
|
172
|
+
expect(p2).toBe(p1);
|
|
173
|
+
await p1;
|
|
174
|
+
// A call AFTER completion also returns the memoized promise.
|
|
175
|
+
const p3 = shutdown.call(stubThis);
|
|
176
|
+
expect(p3).toBe(p1);
|
|
177
|
+
await p3;
|
|
178
|
+
expect(d.stop).toHaveBeenCalledTimes(1);
|
|
179
|
+
expect(handle.shutdown).toHaveBeenCalledTimes(1);
|
|
180
|
+
// shutdown() itself flags the shutdown so the event loop's failure
|
|
181
|
+
// branch can exit promptly.
|
|
182
|
+
expect(stubThis.shutdownRequested).toBe(true);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
describe("shutdown() idempotency — ApiRuntime / MeshExpress (same memoized-promise pattern)", () => {
|
|
186
|
+
beforeEach(() => {
|
|
187
|
+
vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
188
|
+
vi.spyOn(console, "log").mockImplementation(() => { });
|
|
189
|
+
});
|
|
190
|
+
afterEach(() => {
|
|
191
|
+
vi.restoreAllMocks();
|
|
192
|
+
});
|
|
193
|
+
it("ApiRuntime.shutdown() memoizes — one napi handle.shutdown() across repeat calls", async () => {
|
|
194
|
+
const stubThis = {
|
|
195
|
+
handle: { shutdown: vi.fn(async () => { }) },
|
|
196
|
+
shutdownPromise: null,
|
|
197
|
+
shutdownRequested: false,
|
|
198
|
+
};
|
|
199
|
+
const handle = stubThis.handle; // shutdown() nulls this.handle
|
|
200
|
+
const shutdown = ApiRuntime.prototype.shutdown;
|
|
201
|
+
const p1 = shutdown.call(stubThis);
|
|
202
|
+
const p2 = shutdown.call(stubThis);
|
|
203
|
+
expect(p2).toBe(p1);
|
|
204
|
+
await p1;
|
|
205
|
+
expect(shutdown.call(stubThis)).toBe(p1);
|
|
206
|
+
expect(handle.shutdown).toHaveBeenCalledTimes(1);
|
|
207
|
+
expect(stubThis.shutdownRequested).toBe(true);
|
|
208
|
+
});
|
|
209
|
+
it("MeshExpress.shutdown() memoizes — one napi handle.shutdown() across repeat calls", async () => {
|
|
210
|
+
const stubThis = {
|
|
211
|
+
handle: { shutdown: vi.fn(async () => { }) },
|
|
212
|
+
server: null,
|
|
213
|
+
shutdownPromise: null,
|
|
214
|
+
shutdownRequested: false,
|
|
215
|
+
};
|
|
216
|
+
const handle = stubThis.handle;
|
|
217
|
+
const shutdown = MeshExpress.prototype.shutdown;
|
|
218
|
+
const p1 = shutdown.call(stubThis);
|
|
219
|
+
const p2 = shutdown.call(stubThis);
|
|
220
|
+
expect(p2).toBe(p1);
|
|
221
|
+
await p1;
|
|
222
|
+
expect(shutdown.call(stubThis)).toBe(p1);
|
|
223
|
+
expect(handle.shutdown).toHaveBeenCalledTimes(1);
|
|
224
|
+
expect(stubThis.shutdownRequested).toBe(true);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
//# sourceMappingURL=stop-dispatchers.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop-dispatchers.spec.js","sourceRoot":"","sources":["../../src/__tests__/stop-dispatchers.spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAwB,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,SAAS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AC,CAAC;QAC7D,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpB,MAAM,EAAE,CAAC;QACT,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAkC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEnE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACjD,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/agent.d.ts
CHANGED
|
@@ -48,6 +48,13 @@ export declare function __getWorkerToolMap(): Map<string, (...args: unknown[]) =
|
|
|
48
48
|
* - Dependency injection for tool functions
|
|
49
49
|
*/
|
|
50
50
|
export declare class MeshAgent {
|
|
51
|
+
/**
|
|
52
|
+
* Hard cap on the signal-path shutdown sequence. Must exceed the
|
|
53
|
+
* dispatcher drain hard-cap (30s drain + 10s grace, see
|
|
54
|
+
* `stopDispatchers`) so a clean drain isn't cut short; the extra 5s
|
|
55
|
+
* covers pool/A2A teardown and the registry unregister.
|
|
56
|
+
*/
|
|
57
|
+
private static readonly SIGNAL_SHUTDOWN_TIMEOUT_MS;
|
|
51
58
|
private server;
|
|
52
59
|
private config;
|
|
53
60
|
private agentId;
|
|
@@ -63,6 +70,23 @@ export declare class MeshAgent {
|
|
|
63
70
|
private started;
|
|
64
71
|
private tracingEnabled;
|
|
65
72
|
private shutdownRequested;
|
|
73
|
+
/**
|
|
74
|
+
* Memoized in-flight (or completed) teardown. `shutdown()` is
|
|
75
|
+
* idempotent: the first caller creates this promise and every later
|
|
76
|
+
* caller — user code, the signal handler, a second signal — awaits
|
|
77
|
+
* the SAME teardown instead of racing a concurrent one (double
|
|
78
|
+
* dispatcher drain, double napi `handle.shutdown()`).
|
|
79
|
+
*/
|
|
80
|
+
private shutdownPromise;
|
|
81
|
+
/**
|
|
82
|
+
* This agent's own SIGINT/SIGTERM handler references, kept so
|
|
83
|
+
* shutdown() can `process.off` them. Without removal, sequential
|
|
84
|
+
* MeshAgent instances in one process (legal across async chunk
|
|
85
|
+
* boundaries) accumulate stale handlers whose memoized — already
|
|
86
|
+
* resolved — shutdown() would `process.exit(0)` immediately on the
|
|
87
|
+
* next signal, cutting short the LIVE agent's drain.
|
|
88
|
+
*/
|
|
89
|
+
private signalHandlers;
|
|
66
90
|
/**
|
|
67
91
|
* Resolved dependencies: composite key -> proxy
|
|
68
92
|
* Key format: "${toolName}:dep_${depIndex}" (e.g., "myTool:dep_0")
|
|
@@ -190,10 +214,15 @@ export declare class MeshAgent {
|
|
|
190
214
|
* Install signal handlers for graceful shutdown.
|
|
191
215
|
* Ensures agent unregisters from registry on SIGINT/SIGTERM.
|
|
192
216
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
217
|
+
* Runs the FULL `shutdown()` sequence (issue #1163 MED-2): claim
|
|
218
|
+
* dispatchers drain their in-flight jobs (concurrently, under one
|
|
219
|
+
* shared budget — see `stopDispatchers`), A2A clients / HTTP pool /
|
|
220
|
+
* tool-worker pool close, and `handle.shutdown()` unregisters from
|
|
221
|
+
* the registry (which also resolves the event loop's `nextEvent()`
|
|
222
|
+
* with a "shutdown" event, ending it cleanly).
|
|
223
|
+
*
|
|
224
|
+
* The whole sequence is bounded by a force-exit timer so a hang in
|
|
225
|
+
* any cleanup step cannot wedge the process past its SIGTERM grace.
|
|
197
226
|
*/
|
|
198
227
|
private installSignalHandlers;
|
|
199
228
|
/**
|
|
@@ -202,6 +231,15 @@ export declare class MeshAgent {
|
|
|
202
231
|
private startHeartbeat;
|
|
203
232
|
/**
|
|
204
233
|
* Run the event loop to handle mesh events.
|
|
234
|
+
*
|
|
235
|
+
* Resilience (issue #1163 MED-1): the loop must outlive individual
|
|
236
|
+
* failures. A throw from an event handler (e.g. a malformed event
|
|
237
|
+
* hitting a non-null assertion) is logged and the loop continues; a
|
|
238
|
+
* `nextEvent()` rejection (e.g. a transient napi failure) backs off
|
|
239
|
+
* exponentially (capped) and retries. Only the "shutdown" event — or
|
|
240
|
+
* the handle being torn down — exits the loop. Previously a single
|
|
241
|
+
* throw broke the loop permanently, freezing dependency-topology
|
|
242
|
+
* updates for the process lifetime while the agent kept serving.
|
|
205
243
|
*/
|
|
206
244
|
private runEventLoop;
|
|
207
245
|
/**
|
|
@@ -237,6 +275,16 @@ export declare class MeshAgent {
|
|
|
237
275
|
* Get all resolved dependencies.
|
|
238
276
|
*/
|
|
239
277
|
getAllDependencies(): Map<string, McpMeshTool>;
|
|
278
|
+
/**
|
|
279
|
+
* Inject a mock/fake proxy for a capability (the documented mock
|
|
280
|
+
* contract — see `meshctl man testing --typescript`).
|
|
281
|
+
*
|
|
282
|
+
* Fills the dependency slot of every registered tool that declares the
|
|
283
|
+
* capability and marks those slots resolved with the settle state, so
|
|
284
|
+
* the settling-window grace (#1193) never waits on a caller-supplied
|
|
285
|
+
* dependency.
|
|
286
|
+
*/
|
|
287
|
+
setMockDependency(capability: string, mock: McpMeshTool): void;
|
|
240
288
|
/**
|
|
241
289
|
* Get the agent handle for advanced operations.
|
|
242
290
|
*/
|
|
@@ -251,8 +299,20 @@ export declare class MeshAgent {
|
|
|
251
299
|
getAgentId(): string;
|
|
252
300
|
/**
|
|
253
301
|
* Shutdown the agent gracefully.
|
|
302
|
+
*
|
|
303
|
+
* Idempotent and re-entrant: the first call runs the teardown; every
|
|
304
|
+
* later call (user code, the signal handler, a double signal) returns
|
|
305
|
+
* the SAME promise — later calls' `opts` are ignored. The memo is
|
|
306
|
+
* never cleared: shutdown is terminal, and re-running a half-torn-down
|
|
307
|
+
* cleanup after a failure would be worse than surfacing the original
|
|
308
|
+
* rejection to every caller.
|
|
254
309
|
*/
|
|
255
|
-
shutdown(
|
|
310
|
+
shutdown(opts?: {
|
|
311
|
+
/** Shared in-flight-handler drain window for claim dispatchers. */
|
|
312
|
+
drainTimeoutMs?: number;
|
|
313
|
+
/** Headroom on top of the drain window before drains are abandoned. */
|
|
314
|
+
drainGraceMs?: number;
|
|
315
|
+
}): Promise<void>;
|
|
256
316
|
}
|
|
257
317
|
/**
|
|
258
318
|
* Create a MeshAgent wrapping a FastMCP server.
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,EAGL,KAAK,aAAa,EAInB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,WAAW,EAEX,WAAW,EAEX,iBAAiB,EAClB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,EAGL,KAAK,aAAa,EAInB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,WAAW,EAEX,WAAW,EAEX,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAyDpB;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,eAAuC,CAAC;AAiBrE;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAEjF;AAwCD;;;;;;;;GAQG;AACH,qBAAa,SAAS;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