Skip to content

Reliably deliver the issue prompt into opencode's composer - #6798

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-opencode-issue-prompt
Jun 30, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-opencode-issue-prompt

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

What changes

"Start workspace from issue" seeds the issue URL as an editable, unsubmitted draft and pastes it into the launched agent's composer once the TUI is ready. For opencode (and other flag-prompt agents with no prefill flag, e.g. mimo-code) that draft frequently never arrived. This PR makes it land reliably, while keeping it editable and unsubmitted.

What does NOT change

The draft is still editable and unsubmitted — opencode is not launched with --prompt (that would auto-submit the URL immediately). The user still reviews the seeded prompt and presses Enter, exactly as with Claude/codex. No agent's submit behavior changes.

Root cause

Readiness for paste-after-ready used a quiet-output window after bracketed paste was enabled (DECSET 2004, \x1b[?2004h). Measured against real opencode v1.17.11: opencode enables bracketed paste at ~1.4s but its composer doesn't mount until ~3.4s. The 1500ms quiet window therefore resolves at ~2.9s — ~450ms before the composer exists — so the paste lands in a not-yet-mounted input. A slow setup script churning output keeps resetting the quiet timer until the readiness wait hits its 8s hard timeout and the URL is dropped entirely. This matches the report: with a 20–30s setup script the prompt "often doesn't arrive."

Fix

Gate opencode's paste on the DECTCEM show-cursor (\x1b[?25h) emitted after bracketed-paste-enable — the point where opencode's composer row is mounted and focused (analogous to Codex's › composer-prompt signal). Crucially, this signal must not also arm the quiet window: opencode goes silent during the ~1.5–2s between enabling bracketed paste and mounting its composer, so a quiet window armed on that gap fires ~200–400ms before the composer exists and pre-empts the cursor signal (this was caught by A/B testing the real opencode CLI end to end, and an earlier revision of this PR had exactly that bug). The cursor signal therefore waits only for its marker, bounded by the existing hard timeout plus the caller's best-effort process-ownership paste — the same model Codex uses. opencode re-emits show-cursor on every render frame once mounted, so the marker is effectively guaranteed.

The readiness scanner was duplicated: one copy in the renderer (waitForAgentDraftInputReady, desktop-local delivery) and one in the main process (waitForStartupDraftReady in orca-runtime.ts, the delivery path for runtime/SSH/remote-owned worktrees and mobile "Start workspace from issue"). A renderer-only fix would have been inert on the SSH/remote path. This PR extracts a single pure scanner — createDraftPasteReadyScanner in src/shared/ — that both waiters consume, so the fix applies to every delivery surface and the two copies can't drift again.

Design approach

Investigated the delivery path end to end, wrote a design doc (scratch, not shipped), and ran it through design review before implementing. The auto-submit-vs-editable-draft decision was surfaced and resolved as keep editable draft + harden readiness before any code was written. Empirically grounded the choice with a node-pty probe (opencode --prompt auto-submits) and confirmed the new signal with a headless terminal-grid render (URL lands in the editable composer, placeholder replaced, not submitted).

Design-review outcome

Design review converged clean after hardening two points: the fallback must not be starved (the new signal falls through to arm the quiet timer on a miss, unlike Codex's early-return), and the existing default-path test must keep coverage (re-targeted to a still-default agent rather than deleted).

Implementation & deviations

Implemented exactly as designed. One addition beyond the original doc, surfaced by code review: extracting the shared scanner (instead of editing the renderer only) so the runtime/SSH/remote/mobile path is also fixed. No other deviations.

Completeness verification

Verified the full path: issue URL → draftPrompt (empty prompt, so no --prompt) → pasteDraftToAgentPtyWhenReady (forcePaste: true, no submit) → shared scanner gating on \x1b[?25h. Submit stays false end to end. opencode + mimo-code both route through the paste path (no native prefill flag/env). Other agents (Claude, codex, gemini, pi, …) are byte-for-byte unchanged.

Headline behavior status

Implemented. Production code delivers the editable, unsubmitted issue draft into opencode's composer reliably, on both the already-ready and racing-fresh-startup cases.

Broad app consistency

Source-of-truth behavior is "deliver a seeded prompt into the agent composer as an editable, unsubmitted draft," shared by all draft-seeding surfaces (quick "Start workspace from issue", new-workspace composer, direct work-item launch) which all funnel through the readiness waiter. Fixing the shared scanner fixes opencode across all of them at once. No surface special-cases opencode, so there was no divergence to reconcile. Codex (its own signal) and the quiet-window default agents (gemini/cursor/copilot/stdin agents) are intentionally untouched.

Risks, ambiguities, non-goals

  • Non-goal — auto-submit. Deliberately not using --prompt. The draft stays editable.
  • mimo-code is parity-based. It shares opencode's exact flag-prompt paste route and failure mode, so it gets the same signal, but its startup stream was not separately validated (binary not installed in the dev env). The quiet-window fallback bounds the risk if it differs.
  • Fallback is a bound, not a guarantee. If a future opencode/terminal both drops \x1b[?25h and leaves a long silent pre-composer gap, the quiet window can still fire early — exactly as today. The change strictly improves the common case and never regresses it.
  • \x1b[?25h matching cannot collide with \x1b[?25l (hide) or compound sequences like \x1b[?25;1049h (terminator differs), and is only honored after \x1b[?2004h, so pre-composer cursor toggles don't trip it.

Perf

Audited the touched hot path (the per-PTY-chunk observe). The 512-byte ring bounds are preserved, no O(n²) growth, no new timer churn, subscription/timer teardown unchanged, and zero added cost for agents not using the new signal. No measurement needed; verdict: no perf concerns.

Code-review loop

Two rounds, two independent reviewers each. Round 1 both reviewers independently flagged one P0 — the un-updated main-process scanner copy (SSH/remote path); fixed by the shared-scanner extraction. Round 2 both reviewers returned clean (byte-for-byte behavior preservation verified across all three signals); two minor advisory nits (docstring wording for mimo-code, an extra replay-path test) were addressed.

Validation (merge confidence)

  • A/B against the real opencode CLI (v1.17.11), end to end: spawned opencode under node-pty, fed its real startup stream through the actual shipped scanner (compiled from source), pasted at the moment each logic reported "ready", and rendered the final terminal grid with @xterm/headless. Result — old quiet-window logic: URL dropped (resolves before composer mounts); new cursor-gated logic: URL lands in the editable, unsubmitted composer, on both clean and noisy (render-churn) startups, repeatably. This test is what surfaced and then confirmed the fix to the quiet-window pre-emption bug above.
  • Live Electron, against real opencode v1.17.11 inside a dev Orca instance: invoked the production pasteDraftToAgentPtyWhenReady with agent: 'opencode'. The issue URL landed in opencode's composer, unsubmitted (agent stayed "Idle"), both against an already-ready opencode and when racing a freshly-relaunched opencode. Screenshot evidence captured.
  • Unit: shared-scanner tests cover all three signals, cross-chunk split (handshake and cursor), the silent-gap-no-quiet-window case, hide-cursor non-match, pre-handshake ignore, and the SSH/remote replay-buffer case; renderer delivery tests (including "best-effort paste at hard timeout" and "no quiet-window paste") and config invariants updated/added. 77 touched-module tests + 512 orca-runtime tests pass.

Validation gap (stated honestly): the live UI run exercised the renderer/local desktop path. The runtime/SSH/remote and mobile paths use the same shared scanner but were validated via unit tests + byte-for-byte behavior-preservation review, not a live remote run (no SSH remote available in the dev env).

Static checks

Node + web typecheck clean (no new errors; one unrelated pre-existing TS error in useSessionRestoredBannerDismiss.test.tsx exists on the base branch). oxlint and switch-exhaustiveness clean.

"Start workspace from issue" seeds the issue URL as an editable, unsubmitted
draft and pastes it into the agent's composer once the TUI is ready. For
opencode (and other flag-prompt agents with no prefill flag, e.g. mimo-code),
readiness used a quiet-output window after bracketed-paste was enabled. opencode
enables bracketed paste ~2s before its composer actually mounts, so the quiet
window elapses early and the paste lands in a not-yet-mounted input — and a slow
setup script churning output makes it time out entirely. The URL frequently
never arrived.

Gate the paste on opencode's DECTCEM show-cursor (\x1b[?25h) emitted after
bracketed-paste-enable (\x1b[?2004h) — the point where the composer is mounted
and focused — keeping the quiet-window as a fallback so behavior is never worse
than before. The draft stays editable and unsubmitted (no auto-submit).

The readiness scanner was duplicated in the renderer (local delivery) and the
main process (runtime/SSH/remote + mobile delivery). Extract one shared, pure
scanner so both paths get the fix and can't drift, and unit-test it directly.

- Add 'render-cursor-after-bracketed-paste' signal; wire opencode + mimo-code.
- Extract createDraftPasteReadyScanner (src/shared) consumed by both waiters.
- Regression tests at the shared delivery-decision seam plus config invariants.
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 74ed186f-8721-4336-8eb4-d48993600ad9

📥 Commits

Reviewing files that changed from the base of the PR and between 6af424a and 157f069.

📒 Files selected for processing (3)
  • src/renderer/src/lib/agent-paste-draft.test.ts
  • src/shared/draft-paste-ready-scanner.test.ts
  • src/shared/draft-paste-ready-scanner.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/shared/draft-paste-ready-scanner.ts
  • src/renderer/src/lib/agent-paste-draft.test.ts

📝 Walkthrough

Walkthrough

A new shared module, createDraftPasteReadyScanner, centralizes PTY-stream readiness detection. It tracks bracketed-paste enablement and, depending on the signal mode, watches for a show-cursor escape or Codex composer glyph using 512-byte tail buffers for chunk boundaries. DraftPasteReadySignal adds render-cursor-after-bracketed-paste, and opencode and mimo-code now use it. Both waitForAgentDraftInputReady and the main runtime’s observeData path now delegate to the shared scanner. New tests cover scanner behavior and the updated draft-paste flows.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it doesn't follow the required template and omits explicit Screenshots, checklist-style Testing, and the required cross-platform AI review/security sections. Reformat into the required sections and add Screenshots, a checklist-style Testing section, an AI review that explicitly covers macOS/Linux/Windows, plus Security Audit and Notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: making issue prompts reliably reach opencode's composer.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

🧹 Nitpick comments (1)
src/shared/draft-paste-ready-scanner.test.ts (1)

41-47: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a split-2004h handshake regression case.

This suite exercises a split show-cursor, but not a split \x1b[?2004h. The scanner has dedicated pre-handshake buffering for that exact boundary, so a regression there would disable both quiet-window arming and cursor-gated readiness for fragmented PTY packets. A small case like '\x1b[?20' then '04h' (and optionally SHOW_CURSOR) would lock down the other half of the new state machine.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: acf25e79-75b9-4722-b950-acdcf6e12ed4

📥 Commits

Reviewing files that changed from the base of the PR and between ab1aac2 and 684ddee.

📒 Files selected for processing (7)
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/lib/agent-draft-readiness.ts
  • src/renderer/src/lib/agent-paste-draft.test.ts
  • src/shared/draft-paste-ready-scanner.test.ts
  • src/shared/draft-paste-ready-scanner.ts
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-startup.test.ts

Add a regression case where \x1b[?2004h straddles two PTY packets, exercising
the pre-handshake `recent` ring (the other half of the scanner state machine).
…gnal

A/B testing the real opencode CLI (v1.17.11) end to end revealed the cursor
signal was being defeated by its own fallback. opencode enables bracketed paste
(\x1b[?2004h) ~1.5-2s before its composer mounts and stays silent in between,
then emits show-cursor (\x1b[?25h) at mount. The quiet-window fallback armed
during that silent gap fired ~200-400ms BEFORE the composer existed, pre-empting
the cursor signal — so the paste still landed too early and the URL was lost.

Make the cursor signal marker-only, exactly like Codex: it never arms the quiet
window. opencode re-emits show-cursor on every render frame once mounted, so the
marker is effectively guaranteed; the caller's hard timeout (plus its best-effort
process-ownership paste) is the backstop if it is ever missed. Only the default
signal, which has no marker, still uses the quiet window.

Verified against the real opencode CLI: the URL now lands in the editable,
unsubmitted composer on clean and noisy startups; the old logic dropped it.
@brennanb2025
brennanb2025 merged commit 973360c into main Jun 30, 2026
1 check passed
@brennanb2025
brennanb2025 deleted the brennanb2025/fix-opencode-issue-prompt branch June 30, 2026 08:17
@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

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.

2 participants