mcp: refresh last_activity during long bundle processing (#278)#317
Merged
justrach merged 1 commit intorelease/0.2.579from Apr 25, 2026
Merged
mcp: refresh last_activity during long bundle processing (#278)#317justrach merged 1 commit intorelease/0.2.579from
justrach merged 1 commit intorelease/0.2.579from
Conversation
The idle watchdog in main.zig closes stdin when `now - last_activity > idle_timeout_ms` (10 min). But last_activity is only updated once per incoming message — right after readLineBuf (mcp.zig:474). Inside a single bundle call that takes longer than idle_timeout_ms (many slow sub-ops, or ops that shell out to codedb_remote / codedb_tree on big repos), the clock stays frozen at message-arrival time. At the 10-minute mark the watchdog closes stdin mid-processing. The main thread finishes the bundle and writes the response fine (stdout is untouched), but the client — whose write-end of the stdin pipe just got EPIPE'd — reports "Transport closed" on its next tool call. Fix: stamp last_activity at bundle start AND at the end of each sub-op iteration, so active processing keeps us marked live. Every sub-op takes a known-bounded time, so the watchdog can only fire when the main thread truly has nothing in flight. No change to the idle path: a bundle that completes in under 10min doesn't touch last_activity beyond what was already there; sessions that actually go idle still get reaped. Fixes #278 for the bundle case. If "Transport closed" still surfaces on non-bundle paths, we'll need a repro that doesn't go through handleBundle. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Benchmark Regression ReportThreshold: 10.00%
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Diagnosis
`idleWatchdog` in `main.zig` closes stdin when `now - last_activity > idle_timeout_ms` (10 min). But `last_activity` is only updated once per incoming message — right after `readLineBuf` at `mcp.zig:474`. Inside a single `codedb_bundle` call that takes longer than 10 minutes (many slow sub-ops, or ops that shell out to `codedb_remote` / `codedb_tree` on huge repos), the clock stays frozen at message-arrival time. At the 10-minute mark the watchdog closes stdin mid-processing.
The main thread finishes the bundle and writes the response fine (stdout is untouched), but the client — whose write-end of the stdin pipe just got `EPIPE`d — reports "Transport closed" on its next tool call. That matches the reporter's note in #278 that the issue shows up on "long enough sessions".
Fix
Stamp `last_activity` at bundle start AND at the end of each completed sub-op inside `handleBundle`. Every sub-op is bounded by its own logic, so the watchdog can only fire when the main thread truly has nothing in flight.
No change to the idle path: a bundle that completes in under 10 min doesn't touch `last_activity` beyond what was already there; sessions that actually go idle still get reaped on the same schedule.
Scope
Test plan
🤖 Generated with Claude Code