Skip to content

mcp: refresh last_activity during long bundle processing (#278)#317

Merged
justrach merged 1 commit intorelease/0.2.579from
fix/278-bundle-activity-refresh
Apr 25, 2026
Merged

mcp: refresh last_activity during long bundle processing (#278)#317
justrach merged 1 commit intorelease/0.2.579from
fix/278-bundle-activity-refresh

Conversation

@justrach
Copy link
Copy Markdown
Owner

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

  • 9 lines added to `src/mcp.zig` inside `handleBundle`.
  • No test change — this is a timing/watchdog interaction and the existing idle-watchdog tests cover the reaping path; covering this would need a multi-minute slow sub-op mock.
  • Non-bundle code paths unchanged. If "Transport closed" still surfaces on single-tool calls we'll need a separate repro — this is the most obvious trigger given the reporter's description.

Test plan

  • `zig build` green
  • Existing `codedb_bundle` behavior unchanged on short bundles (tested locally)
  • Anecdotal: the original reporter should see "Transport closed" go away on long bundle sessions. Would help to get confirmation before we call Occasional "Transport closed" MCP crash #278 fully closed.

🤖 Generated with Claude Code

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>
@github-actions
Copy link
Copy Markdown

Benchmark Regression Report

Threshold: 10.00%

Tool Base (ns) Head (ns) Delta Status
codedb_bundle 495355 527594 +6.51% OK
codedb_changes 57127 59423 +4.02% OK
codedb_deps 9461 9258 -2.15% OK
codedb_edit 6009 6495 +8.09% OK
codedb_find 65189 67279 +3.21% OK
codedb_hot 99208 101167 +1.97% OK
codedb_outline 243505 240650 -1.17% OK
codedb_read 86757 92590 +6.72% OK
codedb_search 180897 179664 -0.68% OK
codedb_snapshot 2710820 2601748 -4.02% OK
codedb_status 219093 215314 -1.72% OK
codedb_symbol 60097 61571 +2.45% OK
codedb_tree 81844 83382 +1.88% OK
codedb_word 70821 72105 +1.81% OK

@justrach justrach merged commit d58e284 into release/0.2.579 Apr 25, 2026
1 check passed
@justrach justrach deleted the fix/278-bundle-activity-refresh branch April 27, 2026 09:23
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