Skip to content

fix: MCP integration tests consistently timing out in CI #492

Closed

Description

@admarble

Summary

MCP integration tests (mcp-serve.integration.test.ts, mcp-e2e.integration.test.ts) are now failing consistently in CI, not just intermittently. This was observed on both the #490 branch and main during the same timeframe.

Failing Tests (8 total)

  • mcp-e2e.integration.test.ts > Graceful shutdown > AC-8: should disconnect SSE client cleanly on SIGTERM
  • mcp-serve.integration.test.ts > AC-16: graceful shutdown > should exit cleanly on SIGTERM for SSE server
  • mcp-serve.integration.test.ts > AC-16: graceful shutdown > should exit cleanly on SIGINT for SSE server
  • mcp-serve.integration.test.ts > AC-11: MCP client detection > should detect MCP client config paths for current platform
  • mcp-serve.integration.test.ts > AC-11: MCP client detection > should generate valid sequant MCP config entry
  • mcp-serve.integration.test.ts > AC-11: MCP client detection > should add sequant config to an existing MCP config file
  • mcp-serve.integration.test.ts > AC-11: MCP client detection > should create config file and parent directories if they don't exist
  • mcp-serve.integration.test.ts > error scenarios > should handle port already in use for SSE transport

Root Cause

The afterEach hook at mcp-serve.integration.test.ts:114 times out at 60s (vitest default hookTimeout). It kills process groups via SIGKILL and waits for exit, but the promise never resolves — likely because:

  1. The spawned process group has already exited by the time the listener is registered (race condition between proc.exitCode check and proc.on("exit", ...))
  2. OR GitHub Actions runner changes affected process group signal delivery

History

  • Originally fixed in 2026-03-23 with detached: true + process group signaling
  • Was documented as "passes consistently in GitHub Actions CI" but that is no longer true
  • Observed failing consistently on main as of 2026-04-06 (run IDs: 24022361055, 24022099503)

Acceptance Criteria

  • afterEach cleanup handles the race condition where process exits before listener is registered
  • Add explicit timeout to the exit promise (e.g., 5s) with forced resolution to prevent 60s hangs
  • All 8 tests pass consistently in CI (run 3x to verify)
  • Update project_ci_known_failures.md memory to reflect current status

Suggested Fix

afterEach(async () => {
  const exitPromises = spawnedProcesses.map(
    (proc) =>
      new Promise<void>((resolve) => {
        if (proc.exitCode !== null || proc.killed) {
          resolve();
          return;
        }
        const timeout = setTimeout(() => resolve(), 5000);
        proc.on("exit", () => {
          clearTimeout(timeout);
          resolve();
        });
        killProcessGroup(proc, "SIGKILL");
      }),
  );
  await Promise.all(exitPromises);
  spawnedProcesses.length = 0;
});

Activity

  1. added
    bug
    on Apr 6, 2026
  2. admarble commented on Apr 6, 2026

    @admarble
    ContributorAuthor

    → PROCEED — MCP integration test afterEach race condition, fix + 3x CI verify

    exec → qa · 4 ACs · bug fix (no spec needed)

    CI failing on main — unblocks other PRs.

  3. added 2 commits that reference this issue on Apr 6, 2026
  4. admarble commented on Apr 6, 2026

    @admarble
    ContributorAuthor

    /fullsolve Complete

    Status: READY_FOR_MERGE

    AC Coverage

    AC Status Details
    AC-1: afterEach handles race condition ✅ MET Added proc.signalCode !== null check to detect signal-killed processes
    AC-2: Explicit timeout on exit promise ✅ MET 5s timeout with clearTimeout on normal exit
    AC-3: All 8 tests pass 3x in CI ⏳ PENDING 3x local pass verified; CI runs pending
    AC-4: Update CI known failures memory ✅ MET Updated project_ci_known_failures.md

    Summary

    • Files changed: 3 (mcp-serve.integration.test.ts, mcp-e2e.integration.test.ts, mcp-serve-multi-client.integration.test.ts)
    • Root cause: afterEach checked proc.exitCode and proc.killed but not proc.signalCode — signal-killed processes have exitCode=null and killed=false, so the exit listener was registered after the event already fired
    • Fix: Added proc.signalCode !== null to early-exit check + 5s timeout fallback
    • Bonus: Found and fixed same vulnerable pattern in mcp-serve-multi-client.integration.test.ts
    • Tests: 29/29 MCP integration tests pass, 2410/2410 full suite passes

    PR: #493

  5. admarble commented on Apr 6, 2026

    @admarble
    ContributorAuthor

    Documentation Review Complete

    This issue is a test infrastructure bug fix — no user-facing documentation required.

    Changes (all in __tests__/integration/):

    • mcp-serve.integration.test.ts — fixed afterEach race condition
    • mcp-e2e.integration.test.ts — fixed afterEach race condition
    • mcp-serve-multi-client.integration.test.ts — fixed same pattern (found during QA sweep)

    Why no docs:

    • No new features, CLI commands, or configuration options
    • No user-visible behavior change
    • Fix is internal to test cleanup hooks (signalCode check + timeout fallback)

    Internal reference:

    • project_ci_known_failures.md memory updated to reflect fix status

    No documentation action needed.

  6. added 2 commits that reference this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions