Skip to content

Add IB Gateway auto-logoff detection#8

Merged
brycedbjork merged 1 commit into
mainfrom
bryce/ib-auto-reconnect
Feb 23, 2026
Merged

Add IB Gateway auto-logoff detection#8
brycedbjork merged 1 commit into
mainfrom
bryce/ib-auto-reconnect

Conversation

@brycedbjork
Copy link
Copy Markdown
Collaborator

Summary

Detects IB Gateway auto-logoff by actively polling the session every 5 seconds. When the session dies (auto-logoff timer fires or connection is lost), the daemon detects it within one monitor cycle and automatically reconnects using exponential backoff, rather than sitting indefinitely in a zombie-connected state.

Changes

  • IBProvider.check_health(): Pings gateway with reqCurrentTimeAsync() (5s timeout). Returns true if alive; on failure, forces disconnect and reschedules reconnect via existing exponential backoff.
  • IBProvider._force_disconnect(): Defensive disconnect method that tears down stale socket and triggers the reconnect loop.
  • DaemonServer._monitor_loop: Calls check_health() before the drawdown check. On failure, notifies ConnectionLossMonitor and broadcasts a disconnected event.
  • BrokerProvider base: Adds default no-op check_health() for non-IB providers.
  • Tests: 5 new tests covering healthy ping, timeout forcing disconnect, exception handling, and edge cases (not connected, reconnect in progress).

All 102 existing tests pass; 5 new tests added.

🤖 Generated with Claude Code

When IB Gateway's auto-logoff timer fires, the TCP socket can linger without ib_async firing disconnectedEvent, leaving the daemon in a zombie-connected state with no reconnection triggered. This change adds a lightweight active health check (reqCurrentTimeAsync) to the monitor loop that detects stale sessions within seconds and forces reconnection.

Changes:
- IBProvider.check_health(): Pings gateway with 5s timeout, forces disconnect and reschedules reconnect on failure
- IBProvider._force_disconnect(): Tears down stale connection and schedules exponential backoff reconnect
- DaemonServer._monitor_loop: Calls check_health before drawdown check; on failure broadcasts disconnected event
- BrokerProvider base class: Default no-op check_health() for non-IB providers
- Tests: 5 new tests covering alive, timeout, exception, and edge cases

Co-authored-by: Bryce Bjork <brycedbjork@gmail.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
broker-cli Ready Ready Preview Feb 23, 2026 5:07am

Request Review

@brycedbjork brycedbjork merged commit 3a3b941 into main Feb 23, 2026
13 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.

1 participant