Skip to content

fix(opencode): expose v2 setup() on status plugin default export - #21322

Closed
werlang wants to merge 6 commits into
stablyai:mainfrom
werlang:fix/opencode-v2-plugin-setup
Closed

werlang wants to merge 6 commits into
stablyai:mainfrom
werlang:fix/opencode-v2-plugin-setup

Conversation

@werlang

@werlang werlang commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Problem

On OpenCode 2.x the status plugin fails to load and all Orca status updates stop:

Plugin must export a default definition with an id and an effect or setup function.
SchemaError(Missing key at ["default"]["effect"] / Missing key at ["default"]["setup"])

The generated orca-opencode-status.js default-exports the legacy v1 shape { id, server }, which the v2 loader rejects (verified against opencode 2.0.7 server logs: every loading plugin is followed by failed to load plugin).

Fix (4 files, +190/-12)

  • New status-plugin-v2-setup-source.ts: emits a setup() adapter that reuses the tested v1 factory — v1 event maps to ctx.event.subscribe(), v1 dispose maps to the cleanup returned by setup. Includes a client shim adapting v2 ctx.session.get/list to the client.session shape the factory expects (fail-open when neither exists).
  • setup() without an event stream returns a no-op cleanup without instantiating the factory, so a pre-v2 loader invoking it cannot spawn a ghost owner.
  • Default export now carries both keys (server + setup) pointing at the same implementation, so each loader resolves (a { id, server, setup } module loads on 1.18.x because server is present).
  • Contract tests: default exposes callable setup alongside server; no-subscribe setup is side-effect-free (zero hook POSTs); setup() with a v2-style ctx posts SessionBusy.

Validation

  • Existing 1.18.18-pinned tests untouched (server path, named export, lifecycle POST all still asserted).
  • Standalone harness executing the assembled generated module: shape { id, server, setup } + named factory OK; no-op setup produced 0 posts; setup() produced exactly 1 SessionBusy POST with the right paneKey; server() path unchanged.
  • Live 2.0.7 check: patched file loads with no failed to load plugin WARN (previously every load warned).
  • Full vitest suite not run locally (monorepo toolchain); relies on CI.

The v2 server loader rejects the legacy { id, server } default with
Missing key at ["default"]["effect"] / ["default"]["setup"], which
disables all Orca status updates (failed to load plugin). Emit both
server and setup keys pointing at the same factory so pre-v2 and v2
loaders each resolve; setup() bridges ctx.event.subscribe to the v1
event handler and returns dispose as cleanup, and is a side-effect-free
no-op when no event stream exists.
Copilot AI lite review requested due to automatic review settings September 18, 2026 01:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Existing hash expectations fail the test suite, and abort handling can leave requests running past their deadline.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates the generated OpenCode status plugin with OpenCode v2 setup() support while preserving the v1 server() path.

Changes:

  • Adds a v2 event-subscription adapter and session-client shim.
  • Exposes setup alongside server.
  • Adds contract and lifecycle tests.
File summaries
File Summary Review findings
src/main/opencode/status-plugin-v2-setup-source.ts Generates the v2 setup adapter. Moderate: Preserve abort errors before retrying list() to avoid uncancellable requests. (2 votes)
src/main/opencode/status-plugin-factory-source.ts Adds setup to the default export. No findings.
src/main/opencode/hook-service.ts Includes the new source in generated plugins. Critical: Refresh the stale SHA-256 expectations in hook-service.test.ts; the current suite will fail. (3 votes)
src/main/opencode/hook-plugin-module-contract.test.ts Tests v1/v2 module contracts and setup behavior. No findings.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/main/opencode/hook-service.ts Resolved
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The OpenCode plugin now exports both server() and setup() for pre-v2 and v2 loaders. The family plugin source includes the generated v2 setup adapter. The adapter maps execution events to busy and idle lifecycle events, synthesizes root session starts when required, forwards supported events, and disposes hooks on stream termination or cleanup. Contract tests cover the export shape, no-op setup behavior, event translation, session-start reuse, and generated source output.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to e1c62

On OpenCode v2 session-domain contexts, status updates can be skipped because root sessions are not recognized. Correct the session lookup argument before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, implementation, compatibility behavior, and validation, but it does not follow the required template. It omits the required linked issue, template headings, visua… Rewrite the description using the repository template. Add a real issue reference under Linked Issue, complete ELI5, What Changed, Why, Testing, Review, Notes, and Checklist sections, and add Visual Proof with exactly N/A plus a reason if n…
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 3 functions across 5 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 identifies the primary change: exposing v2 setup() on the OpenCode status plugin while remaining specific and concise.
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 explains the problem, implementation, compatibility behavior, and validation, but it does not follow the required template. It omits the required linked issue, template headings, visual-proof statement, checklist items, and complete testing details.

