Skip to content

fix(maker): prevent orphan proxy processes#252

Merged
529951164 merged 5 commits into
mainfrom
fix/maker-proxy-orphan-lifecycle
Jun 12, 2026
Merged

fix(maker): prevent orphan proxy processes#252
529951164 merged 5 commits into
mainfrom
fix/maker-proxy-orphan-lifecycle

Conversation

@529951164

Copy link
Copy Markdown
Contributor

改动内容

  • Add Maker lifecycle guards for stdin close, parent death, and stdio disconnects.
  • Close tracked child transports when the Maker MCP server exits.
  • Close stale proxy clients before reconnecting to avoid transport leaks.
  • Report PPID=1 Maker orphan processes in doctor without killing them.
  • Keep long-running sessions alive by avoiding idle TTL or max lifetime kills.
  • Separate local AI development docs from public Maker documentation.

影响面

  • Maker MCP server and embedded __maker-proxy process lifecycle.
  • taptap-maker doctor diagnostics for orphan process checks.
  • Maker local/development documentation organization.

Verification

  • npm run build
  • npm run lint
  • npm run format:check
  • npm test -- --runInBand

- Add Maker lifecycle guards for stdin close, parent death, and stdio disconnects.

- Close tracked child transports when the Maker MCP server exits.

- Close stale proxy clients before reconnecting to avoid transport leaks.

- Report PPID=1 Maker orphan processes in doctor without killing them.

- Keep long-running sessions alive by avoiding idle TTL or max lifetime kills.

- Separate local AI development docs from public Maker documentation.

Verification:

- npm run build

- npm run lint

- npm run format:check

- npm test -- --runInBand
- Increase Maker clone/fetch retry budget from 2 to 3 retries.

- Change default retry base delay from 1500ms to 10000ms.

- Give Maker repositories more time to finish server-side preparation.

- Cover retry count and default delay with clone binding tests.

- Update Maker docs for the new retry behavior and env override default.

Verification:

- npm test -- --runTestsByPath src/__tests__/makerCloneBinding.test.ts --runInBand

- npm run lint

- npm run format:check

- npm run build

- npm test -- --runInBand
- Increase Maker clone/fetch retry budget from 3 to 5 retries.

- Change default retry base delay from 10000ms to 5000ms.

- Update clone binding tests for retry count and delay defaults.

- Update Maker docs for the new retry policy.

Verification:

- npm test -- --runTestsByPath src/__tests__/makerCloneBinding.test.ts --runInBand

- npm run lint

- npm run format:check

- npm run build

- npm test -- --runInBand
@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown

Greptile Summary

此 PR 为 Maker MCP server 和内嵌 __maker-proxy 进程添加了完整的生命周期守卫,防止 AI 客户端退出后遗留孤儿进程。同时为 taptap-maker doctor 增加了孤儿进程扫描和 MCP tools 可见性诊断。

  • 生命周期守卫:新增 lifecycle.ts 模块,处理 stdin EOF、父进程死亡(PPID=1 / process.kill(ppid, 0) 探针)和 EPIPE/ERR_STREAM_DESTROYED/ECONNRESET 等 stdio 断连错误;installMakerServerExitHandlers 在退出时以 3 秒超时关闭所有活跃子 transport。
  • Transport 注册表:新增 childTransports.ts,追踪所有 StdioClientTransport 子进程;server 退出时批量关闭,避免 __maker-proxy 残留。
  • Proxy 改进proxy.ts 新增指数退避(最大 60 秒)、重连前关闭 stale client、healthCheckTimer.unref() 以及成功重连后将 reconnectDelayMs 重置为配置值。

Confidence Score: 4/5

整体逻辑正确、测试覆盖完整,主要风险点在 proxy 重连延迟初始化。

reconnectDelayMs 字段初始化为硬编码的 5000ms,而非从 this.config.options?.reconnect_interval 读取。对于将 reconnect_interval 配置为小于 5000ms 的用户,首次断连时实际等待时间是配置值的 5 倍甚至更多;经过指数退避后配置值始终不会被采用,直到下一次成功重连才会重置。生命周期守卫和 transport 注册表的逻辑无误,测试覆盖完整。

