mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 09:50:24 +08:00
Memory. A v1.5.7 source deployment grew past 14 GB before V8 aborted; the
causes were independent, so this cut fixes each one and bounds what was
previously unbounded.
- The dev server was never actually capped: `next dev` renders in a worker it
spawns, and V8 flags in argv are not inherited, so
`node --max-old-space-size=4096 .../next dev` never reached the process
holding the memory. Next then substituted 50% of total RAM — a 12 GB heap on
a 24 GB machine. web/scripts/dev.mjs routes the ceiling through NODE_OPTIONS
(which the worker inherits and Next honors), clamped to 4 GB and sized off
the cgroup limit in a container.
- Source installs serve a production build: `deeptutor start` builds once into
.next-deeptutor and reuses it until a fingerprint over the web/ tree, the
version file, or the build-time public settings changes. `--dev` is the
opt-in for HMR and keeps using .next, so neither mode invalidates the other.
- LLM clients and providers come from a bounded event-loop-local LRU pool of 2
instead of one per turn, closed on shutdown and retired on a settings
reload; only the selected backend's SDK is imported.
- Caches gained ceilings: knowledge-task log streams cap events and bytes per
task with a 1h TTL and a completion tombstone, the completed-task table
keeps 256, the LlamaIndex index cache drops 8 -> 2 with a 10-minute idle
evict, and a book runtime is released when its queue drains.
- After a turn, a finished book job, or a completed KB task, cycles are
collected and glibc is asked to return free pages via malloc_trim; the
container and launcher set MALLOC_ARENA_MAX=2 and a lower trim threshold,
both operator-overridable.
- Every uvicorn launch sets --timeout-keep-alive 300. web/proxy.ts forwards
over Node's http.globalAgent, whose 5s idle reaper matched uvicorn's default
exactly; both ends raced to close the same socket and the loser's request
died with ECONNRESET ("Failed to load sessions").
- deeptutor.agents, deeptutor.core.agentic, provider_core, the document
extractor's parser libraries and the LLM error-mapping rules resolve on
first use. `python -m deeptutor.api.run_server` no longer reloads by
default (DEEPTUTOR_DEV_RELOAD=1 restores it).
README prose and all ten translated READMEs now describe the production-build
default instead of dev mode. Release notes: assets/releases/ver1-5-8.md
102 lines
3.2 KiB
TypeScript
102 lines
3.2 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
groupProviderTools,
|
|
groupSelection,
|
|
providerGroupId,
|
|
setGroupSelected,
|
|
toggleToolName,
|
|
} from "../lib/mcp-tool-groups";
|
|
|
|
const NOTION = [
|
|
{ name: "mcp_notion_search", provider_id: "notion", server: "notion" },
|
|
{ name: "mcp_notion_create", provider_id: "notion", server: "notion" },
|
|
];
|
|
const GITHUB = [
|
|
{ name: "mcp_github_issues", provider_id: "github", server: "github" },
|
|
];
|
|
const ALL = [...NOTION, ...GITHUB];
|
|
|
|
test("groupProviderTools folds by provider and keeps backend order", () => {
|
|
const groups = groupProviderTools([NOTION[0], GITHUB[0], NOTION[1]]);
|
|
assert.deepEqual(
|
|
groups.map((group) => [group.id, group.tools.map((tool) => tool.name)]),
|
|
[
|
|
["notion", ["mcp_notion_search", "mcp_notion_create"]],
|
|
["github", ["mcp_github_issues"]],
|
|
],
|
|
);
|
|
assert.deepEqual(
|
|
groups.map((group) => group.kind),
|
|
["mcp", "mcp"],
|
|
);
|
|
});
|
|
|
|
test("providerGroupId falls back to the legacy server field then to other", () => {
|
|
assert.equal(providerGroupId({ name: "a", server: "legacy" }), "legacy");
|
|
assert.equal(providerGroupId({ name: "a" }), "other");
|
|
// provider_id wins when both are present but disagree.
|
|
assert.equal(
|
|
providerGroupId({ name: "a", provider_id: "new", server: "old" }),
|
|
"new",
|
|
);
|
|
});
|
|
|
|
test("groupSelection reports all / none / partial for the group only", () => {
|
|
assert.equal(groupSelection(NOTION, []), "none");
|
|
assert.equal(
|
|
groupSelection(NOTION, ["mcp_notion_search", "mcp_notion_create"]),
|
|
"all",
|
|
);
|
|
assert.equal(groupSelection(NOTION, ["mcp_notion_search"]), "partial");
|
|
// A name from another server must not count toward this group: a count-only
|
|
// derivation would call this "all".
|
|
assert.equal(
|
|
groupSelection(NOTION, ["mcp_notion_search", "mcp_github_issues"]),
|
|
"partial",
|
|
);
|
|
assert.equal(groupSelection(NOTION, ["mcp_github_issues"]), "none");
|
|
// Unknown extras never inflate the state either.
|
|
assert.equal(
|
|
groupSelection(GITHUB, ["mcp_github_issues", "mcp_gone_stale"]),
|
|
"all",
|
|
);
|
|
assert.equal(groupSelection([], ["mcp_notion_search"]), "none");
|
|
});
|
|
|
|
test("setGroupSelected flattens back to tool names and leaves others alone", () => {
|
|
// Assigning a whole service is one click, but the saved value stays flat.
|
|
const granted = setGroupSelected(["mcp_github_issues"], NOTION, true);
|
|
assert.deepEqual(granted.slice().sort(), [
|
|
"mcp_github_issues",
|
|
"mcp_notion_create",
|
|
"mcp_notion_search",
|
|
]);
|
|
|
|
// Partial -> all fills the group without duplicating the already-picked name.
|
|
const filled = setGroupSelected(["mcp_notion_search"], NOTION, true);
|
|
assert.deepEqual(filled.slice().sort(), [
|
|
"mcp_notion_create",
|
|
"mcp_notion_search",
|
|
]);
|
|
|
|
// Clearing a group drops exactly its names.
|
|
assert.deepEqual(
|
|
setGroupSelected(
|
|
ALL.map((tool) => tool.name),
|
|
NOTION,
|
|
false,
|
|
),
|
|
["mcp_github_issues"],
|
|
);
|
|
assert.deepEqual(setGroupSelected(["mcp_github_issues"], NOTION, false), [
|
|
"mcp_github_issues",
|
|
]);
|
|
});
|
|
|
|
test("toggleToolName flips a single name in the flat list", () => {
|
|
assert.deepEqual(toggleToolName(["a"], "b"), ["a", "b"]);
|
|
assert.deepEqual(toggleToolName(["a", "b"], "a"), ["b"]);
|
|
});
|