-
Notifications
You must be signed in to change notification settings - Fork 1
BUG-T9: Orphaned Web UI server process blocks port after MCP client disconnect or config change #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SoundBlaster
merged 8 commits into
main
from
feature/BUG-T9-orphaned-webui-process-clean-exit
Feb 28, 2026
Merged
BUG-T9: Orphaned Web UI server process blocks port after MCP client disconnect or config change #110
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c0873e8
Branch for BUG-T9: orphaned webui process clean exit
SoundBlaster a2e7b97
Select task BUG-T9: Orphaned Web UI server process blocks port
SoundBlaster 142e35e
Plan task BUG-T9: Orphaned Web UI server process blocks port
SoundBlaster 385e464
Implement BUG-T9: terminate orphaned bridge on stdin EOF
SoundBlaster 5e26a43
Archive task BUG-T9: Orphaned Web UI server process blocks port (PASS)
SoundBlaster 928b7b4
Review BUG-T9: orphaned webui process
SoundBlaster 52c645e
Archive REVIEW_bug_t9_orphaned_webui_process report
SoundBlaster 56309d5
Implement BUG-T9: drain pending responses before EOF terminate
SoundBlaster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...b_UI_server_process_blocks_port_after_MCP_client_disconnect_or_config_change.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # PRD: BUG-T9 — Orphaned Web UI server process blocks port after MCP client disconnect or config change | ||
|
|
||
| **Task ID:** BUG-T9 | ||
| **Priority:** P1 | ||
| **Phase:** Known Issues / Bug Tracker | ||
| **Status:** Planned | ||
| **Dependencies:** None | ||
|
|
||
| ## Objective Summary | ||
|
|
||
| When an MCP client disconnects, the wrapper can remain alive because the main loop blocks on `output_queue.get()` while `xcrun mcpbridge` still owns stdout. This leaves the Web UI thread running and the configured port (for example `8080`) occupied by an orphaned process. The objective is to make wrapper shutdown deterministic when stdin reaches EOF by actively terminating the upstream bridge with a bounded timeout, so the stdout reader emits EOF and the main loop exits. The change must preserve normal request handling, avoid regressing existing broker/web-ui flows, and keep behavior cross-platform for supported Python environments. | ||
|
|
||
| ## Deliverables | ||
|
|
||
| - Lifecycle update in `src/mcpbridge_wrapper/bridge.py` and `src/mcpbridge_wrapper/__main__.py` to react to stdin closure. | ||
| - New unit tests covering stdin-EOF shutdown behavior and forced-kill fallback behavior. | ||
| - Validation report documenting quality gates and bug-specific verification. | ||
|
|
||
| ## Success Criteria and Acceptance Tests | ||
|
|
||
| 1. Wrapper requests graceful upstream shutdown immediately after stdin reaches EOF. | ||
| 2. If upstream does not exit within a configured grace window, wrapper escalates to force kill. | ||
| 3. Main loop exits without hanging once EOF-driven shutdown is triggered. | ||
| 4. Existing behavior for normal request/response handling is unchanged. | ||
| 5. Unit tests prove: | ||
| - EOF callback path is executed. | ||
| - Graceful-then-force termination logic is invoked as expected. | ||
| - Existing bridge forwarding tests still pass. | ||
|
|
||
| ## Test-First Plan | ||
|
|
||
| 1. Add failing unit test in `tests/unit/test_bridge.py` proving stdin forwarder emits a closure callback when stdin iteration ends. | ||
| 2. Add failing unit test in `tests/unit/test_main.py` proving main wires an EOF callback that triggers bridge termination logic. | ||
| 3. Add failing unit test for timeout escalation path (terminate then kill) via mocked bridge process. | ||
| 4. Implement lifecycle changes in bridge/main modules. | ||
| 5. Re-run targeted tests, then full required quality gates. | ||
|
|
||
| ## TODO Plan | ||
|
|
||
| ### Phase 1: EOF Signaling Hook | ||
|
|
||
| - **Inputs:** current `run_stdin_forwarder()` behavior, bug report root cause. | ||
| - **Outputs:** optional `on_stdin_closed` callback support and tests. | ||
| - **Verification:** callback invoked once on EOF and on write-error exit paths. | ||
|
|
||
| ### Phase 2: Deterministic Upstream Termination | ||
|
|
||
| - **Inputs:** bridge subprocess handle, EOF signal from Phase 1. | ||
| - **Outputs:** helper that performs terminate -> wait(timeout) -> kill fallback. | ||
| - **Verification:** unit tests assert `terminate()` is called first and `kill()` only after timeout. | ||
|
|
||
| ### Phase 3: Main-Loop Integration and Regression Safety | ||
|
|
||
| - **Inputs:** `main()` threading and cleanup flow. | ||
| - **Outputs:** EOF callback wiring in `main()` and regression tests. | ||
| - **Verification:** tests confirm no hang path and existing metrics/audit flow remains intact. | ||
|
|
||
| ## Decision Points and Constraints | ||
|
|
||
| - Prefer a thread-safe callback approach over polling (`os.getppid`) to minimize runtime overhead and platform complexity. | ||
| - Keep shutdown idempotent: multiple EOF/error signals must not spam termination calls. | ||
| - Preserve current `cleanup_bridge()` finalizer behavior; new logic should unblock normal cleanup rather than replacing it. | ||
| - Avoid changing user-facing CLI flags in this task. | ||
|
|
||
| ## Notes | ||
|
|
||
| - Update BUG-T9 status and resolution checklist in `SPECS/Workplan.md` after implementation. | ||
| - If behavior changes meaningfully for operators, add a short troubleshooting note about automatic stale-process cleanup. | ||
|
|
||
| --- | ||
| **Archived:** 2026-02-25 | ||
| **Verdict:** PASS |
67 changes: 67 additions & 0 deletions
67
...s_port_after_MCP_client_disconnect_or_config_change/BUG-T9_Validation_Report.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Validation Report — BUG-T9 | ||
|
|
||
| **Task:** BUG-T9 — Orphaned Web UI server process blocks port after MCP client disconnect or config change | ||
| **Date:** 2026-02-25 | ||
| **Verdict:** PASS | ||
|
|
||
| ## Summary | ||
|
|
||
| Implemented stdin-EOF shutdown signaling and bounded upstream termination (`terminate -> grace wait -> kill fallback`) so orphaned wrapper processes no longer keep Web UI ports bound after client disconnect. | ||
|
|
||
| ## Quality Gates | ||
|
|
||
| ### 1. Test Suite | ||
|
|
||
| Command: | ||
| ```bash | ||
| PYTHONPATH=src pytest | ||
| ``` | ||
|
|
||
| Result: **PASS** | ||
| Key output: `659 passed, 5 skipped, 2 warnings` | ||
|
|
||
| ### 2. Lint | ||
|
|
||
| Command: | ||
| ```bash | ||
| ruff check src/ | ||
| ``` | ||
|
|
||
| Result: **PASS** | ||
| Key output: `All checks passed!` | ||
|
|
||
| ### 3. Type Check | ||
|
|
||
| Command: | ||
| ```bash | ||
| mypy src/ | ||
| ``` | ||
|
|
||
| Result: **PASS** | ||
| Key output: `Success: no issues found in 18 source files` | ||
|
|
||
| ### 4. Coverage | ||
|
|
||
| Command: | ||
| ```bash | ||
| PYTHONPATH=src pytest --cov=src/mcpbridge_wrapper --cov-report=term-missing | ||
| ``` | ||
|
|
||
| Result: **PASS** | ||
| Total coverage: **91.52%** (required: >= 90%) | ||
|
|
||
| ## Bug-Specific Verification | ||
|
|
||
| - `run_stdin_forwarder()` now supports `on_stdin_closed` callback and invokes it on stdin EOF / forwarding termination. | ||
| - `main()` wires a one-shot stdin-closed callback that triggers bounded bridge termination. | ||
| - `terminate_bridge_process()` behavior validated for: | ||
| - already-exited process (no-op), | ||
| - graceful exit after SIGTERM, | ||
| - SIGKILL fallback after grace timeout. | ||
|
|
||
| ## Artifacts Updated | ||
|
|
||
| - `src/mcpbridge_wrapper/bridge.py` | ||
| - `src/mcpbridge_wrapper/__main__.py` | ||
| - `tests/unit/test_bridge.py` | ||
| - `tests/unit/test_main.py` |
29 changes: 29 additions & 0 deletions
29
..._MCP_client_disconnect_or_config_change/REVIEW_bug_t9_orphaned_webui_process.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| ## REVIEW REPORT — BUG-T9 Orphaned Web UI Process Lifecycle | ||
|
|
||
| **Scope:** origin/main..HEAD | ||
| **Files:** 9 | ||
|
|
||
| ### Summary Verdict | ||
| - [x] Approve | ||
| - [ ] Approve with comments | ||
| - [ ] Request changes | ||
| - [ ] Block | ||
|
|
||
| ### Critical Issues | ||
| - None. | ||
|
|
||
| ### Secondary Issues | ||
| - None. | ||
|
|
||
| ### Architectural Notes | ||
| - The stdin-closure callback plus bounded terminate/kill fallback is a pragmatic fix for the orphaned process path while preserving existing final cleanup semantics. | ||
| - Callback idempotence via `threading.Event` in `main()` prevents repeated termination attempts if multiple closure/error signals occur. | ||
|
|
||
| ### Tests | ||
| - Unit coverage expanded for forwarder EOF callback behavior and terminate escalation behavior. | ||
| - Main-loop wiring tests assert callback registration and one-shot termination trigger. | ||
| - Quality gates verified in validation report with overall coverage at 91.52% (>= 90%). | ||
|
|
||
| ### Next Steps | ||
| - No actionable review findings. | ||
| - FOLLOW-UP phase should be skipped for this task. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.