Skip to content

feat(#388): replace spawnSync with async spawn in MCP sequant_run - #400

Merged
admarble merged 3 commits into
mainfrom
feature/388-mcp-server-replace-spawnsync-with-async-spawn-for-
Mar 23, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/388-mcp-server-replace-spawnsync-with-async-spawn-for-

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

  • Replace spawnSync with async spawn in sequant_run MCP tool so the server event loop remains responsive during workflow execution
  • Add timeout handling with process group cleanup (detached: true + negative PID kill) to prevent orphan processes
  • Wire ENOENT and other spawn errors with descriptive error messages
  • Update all existing tests and add comprehensive new test coverage

Pre-PR AC Verification

AC Source Description Status Evidence
AC-1 Original spawn instead of spawnSync ✅ Implemented src/mcp/tools/run.ts:144
AC-2 Original status/logs responsive during run ✅ Implemented Integration tests verify concurrent tool calls respond while run is pending
AC-3 Original MCP cancellation support ⚠️ Partial AbortSignal available in SDK but registerTool callback type inference prevents accessing extra.signal. Timeout-based cleanup works.
AC-4 Original Output truncated to 2000 chars ✅ Implemented run.ts:84 — stdout.slice(-2000), stderr.slice(-1000)
AC-5 Original Timeout preserved (30 min) ✅ Implemented run.ts:68 — 1800000ms timeout with SIGTERM
AC-6 Original Tests updated for async ✅ Implemented All test files updated to mock async spawn
AC-7 Derived ENOENT handling ✅ Implemented run.ts:166-171 — descriptive error message
AC-8 Derived No orphan processes ✅ Implemented run.ts:184-195 — process group kill via -pid

Test plan

  • npm run build passes
  • npm run lint passes
  • npm test — 1788/1788 tests pass (77 files)
  • Unit tests verify spawn args, output truncation, timeout, ENOENT handling
  • Integration tests verify server responsiveness during pending runs

Closes #388

The MCP server event loop was blocked during workflow execution because
sequant_run used spawnSync. This made sequant_status and sequant_logs
unreachable while a run was in progress.

- Replace spawnSync with async spawn wrapped in Promise (spawnAsync)
- Buffer stdout/stderr via stream handlers, preserve truncation limits
- Add timeout handling with process group kill (detached + negative PID)
- Handle ENOENT and other spawn errors with descriptive messages
- Update all tests to mock async spawn with EventEmitter-based pattern
- Add integration tests verifying concurrent tool call responsiveness

Closes #388

Entire-Checkpoint: 0e5ec6e75627
The MCP SDK passes AbortSignal via the extra parameter on tool callbacks,
but registerTool's TypeScript inference defaults InputArgs to undefined,
collapsing the callback to single-arg. Work around this with a type
assertion to accept the two-arg callback (args, extra).

spawnAsync now accepts an optional signal and kills the process group
when aborted. Also clarifies the empty catch block in killProcessGroup.

Entire-Checkpoint: f4f792a7219d
@admarble
admarble merged commit 9aba881 into main Mar 23, 2026
5 checks passed
@admarble
admarble deleted the feature/388-mcp-server-replace-spawnsync-with-async-spawn-for- branch March 23, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP server: replace spawnSync with async spawn for sequant_run

1 participant