Repository navigation
fix(opencode): give the opencode2 status plugin a distinct id - #22544
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughOpenCode2 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 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)
✅ Passed checks (3 passed)
Full details: Out of Scope Changes checkExplanation The changes to ✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 0374fee9-24bb-46b6-8353-4b85f8f524e9
📒 Files selected for processing (4)
src/main/opencode/hook-plugin-opencode2-setup.test.tssrc/main/opencode/hook-service.test.tssrc/main/opencode/status-plugin-factory-source.tssrc/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 { |
There was a problem hiding this comment.
🩺 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
There was a problem hiding this comment.
ℹ️ 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 —
getStatusPluginFactorySourcenow emitsorca-opencode2-statusfor the opencode2 variant and leaves the v1orca-opencode-statusid untouched (src/main/opencode/status-plugin-factory-source.ts:15). - Fail-open
setup—setupOpenCode2Statusguards onctx.session.hook/ctx.event.subscribe, wraps its body in try/catch returningnoop, 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-emitNextEventsvariant 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:7still says a throw surfaces as an'orca-opencode-status'plugin failure; for the opencode2 variant that id is noworca-opencode2-status.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| } catch { | ||
| return noop; |
There was a problem hiding this comment.
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.
a463972 to
e389ae9
Compare
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'.
e389ae9 to
bc75317
Compare
…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)

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.
getStatusPluginFactorySourceemits:Only the opencode2 variant's id changes —
getOpenCodePluginSource()still emitsorca-opencode-status, so nothing previously installed is orphaned and OpenCode 1's loader sees an unchanged id. Themimo-codedigest is byte-identical, confirming the non-emitNextEventsvariant was untouched.Also included (from the original #22158): plugin
setupnow 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) callswritePluginToConfigDir(resolveOpenCodeConfigDirectory())and returns{}. BothopenCodeHookServiceandopenCode2HookServicetherefore write into the same$XDG_CONFIG_HOME/opencode/plugins/. That is a direct consequence of438744ca779(#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.tsfilters 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 getsstate: { status: "failed", error: "Duplicate plugin ID: …" }.packages/core/test/plugin/supervisor.test.tsasserts exactly that (// Earlier boot order wins).packages/core/src/plugin/source-directory.tssorts lexicographically on the full path, andorca-opencode-status.js<orca-opencode2-status.js(-0x2D <20x32).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:96doesEffect.dieon 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.jshas never been renamed (introduced inee354a35d72;git log -Sfinds no rename), so a pre-fix copy is overwritten in place, not orphaned.buildPtyEnvruns on every PTY launch andwritePluginToConfigDirwrites unconditionally, so the file is rewritten with the new id before the opencode2 process starts.orca-opencode2-status.jsclaiming 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.15andv2.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')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.15source plus upstream's own supervisor test, and the Orca-side tests load the actual installed files.AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
main. It went stale because I merged test(opencode): pin the installed OpenCode plugin to a v2-loadable default export #22389, fix(opencode-usage): read OpenCode 2 session_v2 token totals #22391 and fix(opencode2): only treat the question tool's form as a pane blocker #22399 into the same files after it was opened. Conflicts were instatus-plugin-setup-source.ts(the fail-open wrapper vs fix(opencode2): only treat the question tool's form as a pane blocker #22399'sform.metadata.kindguard — both preserved) and thehook-service.test.tsbyte digest (recomputed). fix(opencode2): resolve subagent session lineage so child work stops taking over the pane #22444's session-client envelope did not conflict.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm testpass locally