Commit 7b06399
Fix port conflict: stdio mode evicts --ws-only server on startup
Root cause: when Claude Code spawns sentinel_mcp.py (stdio mode), it tries
to start a new WebSocket server on 18925. If the extension's Start button
already launched a --ws-only instance holding that port, the new server
silently fails to bind. Claude's _ws_client stays None forever.
Fix:
- _main() calls _try_shutdown_existing() before starting the WS server
It connects to ws://127.0.0.1:18925 and sends {"command":"SHUTDOWN"}
- _ws_handler handles SHUTDOWN by calling sys.exit(0), releasing the port
- _start_ws_server() retries up to 6 times (×0.5s) in case the port is
slow to release — handles the race condition cleanly
- Extension reconnects to the new server within ~3s (our WS_RECONNECT_MIN)
- _send_command waits up to 35s for reconnect, so first tool call succeeds
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 60b9fc2 commit 7b06399
1 file changed
Lines changed: 32 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| |||
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
41 | 58 | | |
42 | | - | |
43 | | - | |
44 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
45 | 70 | | |
46 | 71 | | |
47 | 72 | | |
| |||
280 | 305 | | |
281 | 306 | | |
282 | 307 | | |
283 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
284 | 312 | | |
285 | 313 | | |
286 | 314 | | |
| |||
0 commit comments