Skip to content

fix(plugin-install): guard non-object mcp/mcpServers in plugin install/remove/status (#836, #839) - #837

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-16_836-nonobject-mcp-guard
Sep 17, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-16_836-nonobject-mcp-guard

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

What & why

opencode.json may carry a non-object mcp (e.g. a bare string). "bili" in <non-object> throws TypeError, which on master:

  • crashed bili plugin remove (opencode) — stranding a half-install (installed plugin dir + compaction edits) that could not clean itself up → broken reversibility;
  • surfaced as error: from bili plugin status;
  • also threw from install.

Guard all three opencode sites with a new isPlainMcpObject helper:

  • install: present-but-non-object mcp → skip writing mcp.bili (config left untouched, no crash);
  • remove / status: non-object mcp → degrade to not installed (no crash); remove always completes cleanly, restoring reversibility.

Reproduction (pre-fix, master)

not ok 29 - plugin opencode survives a non-object mcp (issue #836 / #809 N4)
  error: "Cannot use 'in' operator to search for 'bili' in bogus-string"
  name: 'TypeError'

Relation to #824 / #809

Found hands-on testing #824; reported in #809 as finding N4. An equivalent guard (isPlainMcpObject) also ships inside PR #824 (commit 54f8fb2). However #824 is open, unmerged, and based on feat/pi-native-plugin, so master was still exposed today. This PR lands the guard independently on master as a minimal, focused change so it can ship without waiting on the larger feature PR.

⚠️ When #824 eventually merges, its N4 hunk in src/plugin-install.ts will overlap with this change (different surrounding context). One should be dropped during reconciliation — happy to close whichever is redundant at that point.

Pre-flight

  • npm run typecheck — clean
  • npm test — 1650 tests / 1648 pass / 0 fail / 2 pre-existing skip
  • npm run build — success

Regression test added in tests/plugin-agent.test.ts ("plugin opencode survives a non-object mcp").

Fixes #836 · found in #809 · related #824

Review addition (2026-09-16): claude side of the same bug class — #839

Reviewing this PR surfaced that claudeStatus() (src/plugin-install.ts) had the unguarded \"bili\" in data.mcpServers — a non-object mcpServers in .claude.json crashed bili plugin remove claude (remove calls status first, so a half-install could not clean itself up) and surfaced error: rows from bili plugin status. Same shape as #836, claude side. Tracked as #839; fixed by a follow-up commit on this branch reusing isPlainMcpObject, plus a regression test ("plugin claude survives a non-object mcpServers").

Updated pre-flight at 4f9b40c: typecheck clean; tests 1651 total / 1649 pass / 0 fail / 2 pre-existing skip; build success.

…status (#836)

opencode.json may carry a non-object `mcp` (e.g. a bare string); `"bili" in
<non-object>` throws TypeError. remove had no guard and crashed, stranding a
half-install (broken reversibility); status surfaced "error:". Guard all three
sites with isPlainMcpObject: install skips a present non-object mcp, while
remove/status degrade to "not installed" so remove always completes cleanly.

Found hands-on testing #824 (reported in #809 as finding N4). An equivalent
guard also ships inside #824; this PR lands it independently on master, which
was still exposed today. Regression test added in tests/plugin-agent.test.ts.

Full suite green: 1650 tests / 1648 pass / 0 fail / 2 pre-existing skip.
typecheck + build clean.
@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-16_836-nonobject-mcp-guard (4f9b40c)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-837

Each push to this PR publishes a new version under the pr-837 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr837.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Reviewing this PR now: pulled branch 2026-09-16_836-nonobject-mcp-guard (0c7f570), diff is minimal (2 files, +35/-4). Verifying the bug reproduces on master, re-running pre-flight (typecheck / test / build), and checking CI status before giving a final verdict.

…ove (#839)

Found while reviewing #837: claudeStatus() applied an unguarded 'in' operator
to mcpServers from .claude.json — a non-object value crashed pluginRemove('claude')
(which calls status first) and surfaced 'error:' rows from pluginStatusAll(),
the same broken-reversibility shape as #836 but on the claude side.

Reuse the isPlainMcpObject helper introduced by this PR; add a regression test
mirroring the opencode one.
@ranxianglei ranxianglei changed the title fix(plugin-install): guard opencode non-object mcp in install/remove/status (#836) fix(plugin-install): guard non-object mcp/mcpServers in plugin install/remove/status (#836, #839) Sep 16, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Review complete — verified, plus one addition made directly on the branch. Details below.

Verified (original scope, @0c7f570)

Review addition: claude side of the same bug class → #839

While sweeping the rest of src/plugin-install.ts for the same pattern, I found claudeStatus() had the identical unguarded in operator on mcpServers: a non-object mcpServers in .claude.json crashes bili plugin remove claude (remove calls status first → half-install can't clean itself up) and shows error: rows from status. Same broken-reversibility shape as #836, present on master and untouched by this PR. Reproduced both behaviors before touching anything.

Per review practice I fixed it directly on this branch rather than ping-ponging:

  • Filed #839 first (repro, impact, suggested fix), source-tagged to this PR's analysis.
  • Commit 4f9b40c: reuses the PR's own isPlainMcpObject helper in claudeStatus() (+ regression test "plugin claude survives a non-object mcpServers"). The pi/codex/omp sites are already safe (pi guarded by Array.isArray, codex/omp are text-based); a sweep of the rest of src found no other unguarded in-on-parsed-config sites.
  • Updated the PR title/body to reflect the added fix. Updated pre-flight at 4f9b40c: typecheck clean, tests 1651 / 1649 pass / 0 fail / 2 pre-existing skip, build success.

CI

All 7 checks green on head 4f9b40c (test matrix ubuntu/windows × node 22/24, e2e zero-token preflight, build-artifact, version-guard).

Conclusion: original fix is correct and complete for #836, the branch now also closes #839, CI green — ready for you to merge whenever.

中文摘要:审查确认了 opencode 非对象 mcp 的修复(master 上复现了崩溃、分支上验证了降级行为,diff 干净、无重复);review 中发现 claude 侧存在同类未防护的 mcpServers 崩溃(remove/status),已按规范先开 #839 再直接在 PR 分支补上守卫与回归测试(commit 4f9b40c),全套测试与 CI 均绿,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

继续

@ranxianglei
ranxianglei merged commit 432542e into master Sep 17, 2026
7 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-16_836-nonobject-mcp-guard branch October 15, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] plugin-install opencode: non-object mcp crashes remove/status (irreversible)

1 participant