Skip to content

fix: 10min idle timeout + poll stdin for dead clients (#148)#233

Merged
justrach merged 3 commits intomainfrom
fix/148-timeout
Apr 10, 2026
Merged

fix: 10min idle timeout + poll stdin for dead clients (#148)#233
justrach merged 3 commits intomainfrom
fix/148-timeout

Conversation

@justrach
Copy link
Copy Markdown
Owner

Summary

  • extend the MCP idle timeout from 2 minutes to 10 minutes
  • poll stdin for POLLHUP so dead clients are detected sooner
  • add tests for timeout configuration, pipe HUP detection, and MCP exit-on-stdin-close

Verification

  • zig build test

Refs #148

justrach and others added 2 commits April 6, 2026 09:22
Two changes:
1. Idle timeout increased from 2min to 10min — allows long debugging
   sessions where the agent thinks for >2min
2. Watchdog now polls stdin every 10s for POLLHUP — detects dead clients
   immediately instead of waiting for the full timeout. When the client
   pipe closes, server exits within 10 seconds.

This means:
- Client disconnects cleanly → stdin EOF → server exits immediately
- Client crashes/killed → POLLHUP detected → server exits in ≤10s
- Client connected but idle → 10min timeout (plenty for debugging)
- Orphaned process (no client ever) → 10min timeout

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Verify idle_timeout_ms is 10 minutes (600,000ms)
- Verify POLLHUP detected when pipe write end is closed (client gone)
- Verify open pipe does NOT trigger false HUP

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 252a9f1fed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Wait up to 15 seconds for the process to exit
// (watchdog polls every 10s, so it should detect POLLHUP within ~10s)
const start = std.time.milliTimestamp();
const term = child.wait() catch {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add a bounded wait when asserting MCP exit on stdin close

child.wait() blocks indefinitely, so if the MCP process fails to exit after stdin is closed, this test hangs the entire suite until an external timeout kills it. The test comment says it waits “up to 15 seconds,” but there is no actual timeout enforcement before calling wait(), which means this regression test cannot fail fast when the shutdown path breaks.

Useful? React with 👍 / 👎.

test "issue-148: codedb mcp exits when stdin is closed" {
// Integration test: spawn codedb mcp, close stdin, verify it exits
var child = std.process.Child.init(
&.{ "zig", "build", "run", "--", "--mcp" },
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove build latency from the 15s MCP shutdown assertion

This integration test launches zig build run -- --mcp, so compile/link startup time is included in elapsed before the < 15_000 assertion. On slower or cold-cache environments, build time alone can exceed 15s even when stdin-HUP shutdown works correctly, making the test flaky and failing for reasons unrelated to watchdog behavior.

Useful? React with 👍 / 👎.

# Conflicts:
#	src/main.zig
#	src/tests.zig
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 051d6c84e9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +4878 to +4880
switch (term) {
.Exited => |code| _ = code,
else => {},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Assert successful MCP termination in stdin-close test

The new integration test accepts any termination outcome because the switch ignores non-Exited cases and also discards the exit code, so crashes or non-zero exits (for example from a panic or failed zig build run) still satisfy the test as long as the process returns quickly. This can mask regressions in the stdin-HUP shutdown path instead of proving a clean exit.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown

Benchmark Regression Report

Threshold: 10.00%

Tool Base (ns) Head (ns) Delta Status
codedb_bundle 768792 724944 -5.70% OK
codedb_changes 120443 118807 -1.36% OK
codedb_deps 41543 34700 -16.47% OK
codedb_edit 21098 20638 -2.18% OK
codedb_find 151934 152378 +0.29% OK
codedb_hot 160065 162081 +1.26% OK
codedb_outline 457090 443818 -2.90% OK
codedb_read 156927 151860 -3.23% OK
codedb_search 317140 296324 -6.56% OK
codedb_snapshot 4299503 4489036 +4.41% OK
codedb_status 159240 160800 +0.98% OK
codedb_symbol 67464 67472 +0.01% OK
codedb_tree 103382 102918 -0.45% OK
codedb_word 102666 100389 -2.22% OK

@justrach justrach merged commit df15833 into main Apr 10, 2026
1 check passed
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