Skip to content

BUG-T8: Fix broker proxy bridge exits after first write due to BaseProtocol missing _drain_helper#123

Merged
SoundBlaster merged 12 commits intomainfrom
codex/feature/BUG-T8-fix-broker-proxy-stdout-writer
Mar 1, 2026
Merged

BUG-T8: Fix broker proxy bridge exits after first write due to BaseProtocol missing _drain_helper#123
SoundBlaster merged 12 commits intomainfrom
codex/feature/BUG-T8-fix-broker-proxy-stdout-writer

Conversation

@SoundBlaster
Copy link
Owner

Description

Fixes a silent protocol mismatch in BrokerProxy._make_stdout_writer (src/mcpbridge_wrapper/broker/proxy.py).

asyncio.BaseProtocol was used as the protocol for loop.connect_write_pipe, but asyncio.StreamWriter.drain() calls protocol._drain_helper() which only FlowControlMixin (not BaseProtocol) implements. On every first write the AttributeError was swallowed by _forward_stream's broad except Exception: return, causing the socket→stdout bridge task to exit immediately after the initialize response. asyncio.wait(FIRST_COMPLETED) then cancelled the other direction and the proxy process terminated — so all MCP clients using --broker-spawn or --broker-connect received initialize but never received tools/list, showing 0 tools.

Fix: replace asyncio.BaseProtocol with asyncio.StreamReaderProtocol (inherits FlowControlMixin, implements _drain_helper) — the standard asyncio streams pattern.

Also fixes a pre-existing test isolation bug in TestBrokerProxyBasic: setup_method used BrokerConfig.default() which pointed to ~/.mcpbridge_wrapper/broker.sock. When a live broker was running, the socket existed and test_run_raises_timeout_when_no_socket reached _make_stdin_reader instead of timing out, failing with UnsupportedOperation. Fixed by using a tempfile.mkdtemp() socket path guaranteed not to exist.

Closes / implements: BUG-T8

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • CI/CD improvement

Quality Gates

  • make test - All tests pass with ≥90% coverage (715 passed, 5 skipped; coverage 91.61%)
  • make lint - No linting errors (ruff check src/ clean)
  • make format - Code is properly formatted
  • make typecheck - Type checking passes (mypy src/ — no issues in 18 files)
  • make doccheck - Documentation is synced with DocC (if docs changed)

Documentation Sync

  • Documentation changes are synced with DocC catalog (or N/A) — no user-facing docs changed

Testing

  • Added/updated tests for new functionality — fixed TestBrokerProxyBasic.setup_method test isolation
  • All tests pass locally — 715 passed, 5 skipped
  • Manually tested the changes — end-to-end proxy session via --broker-connect returns 20 tools through the full initialize → notifications/initialized → tools/list sequence

Checklist

  • Code follows the project's style guidelines
  • Self-review completed
  • Comments added for complex code
  • Documentation updated (if needed)
  • No new warnings generated
  • PR title is descriptive

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

SoundBlaster and others added 12 commits March 1, 2026 04:59
…helper

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ue to BaseProtocol missing _drain_helper

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… to BaseProtocol missing _drain_helper

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…, fix test isolation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…due to BaseProtocol missing _drain_helper (PASS)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…pper

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…th in docs

~/.mcpbridge_wrapper/ remains the broker runtime dir (socket, PID, log).
~/.config/xcodemcpwrapper/ is the user-facing config dir using the
recognisable tool name rather than the internal package name.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add the missing 'Using Make Commands' subsection to WebUIDashboard.md to
mirror the same section in docs/webui-setup.md. Also add the
./scripts/install.sh --webui install option to docs/webui-setup.md to
match WebUIDashboard.md. Both files now share the same commit, satisfying
the strict DocC same-commit sync requirement.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@SoundBlaster SoundBlaster force-pushed the codex/feature/BUG-T8-fix-broker-proxy-stdout-writer branch from 22a1f37 to a6557f2 Compare March 1, 2026 02:00
@SoundBlaster SoundBlaster merged commit 0afbcce into main Mar 1, 2026
10 checks passed
@SoundBlaster SoundBlaster deleted the codex/feature/BUG-T8-fix-broker-proxy-stdout-writer branch March 1, 2026 02:04
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