Skip to content

Fix broker auto-spawn when stale non-broker PID file blocks spawn#142

Merged
SoundBlaster merged 4 commits intomainfrom
codex/investigate-broker-mode-startup-issue-q26ft0
Mar 6, 2026
Merged

Fix broker auto-spawn when stale non-broker PID file blocks spawn#142
SoundBlaster merged 4 commits intomainfrom
codex/investigate-broker-mode-startup-issue-q26ft0

Conversation

@SoundBlaster
Copy link
Owner

Motivation

  • Broker proxy could skip spawning a new daemon if ~/.mcpbridge_wrapper/broker.pid contained a live but unrelated PID, causing IDE clients to fail to start MCP while direct mode still worked.
  • The existing fast-path trusted os.kill(pid, 0) liveness check without verifying the process identity, which allowed unrelated processes to short-circuit spawn logic.

Description

  • Add a daemon identity guard in BrokerProxy._spawn_broker_if_needed: if a live PID is present but _pid_belongs_to_broker(pid) returns False, the proxy now logs a warning and calls _cleanup_broker_files() so normal socket-check / spawn flow proceeds.
  • Preserve the existing version-mismatch handling and lock-based spawn serialization; only the PID-file fast-path is hardened.
  • Add a new unit test test_live_non_broker_pid_is_treated_as_stale and update related tests to explicitly mock _pid_belongs_to_broker where appropriate to reflect the new logic.

Testing

  • Ran PYTHONPATH=src pytest -q tests/unit/test_broker_proxy.py and all tests passed: 57 passed.
  • Ran PYTHONPATH=src ruff check src/mcpbridge_wrapper/broker/proxy.py tests/unit/test_broker_proxy.py and linting passed.
  • Verified the modified code compiles via python -m py_compile src/mcpbridge_wrapper/broker/proxy.py (success).

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 03280570b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@SoundBlaster SoundBlaster merged commit d401260 into main Mar 6, 2026
10 checks passed
@SoundBlaster SoundBlaster deleted the codex/investigate-broker-mode-startup-issue-q26ft0 branch March 6, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant