Skip to content

fix: suppress idle timeout while MCP bridge is connected - #8

Merged
YumaKakuya merged 1 commit into
mainfrom
fix/bridge-idle-timeout-suppression
Apr 30, 2026
Merged

YumaKakuya merged 1 commit into
mainfrom
fix/bridge-idle-timeout-suppression

Conversation

@sorted-ai-bot

Copy link
Copy Markdown
Collaborator

Summary

  • Bridge connections register with daemon via bridge_attach on MCP initialize, suspending the idle timer while connected
  • Last bridge disconnect resumes 300s idle timer as a grace period (no longer closes session immediately)
  • PID-based deduplication prevents count inflation from duplicate attaches; PID validation on detach prevents spurious decrements
  • 60s heartbeat + 180s dead-bridge janitor detects crashed bridges and resumes idle timer

Problem

When no MCP tools were called for 5 minutes, the daemon's idle timeout fired and transitioned the session to CLOSED. The MCP client (Hatch/OpenCode) caches tools/list from startup and does not re-query, so all Helm tools vanished permanently for the rest of the session — only recoverable by restarting the client.

Changes

File Change
SessionManager.java Added suspendIdleTimer() / resumeIdleTimer() with idleSuspended flag; synchronized on timer operations
StdioBridge.java Sends bridge_attach (with PID) after successful initialize; 60s heartbeat thread sends bridge_ping; bridge_detach now includes PID
ControlHandler.java New handleBridgeAttach / handleBridgePing / handleBridgeDetach (PID-aware); janitor thread (60s interval, 180s expiry); idle timeout guard; removed broken state-transition-based bridge count
SessionManagerTest.java +4 tests: idle timer fires/suspend/resume/flag-cleared-across-sessions
ControlHandlerTest.java +5 tests: attach increments/cancels-idle, detach restarts-idle/not-last-keeps-suppressed, idle-does-not-fire-while-attached

Test Results

175 tests, 0 failures

Bridge connections now register with the daemon via bridge_attach on
initialize. While at least one bridge is connected, the idle timer is
suspended so the session stays OPEN and all tools remain visible.

When the last bridge disconnects, the 300s idle timer resumes as a
grace period allowing reconnection without losing session state.

Includes PID-based deduplication to prevent count inflation from
duplicate attaches, PID validation on detach, a 60s heartbeat with
180s dead-bridge janitor for crash recovery, and a race-condition
guard in the idle timeout callback.
@YumaKakuya
YumaKakuya merged commit 60c2f3c into main Apr 30, 2026
4 checks 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.

2 participants