mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 03:09:49 +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
170 lines
5.1 KiB
TypeScript
170 lines
5.1 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
cliArgvLabel,
|
|
clipLabel,
|
|
describeProviderTool,
|
|
formatProgressLabel,
|
|
mcpToolLabel,
|
|
} from "../lib/trace-tools";
|
|
|
|
/** Stands in for i18next: interpolates so assertions read like the UI does. */
|
|
const t = (key: string, opts?: Record<string, unknown>) =>
|
|
key.replace(/\{\{(\w+)\}\}/g, (_m, name) => String(opts?.[name] ?? ""));
|
|
|
|
test("an MCP tool is named without its generated prefix", () => {
|
|
assert.equal(
|
|
mcpToolLabel("mcp_wolfram_WolframAlpha", "wolfram"),
|
|
"WolframAlpha",
|
|
);
|
|
});
|
|
|
|
test("a server whose own name contains an underscore is still stripped correctly", () => {
|
|
// The reason the server id travels in metadata at all: splitting on
|
|
// underscores here would name the tool "server_search" or "search" depending
|
|
// on which split you guessed.
|
|
assert.equal(
|
|
mcpToolLabel("mcp_my_server_deep_search", "my_server"),
|
|
"deep_search",
|
|
);
|
|
});
|
|
|
|
test("a name that does not carry the expected prefix is left alone", () => {
|
|
// Degrades to something true rather than slicing off a real part of the name.
|
|
assert.equal(mcpToolLabel("search", "wolfram"), "search");
|
|
assert.equal(mcpToolLabel("mcp_other_search", "wolfram"), "mcp_other_search");
|
|
});
|
|
|
|
test("a missing server id does not produce a bogus prefix", () => {
|
|
assert.equal(mcpToolLabel("mcp_x_y", ""), "mcp_x_y");
|
|
});
|
|
|
|
test("CLI arguments join for display and nothing re-splits them", () => {
|
|
assert.equal(
|
|
cliArgvLabel(["diagram", "render", "--out", "a.png"]),
|
|
"diagram render --out a.png",
|
|
);
|
|
});
|
|
|
|
test("an argument containing a space is shown as it is", () => {
|
|
// This is a label, not a command to copy: quoting it would imply a shell that
|
|
// is deliberately not involved.
|
|
assert.equal(cliArgvLabel(["export", "my file.png"]), "export my file.png");
|
|
});
|
|
|
|
test("a non-array args value degrades instead of rendering [object Object]", () => {
|
|
assert.equal(cliArgvLabel("scene list"), "scene list");
|
|
assert.equal(cliArgvLabel(undefined), "");
|
|
assert.equal(cliArgvLabel({ a: 1 }), "");
|
|
});
|
|
|
|
test("a short label is untouched", () => {
|
|
assert.equal(clipLabel("fetching pages", 40), "fetching pages");
|
|
});
|
|
|
|
test("a long label is clipped on a word boundary when one is near the cut", () => {
|
|
const clipped = clipLabel(
|
|
"fetching page seventeen of two hundred and twelve",
|
|
20,
|
|
);
|
|
assert.ok(clipped.endsWith("…"));
|
|
assert.ok(!clipped.includes("seventee…"), `mid-word cut: ${clipped}`);
|
|
assert.ok(clipped.length <= 21);
|
|
});
|
|
|
|
test("a long unbroken label is still cut rather than overflowing", () => {
|
|
const clipped = clipLabel("a".repeat(80), 20);
|
|
assert.equal(clipped, `${"a".repeat(20)}…`);
|
|
});
|
|
|
|
test("surrounding whitespace never survives into the row", () => {
|
|
assert.equal(formatProgressLabel(" indexing "), "indexing");
|
|
});
|
|
|
|
// ── the whole row decision ───────────────────────────────────────────────
|
|
|
|
test("an MCP call names the service, with its tool trailing", () => {
|
|
const row = describeProviderTool(
|
|
"mcp_wolfram_WolframAlpha",
|
|
{ input: "2+2" },
|
|
{ source: "mcp", id: "wolfram" },
|
|
t,
|
|
);
|
|
|
|
assert.deepEqual(row, {
|
|
glyph: "link",
|
|
verb: "Using wolfram",
|
|
chip: "WolframAlpha",
|
|
mono: true,
|
|
});
|
|
});
|
|
|
|
test("a CLI call names the app, with its arguments trailing", () => {
|
|
const row = describeProviderTool(
|
|
"cli_blender",
|
|
{ args: ["render", "--out", "scene.png"] },
|
|
{ source: "cli", id: "blender" },
|
|
t,
|
|
);
|
|
|
|
assert.deepEqual(row, {
|
|
glyph: "command",
|
|
verb: "Running blender",
|
|
chip: "render --out scene.png",
|
|
mono: true,
|
|
});
|
|
});
|
|
|
|
test("a CLI call with no arguments still reads as a row", () => {
|
|
const row = describeProviderTool(
|
|
"cli_blender",
|
|
{},
|
|
{ source: "cli", id: "blender" },
|
|
t,
|
|
);
|
|
assert.equal(row?.verb, "Running blender");
|
|
assert.equal(row?.chip, null);
|
|
});
|
|
|
|
test("a long argument list is clipped rather than pushing the row wide", () => {
|
|
const row = describeProviderTool(
|
|
"cli_blender",
|
|
{ args: ["render", "--input", "a".repeat(80)] },
|
|
{ source: "cli", id: "blender" },
|
|
t,
|
|
);
|
|
assert.ok((row?.chip ?? "").length <= 49, row?.chip ?? "(no chip)");
|
|
});
|
|
|
|
test("a built-in tool is not a provider row", () => {
|
|
// Returning something here would take over the hand-written descriptor for
|
|
// every built-in and label them all generically.
|
|
assert.equal(
|
|
describeProviderTool("read_file", { path: "a.txt" }, null, t),
|
|
null,
|
|
);
|
|
assert.equal(
|
|
describeProviderTool("read_file", {}, { source: "", id: "" }, t),
|
|
null,
|
|
);
|
|
});
|
|
|
|
test("a provider kind this build does not know falls through to the generic row", () => {
|
|
// Honest generic beats a confident wrong label.
|
|
assert.equal(
|
|
describeProviderTool(
|
|
"xyz_thing",
|
|
{},
|
|
{ source: "future-provider", id: "thing" },
|
|
t,
|
|
),
|
|
null,
|
|
);
|
|
});
|
|
|
|
test("a provider with no id still names something rather than nothing", () => {
|
|
const row = describeProviderTool("mcp_x_y", {}, { source: "mcp", id: "" }, t);
|
|
assert.equal(row?.verb, "Using mcp_x_y");
|
|
});
|