Skip to content

fix(server): keep the stdio process alive across stdin EOF and SIGHUP - #48

Open
jack-arturo wants to merge 2 commits into
InstaWP:mainfrom
verygoodplugins:fix/stdio-keepalive
Open

jack-arturo wants to merge 2 commits into
InstaWP:mainfrom
verygoodplugins:fix/stdio-keepalive

Conversation

@jack-arturo

Copy link
Copy Markdown
Contributor

Summary

  • Keep the WordPress MCP server alive when Claude closes stdin or delivers SIGHUP. Those exits were showing up as "Server transport closed unexpectedly" with an empty stderr log.
  • A referenced keepalive stops Node from draining the event loop after stdin EOF. SIGHUP is logged and ignored while the original parent is still alive; the parent watchdog still exits after a real reparent.
  • Diagnostic writes swallow a full or closed stderr pipe, and the watchdog interval is clamped so a value above 2^31−1 cannot overflow Node's timer to 1ms.

Cursor, via jack-arturo.

Test plan

  • npx vitest run tests/lifecycle.test.ts (8 tests, including a subprocess that stays up after stdin.end())
  • npx tsc --noEmit
  • Restart Claude Desktop and confirm the WordPress connector stays connected past the previous crash window

Claude was reporting the WordPress server as exiting early with an empty stderr log. A ref'd keepalive stops Node from draining the event loop when stdin closes, and SIGHUP is logged instead of killing the process.
…ing the process

A full stderr pipe made fs.writeSync throw inside the rejection handler, and a watchdog interval above 2^31-1 overflowed Node's timer to 1ms. Diagnostics now swallow write failures, and the interval is clamped to the timer maximum.
Comment thread src/lifecycle.ts
* closed fd must not turn a diagnostic into a fatal exception. */
export function writeDiagnostic(message: string) {
try {
fs.writeSync(2, message.endsWith("\n") ? message : `${message}\n`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: writeDiagnostic swallows all errors including programming errors

If message is not a string (e.g., null, object), message.endsWith throws TypeError which is silently caught. Consider String(message) for defense in depth.

Comment thread src/lifecycle.ts
const shutdown = (code = 0) => {
if (shuttingDown) return;
shuttingDown = true;
clearInterval(keepalive);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: shutdown function doesn't clear the watchdog interval

The watchdog timer (created at line 155) is unref'd so it won't block exit, but clearing it in shutdown would be cleaner and avoid a tiny resource leak before process.exit.

Comment thread tests/lifecycle.test.ts
() => {},
() => false,
);
expect((timer as NodeJS.Timeout & { _idleTimeout: number })._idleTimeout).toBe(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Test accesses internal Node.js _idleTimeout property

_idleTimeout is not part of the public API and may change across Node versions. Prefer testing behavior (e.g., timer doesn't fire immediately) over implementation details.

@kilo-code-bot

kilo-code-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 3
Issue Details (click to expand)

SUGGESTION

File Line Issue
src/lifecycle.ts 73 writeDiagnostic swallows all errors including programming errors (TypeError on non-string input)
src/lifecycle.ts 102 shutdown function doesn't clear the watchdog interval (minor resource leak)
tests/lifecycle.test.ts 34 Test accesses internal Node.js _idleTimeout property (brittle)
Files Reviewed (3 files)
  • src/lifecycle.ts - 2 issues
  • src/server.ts - 0 issues (pre-existing main catch handler not modified by this PR)
  • tests/lifecycle.test.ts - 1 issue

Fix these issues in Kilo Cloud


Reviewed by nemotron-3-ultra-550b-a55b:free · Input: 54K · Output: 9.9K · Cached: 342K

@jack-arturo

Copy link
Copy Markdown
Contributor Author

@codex review

@jack-arturo

Copy link
Copy Markdown
Contributor Author

Babysit stopped — wait. Codex did not review head 2400743ba5 within the 45-minute baseline wait after one review request (2026-11-11T02:55:16Z, comment 6785602578). No connector review, reviewed-commit marker, 👀, or 👍. No usage-limit notice and no account-connect bounce. CI is green (Node 20.x, Node 22.x, Kilo Code Review). Kilo's three suggestions are not the Codex gate and were left as reported notes. Label writes on InstaWP/mcp-wp returned HTTP 404, so babysit:blocked could not be applied. Do not merge until Codex reviews this head.

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.

1 participant