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

Open
#448 0 comments 0 reactions 0 assignees View on GitHub

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)

  1. No-event-loop fallback lies about state. In the except RuntimeError: branch of start_server_sync, the server is merely enable()d but the status tracker is set to ServerState.RUNNING and 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.

  1. Lazy attribute creation via hasattr - _pending_start_tasks / _pending_stop_tasks are 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.

  1. The start_server_background / stop_server_background closures + 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.