Repository navigation
Open
Labels
backlogDeferred until user traction (100+ WAU)enhancementNew feature or requestroadmapFuture plans and roadmap items
Description
Problem (User Impact)
Users running Sequant via MCP (from Claude Code, Cursor, or other MCP clients) get a degraded experience compared to CLI users:
- No real-time progress — MCP clients see nothing until the entire run completes. The server spawns a subprocess and polls log files
- Double resource usage — The MCP server process spawns a separate
sequant runprocess, doubling memory and CPU - Race condition on results —
run.ts:74in MCP tools watches for log file creation with a 5-minute window. If the run takes longer or the log path is unexpected, results are silently lost - No streaming — MCP protocol supports
notifications/progressbut the current architecture can't use it because execution happens in a subprocess with no communication channel back
The MCP server is architecturally the most important growth vector (headless orchestration for AI-native workflows), but it's currently a second-class citizen.
Why Now
- arch: extract RunOrchestrator — decouple execution engine from CLI wiring #503 (RunOrchestrator) makes the execution engine importable without CLI context
- arch: typed workflow event system for decoupled progress, logging, and MCP streaming #504 (Event system) provides the subscription mechanism for streaming progress
- Together, these two prerequisites eliminate every technical reason for the subprocess indirection
- Interactive relay: bidirectional communication with headless runs #383 (interactive relay) is blocked — bidirectional communication is impossible through a subprocess boundary
Acceptance Criteria
In-Process Execution
- AC-1: MCP
sequant_runtool callsRunOrchestrator.execute()directly in the same process — no subprocess spawn, no log file polling - AC-2: MCP server startup loads the same engine as the CLI. Single process, shared configuration
- AC-3: Run results returned directly from the orchestrator — no log file intermediary. Log files still written (for
sequant logscommand) but not used as the communication channel - AC-4: Memory usage for MCP-initiated runs is comparable to CLI runs (not 2x)
Real-Time Progress Streaming
- AC-5: MCP server subscribes to
WorkflowEventEmitterevents (arch: typed workflow event system for decoupled progress, logging, and MCP streaming #504) and forwards them as MCPnotifications/progressmessages - AC-6: MCP clients see real-time updates: phase started, phase completed, QA verdict, errors — as they happen, not after the run completes
- AC-7: Progress notifications include percentage estimate based on completed phases / total phases
Robustness
- AC-8: If the MCP server crashes mid-run, state is consistent (state-manager's atomic writes ensure no corruption)
- AC-9: Concurrent MCP requests are handled correctly — multiple
sequant_runinvocations use the samep-limitconcurrency control as CLI - AC-10:
sequant_statustool reads from the same in-memory state as the running orchestrator (not from disk), providing instant status without file I/O - AC-11: Graceful shutdown: SIGTERM to MCP server process triggers
RunOrchestratorabort and cleanup (worktree state preserved) - AC-14: Pre-provisioning abort paths in
RunOrchestrator.run()(chain-resume fail-fast,--strict-preflight, the feat(run): pre-flight the skills install — missing .claude/skills/ should fail fast, not flail for 30 minutes as a spec retry #813 skills pre-flight) run their registered cleanup tasks — issue-lock release,LogWriterfinalize — instead ofshutdown.dispose()discarding them; today those paths rely on theprocess.on("exit")backstop to release locks and leave an initialized run log unfinalized, which is invisible in subprocess mode but leaks locks and dangling in-progress logs in a long-lived in-process server (surfaced during feat(run): pre-flight the skills install — missing .claude/skills/ should fail fast, not flail for 30 minutes as a spec retry #813 QA)
Backwards Compatibility
- AC-12:
sequant serveCLI command continues to work identically from the user's perspective - AC-13: MCP tool schemas (
sequant_run,sequant_status,sequant_logs) unchanged — no breaking changes for MCP clients
Scope & Gaps to Watch
- Gap: Process isolation loss — Subprocess execution provided crash isolation — a buggy phase couldn't crash the MCP server. In-process execution means an unhandled exception in a phase could take down the server. Mitigation: ensure
RunOrchestrator.execute()never throws unhandled — all errors are captured and returned as structured results - Gap: Long-running connections — MCP stdio transport assumes a persistent connection. If the MCP client disconnects mid-run, the orchestrator should continue (not abort) and save results to state. The next
sequant_statuscall should find them - Gap: SSE transport — The MCP server has an SSE alternative. Verify that progress notifications work over both stdio and SSE transports
- Gap: Resource cleanup — In subprocess mode, process exit guaranteed cleanup. In-process, the MCP server must explicitly clean up worktrees, locks, and temp files if a run is aborted. Verify shutdown handlers fire correctly
- Gap: Run registry —
src/mcp/run-registry.tsuses a module-level singletonMap. In-process execution should use the orchestrator's state directly instead of maintaining a parallel registry. Remove the registry or reduce it to a thin proxy - Risk: CLI binary resolution —
run.ts:74currently resolves the CLI binary path for subprocess execution. This logic becomes dead code — remove it to avoid confusion
Technical Notes
- Current MCP execution flow:
sequant_runtool →spawn("sequant", ["run", ...])→ poll log directory → parse log JSON → return result - Target flow:
sequant_runtool →orchestrator.execute(config)→ subscribe to events → stream notifications → return result - Current
run-registry.ts: ~50 lines, tracks active runs by issue number. Replace withorchestrator.isRunning(issueNumber)query - MCP SDK progress notifications:
server.notification({ method: "notifications/progress", params: { progressToken, progress, total } }) - Log files should still be written (via event listener from arch: typed workflow event system for decoupled progress, logging, and MCP streaming #504) for
sequant logscommand — but they're no longer the communication mechanism
Dependencies
- Depends on: arch: extract RunOrchestrator — decouple execution engine from CLI wiring #503 (RunOrchestrator), arch: typed workflow event system for decoupled progress, logging, and MCP streaming #504 (Event system)
- Unblocks: Interactive relay: bidirectional communication with headless runs #383 (interactive relay — bidirectional communication now possible in-process)
- Related: Platform abstraction: GitLab and Azure DevOps support #375 (platform abstraction — MCP server should work with any platform provider)
Batch Group
sequant run batch 3 (depends on both #503 and #504 completing first)
Metadata
Metadata
Assignees
Labels
backlogDeferred until user traction (100+ WAU)enhancementNew feature or requestroadmapFuture plans and roadmap items
Activity
docs: add target architecture diagram for #503-#508
admarble commentedon Apr 9, 2026
Architecture Review: Recommend Deferral
After an overcomplexity assessment of the #503-#508 target architecture, this issue should be deferred. The in-process MCP engine is a real improvement, but the cost/benefit doesn't justify it now.
Why defer
Dependency chain cost — This depends on both arch: extract RunOrchestrator — decouple execution engine from CLI wiring #503 (RunOrchestrator) AND arch: typed workflow event system for decoupled progress, logging, and MCP streaming #504 (Event System). It's the terminal node in the dependency graph. By the time prerequisites land, the architecture will have evolved and this issue's ACs will need revision anyway.
The subprocess approach works — MCP is functional today. The double resource usage only matters under heavy MCP usage, which isn't happening at current adoption levels.
The real bugs are small fixes — The two concrete problems (log polling race condition, double resource usage) don't require an architectural rewrite:
Recommended action
roadmaplabel, addfuturelabelWhat this does NOT mean
The
RunOrchestrator(#503) API should still be designed so MCP can call it directly — that AC in #503 is correct. We're deferring the wiring, not closing the door.docs: descope target architecture after overcomplexity review
fix(#494): /assess batch output formatting + label-priority spec-skip (…
admarble commentedon May 11, 2026
→ PARK — Backlog label already applied per author's own architecture review (2026-04-09). Defers in-process MCP engine until either (a) MCP usage justifies the rewrite, (b) #383 interactive relay becomes priority, or (c) a user reports MCP performance issues.
Resume after: triggering condition from the architecture-review comment is met.
Note: the review recommended filing a separate small bug for the log-polling race condition (the only concrete user-facing issue inside this issue's scope). Confirm that follow-up was filed before fully closing this out.
admarble commentedon May 12, 2026
Supersedes prior assess from 2026-05-11 (PARK)
→ PARK — Backlog label remains the live state. None of the architecture-review's unparking conditions are met: MCP usage hasn't grown, #383 (interactive relay) is still open but not active, and no user has reported MCP performance issues.
The architecture-review note about filing the log-polling-race condition as a separate bug is now resolved: filed as #631 (
fix(mcp): log-file lookup races on concurrent runs and stale same-issue logs). #631 covers the concrete user-facing problem (readLatestRunLogtime-window filter without runId correlation) without requiring this issue's full in-process rewrite.Resume after: a triggering condition from the 2026-04-09 architecture review is met.
admarble commentedon Jul 27, 2026
Added AC-14 (Robustness): pre-provisioning abort paths in
RunOrchestrator.run()— chain-resume fail-fast,--strict-preflight, and the #813 skills pre-flight — currently return viashutdown.dispose(), which discards registered cleanup tasks (issue-lock release,LogWriterfinalize) rather than running them. In subprocess mode theprocess.on("exit")backstop releases locks and this is invisible; in-process (this issue's whole premise) the exit event never fires between runs, so aborts would leak issue locks and leave in-progress run logs unfinalized. Concretizes the existing "Gap: Resource cleanup" bullet. Surfaced during #813's QA (PR #821).