GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mcpx(daemon): POST/DELETE /v1/servers handlers never hold reloadMu — concurrent adds lose servers while reporting success · Issue #2674 · developing-today/code

mcpx(daemon): POST/DELETE /v1/servers handlers never hold reloadMu — concurrent adds lose servers while reporting success #2674

New issue
Copy link
New issue
Copy link
Closed
#3135
Closed
mcpx(daemon): POST/DELETE /v1/servers handlers never hold reloadMu — concurrent adds lose servers while reporting success#2674
#3135
Copy link
Assignees
dezren39
Labels
app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

Description

@dezren39
dezren39
opened on Oct 30, 2026
Issue body actions

Problem

The daemon's live server add/remove handlers — handleServersAdd (pkgs/mcpx/internal/daemon/routes_settings.go:588) and handleServersRemove (routes_settings.go:623) — are the only reload-path handlers that do not hold s.reloadMu, the mutex whose documented job is exactly this: “reloadMu serialises reloads, so two requests arriving together do not each rebuild the pool map from the same starting point” (internal/daemon/server.go:137-139).

Every other caller follows the rule:

  • handleSettingsSet locks at routes_settings.go:224
  • handleAdaptersAdd / handleAdaptersRemove lock at routes_settings.go:845 / :935 — and the adapters comment even asserts “The servers handlers hold reloadMu the same way” (routes_settings.go:844), which is not true
  • handleReload and the SIGHUP path lock in server.go
  • Adapters also got a regression test for exactly this property: TestConcurrentAdapterAddsAllLand (internal/daemon/adapter_routes_test.go:88-116). Servers have no equivalent test.

That leaves two races in the servers handlers:

  1. Lost file update. config.AddServer / config.RemoveServer go through config.Edit (internal/config/write.go:91), an unsynchronised read-modify-write: read the file, mutate the decoded map, os.WriteFile the whole document back. Two concurrent POST /v1/servers calls (e.g. two CLI invocations, or a CLI racing a script) can both read the same starting document, each add a different server, and write back — the second write silently discards the first server. Both calls return 200.
  2. Racing reloads. Each handler then calls s.reloadConfig() (routes_settings.go:613, :654) unlocked, so the two reloads can interleave their pool rebuilds from different starting points — the precise failure server.go:137-139 says the mutex exists to prevent.

Evidence (verified this run, main cc52976)

Laptop probe (~/git/fleet/probe-2026-10-30-laneB-serverrace/ on the laptop) using the real internal/config/write.go from this main (md5 3d8605b0c3d4340fbee7a9d1d96cf702, byte-identical to the sandbox clone at cc52976; only its package-level StripJSONC/DirMode/FileMode dependencies are shimmed, and the probe inputs are plain JSON): two goroutines released simultaneously call config.AddServer for two different names against one config file seeded with 3,000 servers, 40 trials:

trial 0: both AddServer returned nil; alpha=false beta=true (one add silently lost)
RESULT lost_updates=40/40 trials (both calls reported success)

