You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 06fa22e
Browse filesBrowse the repository at this point in the historyBrowse files
feat: add MCP auto-reconnect patch for stale remote sessions
When a remote MCP server restarts, the old session ID becomes invalid.
Tool calls fail at the transport layer with HTTP 404 / session errors.
Previously required a manual MCP toggle (ctrl+p) or OpenCode restart.
The patch wraps remote MCP tool execution with try/catch that detects
transport errors, closes the stale client, creates a fresh transport +
client, refreshes tool definitions, and retries the call once.
Addresses: anomalyco/opencode#15247
Copy file name to clipboardExpand all lines: .github/workflows/build-release.yml
+14-6Lines changed: 14 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -173,15 +173,16 @@ jobs:
173
173
uses: softprops/action-gh-release@v2
174
174
with:
175
175
tag_name: v${{ inputs.version }}-patched
176
-
name: OpenCode v${{ inputs.version }} with Caching + Vim + Tool Fix
176
+
name: OpenCode v${{ inputs.version }} with Caching + Vim + Tool Fix + MCP Reconnect
177
177
body: |
178
-
# OpenCode v${{ inputs.version }} with Caching + Vim + Tool Fix
178
+
# OpenCode v${{ inputs.version }} with Caching + Vim + Tool Fix + MCP Reconnect
179
179
180
-
This release applies three patches to OpenCode v${{ inputs.version }}:
180
+
This release applies four patches to OpenCode v${{ inputs.version }}:
181
181
182
182
1. **Prompt caching improvements** from [PR #5422](https://github.com/anomalyco/opencode/pull/5422) (via [opencode-cached](https://github.com/johnnymo87/opencode-cached))
183
183
2. **Vim keybindings** from [PR #12679](https://github.com/anomalyco/opencode/pull/12679)
184
184
3. **Tool use/result mismatch fix** from [PR #16751](https://github.com/anomalyco/opencode/pull/16751)
185
+
4. **MCP auto-reconnect** from [Issue #15247](https://github.com/anomalyco/opencode/issues/15247)
185
186
186
187
## Caching Improvements
187
188
@@ -204,6 +205,10 @@ jobs:
204
205
205
206
Fixes the widespread `tool_use ids were found without tool_result blocks` error ([#16749](https://github.com/anomalyco/opencode/issues/16749)) that corrupts sessions when stream errors cause lost step boundaries. Injects synthetic step-start boundaries at reconstruction time to prevent interleaved tool_use/text in assistant messages.
206
207
208
+
## MCP Auto-Reconnect
209
+
210
+
Automatically reconnects remote MCP servers when the server restarts and the session becomes stale. Without this, tool calls fail with transport errors requiring a manual MCP toggle or OpenCode restart.
This repository combines three unmerged upstream patches into a single OpenCode binary, built automatically for 4 platforms.
5
+
This repository combines four patches into a single OpenCode binary, built automatically for 4 platforms.
6
6
7
7
## Patches Included
8
8
@@ -26,6 +26,12 @@ Supported motions:
26
26
27
27
Stored locally as `patches/tool-fix.patch`. Fixes the widespread `tool_use ids were found without tool_result blocks` error ([#16749](https://github.com/anomalyco/opencode/issues/16749)) that corrupts sessions when stream errors cause lost step boundaries. Injects synthetic step-start boundaries at message reconstruction time to prevent interleaved tool_use/text in assistant messages that the Anthropic API rejects.
Stored locally as `patches/mcp-reconnect.patch`. Automatically reconnects remote MCP servers when the server restarts and the session becomes stale. Without this patch, `callTool` fails at the transport layer with "Session not found" / HTTP 404 errors, requiring a manual MCP toggle (ctrl+p) or full OpenCode restart.
32
+
33
+
The patch wraps remote MCP tool execution with a try/catch that detects transport-level errors (stale sessions, connection refused, etc.), closes the stale client, creates a fresh transport + client, refreshes tool definitions, and retries the call once.
:01 opencode-patched/sync-vim-pr -- checks PR #12679 for changes
80
86
:01 opencode-patched/sync-tool-fix-pr -- checks PR #16751 for changes
81
87
@@ -86,16 +92,17 @@ Timing Chain (every 8 hours):
86
92
87
93
1. Clone upstream OpenCode at the release tag
88
94
2. Fetch `caching.patch` from [opencode-cached](https://github.com/johnnymo87/opencode-cached) (always latest from `main`)
89
-
3. Apply `caching.patch`, then local `vim.patch`, then local `tool-fix.patch`
95
+
3. Apply `caching.patch`, then local `vim.patch`, then `tool-fix.patch`, then `mcp-reconnect.patch`
90
96
4. Build with Bun for 4 platforms (linux/darwin x arm64/x64)
91
97
5. Publish release as `v{VERSION}-patched`
92
98
93
99
### Patch Independence
94
100
95
-
The three patches modify completely different areas of the codebase:
101
+
The four patches modify completely different areas of the codebase:
@@ -141,6 +148,17 @@ If the hashes differ, it opens a GitHub issue labeled `patch-drift`.
141
148
publication is blocked. The drift issue is a prompt to review what changed upstream and
142
149
decide whether to adopt it.
143
150
151
+
### When the MCP Reconnect Patch Breaks (Build Failure)
152
+
153
+
The build fails and creates a GitHub issue automatically. This blocks publication.
154
+
155
+
1. Review the upstream changes to `packages/opencode/src/mcp/index.ts`
156
+
2. Regenerate or manually update `patches/mcp-reconnect.patch`
157
+
3. Review, commit, push
158
+
4. Re-trigger: `gh workflow run build-release.yml --field version=X.Y.Z`
159
+
160
+
**Sunset**: This patch can be dropped when [issue #15247](https://github.com/anomalyco/opencode/issues/15247) is resolved upstream. Unlike the other patches, this one has no upstream PR to track -- it is original work. If an upstream PR appears, add a sync workflow for it.
161
+
144
162
### Sunset Criteria
145
163
146
164
Monthly automated check (`check-sunset.yml`) monitors all upstream PRs:
0 commit comments