Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/fix-session-timeout.md
Original file line number Diff line number Diff line change
@@ -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
```
5 changes: 5 additions & 0 deletions __tests__/codegraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {});
Expand All @@ -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 () => {
Expand Down
9 changes: 8 additions & 1 deletion extensions/codegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ type PendingJsonRpcRequests = Map<number, {
}>;

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);

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.