Repository navigation
fix(mobile): heal a stale input line before sending diff-review notes - #11035
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between c8b78f37e59199d97b583876a87d227df5379ade and ba54d68. 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
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 winAvoid 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.pngis excluded by!**/*.png.pr-screenshots/p2-stale-heal-hosts-unpaired.pngis excluded by!**/*.png
📒 Files selected for processing (2)
mobile/src/session/use-mobile-diff-review-send-actions.test.tsmobile/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.
c8b78f3 to
ba54d68
Compare
Review pass — CodeRabbit adjudication + two fixes pushedEvery CodeRabbit item is either actioned or declined below, none silently dropped. 🔵 Nitpick: "Avoid adding new tests on deprecated
|
| 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.
…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.
Summary
useMobileDiffReviewSendActions.sendPromptToTerminalsubmitted review notes withenter: truewithout first healing a stale agent input line. It now gates the send onhealMobileNativeChatStaleInput, exactly asuse-mobile-native-chat-answer-send.ts:186already 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.sendfor 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.okandreadMobileReviewTerminalSendAcceptedhandling 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.
Testing
pnpm lint— oxlint exit 0pnpm typecheck—tsc --noEmitexit 0pnpm test— mobile suite 350 files / 2563 passed; all 16 CI test shards greenpnpm build— CIpackage+verifygreenUnit tests — 7 added (new file
use-mobile-diff-review-send-actions.test.ts; count fromgit 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):
With the fix restored:
Tests 7 passed (7).terminal.sendresponse still surfaces).The ordering assertion was proven to discriminate, not merely to observe: moving the heal to after
terminal.sendin the source fails 4 tests.calls[0]must be{text: '\x15', enter: false}andcalls[1]must beenter: trueand 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 rootconfig/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 on192.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.
deviceToken: null— settled against the desktop handler, not assumed.src/main/runtime/rpc/methods/terminal.ts:246-249treats a clientless send as legacy mobile and unlocked, andsendTerminalStreamInputskipsbeginMobileInputFloorwhen 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.catchand the!clearedbranch return false with the marker intact. Two tests assert it survives a failed heal.Set.hasearly-return with zero added RPCs, asserted by an exact call count. TheuseCallbackdep array is unchanged, so no new identity churn.\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.terminal.sendkeyed 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.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.sendRPC 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 throughformatMobileDiffReviewPrompt. 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:
Errors from this hook are not surfaced to the user.
sendPromptToTerminalthrows, butMobileDiffReviewDrawers.tsx:76calls it asvoid controller.sendPromptToTerminal(...)andActionSheetModal.tsx:74invokesaction.onPress()with no catch — and there is no unhandled-rejection handler undermobile/. 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 exposingsetActionErrorthrough the controller and changing four paths this PR never touches, which is a second concern. The siblinguseMobileDiffReviewGitActions.runGitMutationalready catches internally and is the pattern to follow.The three diff-review send RPCs are unbounded.
terminal.send,session.tabs.createTerminal, andsession.tabs.listin this file pass notimeoutMs, so perrpc-client.ts:1003they 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.mobile-native-chat-stale-input.tsis now used from diff review too, so itsnative-chatname is cross-domain. Renaming it would touch 4+ modules and swamp an 8-line fix, so it is deliberately left alone.