Both calls return nil in the lost trials — the add reports success for a server that is not in the file (and, because the handler's reload reads the file that survived, not in the running daemon either).

Code inspection this run confirms the missing lock is not compensated elsewhere: grep reloadMu over internal/daemon shows locks in the settings-set, adapters add/remove, watch, SIGHUP and reload handlers — and none in handleServersAdd/handleServersRemove; config.Edit itself takes no lock.

Why it matters

Live server add is a headline mcpx workflow (mcpx servers add, used by scripts and parallel sessions against one shared daemon). A concurrent add that silently vanishes — while reporting success — is the worst failure shape: the caller proceeds believing the server exists, and the missing server is only discovered later, downstream, with no error pointing here. The adapters path was hardened against exactly this in PR #2565 after review; the older servers path was left with the same hole and a comment claiming it was covered.

Acceptance criteria

  • handleServersAdd and handleServersRemove hold s.reloadMu across the file lookup/write and the reload, like the adapters handlers (and the stale comment at routes_settings.go:844 becomes true, or is corrected).
  • A daemon regression test mirroring TestConcurrentAdapterAddsAllLand: N concurrent POST /v1/servers adds all return 200 and all N servers are present in the written file afterwards.
  • A concurrent add/remove mix cannot resurrect a removed server or drop an unrelated one (covered by the same lock, asserted in the test or a sibling).
  • Existing daemon + config tests still pass in CI.

Activity

Next
  1. dezren39
    added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    status/needs-triageNot yet triaged; needs a first look
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    queue/queuedHas a queued queue task
    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)
    effort/xsTrivial: expected under 30 minutes of work
    on Oct 30, 2026
  2. dezren39 commented on Oct 30, 2026

    @dezren39
    dezren39
    on Oct 30, 2026
    MemberAuthor
    More actions

    🤖 Agent note · filed

    • Agent: new-issue-creator (lane B, new-issue-creator-code-b)
    • Session / ID: new-issue-creator-code-b run 2026-10-30 04:50 CDT
    • Found via: filed this run
    • Task: Triage the missing reloadMu in the daemon's live servers add/remove handlers (routes_settings.go): pin that lookup + file write + reload happen under the lock like the adapters handlers, then route a small_fix packet.
    • Expectation: effort/xs — done looks like the acceptance criteria on this issue being pinned and a fix packet routed.
    • Links: evidence in the issue body (file:line at main cc52976 + laptop probe ~/git/fleet/probe-2026-10-30-laneB-serverrace/, lost updates 40/40).
  3. github-actions
    assigned
    dezren39
    on Oct 30, 2026
  4. dezren39
    added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    status/in-progressQueue worker lifecycle state
    and removed
    status/needs-triageNot yet triaged; needs a first look
    queue/queuedHas a queued queue task
    on Oct 31, 2026
  5. 31 remaining items

  6. dezren39 commented on Oct 31, 2026

    @dezren39
    dezren39
    on Oct 31, 2026
    MemberAuthor
    More actions

    🤖 Agent note · parked

    • Agent: queue worker (repo-worker-code), lane F shift
    • Session / ID: queue task 4415
    • Found via: queue claim (resume)
    • Task: PR fix(mcpx/daemon): hold reloadMu in servers add/remove handlers (#2674) #3135 revalidated fresh: all substantive checks PASS (basic lint, plugin tests, stress PR-changed-tests race/shuffle, nix build mcpx-docs); Codex review clean at head c5dcc49 (no findings). Only final: CI time budget remains QUEUED after a 5-minute poll — runner backlog, not a code signal.
    • Expectation: parked 20 min; on resume, if the final check is green, merge PR fix(mcpx/daemon): hold reloadMu in servers add/remove handlers (#2674) #3135, close this issue, complete task 4415 as fixed_merged.
    • Links: PR fix(mcpx/daemon): hold reloadMu in servers add/remove handlers (#2674) #3135
  7. dezren39
    added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    queue/claimedQueue worker lifecycle state
    status/in-progressQueue worker lifecycle state
    and removed
    status/in-progressQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Oct 31, 2026
  8. dezren39
    added a commit that references this issue on Oct 31, 2026

    Merge pull request #3135 from developing-today/queue/4415-2674-server…

    affe09b
  9. dezren39
    closed this as completedin #3135on Oct 31, 2026
  10. dezren39 commented on Oct 31, 2026

    @dezren39
    dezren39
    on Oct 31, 2026
    MemberAuthor
    More actions

    🤖 Agent note · done

    • Agent: queue worker (repo-worker-code), lane E
    • Session / ID: queue task 4415
    • Found via: queue claim (resume from awaiting_ci)
    • Task: PR fix(mcpx/daemon): hold reloadMu in servers add/remove handlers (#2674) #3135 merged — merge commit affe09b at 2026-10-31T18:38Z; this issue auto-closed by the merge. Verification on head c5dcc49: build/lint/plugin/stress all SUCCESS, Codex review state has_any_findings=false / has_unresolved_findings=false, 0 review threads, MERGEABLE. The only non-green item was the final: CI time budget meta check, QUEUED since 16:25Z in the fleet runner backlog — an infra queueing condition, not a code result; merged under the standing merge directive with the change itself verified.
    • Expectation: Done.
    • Links: PR fix(mcpx/daemon): hold reloadMu in servers add/remove handlers (#2674) #3135
  11. dezren39
    removed
    status/in-progressQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @dezren39
    dezren39

Labels

app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.