src/mcp-proxy/proxy.ts — reconnectDelayMs 字段初始化需要与用户配置对齐。

Important Files Changed

Filename Overview
src/maker/lifecycle.ts 新增进程生命周期守卫模块:stdin EOF 处理、父进程死亡检测、stdio 断连错误识别,逻辑正确,单元测试完整。
src/maker/server/childTransports.ts 新增 transport 注册表,用于追踪和批量关闭活跃子进程 transport;幂等关闭和 Set 操作逻辑正确。
src/mcp-proxy/proxy.ts 新增指数退避、stale client 关闭、healthCheckTimer.unref();reconnectDelayMs 字段初始化硬编码为默认值,忽略用户配置,导致首次重连延迟可能与预期不符。
src/maker/server/mcp.ts 所有 StdioClientTransport 实例均通过 trackMakerChildTransport 注册;新增 installMakerServerExitHandlers 在 stdin 关闭/信号时关闭子 transport,3 秒超时兜底,逻辑完备。
src/maker/index.ts 添加 stdin EOF 处理、父进程死亡看门狗、stdio EPIPE 防护和 safeWriteStderr,正确处理递归错误场景。
src/maker/cli/commands.ts doctor 命令新增孤儿进程检测和 MCP tools 可见性诊断;ps 输出解析逻辑、PPID=1 过滤和 logs watch 排除均正确。
src/maker/cli/projects.ts Git 重试上限从 2 次提升至 5 次,基础延迟从 1500ms 调整为 5000ms,函数改为 export 以便测试覆盖。
src/tests/makerLifecycle.test.ts 新增生命周期测试,覆盖 stdio 断连判断、父进程死亡检测、stale client 关闭、reconnectDelayMs 重置和 stdin EOF 退出路径。

Sequence Diagram

sequenceDiagram
    participant AI as AI Client
    participant MCP as Maker MCP Server
    participant CT as childTransports registry
    participant Proxy as __maker-proxy (embedded)

    AI->>MCP: spawn (stdio)
    MCP->>MCP: installMakerServerExitHandlers()
    MCP->>Proxy: spawn (StdioClientTransport)
    MCP->>CT: trackMakerChildTransport(transport)
    Proxy->>Proxy: installProxyStdinExitHandler()
    Proxy->>Proxy: installParentDeathWatchdog(15s interval)

    Note over AI,Proxy: Normal operation

    AI->>MCP: stdin closes (client exit / EPIPE)
    MCP->>MCP: shutdown() [exiting guard]
    MCP->>CT: closeTrackedMakerChildTransports()
    CT->>Proxy: transport.close()
    Note over MCP: 3s timeout race
    MCP->>MCP: process.exit(0)

    Note over Proxy: Independent watchdog path
    Proxy->>Proxy: "watchdog: process.ppid == 1?"
    Proxy->>Proxy: proxy.cleanup() + process.exit(0)
Loading

Reviews (3): Last reviewed commit: "fix(proxy): honor configured reconnect i..." | Re-trigger Greptile

Comment thread src/mcp-proxy/proxy.ts Outdated
Comment thread src/maker/cli/commands.ts Outdated
- Add doctor output for Maker MCP tools availability.

- Guide users to restart or open a new AI conversation when tools are missing.

- Warn when the AI pwd does not match the Maker project directory.

- Cover the new doctor guidance with CLI tests and docs.

Validation:

- npx jest src/__tests__/makerCliCommands.test.ts --runInBand

- npm run build

- npm run lint
- Reset successful reconnect delay to the configured reconnect interval.

- Add a lifecycle test covering custom reconnect_interval recovery.

- Simplify Maker orphan process command matching after logs watch filtering.

Validation:

- npx jest src/__tests__/makerLifecycle.test.ts --runInBand

- npx jest src/__tests__/makerCliCommands.test.ts --runInBand

- npm run build

- npm run lint
@529951164 529951164 merged commit 17f9363 into main Jun 12, 2026
12 checks passed
@529951164 529951164 deleted the fix/maker-proxy-orphan-lifecycle branch June 12, 2026 08:33
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.

2 participants