Skip to content

fix(native-chat): make the launch-draft mirror reachable - #11222

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/native-chat-draft-reachable
Jul 30, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/native-chat-draft-reachable

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #9802. That PR added the native-chat mirror of unsent launch context; this one makes it actually reachable.

Behavior change — draft launches now open in chat

With "open agent tabs in chat by default" on, a draft launch used to be forced into terminal view. It now opens in chat when the draft can be mirrored (see the predicate below). This changes the default view for every mirrorable draft launch.

The gaps

Six originating paths deliver a draft to the agent's TUI. Two problems, both concentrated on the argv-prefill branch (Claude --prefill etc.), where the draft rides inside launchCommand and the plan sets no draftPrompt:

1. Three paths never seeded the chat composer at all. Paste-based branches were already fine — they route through deliverLaunchPromptToAgentTab, which seeds. Only argv prefill fell through, because no paste runs.

Path Was it visible?
folder-workspace-composer-submit.ts Broken today — already opened in chat with an empty composer
launch-agent-in-new-tab.ts (local) Hidden by the terminal-view guard
launch-agent-web-host-tab.ts (web runtime) Hidden by the terminal-view guard

2. The view-mode gate itself missed argv prefill on four paths. worktree-activation.ts derived the gate from startup.draftPrompt != null, which only paste delivery sets. So argv-prefill launches were never classified as drafts and opened in chat unconditionally — including multi-line drafts that are correctly not seeded, producing exactly the empty-composer-beside-filled-TUI failure the predicate exists to prevent. Affected: folder-workspace-composer-submit.ts, launch-work-item-direct.ts, and both worktree-creation-flow.ts producers (useComposerState.submitQuick, github-work-item-background-request.ts).

Fix: a launchDraftText field on the activation startup payload, carrying the resolved draft text for the view-mode decision only. It is deliberately distinct from draftPrompt, which drives the bracketed paste in pty-connection — reusing it would deliver the draft a second time on top of the argv prefill. resolveStartupLaunchDraftText reads either field, and both tab-creation sites share one draftViewModeProps helper so they cannot drift.

Seeded set == chat-opening set, by construction

Lifting the guard outright would have regressed the majority case. seedNativeChatLaunchDraftForAgentTab rejects multi-line text, and multi-line is the common shape:

  • formatDraftContextBlock appends a trailing newline to every Linear block
  • buildLinearLaunchContextBlock joins identifier and URL with a newline
  • note + URL joins with a blank line

A bare issue URL with no note is essentially the only single-line draft. So instead of deleting the guard, both sides gate on one shared predicate, canMirrorLaunchDraftToNativeChat in native-chat-launch-draft-mirrorability.ts.

Draft paths that still do not mirror — by design

Multi-line drafts still open in terminal view, and today that is the majority of draft launches. That is deliberate: the chat send pre-clears the TUI with Ctrl+U, which is kill-to-start-of-line, so a multi-line mirror could concatenate onto the message being sent. The send-protocol work on brennanb2025/native-chat-multiline-send is what flips them.

Note for that worktree — measured, not estimated

The production change stays a one-line edit to the predicate body. The test fallout is larger than I first claimed. Measured by mutating the predicate to accept multi-line and diffing the full src/renderer failure set against baseline: 13 tests across 7 files go red.

  • worktree-activation.test.ts (3), folder-workspace-composer-submit.test.ts (3), native-chat-initial-view-mode.test.ts (2), native-chat-launch-draft-mirrorability.test.ts (1), launch-agent-in-new-tab.test.ts (1)
  • Plus 2 that predate this PR: agent-launch-prompt-delivery.test.ts, launch-work-item-direct.test.ts

Of these, only native-chat-launch-draft-mirrorability.test.ts pins the rule directly; the rest assert multi-line stays in the terminal and flip as a consequence. The consistency suite's 16 agreement assertions stay green throughout — they follow the predicate rather than restating it.

