Skip to content

Commit 1201f1e

Browse files
committed
chore: make GIT_SUBPROCESS_PARALLELISM configurable with smart clamping
Enhances GIT_SUBPROCESS_PARALLELISM to be configurable via env var with auto-clamping to [1, 2×CPU_COUNT] to prevent runaway process spawning. Defaults to 4 for backward compatibility. Improves fleet-scale agent workflows on high-core machines while protecting against misconfiguration. Updated documentation in docs/install.md to explain the env var, default, and the auto-clamping safety mechanism. Fixes #2
1 parent 9cef774 commit 1201f1e

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

docs/install.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,18 @@ Omit any `cwd` / `workingDirectory` field unless your client requires it for unr
9191

9292
| Variable | Default | Purpose |
9393
|----------|---------|---------|
94-
| `GIT_SUBPROCESS_PARALLELISM` | `4` | Number of parallel git subprocesses for inventory operations and `git_status` submodule rows. Increase on high-core machines or for slow network connections; decrease if system resources are constrained. |
94+
| `GIT_SUBPROCESS_PARALLELISM` | `4` | Number of parallel git subprocesses for inventory operations and `git_status` submodule rows. Valid range: 1 to 2×CPU count (auto-clamped to prevent runaway spawning). Increase on high-core machines to accelerate large fleet scans; decrease if system resources are constrained. |
9595

9696
Set these in the environment where the MCP client launches the server (e.g. in your shell, in the MCP client config as `env`, or in a startup script).
9797

98-
Example: Running the server with 8 parallel git processes:
98+
Example: Running the server with 8 parallel git processes on a 4-core machine:
9999

100100
```bash
101101
GIT_SUBPROCESS_PARALLELISM=8 npx -y @rethunk/mcp-multi-root-git
102102
```
103103

104+
On a 4-core machine (CPU count = 4), the max parallelism is clamped to 8 (2×4). The value requested is used if valid.
105+
104106
## Cursor
105107

106108
**User scope (all workspaces):** `~/.cursor/mcp.json` on macOS/Linux, or `%USERPROFILE%\.cursor\mcp.json` on Windows.

src/server/git.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import { spawn, spawnSync } from "node:child_process";
22
import { existsSync, readFileSync } from "node:fs";
3+
import { cpus } from "node:os";
34
import { join } from "node:path";
45

5-
/** Parallel git subprocesses for inventory rows and git_status submodule rows. */
6-
export const GIT_SUBPROCESS_PARALLELISM = parseInt(
7-
process.env.GIT_SUBPROCESS_PARALLELISM ?? "4",
8-
10,
9-
);
6+
/**
7+
* Parallel git subprocesses for inventory rows and git_status submodule rows.
8+
* Reads from GIT_SUBPROCESS_PARALLELISM env var (default 4), clamped to [1, 2×CPU_COUNT].
9+
*/
10+
function resolveGitSubprocessParallelism(): number {
11+
const env = process.env.GIT_SUBPROCESS_PARALLELISM;
12+
if (env) {
13+
const n = Number.parseInt(env, 10);
14+
if (!Number.isNaN(n) && n >= 1) {
15+
const cpuCount = cpus().length;
16+
const maxParallel = cpuCount * 2;
17+
return Math.min(n, maxParallel);
18+
}
19+
}
20+
return 4;
21+
}
22+
23+
export const GIT_SUBPROCESS_PARALLELISM = resolveGitSubprocessParallelism();
1024

1125
// ---------------------------------------------------------------------------
1226
// Git on PATH (lazy probe)

0 commit comments

Comments
 (0)