mpfaffenberger / mpfaffenberger/code_puppy
mcp_/manager: start_server_sync's no-loop fallback reports RUNNING without starting anything; hasattr-lazy task registries; duplicated background-task plumbing
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 814
- Forks
- 278
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 76
Description
File: code_puppy/mcp_/manager.py - start_server_sync / stop_server_sync (~lines 576-700)
Severity: Low-Medium (correctness / Zen)
- No-event-loop fallback lies about state. In the
except RuntimeError:branch ofstart_server_sync, the server is merelyenable()d but the status tracker is set toServerState.RUNNINGand a start time is recorded - no process was started and no health check ran:
except RuntimeError:
# No async loop, just enable the server
managed_server.enable()
self.status_tracker.set_status(server_id, ServerState.RUNNING) # <-- nothing is running
The async path correctly distinguishes STARTING -> RUNNING. The dashboard / /mcp listing will show RUNNING for a server whose subprocess never launched. Suggested: use a distinct state (ENABLED/STOPPED with enabled=True, or STARTING) and let the first actual use transition it.
- Lazy attribute creation via hasattr -
_pending_start_tasks/_pending_stop_tasksare created on first use:
if not hasattr(self, "_pending_start_tasks"):
self._pending_start_tasks = {}
Initialize both in __init__ (explicit is better than implicit); the cleanup_task callbacks also re-check hasattr for the same reason. This pattern appears 4 times in the file.
- The
start_server_background/stop_server_backgroundclosures + task bookkeeping are copy-pasted between the two sync wrappers - extract a_schedule_background(coro_fn, registry_dict, name)helper.
Filed by Zen Reviewer B (code-puppy-60635a)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in code_puppy/mcp_/manager.py around start_server_sync and stop_server_sync (~lines 576-700), then inspect init and the four hasattr checks for pending task registries. Trace the no-event-loop state update and the duplicated background-task closures. Done means state reflects whether a process actually started, registries are initialized explicitly, and shared scheduling behavior remains consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100