Skip to content

fix(opencode): give the opencode2 status plugin a distinct id - #22544

Merged
nwparker merged 3 commits into
mainfrom
nwparker/opencode2-duplicate-plugin-id
Sep 24, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/opencode2-duplicate-plugin-id

Conversation

@nwparker

@nwparker nwparker commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​81
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79 $\color{#cf222e}{\Huge{\mathbf{−}}}$​61 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18

ELI5

Orca installs two versions of its OpenCode status plugin — one for OpenCode 1, one for OpenCode 2 — into the same folder. Both claimed to be the same plugin. OpenCode 2 refuses to load two plugins with the same name, so it kept the OpenCode 1 file and rejected the OpenCode 2 one. The OpenCode 1 file then switches itself off when it sees it's in an OpenCode 2 session. Net result: nothing reports status at all.

What Changed

The opencode2 plugin variant now declares its own id. getStatusPluginFactorySource emits:

pluginID = expectedAgent === 'opencode2' ? 'orca-opencode2-status' : 'orca-opencode-status'

Only the opencode2 variant's id changes — getOpenCodePluginSource() still emits orca-opencode-status, so nothing previously installed is orphaned and OpenCode 1's loader sees an unchanged id. The mimo-code digest is byte-identical, confirming the non-emitNextEvents variant was untouched.

Also included (from the original #22158): plugin setup now fails open, so a probe with an unusable context can't take the plugin down.

Why

Fixes #22506. Reported on Orca 1.4.209 / opencode 2.0.15, but the generated source is shared, so it is not Windows-specific.

How both files end up in one directory: when the user has not set OPENCODE_CONFIG_DIR — the common case — buildPtyEnv (hook-service.ts:130-138) calls writePluginToConfigDir(resolveOpenCodeConfigDirectory()) and returns {}. Both openCodeHookService and openCode2HookService therefore write into the same $XDG_CONFIG_HOME/opencode/plugins/. That is a direct consequence of 438744ca779 (#21854), which moved plugin installation into the shared global dir — which is why #22506 appears on 1.4.209 and not earlier.

The failure is deterministic, not racy — verified against v2.0.15:

  • packages/core/src/plugin/supervisor.ts filters duplicates before handing the generation to the registry, commenting: "Registry activation dies on a duplicate ID, which would drop the whole generation including builtins. Keep the first occurrence in boot order and report later ones like any other plugin setup failure." The loser gets state: { status: "failed", error: "Duplicate plugin ID: …" }.
  • Upstream's own test packages/core/test/plugin/supervisor.test.ts asserts exactly that (// Earlier boot order wins).
  • Boot order is guaranteed: packages/core/src/plugin/source-directory.ts sorts lexicographically on the full path, and orca-opencode-status.js < orca-opencode2-status.js (- 0x2D < 2 0x32).

So the V1 file always wins and the V2 file is always the one reported failed. The reporter's read was exactly right.

Worth correcting for the record: plugin.ts:96 does Effect.die on a duplicate, which reads like it would kill the whole plugin generation — but the supervisor's pre-filter means that path is never reached. It is a clean per-plugin failure, not a crash.

Stale-file cleanup is not needed. I checked, because a fix that leaves upgraders broken would be useless:

  • orca-opencode2-status.js has never been renamed (introduced in ee354a35d72; git log -S finds no rename), so a pre-fix copy is overwritten in place, not orphaned.
  • buildPtyEnv runs on every PTY launch and writePluginToConfigDir writes unconditionally, so the file is rewritten with the new id before the opencode2 process starts.
  • Residual case, self-healing and non-blocking: a user who upgrades and launches a V1-family session first still has a stale orca-opencode2-status.js claiming the old id. Because order is deterministic and the V1 file sorts first, the V1 plugin — the one serving that session — loads fine; the stale file is reported failed and is corrected by the next opencode2 launch. Not worth an overlay-manifest cleaner.

Linked Issue

Fixes #22506

Visual Proof

N/A — the change is a string identifier inside generated plugin source. The user-visible effect is that status resumes, which a screenshot cannot distinguish from any other working session. The meaningful proof is the installed-file assertion in the new test plus the upstream loader semantics quoted above.

Testing

Platforms: macOS; source verification against v2.0.15 and v2.0.12.

New test — "installs both family plugins into one config dir under distinct ids": runs both hook services against one real config dir, imports the two installed files as ES modules, and asserts ['orca-opencode-status', 'orca-opencode2-status']. That is the end-to-end shape of #22506; the pre-existing tests only pinned generated source strings, which is how this escaped.

Verified fail-without-fix by reverting only the source files and keeping the tests:

  • exposes a distinct plugin id per agent variant → expected 'orca-opencode-status' to be 'orca-opencode2-status'
  • fails open when setup is probed without a usable context → TypeError: Cannot read properties of undefined (reading 'session')
  • disposes cleanly when the prompt hook returns nothing to dispose → TypeError: … (reading 'dispose')
  • the new installed-file test → fails on the id tuple

Suites: pnpm test src/main/opencode src/main/opencode2 → 17 files, 218 passed. pnpm tc → 0. pnpm run check:code-quality:changed → 0 new findings.

Not verified: I did not run a real OpenCode 2 binary with both plugin files present. The duplicate-id behaviour rests on v2.0.15 source plus upstream's own supervisor test, and the Orca-side tests load the actual installed files.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • 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 pass locally

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: a17f22e1-41c0-4ee1-bfad-65b3c717324d

📥 Commits

Reviewing files that changed from the base of the PR and between e389ae9 and bc75317.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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: 13afa278-e2b2-4386-8c42-a5d7c6b14eed

📥 Commits

Reviewing files that changed from the base of the PR and between a463972 and e389ae9.

📒 Files selected for processing (2)
  • src/main/opencode/hook-service.test.ts
  • src/main/opencode2/status-plugin-setup-source.ts

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


📝 Walkthrough

Walkthrough

OpenCode2 setup now returns a no-op cleanup when required context APIs or an event handler are unavailable, or when initialization fails. Cleanup catches errors during disposal and event consumption. The generated plugin source now assigns OpenCode2 a distinct ID from OpenCode. Tests cover setup edge cases, generated IDs, and installation of both plugins in the shared plugin directory.

Merge Risk: 🟡 Moderate · up to e389a

OpenCode 2 plugin failures can leave stale status ownership. Resolve the disposal paths before merging; the distinct plugin IDs address the reported collision.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The changes to src/main/opencode2/status-plugin-setup-source.ts alter setup probing, initialization error handling, cleanup, and event-consumption behavior. Issue #22506 addresses duplicate plugin I… Move the setup and cleanup behavior changes to a separately scoped pull request, or link a coding requirement that requires them. Keep the duplicate-ID change and its focused tests in this pull request.
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 and concisely identifies the main change: assigning a distinct ID to the OpenCode 2 status plugin.
Description check ✅ Passed The description is complete and directly addresses the template. It explains the problem, change, rationale, linked issue, testing, compatibility, and visual-proof rationale. The listed tests and chec…
Linked Issues check ✅ Passed Issue #22506 requires distinct plugin IDs when OpenCode 1 and OpenCode 2 files share one plugin directory. getStatusPluginFactorySource now emits orca-opencode-status for OpenCode 1 and `orca-open…
Full details: Out of Scope Changes check

Explanation

The changes to src/main/opencode2/status-plugin-setup-source.ts alter setup probing, initialization error handling, cleanup, and event-consumption behavior. Issue #22506 addresses duplicate plugin IDs and does not require these setup changes. The related tests cover this separate behavior.

✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • 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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0374fee9-24bb-46b6-8353-4b85f8f524e9

📥 Commits

Reviewing files that changed from the base of the PR and between 519bde8 and a463972.

📒 Files selected for processing (4)
  • src/main/opencode/hook-plugin-opencode2-setup.test.ts
  • src/main/opencode/hook-service.test.ts
  • src/main/opencode/status-plugin-factory-source.ts
  • src/main/opencode2/status-plugin-setup-source.ts

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

await promptRegistration?.dispose?.();
await consuming;
await hooks.dispose?.();
} catch {

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Dispose the factory on every failure path.

If ctx.session.hook() rejects after factory creation, the outer catch returns noop without calling hooks.dispose(). If promptRegistration.dispose() rejects during unload, the cleanup catch skips hooks.dispose(). Either path can retain a dead factory ID and leave status ownership stale. Dispose an existing factory after setup failure, and run cleanup steps independently so one rejection does not skip the others.

Also applies to: 73-74

@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 minor observability suggestion inline, plus a stale-comment nitpick.

Reviewed changes

This rebased fix gives the OpenCode 2 plugin variant its own id so the two variants no longer collide in the shared global config dir.

  • Distinct plugin id — getStatusPluginFactorySource now emits orca-opencode2-status for the opencode2 variant and leaves the v1 orca-opencode-status id untouched (src/main/opencode/status-plugin-factory-source.ts:15).
  • Fail-open setup — setupOpenCode2Status guards on ctx.session.hook / ctx.event.subscribe, wraps its body in try/catch returning noop, and optional-chains the dispose handles, so an unusable probe context can't fail the plugin (src/main/opencode2/status-plugin-setup-source.ts).
  • Installed-file test — a new end-to-end case installs both variants into one config dir and imports the installed files to assert the id tuple, which is the shape of #22506 that the source-string tests missed (src/main/opencode/hook-service.test.ts:320).
  • Digest bump — getOpenCodePluginSource()'s pinned digest moves because that source embeds the shared v2 setup code; the mimo-code digest is unchanged, confirming the non-emitNextEvents variant is untouched.

I ran hook-service.test.ts, hook-plugin-opencode2-setup.test.ts, and hook-plugin-module-contract.test.ts: 69 passed. The pre-fix failure mode itself confirms OpenCode 2 dedups on the declared id (two different filenames, same id, one rejected), so distinct ids load both files; the ORCA_OPENCODE_AGENT guard keeps exactly one variant active per session, and post() still requires ORCA_PANE_KEY plus live coords, so there's no duplicate-reporting regression.

ℹ️ Nitpicks

  • The "Why" comment at src/main/opencode2/status-plugin-setup-source.ts:7 still says a throw surfaces as an 'orca-opencode-status' plugin failure; for the opencode2 variant that id is now orca-opencode2-status.

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

Comment on lines +73 to +74
} catch {
return noop;

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.

The outer catch implements the intended fail-open, but it also swallows genuine failures (a bug in the factory, a future setup-API rename) with no signal, whereas the subscription path logs via console.warn("[orca-hook] event subscription failed:", ...). Binding the error and emitting a single console.warn keeps the TUI clean while leaving a diagnostic for the case where status silently stops.

@nwparker
nwparker force-pushed the nwparker/opencode2-duplicate-plugin-id branch from a463972 to e389ae9 Compare September 23, 2026 22:30
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.
Orca installs both family plugins into one global plugins dir, so a shared
plugin id makes OpenCode 2 fail the later one with 'Duplicate plugin ID'.
@nwparker
nwparker force-pushed the nwparker/opencode2-duplicate-plugin-id branch from e389ae9 to bc75317 Compare September 23, 2026 23:09
@nwparker
nwparker merged commit 8352752 into main Sep 24, 2026
30 checks passed
@nwparker
nwparker deleted the nwparker/opencode2-duplicate-plugin-id branch September 24, 2026 00:51
flosrn pushed a commit to flosrn/orca that referenced this pull request Sep 25, 2026
…ai#22544)

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

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.

* fix(opencode): drop unused oxlint-disable in setup fail-open test

* test(opencode): pin distinct plugin ids for the shared global config dir

Orca installs both family plugins into one global plugins dir, so a shared
plugin id makes OpenCode 2 fail the later one with 'Duplicate plugin ID'.

(cherry picked from commit 8352752)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant