diff --git a/.changeset/fix-session-timeout.md b/.changeset/fix-session-timeout.md new file mode 100644 index 0000000..eed2bb8 --- /dev/null +++ b/.changeset/fix-session-timeout.md @@ -0,0 +1,11 @@ +--- +"@vndv/pi-codegraph": patch +--- + +Make MCP session timeout configurable via `CODEGRAPH_TIMEOUT_MS` environment variable + +The default timeout has been increased from 20s to 60s to accommodate larger projects where `codegraph serve --mcp` cold start exceeds the previous limit. Users can override via: + +```bash +export CODEGRAPH_TIMEOUT_MS=90000 # 90 seconds +``` diff --git a/__tests__/codegraph.test.ts b/__tests__/codegraph.test.ts index fd3bd60..0c0114b 100644 --- a/__tests__/codegraph.test.ts +++ b/__tests__/codegraph.test.ts @@ -286,6 +286,9 @@ describe("pi-codegraph extension", () => { it("times out when the MCP session never completes", async () => { const { spawn } = await import("node:child_process"); + const originalEnv = process.env.CODEGRAPH_TIMEOUT_MS; + process.env.CODEGRAPH_TIMEOUT_MS = "20000"; + vi.resetModules(); const { withCodeGraphMcp, SessionTimeoutMs } = await import("../extensions/codegraph.js"); const killMock = vi.fn(() => {}); @@ -303,6 +306,8 @@ describe("pi-codegraph extension", () => { await expect(promise).rejects.toThrow("CodeGraph MCP session timed out after " + SessionTimeoutMs); expect(killMock).toHaveBeenCalled(); + if (originalEnv === undefined) delete process.env.CODEGRAPH_TIMEOUT_MS; + else process.env.CODEGRAPH_TIMEOUT_MS = originalEnv; }, 22000); it("normalizes codegraph_files path before forwarding to the MCP server", async () => { diff --git a/extensions/codegraph.ts b/extensions/codegraph.ts index 27b6c60..792a775 100644 --- a/extensions/codegraph.ts +++ b/extensions/codegraph.ts @@ -121,7 +121,14 @@ type PendingJsonRpcRequests = Map; export const MaxDiagnosticLength = 1000; -export const SessionTimeoutMs = 20_000; +export const SessionTimeoutMs = (() => { + const envValue = process.env.CODEGRAPH_TIMEOUT_MS; + if (envValue !== undefined) { + const parsed = parseInt(envValue, 10); + if (!Number.isNaN(parsed) && parsed > 0) return parsed; + } + return 60_000; +})(); export const codegraphToolNames = ToolDefinitions.map((tool) => tool.name); diff --git a/package-lock.json b/package-lock.json index 6a16189..1fa0604 100644 --- a/package-lock.json +++ b/package-lock.json @@ -911,7 +911,7 @@ "typebox": "1.1.38" }, "bin": { - "pi-ai": "./dist/cli.js" + "pi-ai": "dist/cli.js" }, "engines": { "node": ">=22.19.0"