Resolution

Rewrite the description using the repository template. Add a real issue reference under Linked Issue, complete ELI5, What Changed, Why, Testing, Review, Notes, and Checklist sections, and add Visual Proof with exactly N/A plus a reason if no visual or interaction change exists.


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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 205bc3b0-55d6-45a9-b217-f445ed3b3e28

📥 Commits

Reviewing files that changed from the base of the PR and between 27bddc6 and 58a3f51.

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

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

- list() shim rethrows when the lookup signal aborted instead of
  retrying without the signal as an uncancellable request.
- hook-service.test.ts stability digests regenerated for the new
  generated bytes, plus containment pins for the setup adapter.
@werlang

werlang commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Both review findings addressed in 66060c5:

  1. Stale SHA-256 expectations — regenerated both digests in hook-service.test.ts:77-82 from the new generated bytes (verified via the same assembly path), and added containment pins (setup: OrcaOpenCodeStatusSetup,, async function OrcaOpenCodeStatusSetup(ctx)) so the snapshot refresh is backed by an intentional contract check rather than a blind hash update.
  2. Abort swallowed by list() retry — the shim now rethrows when signal?.aborted before falling back to a signalless call, mirroring the get shim. Verified both guards present in the generated bytes.

Re-ran the standalone generated-module harness after the change: shape { id, server, setup } OK, no-subscribe setup side-effect-free (0 posts), setup() posts exactly 1 SessionBusy, server() path unchanged.

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

Caution

The setup() adapter forwards the wrong event shape. On opencode 2.0.7 the plugin event stream yields { type, data } events under v2 names, while the reused v1 factory reads event.properties.* and v1 names — so v2 still reports no status. A pinned generated-source digest test also fails. The loader-shape fix itself is correct.

Reviewed changes

  • Dual-key default export — { id, server, setup } so the pre-v2 (server) and v2 (setup) loaders both resolve. This part checks out; I verified both loader schemas ignore the extra key, and this is opencode's documented V1+V2 migration shape.
  • New setup() adapter (status-plugin-v2-setup-source.ts) — reuses the v1 factory behind a client.session shim, subscribes to ctx.event.subscribe({ signal }), and returns an abort/dispose cleanup.
  • Contract tests — pin setup presence, a no-op setup without an event stream, and a SessionBusy post driven through a fabricated v2 context.

⚠️ Generated-source digest test is stale and fails

src/main/opencode/hook-service.test.ts:77-82 pins the sha256 of the assembled plugin source, and this PR changes that source without updating the pins. I ran the file: expected 'd14859a36c88aefe3a45cd232789503296e0a…' to be 'd14859…' — received fa4700f1a99f06f7e97ef578e270027cf9bda19fb76157236c9d514709875159. The second pin (the /hook/mimo-code family source) also changes because it shares the added part. This is a CI failure, not a runtime one, but it blocks the merge; regenerate both digests after the event-bridge fix below lands so the bytes are pinned once.

Technical details
# Stale generated-source digest pins

## Affected sites
- `src/main/opencode/hook-service.test.ts:74-83` — `keeps generated plugin bytes stable across the module split` asserts exact digests of `getOpenCodePluginSource()` and `getOpenCodeFamilyPluginSource('/hook/mimo-code', { emitSessionStart: false })`.
- `src/main/opencode/hook-service.ts:65` — adding `...getStatusPluginV2SetupSource()` changes both assembled strings.

## Required outcome
- Both pinned digests match the assembled source once the final adapter shape is settled.

## Suggested approach (optional)
- Update the pins from the failure output (or recompute via the test's own `digest()` helper). Do this after the event-bridge fix, since that fix will change the bytes again.

ℹ️ Nitpicks

  • src/main/opencode/status-plugin-factory-source.ts:218-219 says both keys point at "the same implementation", but server is OrcaOpenCodeStatusPlugin and setup is the separate OrcaOpenCodeStatusSetup adapter. Consider "both keys resolve to the shared factory" to avoid implying one function.
  • buildV1ClientShim always returns a session.list, but opencode 2.0.7's SessionDomain exposes no list (only get, create, prompt, …). It is only a fallback because get exists, and failures are caught upstream as fail-open, but advertising a method the host does not have is misleading.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | 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.

ℹ️ Delta is clean — the digest pins are refreshed and the list shim now preserves abort. The v2 event-shape blocker from the prior review is still open.

Reviewed changes (since the prior review at 58a3f51)

  • Refreshed generated-source digest pins — hook-service.test.ts now pins the post-change hashes and asserts the v2 setup symbols are present. pnpm test src/main/opencode/ passes 116/116.
  • Abort preserved in the list shim — status-plugin-v2-setup-source.ts:46-52 rethrows when the deadline signal is aborted rather than retrying without it, so a cancelled lookup stays cancelled.

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

- toV1LifecycleEvent maps encoded OpenCodeEvent {type, data} to the
  v1 {type, properties} shape for session.status/idle/created and
  permission.asked/replied only; v2 text/preview vocabulary is dropped
  rather than mislabeled, and session.created's flat id is nested under
  info as the factory expects.
- Adapter disposes the factory in a finally when the subscribe stream
  terminates so a dead stream cannot pin a busy owner.
- Simplify list shim to the single-input v2 form; errors propagate to
  the lookup timeout/fail-open path.
- Contract tests use real v2 envelopes throughout; created->Start,
  delta-drop, busy->idle-on-stream-end, and permission attention covered.
  Stability digests regenerated.
@werlang

werlang commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Update in f6b683e — both new findings addressed, and pullfrog's envelope catch was correct and important:

V2 envelope translation (pullfrog). Verified against the published 2.0.7 packages: ctx.event.subscribe() yields encoded OpenCodeEvent (packages/plugin/src/promise/adapter.ts maps the event stream through Schema.encodeUnknownEffect(OpenCodeEvent)), and per @opencode/schema the payload lives under data (session.status -> data: { sessionID, status }, session.created -> flat data.id/data.parentID, permission.asked -> data: { sessionID, id, ... }). The adapter now translates via an explicit allowlist (session.status/session.idle/session.created/permission.asked/permission.replied, with created nested under info); everything else — including session.text.delta et al, which carry no v1 role/message identity — is dropped rather than mislabeled. My earlier test has been rewritten to use real v2 envelopes throughout, so it now fails on a verbatim forward.

Dispose on stream end (coderabbit). The subscription task now disposes the factory in a finally, so a terminated stream can't pin a busy owner; dispose is idempotent so loader cleanup stays safe. Pinned by test: busy -> stream end yields SessionIdle before explicit cleanup runs.

Validation (standalone harness executing the assembled generated module): v2 busy -> SessionBusy then stream-end SessionIdle; v2 created -> exactly ['SessionStart'] with the delta dropped; v1-shaped verbatim event posts nothing; v2 permission.asked -> PermissionRequest. Stability digests regenerated again for the new bytes.

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

Important

The v2 event bridge only fires for session.status/session.idle. The session.created and permission.* branches target v1 event names/payloads that opencode 2.x's server stream does not carry, so SessionStart and PermissionRequest never post on 2.x.

Reviewed changes (since the prior review at 66060c5)

  • Event-shape bridge — toV1LifecycleEvent maps the v2 { type, data } envelope to the v1 factory's { type, properties } shape for a lifecycle whitelist and drops everything else.
  • Client shim narrowed — buildV1ClientShim exposes get/list only when the v2 session domain has them and drops the signal/arg-shape probing.
  • Stream-end dispose — setup() disposes the factory in a finally when the event stream ends.
  • Tests + digest pins — added a v2 session.status case and a session.created/text-drop case; refreshed the generated-source hashes (pnpm test src/main/opencode/ passes 117/117).

ℹ️ Pane previews and session start stay unmapped on v2

The default: return null branch drops every session.next.* event, which is where v2 carries prompt/reply text (session.next.prompted, session.next.text.ended) and session lifecycle. The test documents this as a deliberate choice, but it means this fix restores busy/idle while pane previews and SessionStart remain blank on 2.x. Worth deciding explicitly whether those are follow-ups or out of scope.

Technical details
# v2 preview/session-start scope

## Affected sites
- `src/main/opencode/status-plugin-v2-setup-source.ts:31-32` — `default: return null`.
- `src/main/opencode/hook-plugin-module-contract.test.ts:241-244` — asserts the delta is dropped.

## Open questions for the human (optional)
- Is v2 preview/session-start parity a follow-up, or intentionally out of scope for this fix?

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

@werlang

werlang commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Checked both new findings against the published 2.0.7 packages (npm pack @opencode/[email protected] @opencode/[email protected]) — no code change needed, details below so anyone can reproduce.

1. session.created IS a v2 server event with flat data. event-manifest.d.ts contains the "session.created" literal, and its data struct keys are flat — projectID, location, parentID, slug, title, agent, model, id, ... — with no info wrapper. The { sessionID, info } shape cited lives in v1/session.ts, but SessionV1 appears in the manifest only as a Brand type reference (SessionV1.MessageID), never as event definitions. So the adapter branch mapping data.id/data.parentID -> properties.info matches what the server emits, and the contract test fabricates that same flat shape.

2. permission.v2.* does not exist in 2.0.7. Neither event-manifest.d.ts nor permission.d.ts contains permission.v2.asked/permission.v2.replied anywhere, while the v1-named permission.asked/permission.replied ARE manifest members (ephemeral), with data: { sessionID, id: Permission.ID, ... } and data: { sessionID, requestID, ... } respectively — exactly the properties.sessionID/properties.id/properties.requestID fields the factory reads. The mapped cases are live; there is nothing to rename to.

Consistent with this, question.asked and session.error are genuinely absent from the manifest, which is why the adapter allowlists only the five mapped names.

Live 2.0.7 turns emit no session.status/session.idle; liveness is
session.execution.started -> ...succeeded|failed|interrupted. Map those
to v1 busy/idle and synthesize SessionStart on first sight of a
lookup-confirmed root (skipped for children and on lookup failure).
Real creation events mark first sight to avoid double Start. Contract
tests rewritten around observed v2 flows; digests regenerated.
@werlang

werlang commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Live probing changed the picture — pushed 4f38212. I ran an instrumented copy of the adapter against a real 2.0.7 turn and found a full successful turn emits no session.status, session.idle, or session.created at all. Liveness is session.execution.started -> ...succeeded|failed|interrupted, each carrying only { sessionID }. The previous revision loaded cleanly but would have stayed silent — the gray icon would not have moved.

What changed:

  • toV1LifecycleEvent maps execution.started -> v1 busy and execution.succeeded|failed|interrupted -> v1 idle, reusing the aggregation/child-attribution/retry machinery unchanged. Direct session.status/idle mappings stay for flows that do emit them.
  • Synthetic SessionStart on first sight of a lookup-confirmed root only (children and lookup failures skip it — a wrongly-rooted child would poison the session cache; busy still posts either way). Real creation events mark first sight so Start never double-posts.
  • Tests rewritten around the observed flows: execution -> [SessionStart, SessionBusy, SessionIdle]; created+delta+execution -> single Start with the delta dropped. Verified additionally that a child execution synthesizes no Start while its busy rolls up, and permission.asked still raises PermissionRequest. Digests regenerated.

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

Important

The new busy/idle derivation is correct against opencode 2.0.7, but the session.created signal it builds on is misread: v2 sends { sessionID, parentID, … }, not { id, … }, so the real creation event is still dropped and SessionStart depends entirely on the execution.started lookup path.

Reviewed changes (since the prior review at f6b683e)

  • Derived v2 busy/idle from execution events — toV1LifecycleEvent maps session.execution.started to a v1 busy session.status and …succeeded|failed|interrupted to session.idle, so a normal turn now flips the pane.
  • Synthesized session.created for confirmed roots — on the first execution.started the adapter looks up the session and, when it has no parentID, forwards a v1-shaped session.created so the factory posts SessionStart before the busy transition.
  • Bounded seen-session set — seenV2SessionIDs (128, FIFO) prevents a repeated start; session.created is also meant to mark first sight.
  • Tests and digest pins refreshed — the execution-event test asserts the exact SessionStart/SessionBusy/SessionIdle order and both generated-source hashes are re-pinned.

ℹ️ The prior permission.asked / permission.replied finding was based on the wrong file

The open thread at status-plugin-v2-setup-source.ts:25-29 is a false positive: opencode 2.0.7's packages/schema/src/permission.ts defines permission.asked / permission.replied (carrying id and sessionID) and event-manifest.ts includes Permission.Event.Definitions in ServerDefinitions. permission-v1.ts is the legacy re-export. No change is needed on those cases.

Technical details
# v2 permission events keep their v1 names

## Evidence (opencode v2.0.7)
- `packages/schema/src/permission.ts` — `Asked = ephemeral({ type: "permission.asked", schema: Request.fields })`, `Replied = ephemeral({ type: "permission.replied", … })`.
- `packages/schema/src/event-manifest.ts` — `Permission.Event.Definitions` is part of `featureDefinitions`, hence `ServerDefinitions`.
- `packages/schema/src/permission-v1.ts` — `export * from "./v1/permission.js"` (legacy, not in the server manifest).

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

- session.created carries data.sessionID per packages/schema source,
  not data.id; mapping and first-sight marking corrected, tests now use
  the genuine envelope.
- ensureV2SessionStart reuses resolveRootSessionID instead of a bare
  session.get, inheriting its deadline and cache so a hung lookup can
  never stall the event loop; unknown lineage skips the synthetic.
- Digests regenerated.
@werlang

werlang commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Pushed e1c6220 addressing the two new findings — one of them caught a genuine bug in my revision:

session.created shape — you were right, I was wrong. I checked the actual source (packages/schema/src/session-event.ts in the 2.0.7 tree): Created spreads Base (sessionID) plus flat metadata, so the id is data.sessionID, not data.id — my earlier read of the compiled .d.ts mistook nested id keys for a data field. Mapping, first-sight marking, and the test fake all corrected to the genuine envelope. (The permission correction is also acknowledged — those cases were already live and stay as-is.)

Start-synthesis timeout. Adopted the suggested approach wholesale: ensureV2SessionStart now goes through resolveRootSessionID instead of a bare session.get, inheriting its deadline and cache. Root synthesizes, child and unknown lineage skip (Busy still posts either way).

Validated against the assembled bytes: created(sessionID)+execution -> [SessionStart, SessionBusy, SessionIdle]; child execution synthesizes no Start while Busy rolls up; failed lookup skips Start while Busy still posts. Digests regenerated.

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Pass the scalar session ID to the v2 session domain. · status-plugin-v2-setup-source.ts:84-106

src/main/opencode/status-plugin-v2-setup-source.ts:84-106
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Pass the scalar session ID to the v2 session domain. OpenCode 2.0.7 defines context.data.session.get(sessionID). The shim passes { sessionID } to that domain without another wrapper. The root lookup can therefore fail, and ensureV2SessionStart skips the synthetic SessionStart event. session.list({}) uses the valid v2 list shape. Fix buildV1ClientShim; the native ctx.client.session path is unaffected.

Proposed fix
-      const raw = await sessionDomain.get({ sessionID });
+      const raw = await sessionDomain.get(sessionID);

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: dfedef9f-4421-49fc-9ffe-dd6ff926e6b0

📥 Commits

Reviewing files that changed from the base of the PR and between 4f38212 and e1c6220.

📒 Files selected for processing (3)
  • src/main/opencode/hook-plugin-module-contract.test.ts
  • src/main/opencode/hook-service.test.ts
  • src/main/opencode/status-plugin-v2-setup-source.ts

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

@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 — the prior review's findings are addressed; one test-coverage suggestion inline.

Reviewed changes (since the prior review at 4f38212)

  • Corrected the session.created shape — toV1LifecycleEvent and the loop's mark-seen check now read data.sessionID/data.parentID (the real v2 payload) instead of data.id, so a root creation event posts SessionStart at creation rather than only via the execution.started synthesis.
  • Timeout-safe start synthesis — ensureV2SessionStart now resolves lineage through resolveRootSessionID, inheriting its SESSION_LOOKUP_TIMEOUT_MS deadline and lookup cache, so a hung ctx.session.get cannot stall the event loop.
  • Updated the v2 creation test — the fake context now feeds the real { sessionID } shape.
  • Refreshed digest pins — both generated-source hashes re-pinned; pnpm test src/main/opencode/ passes.

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

…er shim

- Skip forwarding real session.created when Start was already posted
  (either order), closing the reverse-order double post.
- Release the first-sight mark when lineage resolves non-root/unknown
  so transient failures retry instead of suppressing Start forever.
- Trim client shim to observed shapes (native v1 passthrough, single
  ctx.session domain, documented v1 call forms); document why the abort
  signal has no v2 channel and why raw results need no unwrap.
- Contract tests share fetch-capture/context helpers; created-mapping
  test drops the session domain so only the mapping can post Start;
  new reverse-order test pins single Start.
- Cite verified 2.0.7 shapes in-code; digests regenerated.
@werlang

werlang commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Batch pushed in af99bb8 covering the latest review round plus my own review pass:

Bot finding fixed: the created-mapping test now drops the session domain, so the mapping is the only route to Start and the test genuinely pins it. New reverse-order test (execution-then-late-creation) pins single Start.

From my review pass:

  • Reverse-order double Start closed: real creations for already-seen sessions are skipped.
  • Sticky suppression closed: the first-sight mark is released when lineage resolves non-root/unknown, so transient failures retry on the next execution (Busy never waits).
  • Shim trimmed to observed shapes with comments stating what was verified and why the abort signal has no v2 channel.
  • Test fixtures deduplicated into shared helpers; verified 2.0.7 shapes cited in-code.

Deliberately left alone: the silent per-event catch (matches the file's fail-open design — changing that philosophy deserves its own discussion), and the bridge (no such events exist in 2.0.7 — verified, not assumed).

Validated against the assembled bytes: execution -> [Start, Busy, Idle]; created+delta+execution -> same with the delta dropped and one Start; reverse order -> one Start; child execution -> Busy with no Start; failed-then-recovered lookup -> Busy throughout with Start posted on recovery. Digests regenerated.

@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 — the delta is clean and the prior test-coverage finding is addressed. This is not an approval only because an earlier verified-false-positive thread (the permission.asked/permission.replied callout) remains open; no action is needed on it.

Reviewed changes (since the prior review at e1c6220)

  • Refactored the contract tests — shared captureHookPosts/hookNames/makeV2Ctx/rootSessionGet helpers replace four copies of the fetch mock and the inline v2 contexts.
  • Pinned the session.created mapping — the creation test now runs without a session domain, so the synthesis path cannot mask a regression; confirmed it fails if the read reverts to data.id.
  • Added a double-post guard test — execution.started followed by a late session.created posts exactly one SessionStart; confirmed it fails (['SessionStart','SessionStart']) when the mark-seen guard is removed.
  • Retryable start synthesis — ensureV2SessionStart releases its seen-mark when the lineage lookup does not confirm a root, so a transient failure retries on the next execution instead of suppressing Start forever.
  • Slimmed the client shim — buildV1ClientShim adapts only ctx.session.get, dropping the unused list shim and the ctx.data.session/first.id fallbacks. Verified against opencode v2.0.7 that ctx.session.get({ sessionID }) is the real signature and the result is unwrapped SessionInfo.
  • Refreshed digest pins — pnpm test src/main/opencode/ passes 41/41 locally.

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

@oliver-mee

Copy link
Copy Markdown
Contributor

Validated the branch independently in an ARM container (node 24, pnpm 12, frozen lockfile): 142/142 unit tests pass across src/main/opencode. Two nits, both in hook-plugin-module-contract.test.ts: oxfmt flags the file, and the quality gate reports eslint(curly) at line 126, a braceless for-of in the shared fake-context generator:

for (const event of events) yield event

Suggested:

for (const event of events) {
  yield event
}

Full-project typecheck exceeded the container, leaving that lane to repo CI. Separately, one scope observation from comparing against the v1 factory and the Claude/Codex surfaces: neither this PR nor #20410 bridges session.tool.*, so the in-flight-tool readout both siblings enjoy has no opencode path. Happy to help test a revision, including an effect() formulation if you go that way.

@werlang

werlang commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded — the work here already shipped through a parallel implementation.

None of the six commits here are on main (verified by patch-id), and the branch now conflicts with those two changes. I also checked what this branch added beyond them, and both parts are already present on main:

  1. Bounded session lookup — status-plugin-session-lineage-source.ts wraps lookupRootSessionID in an AbortController plus SESSION_LOOKUP_TIMEOUT_MS = 2000, passes the signal into client.session.get, and falls back to null on timeout, so a hung lookup cannot stall the event loop.
  2. OpenCode v2 contract coverage — hook-plugin-opencode2-setup.test.ts covers setup subscription/disposal and permission/form/text mapping, and hook-plugin-module-contract.test.ts pins the permission.v2 mapping.

Rebasing would mean re-resolving three review rounds against a redesigned file location (opencode/ vs opencode2/) to ship a duplicate code path with no user-visible change, so there is nothing left to merge here. Reopen if you think any of it is still worth landing.

@werlang werlang closed this Sep 22, 2026
@werlang
werlang deleted the fix/opencode-v2-plugin-setup branch September 22, 2026 16:24
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.

3 participants