Repository navigation
Description
Summary
POST /api/location/reload is the only in-place way to reload a location (used to pick up a rebuilt
MCP server without restarting the daemon). It invalidates every loaded location and boots the
replacements, so the server side is ready when the call returns — but the step that performed the
reload still holds the invalidated build, and its tool catalog is empty until the next request
re-resolves the location. Any tool call made in that window fails as Unknown tool '<server>.<name>',
which is indistinguishable from an MCP server that is not connected.
Environment
- opencode version: v2.2.0 (local clone,
fa1260d6ca) - OS: Linux 7.0.0-42-generic (x64)
- Terminal: TERM=xterm-256color, COLORTERM=truecolor (kitty)
- Shell: /bin/bash
- Install/channel: local dev checkout (
~/repos/opencode),opencode servedaemon shared by sessions - Active plugins: none
Reproduction
- Start the daemon (
opencode), open a session in a project with a local MCP server
(.opencode/opencode.json→mcp["llm-pipeline"]). - Confirm the server's tools are callable in that session.
- From a tool call in the same session,
POST http://127.0.0.1:<port>/api/location/reload
(basic auth from~/.local/state/opencode/service.json). - Immediately make another MCP tool call from the same session.
Expected Behavior
Either the reload keeps the previous build alive for consumers that still hold it, or the caller's
next tool call re-resolves the location transparently. The model should never see a tool it had a
second ago as "unknown".
Actual Behavior
The next call fails with Unknown tool 'llm-pipeline.check_mcp' (and the session's tool list shows
only the non-MCP tools). The retry of the same call — i.e. the request after the next one —
answers normally, against the NEW revision. Measured three times (2026-10-22 ×2, 2026-10-28) on
2.0.32 and 2.2.0-shaped builds; the daemon pid never changes.
Additional Context
Localisation (read-only, no patch attempted):
packages/server/src/handlers/location.ts→location.reload→LocationServiceMap.reload()
(packages/core/src/location-service-map.ts), which invalidates each location's layer and
re-boots the replacement, waiting for the builds. So the server is ready on return.packages/server/src/location.tsresolves location services per REQUEST, which is why the request
after the reload sees the new instance — and why the request that performed the reload does not.- The tool registry is not the culprit:
packages/core/src/tool/mcp.tsreconciles from the
McpEvent.ToolsChangedbus event with a 100 ms debounce, and
packages/core/src/mcp/index.ts(connect) publishes that event after
stopServer+startServerunder the per-server lock.
Suggestion: a per-server restart already exists as
POST /api/experimental/mcp/:server/connect and does not touch the location at all — that is the
endpoint a caller who only needs a fresh MCP server should use, and it is what we now use. If the
intent of location.reload is to serve holders of the old build as well, keeping the previous build
alive until its refs drain (or retrying internally inside the session) would remove this window.
Impact: an agent that refreshes its MCP server between steps loses the tool channel for one turn and
tends to conclude the server is down; the documented remedy had to become "retry the same call once",
which is a property of this API rather than of the caller.
Activity
opencodejr commentedon Oct 28, 2026
Thanks for the detailed report. I can reproduce this on 2.2.0, and it still happens on the latest
dev(a882cf98a0).Setup: a minimal local stdio MCP server, set to
codemode: falseso its tool shows up as a plain tool namedpipe_check, and a simulated model. In one turn:pipe_checkworks.shelltool call is in progress whilePOST /api/location/reloadruns, and the reload returns successfully.pipe_check. Calling it returnsNo tool named "pipe_check" is currently available.In my run, the tool stayed missing for the rest of that turn, not just the next call. The next user prompt got the tool back, served by a new MCP server process.
The recording and script below show the whole sequence. As you noted, restarting just the server with
POST /api/experimental/mcp/:server/connectavoids this.recording.mp4
Reproduction script (drive.ts)
Run it with opencode-drive:
opencode-drive run ./drive.ts. It drivesopencodefrom yourPATH; setOC_DEVto the path of an OpenCode checkout to run that from source instead.GladSI commentedon Oct 28, 2026
Correction from the reporter, measured after filing — the per-server suggestion is not sufficient, and the summary above overstates what it fixes.
I tried
POST /api/experimental/mcp/<server>/connectas the workaround instead ofPOST /api/location/reload: it is accepted, it replaces the server process (407255 -> 450487), and it does not invalidate the location. The first tool call after it still failed withUnknown tool 'llm-pipeline.<name>', and the next request saw the full catalog again — the same symptom, now 4/4 occurrences across both endpoints.So the empty-catalog window is not produced by
LocationServiceMap.reloadalone. The tool registry is rebuilt from the sameMcpEvent.ToolsChangedevent either way (packages/core/src/tool/mcp.ts→tools.reload()inreconcile), and the step that issued the restart keeps the registry it had already resolved; only the next request re-resolves it. A per-server restart avoids tearing down the location, which is worth having, but it does not remove the window.What would still be worth looking at on your side: either keep the previous tool-registry snapshot usable until its holders release it (mirroring the "old build for existing consumers" idea), or make the reconcile update the registry in place instead of replacing what a running step holds.
The retry-once rule on our side is now unconditional for both endpoints; the issue remains valid as a report of the window, with this comment as the corrected scope.