Skip to content

fix(native-chat): mirror multi-line launch drafts into the chat composer - #11253

Merged
brennanb2025 merged 18 commits into
mainfrom
brennanb2025/native-chat-multiline-send
Jul 30, 2026
Merged

brennanb2025 merged 18 commits into
mainfrom
brennanb2025/native-chat-multiline-send

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Follow-up to #9802. seedNativeChatLaunchDraftForAgentTab rejected any text containing a newline, so every Linear launch (Linked Linear issue: X\n<url>) and any GitHub launch with a typed note was invisible in the chat composer. That rejection existed because the chat send pre-cleared the TUI with a single Ctrl+U, which cannot clear a buffer with embedded newlines.

The measured law (please don't re-derive this)

Step 1 was an empirical probe, not design: real PTYs driven with node-pty, screens read through @xterm/headless, against Claude Code v2.1.220 and codex gpt-5.6-sol. Both agents behaved identically.

Clearing a buffer of N logical lines costs 2N-1 Ctrl+U. Each one kills to the start of the current logical line; when that line is already empty, the next deletes the newline and joins to the previous line — N kills + (N-1) joins. Measured: N=2 needs 3; N=4 with 5 leaves residue; N=4 with 7 is clean.

What does not work, all measured:

Sequence Result on a multi-line buffer
single \x15 kills only the current (last) logical line
\x01 \x0b \x15 (ctrl+a, ctrl+k, ctrl+u) does NOT clear. Acts within the current logical line only; leaves earlier lines and parks the cursor at the end of the previous one, so the next paste glues straight onto it — strictly worse than a single Ctrl+U
Esc no effect on the buffer whatsoever
a fixed repeat count silently wrong: 5 clears 3 lines, leaves residue at 4

A comparable desktop app that wraps an agent TUI uses the ctrl+a/ctrl+k/ctrl+u sequence as its pre-paste clear. The measurement beats that prior art — please don't "fix" this later by reaching for it. The law, the mechanism, and these negative results are documented at the clear site in src/shared/agent-tui-input-clear.ts.

Two further measurements that make an upper bound safe: overshoot is free (41 Ctrl+U against a 1-line buffer is clean) and visual wrapping costs nothing (one 300-char line wrapping several rows dies to a single Ctrl+U). Only logical newlines count.

The fix

Primary path — submit in place. Orca injects the draft itself, so when the composer still holds exactly what was injected, the TUI buffer already is the message: the send is the submit key alone. No clear, no paste, nothing that can concatenate, and multi-line submits as one turn for free (measured: a bare CR submits a multi-line buffer whole on both agents).

Submitting in place requires positive evidence the draft is still on the input line — the user can clear or retype that line directly in terminal view, and pressing Enter on a buffer that no longer holds the draft would silently lose the message. Anything short of "yes, it's still there" falls through to replace-draft, which is correct in every state.

Fallback — sized clear, for the edited case only. The burst is sized from the injected text (the buffer holds what Orca injected, not what the composer now shows), biased upward by 8 lines of slack because the injected count is a lower bound — the user can type into the TUI line too.

Verification, not assumption. Desktop reads the agent's rendered input line (readTerminalScreen) after the clear and widens to a maximal burst if the draft is still visible. Polarity is deliberate: only a positive observation that the draft is gone counts as cleared; unreadable screen, unlocatable prompt line, or unusable fingerprint all mean "not confirmed" and trigger another (harmless) burst. Mobile cannot do this — there is no screen read on that surface, and the code says so rather than pretending otherwise.

Then the '\n' rejection is dropped, so multi-line drafts mirror.

Live QA — both surfaces

Desktop (Electron + CDP) and mobile (iOS sim paired to this dev desktop), against stablyai/demo-project issue #17 with a typed note (note + URL joins with a blank line — the multi-line case).

Proof Result
Multi-line draft mirrors into the composer PASS — seeded and rendered with the blank line intact; on main this is drafts: {}
Sending unedited → one clean turn PASS — transcript shows the draft verbatim, newlines preserved, 1 occurrence, no residue
Sending edited → one clean turn PASS — received prompt is exactly the edited text; the original draft string appears zero times
Image + text still delivers the image PASS — [Image #1] plus the exact draft text, one turn; the agent described the test PNG ("solid red square ~#FA4D4D")
Mobile: mirrors + sends clean PASS after two fixes found by this QA (below)

What live QA caught that unit tests could not

The first mobile run failed. The received message was draft + 21 literal \x15 + body — the burst, prefixed onto the body in the same terminal.send, reached the agent as literal Ctrl+U characters, so nothing was cleared and the draft concatenated. The unit tests were green because they assert the string handed to the RPC layer, which was correct; the host/TUI handling is what differs.

Fix: send the burst as its own non-submitting write — the shape pasteMobileNativeChatImagePaths has always used. Re-testing then surfaced a second, smaller instance of the same effect: the body write's own single-Ctrl+U prefix also landed as a literal character heading the message, so it's now skipped once the dedicated clear has run. Third run is clean: exactly the draft, one turn, zero control characters.

Worth flagging separately: that second observation suggests a mobile text send with clearInputFirst: true and no parked draft may already prepend a literal \x15 on main. I did not change that path and did not chase it — noting it as a possible pre-existing defect.

Tests

Every added test was mutation-checked: production line reverted, suite confirmed RED, restored. 21/21 RED. Two were caught being vacuous first and fixed — a fingerprint-length mutation survived because no test screen wrapped (added a wrapped-line case), and a mobile mutation reported a false RED because those tests were already failing at baseline, which surfaced that this change had broken two existing harnesses that construct hooks without the new required arg (both fixed).

Two max-lines violations were resolved by splitting — resolveNativeChatLaunchDraftSend out of the composer, use-mobile-native-chat-launch-draft-seed.ts out of the mobile drafts hook. No disables, no per-file cap bumps.

Rebase note for reviewers

This depends on #11222 (the canMirrorLaunchDraftToNativeChat extraction) landing first. After rebasing, the relaxation belongs in that predicate's body — the rule must stay single-source. Their author measured the fallout: 13 tests across 7 files go red, two of which predate that PR. Those are expected reds that pin the current single-line rule; they'll be updated to assert the new behavior (multi-line mirrors and opens in chat), not deleted.

That interaction is user-visible and rides on this PR: once multi-line becomes mirrorable, multi-line drafts start opening in chat view. The worktree-creation / folder-workspace path needs QA alongside launchAgentInNewTab once their argv-prefill fix lands.

seedNativeChatLaunchDraftForAgentTab rejected any text containing a newline,
so every Linear launch ("Linked Linear issue: X\n<url>") and any GitHub launch
with a typed note was invisible in chat. The rejection existed because the send
path pre-cleared the TUI with a single Ctrl+U, which cannot clear a buffer with
embedded newlines.

Orca injects the draft itself, so when the composer still holds exactly what was
injected the buffer already IS the message: the send becomes the submit key
alone — no clear, no paste, nothing that can concatenate, and multi-line submits
as one turn for free. Only the edited case needs real buffer replacement, and
that now clears every line and verifies against the agent's rendered input line
instead of firing blind.

Measured on real PTYs against Claude Code and codex (both agree exactly):
clearing N logical lines costs 2N-1 Ctrl+U. See src/shared/agent-tui-input-clear.ts
for the law, the sequences that do NOT work, and why an upper bound is safe.
Live QA caught the bundled form failing: a multi-line burst prefixed onto the
body in the SAME terminal.send reached the agent as LITERAL Ctrl+U characters,
so the parked draft survived and the message arrived as
draft + 21x \x15 + body. Sending the burst as its own non-submitting write —
the shape the image paste has always used — clears as intended.

The body write's own single-Ctrl+U prefix is dropped once that dedicated clear
ran, for the same reason: a Ctrl+U immediately followed by body text in one
write lands as a literal control character and headed the received message.

Re-verified live end to end: received prompt is exactly the draft, one turn,
zero control characters.
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review 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 change adds structured launch-draft metadata and lifecycle tracking, including creation timestamps and seeded-draft readers. Native chat clearing now supports multi-line Ctrl+U bursts, confirmation, deadline handling, and dedicated mobile clear writes. Desktop composer and runtime sends use launch-draft replacement options. Mobile message and image attachment flows clear parked drafts appropriately and forward resolved draft metadata. Tests cover clearing, sequencing, draft adoption, retraction, image sending, and multi-line launch seeding.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary and testing, but it omits required template sections like Screenshots, AI Review Report, Security Audit, and Notes. Add the missing sections, including Screenshots (or 'No visual change'), a testing checklist, an AI Review Report, a Security Audit, and Notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% 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 reflects the main change: mirroring multi-line launch drafts into the chat composer.
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: 1

Caution

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

⚠️ Outside diff range comments (1)
mobile/src/session/use-mobile-native-chat-message-send.ts (1)

104-149: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Avoid clearing after the image paste.

For image sends, mobile/src/session/use-mobile-native-chat-image-attachments.ts already clears the seeded draft before pasting. This branch then clears again in baseSend, erasing the pasted image before the caption is submitted. Only run this dedicated clear for text-only sends.

Proposed fix
-      if (seededLaunchDraft) {
+      if (seededLaunchDraft && !images?.length) {
🧹 Nitpick comments (2)
src/shared/agent-tui-input-clear.ts (1)

1-30: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Condense implementation-history comments.

Keep the invariant and failure mode near the code; move measurement narratives and rejected alternatives to tests or dedicated documentation.

  • src/shared/agent-tui-input-clear.ts#L1-L30: reduce this to a short explanation of the 2N-1 invariant.
  • mobile/src/session/mobile-native-chat-send.ts#L93-L101: retain only the standalone-write requirement and its literal-control-character failure mode.

As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.

Source: Coding guidelines

src/renderer/src/components/native-chat/native-chat-runtime-send-launch-draft.test.ts (1)

123-140: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider covering the image path with confirmCleared.

Both image tests omit confirmCleared, so the image-specific confirm gap (clearConfirmDurationMs added to durationMs) and the widened-burst-before-image-paste ordering are untested.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 55b43b99-6cf8-4ae2-bd38-6784ae9ed680

📥 Commits

Reviewing files that changed from the base of the PR and between 3a67186 and 6093aeb.

📒 Files selected for processing (23)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/mobile-native-chat-image-send.test.ts
  • mobile/src/session/mobile-native-chat-image-send.ts
  • mobile/src/session/mobile-native-chat-send.test.ts
  • mobile/src/session/mobile-native-chat-send.ts
  • mobile/src/session/use-mobile-native-chat-controller.test.ts
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/use-mobile-native-chat-drafts.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.test.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.ts
  • mobile/src/session/use-mobile-native-chat-launch-draft-seed.ts
  • mobile/src/session/use-mobile-native-chat-message-send.test.ts
  • mobile/src/session/use-mobile-native-chat-message-send.ts
  • mobile/src/session/use-mobile-session-image-attachments.ts
  • src/renderer/src/components/native-chat/NativeChatComposer.tsx
  • src/renderer/src/components/native-chat/native-chat-launch-draft-send.test.ts
  • src/renderer/src/components/native-chat/native-chat-launch-draft-send.ts
  • src/renderer/src/components/native-chat/native-chat-runtime-send-launch-draft.test.ts
  • src/renderer/src/components/native-chat/native-chat-runtime-send.ts
  • src/renderer/src/lib/agent-launch-prompt-delivery.test.ts
  • src/renderer/src/lib/agent-launch-prompt-delivery.ts
  • src/shared/agent-tui-input-clear.test.ts
  • src/shared/agent-tui-input-clear.ts

Comment on lines +45 to +49
/** Bounds the burst so a pathological draft cannot emit an unbounded write. */
export const AGENT_TUI_CLEAR_MAX_LINES = 40

/** Widest burst we ever send — the remedy when a clear is not observed to land. */
export const AGENT_TUI_CLEAR_INPUT_MAX = buildAgentTuiClearInput(AGENT_TUI_CLEAR_MAX_LINES)

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 | 🟠 Major | 🏗️ Heavy lift

Do not silently under-clear drafts exceeding 40 logical lines.

A 41-line draft receives only the 79 Ctrl+U bytes needed for 40 lines; the desktop fallback repeats that same insufficient maximum, while mobile proceeds after the accepted clear write. This can append the new body to residual seeded text.

  • src/shared/agent-tui-input-clear.ts#L45-L49: expose overflow/chunked clearing and ensure replacement sends cannot continue after an incomplete clear.
  • src/shared/agent-tui-input-clear.test.ts#L38-L41: add a 41+ logical-line regression case that requires complete clearing or a safe rejected path rather than truncation.
📍 Affects 2 files
  • src/shared/agent-tui-input-clear.ts#L45-L49 (this comment)
  • src/shared/agent-tui-input-clear.test.ts#L38-L41

@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes multi-line launch drafts (Linear issue links, typed notes) being silently dropped by the native-chat composer. The previous single \x15 clear could only kill one logical line; this PR introduces an empirically-derived 2N-1 Ctrl+U law, a sized-clear burst with slack, and a confirmation step that widens to a maximal burst when the clear isn't observed to land.

  • Core algorithm (agent-tui-input-clear.ts): shared buildAgentTuiClearInput(N) emitting (2N-1) Ctrl+U + (2N-1) Ctrl+K, capped at 40 lines; canMirrorLaunchDraftToNativeChat relaxed from "no \ \ " to "≤ 40 logical lines and no Unicode line separators."
  • Desktop send path: resolveNativeChatLaunchDraftSend wires a clearInput/confirmCleared option pair into both message-send functions; clearThenWrite pauses to read the screen and widens to AGENT_TUI_CLEAR_INPUT_MAX if residue is still visible.
  • Mobile send path: a dedicated clearMobileNativeChatInput write precedes the body; the new use-mobile-native-chat-launch-draft-seed hook tracks the parked seed per-tab and exposes readSeededLaunchDraftSeed for sizing.

Confidence Score: 4/5

The functional fix is correct and well-tested; one structural change in the PTY send queue removes a documented safety fallback that could permanently stall sends to a terminal if a timer callback throws.

The removal of the durationMs safety timeout was necessary to fix incorrect timing when confirmCleared extends completion past the nominal window, but it eliminates the only unconditional release path. A throw in any delay-callback before markSubmitted() permanently stalls that PTY queue for the tab session.

Files Needing Attention: src/renderer/src/components/native-chat/native-chat-pty-send-queue.ts — consider whether a try/catch around delay-callback invocations, or a Promise.race timeout, should replace the removed safety net.

Important Files Changed

Filename Overview
src/shared/agent-tui-input-clear.ts New shared utility implementing the empirically-measured 2N-1 law; well-bounded with MAX_LINES cap and Ctrl+K suffix for forward clearing.
src/renderer/src/components/native-chat/native-chat-pty-send-queue.ts Removes the durationMs safety-fallback timeout; a throw before markSubmitted() now permanently stalls the PTY send queue.
src/renderer/src/components/native-chat/native-chat-launch-draft-send.ts New module wiring the sized-clear path; agentInputLineCleared correctly treats unreadable screens and placeholders as unconfirmed.
src/renderer/src/components/native-chat/native-chat-runtime-send.ts clearThenWrite + NativeChatSendOptions; durationMs correctly inflated by clearConfirmDurationMs; cancel path updated.
src/renderer/src/components/native-chat/NativeChatComposer.tsx Wires resolveNativeChatLaunchDraftSend into every send branch; new deps correctly added to useCallback.
mobile/src/session/use-mobile-native-chat-launch-draft-seed.ts New hook; null-sentinel for declined seeds; retraction effect guards with text equality.
mobile/src/session/use-mobile-native-chat-message-send.ts Dedicated clearMobileNativeChatInput write; correctly skips for image sends; clearInputFirst conditioned correctly.
mobile/src/session/use-mobile-native-chat-image-attachments.ts Passes sized clearInput to pasteMobileNativeChatImagePaths; readSeededLaunchDraft now in dependency array.
src/main/runtime/orca-runtime.ts Tombstone map with LRU eviction at 200 entries; fence correctly strips resolved drafts from mobile snapshots.
src/renderer/src/lib/native-chat-launch-draft-mirrorability.ts Drops \r\n rejection; permits drafts up to AGENT_TUI_CLEAR_MAX_LINES logical lines.

Comments Outside Diff (1)

  1. src/renderer/src/components/native-chat/native-chat-pty-send-queue.ts, line 135-142 (link)

    P1 Safety-timeout removal can permanently stall the PTY send queue

    The old durationMs safety timer—explicitly documented as "always release after the declared duration so a cancel mid-flight cannot stall the per-pty queue forever"—has been removed. The queue entry now resolves only when markSubmitted() or cancel() calls finishEntry(). If any delay-callback in the chain throws before reaching markSubmitted() (e.g. sendRuntimePtyInput throws on an IPC error before the follow-on delay(NATIVE_CHAT_SUBMIT_DELAY_MS, …) is scheduled), finishEntry() is never invoked, runPromise never settles, and every subsequent send to that PTY blocks indefinitely. The user would have to navigate away from the tab to recover.

    Concrete path: sendRuntimePtyInput(buildNativeChatPasteBytes(text)) throws inside writeBody → the submit timer is never scheduled → markSubmitted() is never called → state.tail chain never advances.

Reviews (7): Last reviewed commit: "test(mobile): stabilize QR capacity boun..." | Re-trigger Greptile

…xpectation

The Linear work-item launch seeds `Linked Linear issue: ENG-42\n<url>\n`.
This test pinned the pre-relaxation rule (multi-line drafts withheld), which
the send path no longer needs now that it submits the TUI buffer in place or
clears every line first — so it asserted the exact behavior the fix removes.

Assert the seeded payload instead of absence, so the test fails if the mirror
regresses to single-line-only.

@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)
mobile/src/session/use-mobile-native-chat-message-send.ts (1)

104-114: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Condense the new explanatory comments.

Keep only the non-obvious contract: clear every seeded line in a separate write and do not bundle Ctrl+U with the body. The current multi-paragraph comments walk through implementation details and violate the concise-comment guideline.

As per coding guidelines, comments must be concise and limited to non-obvious information.

Also applies to: 138-148

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 34dea18d-790e-4bc6-a1c9-96bb37bce156

📥 Commits

Reviewing files that changed from the base of the PR and between 78bcb5f and b5982ba.

📒 Files selected for processing (10)
  • mobile/src/session/use-mobile-native-chat-image-attachments.ts
  • mobile/src/session/use-mobile-native-chat-message-send.test.ts
  • mobile/src/session/use-mobile-native-chat-message-send.ts
  • src/renderer/src/components/native-chat/NativeChatComposer.tsx
  • src/renderer/src/components/native-chat/native-chat-launch-draft-send.test.ts
  • src/renderer/src/components/native-chat/native-chat-launch-draft-send.ts
  • src/renderer/src/components/native-chat/native-chat-runtime-send-launch-draft.test.ts
  • src/renderer/src/components/native-chat/native-chat-runtime-send.ts
  • src/renderer/src/lib/agent-launch-prompt-delivery.test.ts
  • src/renderer/src/lib/agent-launch-prompt-delivery.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/lib/agent-launch-prompt-delivery.ts
  • src/renderer/src/lib/agent-launch-prompt-delivery.test.ts

@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: Pro Plus

Run ID: 2445a7de-eb14-484d-a6bd-1b75c4072806

📥 Commits

Reviewing files that changed from the base of the PR and between b5982ba and 8140491.

📒 Files selected for processing (2)
  • src/renderer/src/components/native-chat/native-chat-runtime-send-launch-draft.test.ts
  • src/renderer/src/components/native-chat/native-chat-runtime-send.ts

Comment on lines +160 to +162
expect(writes().indexOf(NATIVE_CHAT_SUBMIT)).toBeLessThan(
writes().indexOf(NATIVE_CHAT_CLEAR_UNSUBMITTED_INPUT)
)

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

Assert that the image send actually submitted.

Line 160 passes when NATIVE_CHAT_SUBMIT is absent (-1) and the queued send clears. Assert a non-negative submit index before comparing order.

Proposed fix
-    expect(writes().indexOf(NATIVE_CHAT_SUBMIT)).toBeLessThan(
-      writes().indexOf(NATIVE_CHAT_CLEAR_UNSUBMITTED_INPUT)
-    )
+    const submitIndex = writes().indexOf(NATIVE_CHAT_SUBMIT)
+    const nextClearIndex = writes().indexOf(NATIVE_CHAT_CLEAR_UNSUBMITTED_INPUT)
+    expect(submitIndex).toBeGreaterThanOrEqual(0)
+    expect(submitIndex).toBeLessThan(nextClearIndex)
📝 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
expect(writes().indexOf(NATIVE_CHAT_SUBMIT)).toBeLessThan(
writes().indexOf(NATIVE_CHAT_CLEAR_UNSUBMITTED_INPUT)
)
const submitIndex = writes().indexOf(NATIVE_CHAT_SUBMIT)
const nextClearIndex = writes().indexOf(NATIVE_CHAT_CLEAR_UNSUBMITTED_INPUT)
expect(submitIndex).toBeGreaterThanOrEqual(0)
expect(submitIndex).toBeLessThan(nextClearIndex)

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

⚠️ Outside diff range comments (1)
mobile/src/session/use-mobile-native-chat-launch-draft-seed.ts (1)

41-55: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Scope seeded state by launch-draft generation, not only by draftKey.

The has(draftKey) guard makes the first draft permanent. After retraction, storing null leaves the key in the map, so a new launch draft for the same tab is never adopted. Late createdAt updates are also ignored. Track (text, createdAt) generation state alongside the declined/null entry and add regression coverage for retraction followed by a new draft.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dc81da21-5e17-4bbf-9ea1-19b3297b483a

📥 Commits

Reviewing files that changed from the base of the PR and between 8140491 and 6ec7646.

📒 Files selected for processing (13)
  • mobile/app/h/[hostId]/session/mobile-session-route-types.ts
  • mobile/src/session/mobile-native-chat-eligibility.ts
  • mobile/src/session/mobile-native-chat-send.test.ts
  • mobile/src/session/mobile-native-chat-send.ts
  • mobile/src/session/mobile-terminal-records.test.ts
  • mobile/src/session/mobile-terminal-records.ts
  • mobile/src/session/use-mobile-native-chat-controller.test.ts
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/use-mobile-native-chat-drafts-launch-draft.test.ts
  • mobile/src/session/use-mobile-native-chat-drafts.ts
  • mobile/src/session/use-mobile-native-chat-launch-draft-seed.ts
  • mobile/src/session/use-mobile-native-chat-message-send.test.ts
  • mobile/src/session/use-mobile-native-chat-message-send.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • mobile/src/session/use-mobile-native-chat-controller.test.ts

@brennanb2025
brennanb2025 merged commit bbb3e7e into main Jul 30, 2026
45 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ser (stablyai#11253)

* fix(native-chat): mirror multi-line launch drafts into the chat composer

seedNativeChatLaunchDraftForAgentTab rejected any text containing a newline,
so every Linear launch ("Linked Linear issue: X\n<url>") and any GitHub launch
with a typed note was invisible in chat. The rejection existed because the send
path pre-cleared the TUI with a single Ctrl+U, which cannot clear a buffer with
embedded newlines.

Orca injects the draft itself, so when the composer still holds exactly what was
injected the buffer already IS the message: the send becomes the submit key
alone — no clear, no paste, nothing that can concatenate, and multi-line submits
as one turn for free. Only the edited case needs real buffer replacement, and
that now clears every line and verifies against the agent's rendered input line
instead of firing blind.

Measured on real PTYs against Claude Code and codex (both agree exactly):
clearing N logical lines costs 2N-1 Ctrl+U. See src/shared/agent-tui-input-clear.ts
for the law, the sequences that do NOT work, and why an upper bound is safe.

* fix(native-chat): send the mobile clear burst as its own write

Live QA caught the bundled form failing: a multi-line burst prefixed onto the
body in the SAME terminal.send reached the agent as LITERAL Ctrl+U characters,
so the parked draft survived and the message arrived as
draft + 21x \x15 + body. Sending the burst as its own non-submitting write —
the shape the image paste has always used — clears as intended.

The body write's own single-Ctrl+U prefix is dropped once that dedicated clear
ran, for the same reason: a Ctrl+U immediately followed by body text in one
write lands as a literal control character and headed the received message.

Re-verified live end to end: received prompt is exactly the draft, one turn,
zero control characters.

* test(native-chat): invert the multi-line Linear launch-draft mirror expectation

The Linear work-item launch seeds `Linked Linear issue: ENG-42\n<url>\n`.
This test pinned the pre-relaxation rule (multi-line drafts withheld), which
the send path no longer needs now that it submits the TUI buffer in place or
clears every line first — so it asserted the exact behavior the fix removes.

Assert the seeded payload instead of absence, so the test fails if the mirror
regresses to single-line-only.

* fix(native-chat): preserve launch draft send contents

* fix(native-chat): preserve confirmed send queue ordering

* fix(native-chat): preserve send pacing after renderer stalls

* test(native-chat): align activation with multiline draft mirroring

* fix(native-chat): clear launch drafts from any cursor

* fix(native-chat): retire mobile-consumed launch drafts

* test(mobile): stabilize QR capacity boundary fixture
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