Tests

Every added test was mutation-checked — production line reverted, test confirmed RED, restored.

Gate and all four producers, each mutated independently:

Mutation Result
Gate reverted to draftPrompt-only (the shipped bug) 2 RED
Folder producer stops emitting launchDraftText 1 RED
worktree-creation-flow producer dropped 1 RED
launch-work-item-direct-agent producer dropped 1 RED
launch-work-item-direct caller stops passing draftContent 1 RED

Seeding, from the first round:

Mutation Result
Folder seeding disabled 2 RED
Naive startupPlan.draftPrompt-keyed implementation 1 RED
Local argv-prefill seed removed 1 RED
Web-host seed disabled / draft branch removed 1 RED each
View-mode grows its own inline rule 8 RED — 6 in the consistency suite (3 discriminating texts × 2 assertions) + 2 in the view-mode suite
Guard deleted outright (the literal original brief) 16 RED

The end-to-end invariant test in folder-workspace-composer-submit.test.ts runs the real submitFolderWorkspaceCreate and the real view-mode decision over all four delivery/shape combinations and asserts seeded === opensInChat. Its module mock uses importOriginal so it exercises the shipped resolveStartupLaunchDraftText rather than a copy — without that it silently tested a reimplementation.

Note on the original target

The brief named useComposerState.ts's submit. That branch is dead: NewWorkspaceComposerModal is the only consumer of useComposerState and uses submitQuick only (it also overrides cardProps.onCreate), and submit builds its plan with buildAgentStartupPlan, which never sets draftPrompt. Seeding it would have been inert with an unfalsifiable test.

Also here

launch-agent-in-new-tab.ts crossed the 300-line max-lines cap. Per AGENTS.md I split rather than bump it: launch-agent-startup-prompt-plan.ts (how a launch delivers its prompt) and launch-agent-paste-timeout-notice.ts (the dropped-paste notice). Both are pure moves.

