all_tool_descriptions: first test pays every module's cold import inside the 5 s default timeout, red under load #14

Open
opened 2026-12-02 14:39:03 +00:00 by neptunus · 1 comment
Member

Purpose (fix): src/all_tool_descriptions.test.ts tests what it names, not how fast a loaded box imports every tool module.

"registers the same set of tool names regardless of MACULA_MCP_TERSE_TOOLS" is the first test to import every register module cold (captureAllDescriptions). It does that inside vitest's default 5 s test timeout. On host00 under load (load average 11-14, nice -n 10, the whole suite in parallel) it times out at 5.0-5.2 s:

  • on main 2cb8721, from a clean tree;
  • on PR 12 (macula-mcp#11), with and without that PR's new test files.

Alone it passes in about 0.4 s. CI's test job on PR 12 (run 6953, task 21989) was green, so this is a local-gate red, not a CI one.

Done when

  • The cold import is paid outside the 5 s test body (a beforeAll with its own timeout, or an explicit timeout on that test), and the test still fails when a tool's terse and full name sets differ.
  • A full local vitest run at load average 12 or more passes it three times in a row.
Purpose (fix): `src/all_tool_descriptions.test.ts` tests what it names, not how fast a loaded box imports every tool module. "registers the same set of tool names regardless of MACULA_MCP_TERSE_TOOLS" is the first test to import every register module cold (`captureAllDescriptions`). It does that inside vitest's default 5 s test timeout. On host00 under load (load average 11-14, `nice -n 10`, the whole suite in parallel) it times out at 5.0-5.2 s: - on main 2cb8721, from a clean tree; - on PR 12 (macula-mcp#11), with and without that PR's new test files. Alone it passes in about 0.4 s. CI's `test` job on PR 12 (run 6953, task 21989) was green, so this is a local-gate red, not a CI one. ## Done when - [ ] The cold import is paid outside the 5 s test body (a `beforeAll` with its own timeout, or an explicit timeout on that test), and the test still fails when a tool's terse and full name sets differ. - [ ] A full local `vitest run` at load average 12 or more passes it three times in a row.
Member

Cause, measured on host00 (4 cores, a full vitest run, 3 workers in parallel, nice -n 10):

  • At load ~21 the first test took 5098 ms and hit the 5 s default; alone at the same load the file takes ~0.7 s. So the body's cost scales with what else the box runs -- it is not a fixed 5 s that a bigger number would simply absorb.
  • Instrumenting captureAllDescriptions per module: 27 tool modules, the cold pass costs ~4.9 s, and five first imports dominate it -- mesh_identity 1.38 s (it carries connect_to_mesh, realm, citizenship, serve_rings), mesh_dht 1.01 s, mesh_role 0.91 s, mesh_call 0.40 s, mesh_help 0.39 s. The warm pass (terse) is 102 ms in total.
  • None of those modules does work at top level -- no I/O, no key reads, no client built on load; they only import. The cost is Vite transforming each module graph on first import and Node evaluating it (the suite's own report: transform 34 %, import 17 % of the run), multiplied by CPU contention.
  • Both assertions cost 2 ms and 0 ms once the modules are warm.

So the fix is where the work sits, not a number: the discovery and both captures move into a beforeAll with its own 60 s timeout, computed once for both tests (they previously captured twice each), and the test bodies keep vitest's 5 s default for what they assert. No test-body timeout is raised.

The test still fails when a tool's terse and full name sets differ: a tool registered only when MACULA_MCP_TERSE_TOOLS is set made it fail (expected [ 'mesh_agents', …(35) ] to deeply equal [ 'mesh_agents', …(34) ]).

Three full local vitest runs in a row at load 12.6 / 12.8 / 13.4 (5-minute 19.3-20.0): 749 passed, 749 passed, 749 passed. (Run with MACULA_MCP_IDENTITY unset -- this shell exports it, and the unrelated node_id.test.ts refuses an agent and an identity both set.)

Cause, measured on host00 (4 cores, a full `vitest run`, 3 workers in parallel, `nice -n 10`): - At load ~21 the first test took **5098 ms** and hit the 5 s default; alone at the same load the file takes ~0.7 s. So the body's cost scales with what else the box runs -- it is not a fixed 5 s that a bigger number would simply absorb. - Instrumenting `captureAllDescriptions` per module: 27 tool modules, the **cold pass costs ~4.9 s**, and five first imports dominate it -- `mesh_identity` 1.38 s (it carries `connect_to_mesh`, `realm`, `citizenship`, `serve_rings`), `mesh_dht` 1.01 s, `mesh_role` 0.91 s, `mesh_call` 0.40 s, `mesh_help` 0.39 s. The **warm pass (terse) is 102 ms in total**. - None of those modules does work at top level -- no I/O, no key reads, no client built on load; they only import. The cost is Vite transforming each module graph on first import and Node evaluating it (the suite's own report: transform 34 %, import 17 % of the run), multiplied by CPU contention. - Both assertions cost **2 ms and 0 ms** once the modules are warm. So the fix is where the work sits, not a number: the discovery and both captures move into a `beforeAll` with its own 60 s timeout, computed once for both tests (they previously captured twice each), and the test bodies keep vitest's 5 s default for what they assert. No test-body timeout is raised. The test still fails when a tool's terse and full name sets differ: a tool registered only when `MACULA_MCP_TERSE_TOOLS` is set made it fail (`expected [ 'mesh_agents', …(35) ] to deeply equal [ 'mesh_agents', …(34) ]`). Three full local `vitest run`s in a row at load 12.6 / 12.8 / 13.4 (5-minute 19.3-20.0): **749 passed, 749 passed, 749 passed**. (Run with `MACULA_MCP_IDENTITY` unset -- this shell exports it, and the unrelated `node_id.test.ts` refuses an agent and an identity both set.)
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
macula-io/macula-mcp#14
No description provided.