Skip to content

fix(opencode): fail-open plugin setup and distinct opencode2 plugin id - #22158

Closed
nwparker wants to merge 2 commits into
mainfrom
nwparker/codex-bench
Closed

nwparker wants to merge 2 commits into
mainfrom
nwparker/codex-bench

Conversation

@nwparker

@nwparker nwparker commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​56 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​55
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​70 $\color{#cf222e}{\Huge{\mathbf{−}}}$​52 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18

ELI5

When you launch OpenCode 2 from Orca, OpenCode 2 checks our status plugin as it starts up. Our plugin crashed during that check instead of quietly standing down, so OpenCode 2 showed an orca-opencode-status plugin failure message. Now the plugin stands down quietly when the check does not look the way it expects, and the two plugin files have different names internally so they cannot be confused with each other.

What Changed

Before: opening an opencode2 terminal could show a plugin failure naming orca-opencode-status, and status reporting for that pane was dead. After: no failure message; status reporting works when the plugin API matches and silently stays off when it does not.

Mechanism (2 source files):

  • src/main/opencode2/status-plugin-setup-source.ts: setupOpenCode2Status() (the code injected into both generated plugin files) now validates its context up front, wraps everything in try/catch returning a no-op cleanup, and made unload defensive (promptRegistration?.dispose?.(), hooks.dispose?.()).
  • src/main/opencode/status-plugin-factory-source.ts: the opencode2 variant now exports id orca-opencode2-status instead of sharing orca-opencode-status (both files load from the same config dir).

Why

Alternatives considered: pinning to one exact OpenCode 2 setup-API shape, or removing setup from the v1 file. Both reintroduce the same crash the next time the API drifts or a stale file loads in the other binary. Fail-open matches the existing philosophy everywhere else in this integration (overlay writes, hook posts, and the server() factory already fail open), and the distinct id removes the duplicate-id collision for good.

Linked Issue

N/A — reported directly by the user in-session; no filed issue.

Visual Proof

N/A — no UI change in Orca itself. The user-visible change is the absence of OpenCode 2's plugin-failure message.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated

  • New regression tests in hook-plugin-opencode2-setup.test.ts: setup resolves to callable cleanup for undefined / {} / partial contexts, cleanup tolerates a hook returning nothing, distinct id per variant.

  • Updated pinned source hash in hook-service.test.ts.

  • Full suites green: src/main/opencode/, src/main/opencode2/, relay overlay + WSL + agent-hook integration (213 tests).

  • Live verification of generated sources (bundled via esbuild, imported as ESM): 17/17 checks pass — distinct ids, fail-open matrix on both variants, server(undefined) OK, positive control posts SessionBusy/SessionIdle through a valid context, mismatched-agent guard still no-ops.

  • pnpm tc:node, oxlint, oxfmt --check clean on changed files. Tested on macOS; change is platform-independent (pure JS string generation) and flows to SSH/WSL automatically since relay and guest installs receive generated source at session-ready.

Agent skill upstream boundary

  • Not applicable — no skill sources touched.

Notes

Security/cross-platform/SSH/mobile/backcompat: no new filesystem, network, or platform behavior; generated plugin is strictly more permissive about when it stays silent. Stale plugin files already on disk refresh automatically on next PTY spawn (local) or relay materialization (SSH/WSL) — no migration needed.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

setup() threw when OpenCode 2 probed it without a full context, which the
TUI reported as an 'orca-opencode-status' plugin failure. Both plugin files
also shared one id while living in the same config dir.
@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: db889f82-cc9a-4b2d-989f-e2db12123007

📥 Commits

Reviewing files that changed from the base of the PR and between 2ea78a9 and 4268186.

📒 Files selected for processing (1)
  • src/main/opencode/hook-plugin-opencode2-setup.test.ts
💤 Files with no reviewable changes (1)
  • src/main/opencode/hook-plugin-opencode2-setup.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The OpenCode status plugin now selects a distinct ID for each agent variant. The OpenCode2 setup validates context and hook functions before use, returns a no-op cleanup for unsupported setup states, and guards teardown operations. Tests cover incomplete contexts, missing session hooks, agent-specific IDs, and the updated generated plugin source digest.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 42681

The change separates plugin IDs and hardens invalid-context setup and cleanup behavior. No actionable production risk remains identified, so it is mergeable with normal checks.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed and covers the change, rationale, testing, visual proof, compatibility, and checklist items. However, the required Linked Issue section is marked N/A even though the templa… Add the GitHub issue reference in the Linked Issue section, using the required Fixes #<issue-number> format. If no issue exists, create or link the issue before merging.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two primary changes: fail-open OpenCode plugin setup and a distinct OpenCode 2 plugin ID.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is detailed and covers the change, rationale, testing, visual proof, compatibility, and checklist items. However, the required Linked Issue section is marked N/A even though the template states that an issue must always be linked.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one stale comment nitpick.

Reviewed changes

  • Fail-open setupOpenCode2Status — the generated setup now validates its context (ctx.session.hook and ctx.event.subscribe callable) and wraps its body in try/catch returning a no-op cleanup, with defensive disposal (promptRegistration?.dispose?.(), hooks.dispose?.()). This stops the startup probe from surfacing as a TUI plugin-failure.
  • Distinct default-export id per variant — status-plugin-factory-source.ts now emits orca-opencode2-status for the opencode2 variant instead of sharing orca-opencode-status, since both files land in the same managed config dir.
  • Regression tests — new fail-open matrix, a no-op-disposal case, and a distinct-id assertion in hook-plugin-opencode2-setup.test.ts; the pinned sha256 of getOpenCodePluginSource() was updated in hook-service.test.ts.

I ran the affected suites (src/main/opencode, src/main/opencode2, src/main/mimo, relay overlay + WSL install handlers): 235 tests pass. The new guard matches exactly what setup touches synchronously, and ctx.session.get is only reached lazily inside event handling where consume().catch already absorbs throws, so the guard's scope is coherent. No other reference to the plugin id exists in src, config, or docs; MiMo's reuse of orca-opencode-status is safe because it writes into a separate MIMEOCODE_HOME-scoped config dir.

ℹ️ Nitpicks

  • src/main/opencode2/status-plugin-setup-source.ts:7 — the new fail-open rationale says a throw "surfaces as an 'orca-opencode-status' plugin failed error", but this source is emitted verbatim into both plugin files and the opencode2 one now reports as orca-opencode2-status. Consider wording that doesn't hardcode a single id (e.g. referencing the plugin name generically or naming both).

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Incremental review of the delta since 2ea78a9f51: the only new change is 4268186287, which removes the now-unused // oxlint-disable-next-line require-yield above the empty subscribe: async function* () {} in the fail-open test. I confirmed npx oxlint reports 0 warnings/0 errors on the file without the disable, so dropping it is correct. No other files changed; the substance reviewed at 2ea78a9f51 (fail-open setupOpenCode2Status, distinct orca-opencode2-status id) is unchanged.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor Author

Superseded by #22544, which is this PR rebased onto current main (it had gone DIRTY because I merged #22389, #22391 and #22399 into the same files after it was opened). Both halves survived: the fail-open setup and the distinct orca-opencode2-status id. #22544 is merged and closed #22506. Closing this one.

@nwparker nwparker closed this Sep 24, 2026
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.

1 participant