Verification

  • npm run typecheck clean (after rm -f config/*.tsbuildinfo)
  • npm run lint clean, including the native and type-aware quality audits
  • Changed-code quality gate: 0 new findings across 22 changed files (react-compiler + react-doctor)
  • All 203 tests across the 10 affected suites pass
  • Full vitest suite: remaining failures are pre-existing — identical set on b41e813cb5 with the same command, and they survive --maxWorkers=2, so they are not load flakes
  • The mobile suite was NOT run in this worktree. expo is not installed here, so all 351 mobile files fail to parse (TSConfckParseError: failed to resolve "extends":"expo/tsconfig.base.json"). No mobile files are changed, but CI green does not represent local mobile coverage.
  • No live QA on this branch; evidence is unit-level plus a static call-graph trace.

Seed the chat-composer copy of unsent launch context on every originating
draft path, then let those launches open in chat by default.

Three paths delivered a draft to the TUI without mirroring it into chat:
folder-workspace create, the local argv-prefill branch of launchAgentInNewTab,
and the web-host equivalent. The first was invisible; the other two were hidden
only because draft launches were forced into terminal view.

The view-mode decision now gates on the same predicate as seeding
(canMirrorLaunchDraftToNativeChat), so a draft can never open in chat with a
composer chat would refuse to fill.
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@brennanb2025, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 7 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a769105-da29-4e4c-a144-fb0ec059677d

📥 Commits

Reviewing files that changed from the base of the PR and between f1b4057 and 93580a2.

📒 Files selected for processing (12)
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktrees.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/lib/native-chat-launch-draft-mirrorability.test.ts
  • src/renderer/src/lib/native-chat-launch-draft-mirrorability.ts
  • src/renderer/src/lib/worktree-creation-agent-seeds.test.ts
  • src/renderer/src/lib/worktree-creation-agent-seeds.ts
  • src/renderer/src/lib/worktree-creation-flow.test.ts
  • src/renderer/src/lib/worktree-creation-flow.ts
  • src/renderer/src/lib/worktree-draft-startup-view-mode.ts
  • src/shared/types.ts
📝 Walkthrough

Walkthrough

The change centralizes launch prompt planning, adds shared single-line draft mirrorability checks, and uses them for native-chat view selection and composer seeding. Folder-workspace creation now resolves and mirrors linked drafts. Web-runtime launches use a draft-aware terminal creation helper. Paste timeout notifications are encapsulated in a reusable factory, and tests cover startup plans, native-chat behavior, folder workspaces, worktree activation, and web-runtime launches.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning It describes the change and tests, but it misses the required template sections and several required details. Rewrite the description to match the template and add Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 58.82% which is insufficient. The required threshold is 80.00%. 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 is concise and accurately summarizes the main native-chat launch-draft reachability change.
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 💡 1
📝 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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 24c371da-625f-42ae-90bd-28df875702a3

📥 Commits

Reviewing files that changed from the base of the PR and between 2b88931 and 19e84eb.

📒 Files selected for processing (16)
  • src/renderer/src/components/sidebar/folder-workspace-composer-submit.test.ts
  • src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts
  • src/renderer/src/lib/agent-launch-prompt-delivery.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/renderer/src/lib/launch-agent-paste-timeout-notice.ts
  • src/renderer/src/lib/launch-agent-startup-prompt-plan.ts
  • src/renderer/src/lib/launch-agent-web-host-tab.ts
  • src/renderer/src/lib/native-chat-initial-view-mode.test.ts
  • src/renderer/src/lib/native-chat-initial-view-mode.ts
  • src/renderer/src/lib/native-chat-launch-draft-mirrorability.test.ts
  • src/renderer/src/lib/native-chat-launch-draft-mirrorability.ts
  • src/renderer/src/lib/worktree-activation.test.ts
  • src/renderer/src/lib/worktree-activation.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts

})

it('seeds the chat composer for a draft that rode in on the launch command', async () => {
const runtimeCall = vi.fn(async (request: { method: string; params?: unknown }) => {

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 | 🔴 Critical | ⚡ Quick win

Remove the duplicate runtimeCall declaration.

Line 1258 declares runtimeCall twice, producing invalid test structure and preventing TypeScript from compiling.

Proposed fix
-    const runtimeCall = vi.fn(async (request: { method: string; params?: unknown }) => {
     const runtimeCall = vi.fn(async (request: { method: string; params?: unknown }) => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const runtimeCall = vi.fn(async (request: { method: string; params?: unknown }) => {
const runtimeCall = vi.fn(async (request: { method: string; params?: unknown }) => {

@greptile-apps

greptile-apps Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR makes draft launches actually open in native chat by fixing two interconnected gaps: (1) three code paths that never seeded the chat composer for argv-prefill draft launches, and (2) a view-mode gate that used draftPrompt as a proxy for "this is a draft" but missed argv-prefill plans entirely (since those carry the draft in launchCommand with no draftPrompt).

  • Introduces launchDraftText on WorktreeStartupPayload as a view-mode-only signal for argv-prefill launches, deliberately distinct from draftPrompt to avoid a double-delivery to the TUI. resolveStartupLaunchDraftText reads either field, keeping both tab-creation sites in sync.
  • Extracts canMirrorLaunchDraftToNativeChat as the single predicate governing both seeding and view-mode decisions, so a draft can never open in chat with an empty composer beside a filled TUI input; multi-line drafts remain in terminal view until safe multi-line send is available.
  • Adds composer seeding for the three previously broken paths (folder-workspace argv-prefill, local launchAgentInNewTab draft, and web-host tab via createWebRuntimeAgentSessionTerminalWithLaunchDraft), and propagates viewMode through the backend startup payload for background-spawned worktrees.

Confidence Score: 5/5

Safe to merge. The invariant that seeding and view-mode decisions are always driven by the same predicate is enforced structurally, and every new code path is covered by mutation-verified tests.

The change is careful and well-bounded: a shared predicate (canMirrorLaunchDraftToNativeChat) ensures the chat-opening set and the composer-seeding set can never drift apart. The new launchDraftText field is deliberately distinct from draftPrompt to prevent double-delivery to the TUI. All six originating launch paths are accounted for, the consistency suite catches any inline reimplementation, and the mutation results documented in the PR description confirm each test actually fails when its corresponding production line is reverted. The multi-line-draft guard that protects against TUI Ctrl+U concatenation remains intact by construction.

Files Needing Attention: No files require special attention. worktree-draft-startup-view-mode.ts and worktree-creation-agent-seeds.ts are the most novel paths, but both are covered by the new worktree-creation-flow and worktree-creation-agent-seeds test suites.

Important Files Changed

Filename Overview
src/renderer/src/lib/native-chat-launch-draft-mirrorability.ts New single-source-of-truth predicate; correctly covers \r, \n, U+2028, U+2029 line separators and rejects empty/whitespace-only text.
src/renderer/src/lib/worktree-activation.ts Adds launchDraftText field, resolveStartupLaunchDraftText helper, and shared draftViewModeProps so both tab-creation sites use identical logic.
src/renderer/src/lib/worktree-draft-startup-view-mode.ts New helper resolves backend startup viewMode; correctly handles local/remote grok readability, but connectionId lookup returns undefined (not null) when repo is missing, creating a minor type inconsistency that is safe in practice.
src/renderer/src/lib/worktree-creation-agent-seeds.ts Adds applyBackendSpawnedDraftViewMode to correct view mode after backend worktree create; handles both local tab and web-runtime tab (via dynamic import) cases correctly.
src/renderer/src/lib/launch-agent-in-new-tab.ts Refactored to extract startup-plan logic; adds argv-prefill seeding branch (pasteDraftAfterLaunch === null) and passes launchDraftText to view-mode props.
src/renderer/src/runtime/web-runtime-session.ts New createWebRuntimeAgentSessionTerminalWithLaunchDraft function correctly seeds the composer once the mirrored host tab id is known from the creation result.
src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts Extracts resolveFolderWorkspaceLaunchDraft for reuse, adds launchDraftText to startup payload, and seeds the composer after activation for both argv-prefill and paste paths.
src/renderer/src/lib/worktree-creation-flow.ts Adds launchDraftText to buildStartupOpt and calls resolveBackendDraftStartup to inject viewMode into the backend startup payload before createWorktree.
src/shared/types.ts Adds viewMode to WorktreeStartupLaunch; minimal and correct change to the shared type.
src/main/runtime/orca-runtime.ts Three call sites propagate viewMode from sequencedStartup/effectiveStartup to createTerminal; correct conditional spread pattern matches existing launchConfig/launchAgent handling.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Draft Launch Triggered] --> B{Delivery Method}
    B -->|argv prefill\nClaude --prefill| C[launchCommand carries draft\ndraftPrompt = undefined\nlaunchDraftText = draft text]
    B -->|bracketed paste\nCodex| D[draftPrompt = draft text\nlaunchDraftText = draft text]
    C --> E{canMirrorLaunchDraftToNativeChat}
    D --> E
    E -->|Single-line, non-empty| F[View mode = chat\nSeed chat composer]
    E -->|Multi-line or empty| G[View mode = terminal\nDo NOT seed composer]
    F --> H{Launch Path}
    G --> H
    H -->|launchAgentInNewTab local| I[Create tab with viewMode\nargv: seedNativeChatLaunchDraftForAgentTab\npaste: deliverLaunchPromptToAgentTab seeds]
    H -->|launchAgentInNewTab web-host| J[createWebRuntimeAgentSessionTerminalWithLaunchDraft\nSeeds composer after host tab id known]
    H -->|folder-workspace| K[activateAndRevealFolderWorkspace\nresolveFolderWorkspaceLaunchDraft\nseedNativeChatLaunchDraftForAgentTab]
    H -->|worktree creation flow background| L[resolveBackendDraftStartup\nSets viewMode on startup payload\napplyBackendSpawnedDraftViewMode corrects after create]
    H -->|launchWorkItemDirect| M[buildDirectWorkItemStartupOpts\nlaunchDraftText passed through\nworktree-activation reads it]
Loading

Reviews (3): Last reviewed commit: "fix(native-chat): reconcile backend draf..." | Re-trigger Greptile

The draft view-mode gate read `startup.draftPrompt`, which only the
post-ready-paste delivery sets. An argv-prefill launch carries its draft
inside `launchCommand`, so the gate never saw one and the tab opened in
chat unconditionally — a multi-line draft was correctly not seeded yet
still opened chat, leaving an empty composer beside a filled TUI input.

Adds `launchDraftText` to the activation startup payload as a view-mode-only
field, deliberately distinct from `draftPrompt` so it cannot double-deliver
the draft through pty-connection's bracketed paste, and sets it at all four
originating producers.

@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/renderer/src/lib/worktree-activation.ts (1)

86-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep one concise launch-draft contract. The same implementation rationale is repeated across API docs, call sites, and tests.

  • src/renderer/src/lib/worktree-activation.ts#L86-L93: reduce this to one concise contract sentence.
  • src/renderer/src/lib/worktree-activation.ts#L101-L106: remove this duplicate helper walkthrough.
  • src/renderer/src/lib/worktree-activation.ts#L583-L584: remove this call-site duplication.
  • src/renderer/src/lib/worktree-activation.test.ts#L536-L538: remove the test-side duplication.
    As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fb5aed80-ea88-42c4-a970-56cb812c5d15

📥 Commits

Reviewing files that changed from the base of the PR and between 19e84eb and f1b4057.

📒 Files selected for processing (10)
  • src/renderer/src/components/sidebar/folder-workspace-composer-submit.test.ts
  • src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts
  • src/renderer/src/lib/launch-work-item-direct-agent.test.ts
  • src/renderer/src/lib/launch-work-item-direct-agent.ts
  • src/renderer/src/lib/launch-work-item-direct.test.ts
  • src/renderer/src/lib/launch-work-item-direct.ts
  • src/renderer/src/lib/worktree-activation.test.ts
  • src/renderer/src/lib/worktree-activation.ts
  • src/renderer/src/lib/worktree-creation-flow.test.ts
  • src/renderer/src/lib/worktree-creation-flow.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts

@brennanb2025
brennanb2025 merged commit 5517bfc into main Jul 30, 2026
41 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
)

* fix(native-chat): make the launch-draft mirror reachable

Seed the chat-composer copy of unsent launch context on every originating
draft path, then let those launches open in chat by default.

Three paths delivered a draft to the TUI without mirroring it into chat:
folder-workspace create, the local argv-prefill branch of launchAgentInNewTab,
and the web-host equivalent. The first was invisible; the other two were hidden
only because draft launches were forced into terminal view.

The view-mode decision now gates on the same predicate as seeding
(canMirrorLaunchDraftToNativeChat), so a draft can never open in chat with a
composer chat would refuse to fill.

* fix(native-chat): gate draft view mode on argv-prefill launches too

The draft view-mode gate read `startup.draftPrompt`, which only the
post-ready-paste delivery sets. An argv-prefill launch carries its draft
inside `launchCommand`, so the gate never saw one and the tab opened in
chat unconditionally — a multi-line draft was correctly not seeded yet
still opened chat, leaving an empty composer beside a filled TUI input.

Adds `launchDraftText` to the activation startup payload as a view-mode-only
field, deliberately distinct from `draftPrompt` so it cannot double-deliver
the draft through pty-connection's bracketed paste, and sets it at all four
originating producers.

* fix(native-chat): reconcile backend draft launch tabs
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