Skip to content

fix(opencode2): block on any session-owned form, not just the question tool's - #22548

Merged
nwparker merged 1 commit into
mainfrom
nwparker/opencode2-form-unknown-kind-blocks
Sep 23, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/opencode2-form-unknown-kind-blocks

Conversation

@nwparker

@nwparker nwparker commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When an OpenCode agent needs an answer from you, Orca marks the pane "needs input". A recent change of mine narrowed that to one specific kind of prompt — and in doing so, taught Orca to ignore some prompts that genuinely block the agent. The pane then looks busy while the agent sits waiting for you forever. This widens it back, and picks a rule that can't rot.

What Changed

The guard from #22399 was:

if (!form || !form.metadata || form.metadata.kind !== "question") continue;

It is now:

const NON_SESSION_FORM_OWNERS = new Set(["global"]);
…
if (!form || NON_SESSION_FORM_OWNERS.has(form.sessionID)) continue;
const fields = Array.isArray(form.fields) ? form.fields : [];

An allow-list on kind became a one-entry deny-list on the form's owner. metadata no longer appears in the guard at all.

Also: form.fields is defaulted to []. Previously only question-tool forms reached form.fields.map(…); now arbitrary client-created forms do, and a throw inside the for await loop kills the entire event subscription — it is caught only by the outer .catch that ends consume. Widening admission without this would trade a silent blocker for silent total status death.

Why

#22399 made two mistakes, both in the dangerous direction. Found by adversarial review, then confirmed from OpenCode source at v2.0.15.

1. kind is not a contract. packages/schema/src/form.ts:15 — Metadata = Schema.Record(Schema.String, Schema.Unknown), an untyped open record in which kind does not appear at all. Line 130 — metadata: Metadata.pipe(optional), so metadata itself is optional on Form.Info, and line 169's form.created carries that same Info. This is the same objection #22399 used to reject matching on form title; I applied it to titles and then missed it on kind.

The reachable path is a published API: packages/protocol/src/groups/session.ts registers POST /api/session/:sessionID/form with metadata optional; packages/server/src/handlers/session.ts:646 calls form.create(…) directly, which publishes Form.Event.Created omitting metadata entirely when undefined. A client raising a genuinely blocking form on a real session with no metadata was dropped — pane painted Busy, OpenCode waiting forever.

