Skip to content

mcpx: stop --all builds its per-daemon clients from the caller's paths, not the found daemon's (both mcpx copies) #316

Closed

Description

@dezren39

Problem

mcpx stop --all builds the client for every daemon it finds from the caller's paths, not from the paths of the state directory that daemon was actually found in. Its sibling mcpx daemons does it correctly — the two call sites of the same listing helper disagree.

Verified on current main in both repos that carry this code (identical except issue-number comments):

developing-today/code — pkgs/mcpx/internal/cli/commands.go

  • stopAll (line 1570): p := a.Paths; p.Socket = info.Socket; c := NewClient(p, info.ConfigPath) (lines 1579–1581) — only the socket is taken from the found daemon; State, Cache and Info are the caller's.
  • CmdDaemons (line 1638): p := listing.paths; p.Socket = info.Socket — the found daemon's own paths.
  • allDaemons (line 1554) builds each listing's paths as daemon.Paths{State: dir} — a partial Paths with Cache, Socket and Info left empty, so even the correct call site hands the client an incomplete value.

dezren39/nix — pkgs/mcpx/internal/cli/commands.go

  • Same code at the same lines (1570 / 1579–1581 / 1638 / 1554). This repo's flake.nix notes pkgs/mcpx is vendored verbatim from developing-today/code, so the fix belongs in both copies, tracked by this one issue.

Why it matters

Nothing breaks today: the only Client methods stopAll calls (Ping, Shutdown, and waitUntilStopped's Ping) dial paths.Socket, which is overridden. But Client does read the rest of Paths — e.g. EnsureDaemon (internal/cli/client.go:374-375) opens c.paths.State + "/daemon.log" and calls c.paths.EnsureDirs() — so the first time the stop path (or any future per-daemon operation) touches a state-dir-derived field, stop --all will act on the caller's state directory for a daemon that lives in another one: wrong log, wrong dirs, potentially the wrong daemon's record. The partial Paths{State: dir} in allDaemons has the mirror-image problem for any consumer that needs Info (e.g. RemoveInfo/mirrorInfoPath are no-ops when Info == "").

This is a latent cross-directory bug one innocent refactor away from going live, in the command whose whole job is to act on daemons from other directories.

Suggested fix

  1. allDaemons: construct each listing's paths with daemon.PathsAt(dir, "") instead of daemon.Paths{State: dir}, so every listing carries a complete Paths for its own directory (Info = <dir>/daemon.json). PruneStale/ListDaemons only read State, so their behaviour is unchanged.
  2. stopAll: build the client from listing.paths, exactly like CmdDaemons.
  3. Apply the identical change to the dezren39/nix copy of pkgs/mcpx.

Acceptance criteria

  • stopAll and CmdDaemons construct their per-daemon clients the same way, from the listing's paths.
  • allDaemons listings carry a complete Paths (non-empty Info pointing inside the listing's own state directory).
  • New regression test: a daemon record that exists only in the default state directory is listed with paths rooted in that directory, and stop --all actually stops a fake daemon serving on that record's socket (both were untested: no test references allDaemons/stopAll today).
  • Existing internal/cli and internal/daemon suites pass in both repos.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions