Skip to content

fix(mobile): heal a stale input line before sending diff-review notes - #11035

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/p2-diff-review-stale-heal
Jul 28, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/p2-diff-review-stale-heal

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

useMobileDiffReviewSendActions.sendPromptToTerminal submitted review notes with enter: true without first healing a stale agent input line. It now gates the send on healMobileNativeChatStaleInput, exactly as use-mobile-native-chat-answer-send.ts:186 already does.

This completes a follow-up deliberately deferred by #10480.

Why the two surfaces connect. The stale marker is keyed by terminal handle (staleInputTerminals: Set<string>), not by surface. A marker set by the native-chat image-paste path is still set when the user then sends diff-review notes to that same terminal — so those notes were submitted on top of the orphaned paste (#10228).

When the heal reports the line is not safe, the send is skipped: no terminal.send for the notes, markNotesSent / triggerSuccess / setSendSheet(null) are all skipped, and the marker stays set so the next attempt retries. The notes are neither lost nor marked sent. The existing !response.ok and readMobileReviewTerminalSendAccepted handling is unchanged and still runs after the heal.

Screenshots

Emulator QA — PARTIAL, see the Testing section for exactly what this does and does not prove.

app loaded

hosts unpaired

Testing

  • pnpm lint — oxlint exit 0
  • pnpm typecheck — tsc --noEmit exit 0
  • pnpm test — mobile suite 350 files / 2563 passed; all 16 CI test shards green
  • pnpm build — CI package + verify green
  • Added or updated high-quality tests that would catch regressions

Unit tests — 7 added (new file use-mobile-diff-review-send-actions.test.ts; count from git diff <parent> <head>, so no inherited tests are credited here). This hook had no test file before.

Revert-check via the patch method (revert the source fix only, keep the tests):

 × heals a marked terminal BEFORE submitting the notes
 × does not submit when the heal reports the line is not safe
 × keeps the marker and skips the notes when the clear throws
 × still reports a rejected terminal.send after a successful heal
 Test Files  1 failed (1)
      Tests  4 failed | 3 passed (7)

With the fix restored: Tests 7 passed (7).

  • 4 tests encode NEW behavior and fail on revert (call ordering, not-safe → no send, clear-throws → no send, post-heal rejection still reported).
  • 3 tests are regression guards that pass on both sides (unmarked terminal sends with exactly one RPC, only the marked terminal is healed, a failed terminal.send response still surfaces).

The ordering assertion was proven to discriminate, not merely to observe: moving the heal to after terminal.send in the source fails 4 tests. calls[0] must be {text: '\x15', enter: false} and calls[1] must be enter: true and contain the note body, so a swapped or duplicated-clear implementation cannot pass.

Note for anyone re-running these: mobile uses its own mobile/vitest.config.ts, not the root config/vitest.config.ts.

NOT verified on the emulator: the diff-review note send end-to-end, and the stale precondition. The simulator has no live desktop pairing — all 13 saved pairings are on networks this machine has left (10.0.0.4, 172.16.101.141; the Mac is on 192.168.0.x). Re-pairing requires the desktop Settings > Mobile UI and has no CLI path, and the only workaround would have been a second runtime, which risks the known singleton-lock / runtime-metadata clobber against a live primary instance. What the screenshots prove is only that the app loads and runs this branch's bundle. The ordering, the not-safe-→-no-send behavior, and the no-regression claim rest on the unit tests above, not on live emulator evidence.

AI Review Report

Reviewed with two independent Opus subagent lanes (correctness/vacuity, and scope/CodeRabbit adjudication) plus a lead pass. Risks checked: test vacuity, call ordering, the silent-drop path, marker lifecycle, regressions on untouched branches, perf on the common path, and scope.

  • Vacuity — confirmed non-vacuous by actually reverting the source and re-running (output above).
  • deviceToken: null — settled against the desktop handler, not assumed. src/main/runtime/rpc/methods/terminal.ts:246-249 treats a clientless send as legacy mobile and unlocked, and sendTerminalStreamInput skips beginMobileInputFloor when there is no client id. The notes send this heal precedes is itself clientless, so the clear is authorized identically to the write it guards. A null token cannot make the heal fail where the send would have succeeded.
  • Marker lifecycle — the marker is consumed only after the host accepts the clear; both the catch and the !cleared branch return false with the marker intact. Two tests assert it survives a failed heal.
  • Perf — the common (unmarked) path is a Set.has early-return with zero added RPCs, asserted by an exact call count. The useCallback dep array is unchanged, so no new identity churn.
  • Cross-platform (macOS / Linux / Windows) — explicitly checked and N/A. No path handling, no shortcuts or shortcut labels, no Electron platform branches in the diff. The only literal is \x15 (Ctrl+U), a PTY control byte written into a stream, not a key event, and platform-independent at the mobile end. The desktop code that interprets it is untouched.
  • SSH hosts — exercised but not at risk: the heal writes via terminal.send keyed by an opaque handle, and the desktop routes to whichever host owns the pane. Ctrl+U is readline/TUI-level and travels the PTY identically.
  • Folder workspaces — N/A; the heal keys on terminal handle only, with no worktree or repo assumption.
  • Non-GitHub providers — N/A; diff comments are local records formatted into a prompt, nothing provider-specific.

Security Audit

No new attack surface. No command execution, no path handling, no auth or secrets, no dependency change. The one new outbound write is a terminal.send RPC carrying a fixed control byte (\x15) to a terminal handle the caller already holds and is already authorized to write to on the next line — it grants no capability the existing send did not. Input handling is unchanged: note bodies still flow through formatMobileDiffReviewPrompt. The clientless-send authorization path is pre-existing and documented above. No IPC surface added.

Notes

Two follow-ups, deliberately not done here to keep this PR to one concern:

  1. Errors from this hook are not surfaced to the user. sendPromptToTerminal throws, but MobileDiffReviewDrawers.tsx:76 calls it as void controller.sendPromptToTerminal(...) and ActionSheetModal.tsx:74 invokes action.onPress() with no catch — and there is no unhandled-rejection handler under mobile/. So on a failed heal the user sees nothing and the sheet stays open (skipAutoClose: true). This is pre-existing: all four existing throws in this hook ('Waiting for desktop...', !response.ok, 'Terminal input is locked', 'Failed to create terminal') die the same way, and this change adds a fifth to an already-broken channel. It is not a data-loss path — the notes stay unsent and unmarked, so a retry is correct and safe. Fixing it properly means exposing setActionError through the controller and changing four paths this PR never touches, which is a second concern. The sibling useMobileDiffReviewGitActions.runGitMutation already catches internally and is the pattern to follow.

  2. The three diff-review send RPCs are unbounded. terminal.send, session.tabs.createTerminal, and session.tabs.list in this file pass no timeoutMs, so per rpc-client.ts:1003 they wait for reconnect indefinitely. Worth bounding, but it needs a UX decision about what the review screen shows on timeout and applies to all three equally.

  3. mobile-native-chat-stale-input.ts is now used from diff review too, so its native-chat name is cross-domain. Renaming it would touch 4+ modules and swamp an 8-line fix, so it is deliberately left alone.

The stale-input marker is keyed by terminal handle, not by surface, so a
paste orphaned on a terminal by native chat is still marked when the user
sends diff-review notes to that same terminal — and those notes were
submitted on top of it. Gate the send on the heal, as the native-chat
answer send already does; when the clear fails, surface the error instead
of dropping the note silently.

Completes a follow-up deliberately deferred by #10480.
@coderabbitai

coderabbitai Bot commented Jul 28, 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 Plus

Run ID: 2cea9867-d894-4347-b50b-cc47f71fa105

📥 Commits

Reviewing files that changed from the base of the PR and between c8b78f37e59199d97b583876a87d227df5379ade and ba54d68.

📒 Files selected for processing (2)
  • mobile/src/session/use-mobile-diff-review-send-actions.test.ts
  • mobile/src/session/use-mobile-diff-review-send-actions.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • mobile/src/session/use-mobile-diff-review-send-actions.ts
  • mobile/src/session/use-mobile-diff-review-send-actions.test.ts

📝 Walkthrough

Walkthrough

sendPromptToTerminal now heals stale native-chat input for the target terminal before sending review notes. Healing failures stop the send and preserve the stale marker, while successful healing proceeds to terminal.send. Tests cover RPC ordering, terminal scoping, unsafe or rejected healing, locked input responses, explicit send errors, persistence, and UI state updates.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: healing stale mobile input before sending diff-review notes.
Description check ✅ Passed The description includes all required sections and covers summary, screenshots, testing, AI review, security, and notes with sufficient detail.
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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
mobile/src/session/use-mobile-diff-review-send-actions.test.ts (1)

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

Avoid adding new tests on deprecated react-test-renderer.

React 19.2 deprecates this package, and the harness now suppresses its warning. Migrate this hook test to the repository’s supported Testing Library setup, then remove the suppression.

Also applies to: 84-97


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ef2dd5dc-d6ab-45f6-a5cd-3d98bdf34a3d

📥 Commits

Reviewing files that changed from the base of the PR and between b316174 and 215b1562076a948523f5506b80f1800a70a1770e.

⛔ Files ignored due to path filters (2)
  • .pr-screenshots/p2-stale-heal-app-loaded.png is excluded by !**/*.png
  • .pr-screenshots/p2-stale-heal-hosts-unpaired.png is excluded by !**/*.png
📒 Files selected for processing (2)
  • mobile/src/session/use-mobile-diff-review-send-actions.test.ts
  • mobile/src/session/use-mobile-diff-review-send-actions.ts

Keeps the terminal-handle keying and the #10228 link (why a NativeChat-named
helper runs in diff review) and the deviceToken rationale; drops the clause
that restated the call. Addresses CodeRabbit review feedback.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/p2-diff-review-stale-heal branch from c8b78f3 to ba54d68 Compare July 28, 2026 01:54
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review pass — CodeRabbit adjudication + two fixes pushed

Every CodeRabbit item is either actioned or declined below, none silently dropped.

🔵 Nitpick: "Avoid adding new tests on deprecated react-test-renderer" — declined

Verified by count in this repo:

count
mobile test files importing react-test-renderer 48
mobile files importing @testing-library/react-native 0
@testing-library/react-native in mobile/package.json not a dependency

Adopting a second test harness for one new file would add inconsistency without removing the deprecation, and would require adding the dependency. The migration is a suite-wide change and belongs in its own PR. The new file does locally suppress the deprecation warning (use-mobile-diff-review-send-actions.test.ts:84-97), narrowly matched on the warning string and restored in a finally, so it doesn't swallow unrelated console.error.

⚠️ Pre-merge "Description check" — actioned

The body now follows .github/pull_request_template.md: Summary, Screenshots, Testing (with the checklist), AI Review Report (including the explicit macOS/Linux/Windows confirmation the template requires), Security Audit, and Notes.

🟡 Minor (comment length) — partially actioned, see inline reply

🟠 Major (shared deadline) — declined on evidence, see inline reply; CodeRabbit's premise about a second budget doesn't hold here


Two things this review changed

1. QA screenshots moved out of git history. .pr-screenshots/ has never existed on main — every prior commit adding it sits on an unmerged branch. Merging this would have put 403 KB of PNGs permanently into history for evidence that has a zero-cost CDN home. The two images are now hosted on the user-attachments CDN (verified HTTP 200 image/png, byte-identical at 199,407 / 203,522), the body references those URLs, and commit 215b156207 has been dropped. Branch force-pushed with --force-with-lease.

2. A false claim in the body was corrected. The body previously said a failed heal "surfaces through the same throw new Error(...) → setActionError path the function's existing failure branches use." That is not true, and it was traced to ground: MobileDiffReviewDrawers.tsx:76 calls void controller.sendPromptToTerminal(...), ActionSheetModal.tsx:74 invokes action.onPress() with no catch, and there is no unhandled-rejection handler anywhere under mobile/. So the throw becomes a silent unhandled rejection and the sheet just sits there (skipAutoClose: true).

This is pre-existing, not introduced here — all four existing throws in this hook die the same way, and this change adds a fifth to an already-broken channel. It is also not a data-loss path: on a failed heal the notes stay unsent and unmarked and the marker survives, so a retry is correct and safe. Fixing it properly means exposing setActionError through the controller and changing four paths this PR never touches — a second concern, now written up as follow-up #1 rather than asserted as already working.

Verification

Revert-check re-run independently against the current tree (patch method, source reverted, tests kept):

 × heals a marked terminal BEFORE submitting the notes
 × does not submit when the heal reports the line is not safe
 × keeps the marker and skips the notes when the clear throws
 × still reports a rejected terminal.send after a successful heal
 Test Files  1 failed (1)
      Tests  4 failed | 3 passed (7)

Restored → Tests 7 passed (7), working tree clean. The ordering assertion was also proven to discriminate: moving the heal to after terminal.send fails 4 tests, so a swapped or duplicated-clear implementation cannot pass.

deviceToken: null was settled against the desktop handler rather than assumed — src/main/runtime/rpc/methods/terminal.ts:246-249 treats a clientless send as legacy mobile and unlocked, and the notes send this heal precedes is itself clientless, so the clear is authorized identically to the write it guards.

Scope stayed at one concern: the diff against main is now exactly two files, +228 lines. The mobile-native-chat-stale-input.ts rename is correctly deferred — the name is stale, not vague, and renaming would touch 4+ modules to swamp an 8-line fix.

@brennanb2025
brennanb2025 merged commit 84c70d6 into main Jul 28, 2026
23 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…stablyai#11035)

* fix(mobile): heal a stale input line before sending diff-review notes

The stale-input marker is keyed by terminal handle, not by surface, so a
paste orphaned on a terminal by native chat is still marked when the user
sends diff-review notes to that same terminal — and those notes were
submitted on top of it. Gate the send on the heal, as the native-chat
answer send already does; when the clear fails, surface the error instead
of dropping the note silently.

Completes a follow-up deliberately deferred by stablyai#10480.

* test(mobile): assert the post-heal send carries the notes, not another clear

* style(mobile): trim the stale-heal comment to its non-obvious why

Keeps the terminal-handle keying and the stablyai#10228 link (why a NativeChat-named
helper runs in diff review) and the deviceToken rationale; drops the clause
that restated the call. Addresses CodeRabbit review feedback.
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