Scoped honestly: this is latent, not live. A sweep for .form.create( across the whole monorepo at v2.0.15 returns zero callers; all 7 session.form.create hits are definitional (protocol declaration, openapi.json, both generated client bindings, api wiring, the handler). Nothing in tui, desktop, console, cli, sdk, or plugin invokes it. So this is a robustness defect on a versioned, SDK-bound public extension surface with no first-party consumer yet — not an active break on a stock install. It is worth fixing because the surface is published and metadata is optional by declaration, not because anyone is hitting it today.

Enumerating Form.ask structurally could not find this: form.created is published inside Form.create (core/src/form.ts:120), ask (:148) is merely a wrapper, and the server handler calls create directly. Counting Form.ask sites gives five; the in-tree producer set of form.created is six.

2. websearch.provider should never have been dropped. Both websearch call sites pass the real context.sessionID, so that blocker retires correctly. The un-retirable argument that justified #22399 applies only to MCP elicitation, which uses GLOBAL_ELICITATION_SESSION_ID = "global" (core/src/mcp/index.ts:82). Dropping websearch left the pane reading Busy while the turn was genuinely parked on a provider picker — a second instance of the exact bug #22399 set out to fix.

Re-derived producer table (git grep -n "\.ask(" v2.0.15 -- packages/core/src, five sites, exhaustive in-tree):

file kind sessionID
core/src/tool/plugin/question.ts:75 question context.sessionID
core/src/tool/plugin/websearch.ts:75 websearch.provider context.sessionID
core/src/tool/plugin/websearch.ts:108 websearch.provider context.sessionID
core/src/mcp/index.ts:234 mcp-elicitation "global"
core/src/mcp/index.ts:262 mcp-elicitation "global"

Why key on the owner rather than on kind. The real discriminator is not "is this the question tool" but "can this blocker ever be retired" — and only the "global" sentinel fails that test, because it is not a session and so no session-idle can clear it. Keying there also makes the exclusion self-expiring: packages/schema/src/form.ts:122-129 says sessionID is a plain string only because "MCP elicitation temporarily needs the "global" sentinel owner… Once elicitations can be attributed to real sessions, revert this to SessionID." When upstream does that, Orca starts blocking on elicitations correctly with no code change. A kind-keyed exclusion would silently keep dropping them.

Why unknown shapes now block. A spurious visible blocker is recoverable by the user and is merely the old over-blocking bug. A silently swallowed real question is not recoverable at all. Alternatives considered: an allow-list with extra known kinds — same rot, one release later; matching on title — user-facing English, not a contract.

Consequence worth stating: a hypothetical future non-question kind on a real session will now block the pane. That is intended. It also means the "known non-question kinds" table is no longer encoded in code — it lives in the reproduction doc. Encoding it would recreate the schema-less allow-list this PR removes.

Linked Issue

Refs #22371, and fixes a regression I introduced in #22399.

Visual Proof

N/A — the change decides which OpenCode 2 events become a pane blocker, and the user-visible difference is the presence of an indicator that previously never appeared. Reproducing it on screen needs a client calling the public form-create endpoint, which no first-party caller does today; a screenshot of a hand-posted form would look identical to a real one and prove nothing a test does not. Proof is the source citations above plus the fail-without-fix run below.

Testing

Platforms: macOS; source verification against v2.0.15.

Restored the pre-fix guard and re-ran the unchanged new tests — 12 of 12 new instances failed (6 cases × the opencode/opencode2 parametrization), while the 18 pre-existing assertions passed:

× blocks the pane on a session-owned form with no metadata at all
× blocks the pane on a session-owned form with metadata without a kind
× blocks the pane on a session-owned form with an unrecognised kind
× blocks the pane on a session-owned form with the web search provider picker
× retires an admitted unknown-kind blocker on form.replied
× retires an admitted unknown-kind blocker on form.cancelled
Tests  12 failed | 18 passed (30)

With the fix: 30 passed. The sentinel-ignore test passes on both sides by design — it pins behaviour this PR deliberately preserves.

Resolution path re-checked: clearAttentionForResolution builds attentionKey(factoryID, "AskUserQuestion", requestID, sessionID) and returns null on a miss, so a resolution for a dropped sentinel form keys […, formID, "global"], matches nothing, and publishes nothing. More forms are admitted now, but each still gets its own exact key, so a stray resolution still cannot retire an unrelated live blocker. The admitted-id guard removed in #22399 remains unnecessary.

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

Plugin byte digest re-pinned. The mimo-code digest is unchanged, confirming the OpenCode 1-only variant is untouched.

  • 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

  • The reproduction doc was wrong and is corrected. docs/bug-reproductions/opencode2-form-created-kinds/README.md presented metadata.kind as the discriminator. It is rewritten around sessionID, with the schema and endpoint citations, so the next reader does not repeat the mistake.
  • Backwards compatibility: OpenCode 1 is untouched — this file feeds only the OpenCode 2 setup() bridge.
  • Failure direction: over-blocking is visible and user-recoverable; under-blocking is silent. This PR moves every ambiguous case to the visible side.
  • SSH/remote, WSL, mobile, cross-platform, performance: unaffected — no wire change, no new I/O, one Set.has per form event.

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

#22399 admitted an OpenCode 2 form.created as a pane blocker only when
metadata.kind === "question". On v2.0.15 that is an allow-list on a field
with no contract: packages/schema/src/form.ts declares Metadata as an open
Schema.Record and metadata itself as optional, and the public
POST /api/session/:sessionID/form endpoint lets any client raise a real
blocking form on a real session with no metadata. Orca dropped those, so
the pane painted no blocker while OpenCode waited forever.

Invert the default. Every form whose owner is a real session blocks;
only a form owned by the "global" MCP-elicitation sentinel is dropped,
because that owner is not a session and never goes idle, so its blocker
could not be retired. That also restores websearch.provider as a blocker:
it carries the real context.sessionID, session idle retires it, and while
it is pending the agent is genuinely stalled on the user.

Resolution is unchanged: clearAttentionForResolution keys on the exact
form id plus source session, so a resolution for a dropped form matches
nothing and cannot retire a live blocker.
@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.

📝 Walkthrough

Walkthrough

The OpenCode 2 plugin now classifies form.created events by sessionID instead of metadata.kind. It skips forms owned by "global" and surfaces forms owned by a session as blockers, using an empty fields array when form.fields is not an array. Tests cover forms with missing or unrecognised metadata and blocker retirement. The documentation and generated-plugin digest assertion were updated.

Merge Risk: 🔵 Low · up to 6028c

The MCP reproduction demonstrates the opposite of the documented exclusion. Correct the steps; this does not block the form-handling change.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: OpenCode 2 now blocks on session-owned forms instead of only question-tool forms.
Description check ✅ Passed The description is complete and directly addresses the template. It explains the user impact, implementation, rationale, linked issues, visual-proof decision, testing, compatibility, and checklist sta…
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)

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

@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: b5a9cd0e-59d6-4214-87cb-d8c929298e51

📥 Commits

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

📒 Files selected for processing (4)
  • docs/bug-reproductions/opencode2-form-created-kinds/README.md
  • src/main/opencode/hook-plugin-opencode2-setup.test.ts
  • 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; 1 remains after this review.

| `websearch.provider` | `Web Search` / `Choose a web search provider` | the session | no — a provider picker |
| `mcp-elicitation` | `<server> is requesting input` | `"global"` | no — an MCP server prompt |
| `websearch.provider` | `Web Search` / `Choose a web search provider` | the session | yes — the turn is stalled |
| `mcp-elicitation` | `<server> is requesting input` | `"global"` | no — see below |

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Correct the MCP reproduction to use the "global" owner.

The Reproduce section at Lines 67–70 tells readers to POST an mcp-elicitation form to /api/session/<sid>/form. OpenCode assigns <sid> to form.sessionID, regardless of metadata.kind. The new guard therefore blocks that form, contrary to this row. Use a real MCP elicitation or a plugin fixture with sessionID: "global" to demonstrate the excluded case. (raw.githubusercontent.com)

@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 — initial review of the OpenCode 2 form.created pane-blocker guard and its tests.

  • Guard re-keyed on the form's owner — form.created now blocks unless form.sessionID is the non-session sentinel "global", replacing the metadata.kind === "question" allow-list that silently dropped genuinely blocking forms. Verified against upstream v2.0.15: Metadata is an optional open record and Form.create publishes Form.Event.Created for every producer, so neither kind nor metadata can serve as the discriminator.
  • Producer table holds — the only in-tree Form.ask call site with a non-session owner is MCP elicitation (GLOBAL_ELICITATION_SESSION_ID = "global"); question.ts and both websearch.ts sites pass context.sessionID. The deny-list drops exactly the un-attributable producer.
  • Retirement path intact — form.replied/form.cancelled carry the same id and sessionID as the created form, so each admitted form keys its own (factoryID, AskUserQuestion, form.id, sessionID) attention entry and a resolution for a dropped sentinel matches nothing.
  • form.fields defaulted — the Array.isArray guard prevents a throw inside the for await from killing the entire subscription. The schema enforces NonEmptyArray(Field), so this is version-skew defense rather than a live path; harmless and cheap.
  • Tests are meaningful — restoring the old guard in place fails exactly 12 of the 30 setup cases (matching the PR's claim), while the pre-existing 18 pass; with the fix pnpm test src/main/opencode src/main/opencode2 reports 17 files / 221 passed. The digest re-pin matches, and the mimo-code bytes are unchanged (that variant omits the setup source).

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

@nwparker
nwparker merged commit f1eb191 into main Sep 23, 2026
31 checks passed
@nwparker
nwparker deleted the nwparker/opencode2-form-unknown-kind-blocks branch September 23, 2026 20:53
flosrn pushed a commit to flosrn/orca that referenced this pull request Sep 25, 2026
…22548)

stablyai#22399 admitted an OpenCode 2 form.created as a pane blocker only when
metadata.kind === "question". On v2.0.15 that is an allow-list on a field
with no contract: packages/schema/src/form.ts declares Metadata as an open
Schema.Record and metadata itself as optional, and the public
POST /api/session/:sessionID/form endpoint lets any client raise a real
blocking form on a real session with no metadata. Orca dropped those, so
the pane painted no blocker while OpenCode waited forever.

Invert the default. Every form whose owner is a real session blocks;
only a form owned by the "global" MCP-elicitation sentinel is dropped,
because that owner is not a session and never goes idle, so its blocker
could not be retired. That also restores websearch.provider as a blocker:
it carries the real context.sessionID, session idle retires it, and while
it is pending the agent is genuinely stalled on the user.

Resolution is unchanged: clearAttentionForResolution keys on the exact
form id plus source session, so a resolution for a dropped form matches
nothing and cannot retire a live blocker.

(cherry picked from commit f1eb191)
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