Skip to content

fix(mobile): stop held accessory keys after release under latency - #14219

Merged
brennanb2025 merged 18 commits into
mainfrom
brennanb2025/sta-3919-mobile-picker-lag
Aug 28, 2026
Merged

brennanb2025 merged 18 commits into
mainfrom
brennanb2025/sta-3919-mobile-picker-lag

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • response-pace only timer-generated repeats within one held mobile accessory-key press
  • dispatch every distinct tap immediately, without waiting for an earlier tap acknowledgement
  • stop future repeats after release, terminal/client/connection changes, RPC failure, transport rejection, or IME/local-edit failure
  • preserve the existing 400 ms hold delay, 45 ms repeat interval, and terminal.send wire contract

ELI5: user-facing before and after

Before: If a user pressed and held an on-screen arrow, mobile could send repeat commands faster than the host processed them. Those commands could pile up, make a picker overshoot, and keep moving briefly after the finger was lifted.

After: A held arrow waits for each repeat to finish before generating the next repeat, and releasing the arrow prevents any future repeat from being scheduled. Separate quick taps still fire immediately; they are not queued behind earlier network acknowledgements.

Scope

This is a held-button reliability fix. It does not establish or fix the root cause of the ordinary single-tap lag reported in STA-3919 / #13845, so that issue remains open for separate investigation.

Reliability contract

  • Within one held press, at most one timer-generated repeat send and one repeat timer are active.
  • Distinct user presses dispatch immediately, matching the pre-PR tap behavior.
  • A hold remains pinned to the terminal, client, and connection active at press time.
  • No persisted state, RPC shape, stream opcode, dependency, host process, SSH, relay, WSL, Windows, Linux, or Git-provider behavior changes.

Validation

  • exact pushed head: df9a4a236ee16bfef264f80a5d8a690965122e75
  • 90 focused tests across six mobile terminal files passed
  • mobile TypeScript passed
  • Oxlint on all 10 changed files passed
  • Oxfmt check and git diff --check passed
  • same-model review/fix/re-review loop: clean
  • opening readiness found and drove the tap-dispatch correction; final readiness passed with no P0/P1/P2 findings
  • earlier paired iOS evidence demonstrated post-release stability for the held-repeat behavior; exact-head native timing was not rerun because the permitted emulator worker was blocked before execution

Before: open-loop held repeats

sta3919-before-clean.mp4

After: response-paced held repeats and release fence

sta3919-after-proof.mp4

Earlier paired iOS rerun

pr14219-current-main.mp4

Related: STA-3919 / #13845 remains open.

@coderabbitai

coderabbitai Bot commented Aug 13, 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 terminal raw-send helper now returns a boolean status for accepted, unavailable, and failed sends. Input commit paths await mirror and control-byte results and return suppress-raw on failure. A repeat controller manages immediate and scheduled accessory input, prevents overlapping sends, and stops after cancellation or failed dispatch. The session screen validates the client, terminal, connection state, and connection epoch before delivery. Tests cover send results, input-commit failures, repeat timing, cancellation, rejection, and stale queued sends.

Merge Risk: 🟡 Moderate · up to df9a4

The PR improves held-key repeat pacing and release handling, but a rejected mirrored input can leave the client baseline ahead of the terminal; a later edit may send incorrect erase or delta bytes and mutate the user's command. This bounded correctness issue should be fixed or explicitly accepted before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes directly address issue #13845 by pacing held direction-key repeats, preventing stale or failed sends, and improving option-list navigation under host latency. The description correctly lim…
Out of Scope Changes check ✅ Passed The implementation and tests stay within terminal accessory repeat delivery, stale-target protection, send-result propagation, and related regression coverage. No unrelated product, persistence, proto…
Title check ✅ Passed The title clearly identifies the main fix: stopping held mobile accessory-key repeats after release under host latency.
Description check ✅ Passed The description provides a clear ELI5 explanation, change summary, rationale, scope, reliability contract, linked issue reference, visual evidence, and detailed validation results. It is sufficiently …
Full details: Linked Issues check

Explanation

The changes directly address issue #13845 by pacing held direction-key repeats, preventing stale or failed sends, and improving option-list navigation under host latency. The description correctly limits this PR to held-repeat reliability and leaves ordinary single-tap lag for separate investigation.

Full details: Out of Scope Changes check

Explanation

The implementation and tests stay within terminal accessory repeat delivery, stale-target protection, send-result propagation, and related regression coverage. No unrelated product, persistence, protocol, dependency, or platform changes are present.

Full details: Description check

Explanation

The description provides a clear ELI5 explanation, change summary, rationale, scope, reliability contract, linked issue reference, visual evidence, and detailed validation results. It is sufficiently complete despite not reproducing every template heading or checklist item.

  • Fix all pre-merge checks with AI
✨ 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: 8548b08e-f4ba-4942-9b7d-12854271bade

📥 Commits

Reviewing files that changed from the base of the PR and between 9a10561 and 89299be.

📒 Files selected for processing (5)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/terminal/terminal-accessory-repeat.test.ts
  • mobile/src/terminal/terminal-accessory-repeat.ts
  • mobile/src/terminal/terminal-live-accessory-raw-send.test.ts
  • mobile/src/terminal/terminal-live-accessory-raw-send.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Addressed both review findings on the latest main: held repeats are pinned to the press-time terminal, and fulfilled RPC failures now stop repetition. Added fail-before-fix regressions, reran the real paired Claude Code /model picker (stable for 2.292 s after release), and verified 10 focused tests plus the 469-file mobile suite, typecheck, lint, and formatting.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@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: 06a830f0-80d2-4225-9250-30509ff75c53

📥 Commits

Reviewing files that changed from the base of the PR and between 3179a57 and 1bde6c6.

📒 Files selected for processing (5)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/terminal/terminal-accessory-repeat.test.ts
  • mobile/src/terminal/terminal-accessory-repeat.ts
  • mobile/src/terminal/terminal-live-accessory-raw-send.test.ts
  • mobile/src/terminal/terminal-live-accessory-raw-send.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • mobile/src/terminal/terminal-live-accessory-raw-send.ts
  • mobile/app/h/[hostId]/session/[worktreeId].tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

@brennanb2025

brennanb2025 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Final review status for df9a4a236ee16bfef264f80a5d8a690965122e75: review-clean and CI-green.

ELI5: what changes for the user?

Before: If a user pressed and held an on-screen arrow, mobile could generate repeat commands faster than the host handled them. The commands could pile up, make a picker overshoot, and keep moving briefly after the finger was lifted.

After: A held arrow waits for each repeat to finish before generating the next one. Releasing it prevents future repeats from being scheduled, so the picker should stop instead of draining a backlog.

Ordinary quick taps: Each separate tap now dispatches immediately and is not held behind an earlier network acknowledgement. This prevents this PR from making ordinary tap latency worse, but it does not identify or fix the original single-tap lag reported in STA-3919 / #13845. That issue remains open.

Final status

  • Read the existing PR conversation first and did not duplicate resolved review work.
  • Integrated current main through f27ea956f2 before the final exact-head review.
  • Opening readiness found one P1: the prior implementation serialized distinct taps behind RPC acknowledgements. The fix removed cross-press serialization while retaining response pacing only for repeats within one held press.
  • Same-model review/fix/re-review loop is clean. Final readiness passed with no P0/P1/P2 findings.
  • Exact-head local validation passed: 90 focused tests across six files, mobile TypeScript, changed-file Oxlint, Oxfmt, and git diff --check.
  • Required GitHub checks are green at the pushed head.
  • Existing paired-iOS evidence remains useful for the held-release behavior. A fresh exact-head native run was attempted through the required Grok orchestration and Orca-emulator path, but the worker stalled before execution; no fallback interaction method was used and no misleading fresh screenshot was added.
  • The PR title/body now frame this as a separate held-accessory-repeat reliability fix and no longer claim to close Mobile: Claude Code option picker direction-key navigation is severely laggy #13845.

Recommendation: mergeable as the separate held-repeat reliability fix described above; do not treat this merge as resolving STA-3919 / #13845.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@brennanb2025 brennanb2025 changed the title fix(mobile): keep accessory key repeats responsive under latency fix(mobile): stop held accessory keys after release under latency Aug 27, 2026

@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: 9ec2d2b7-28fa-4d93-9738-1f2a6063afb9

📥 Commits

Reviewing files that changed from the base of the PR and between f27ea95 and df9a4a2.

📒 Files selected for processing (10)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/terminal/terminal-accessory-repeat.test.ts
  • mobile/src/terminal/terminal-accessory-repeat.ts
  • mobile/src/terminal/terminal-live-accessory-raw-send.test.ts
  • mobile/src/terminal/terminal-live-accessory-raw-send.ts
  • mobile/src/terminal/use-terminal-live-accessory-input-commit.test.ts
  • mobile/src/terminal/use-terminal-live-accessory-input-commit.ts
  • mobile/src/terminal/use-terminal-live-input-commit.test.ts
  • mobile/src/terminal/use-terminal-live-input-commit.ts
  • mobile/src/terminal/use-terminal-live-pending-input-flush.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • mobile/src/terminal/terminal-live-accessory-raw-send.ts
  • mobile/src/terminal/terminal-accessory-repeat.ts
  • mobile/src/terminal/terminal-live-accessory-raw-send.test.ts
  • mobile/app/h/[hostId]/session/[worktreeId].tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment on lines +160 to +161
(handle: string, fieldText: string, composing?: boolean): Promise<boolean> =>
runMirrorStep(handle, fieldText, false, composing),

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

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n -C 12 'queueTerminalLiveMirrorSend|handleLiveInputAccessoryBytes|suppress-raw' mobile/src mobile/app

Repository: stablyai/orca

Length of output: 49033


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- review conventions ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print \
  | while read -r f; do
      case "$f" in
        */learnings/*) ;;
        *) printf '%s\n' "--- $f"; cat "$f" ;;
      esac
    done

printf '%s\n' '--- changed hook and directly bound helpers ---'
cat -n mobile/src/terminal/use-terminal-live-pending-input-flush.ts | sed -n '24,170p'
cat -n mobile/src/terminal/terminal-live-pending-flush-state.ts | sed -n '1,145p'

Repository: stablyai/orca

Length of output: 17107


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- remaining flush paths and mirror computation ---'
cat -n mobile/src/terminal/use-terminal-live-pending-input-flush.ts | sed -n '159,245p'
cat -n mobile/src/terminal/terminal-live-preedit-mirror.ts | sed -n '1,220p'

printf '%s\n' '--- sender binding and failure handling ---'
rg -n -C 10 'sendLiveTerminalInputRef|sendLiveTerminalInput|sendQueuedMirrorPayload|sendTerminalLiveAccessoryRawBytes' mobile/src mobile/app

Repository: stablyai/orca

Length of output: 50369


Rebase the mirror baseline when a send fails.

When queueTerminalLiveMirrorSend returns false, sentLiveInputTextRef still contains the optimistic text. The suppress-raw branch does not reset it. A failed Backspace followed by new input can therefore leave stale text in the PTY, such as a, failed DEL, then b producing ab. Invalidate the baseline and force resynchronization before accepting later edits. Add a regression for this sequence.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Follow-up after the final rereview and fresh QA attempt at exact head df9a4a2:

Scope clarification

This is not an up/down-only special case. The same controller covers all six built-in repeatable accessory keys: Backspace, Delete, Up, Down, Left, and Right. Non-repeatable/custom keys cannot create the timer-generated held-repeat backlog, and any future built-in marked repeatable automatically uses this path.

Separate taps dispatch immediately and independently. Only repeats generated during one continuous hold are acknowledgement-paced, which prevents backlog, overshoot, and movement after release under latency.

Relationship to #13845

A second code-path review found that ordinary taps were already dispatched concurrently before this PR. The terminal.send acknowledgement is also not on the tap-to-first-visible-output critical path: the host writes to the PTY before replying, while terminal output returns independently.

So this PR fixes a real held-repeat reliability problem, but it does not establish the root cause of #13845's reported one-tap lag. That report is currently not reproducible, and host load, network/relay latency, TUI redraw time, or phone rendering are all still plausible without enough evidence to rank them. The senior next step for #13845 is one native reproduction with content-free timestamps across press, socket send, host PTY write, first PTY output, phone receive, WebView post, and xterm paint—not another speculative production patch.

Current validation status

  • Exact-head same-model rereview is clean; closing readiness found no P0/P1/P2 issues.
  • 58 focused tests passed, along with mobile TypeScript, changed-file lint, formatting, and git diff checks.
  • Required GitHub checks are green and the PR is merge-clean.
  • A fresh exact-head Grok run verified the isolated Electron instance identity, but its native mobile result was rejected after it left the required Orca-emulator-only interaction path. The worker was stopped, its exact terminals/processes were cleaned up, no fallback evidence was accepted, and no new screenshot is attached. Fresh native timing therefore remains blocked; the earlier paired-iOS evidence is historical only.

One integration guardrail for follow-up work: any future fire-and-forget accessory transport must keep timer-generated repeats acknowledgement-paced, or it will recreate the open-loop backlog fixed here.

Status: mergeable as the separate held-repeat reliability fix above. Do not close #13845 based on this PR.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Fresh Grok retry addendum at exact head df9a4a236ee16bfef264f80a5d8a690965122e75 — this corrects the earlier note that no fresh native result was available.

What the clean retry verified

  • Grok stayed within the required interaction boundary: Playwright CDP for Electron and orca emulator for all mobile interaction. No simctl, raw WebSocket input, desktop automation, or fallback interaction path was used.
  • Electron identity matched this exact worktree.
  • The current-worktree Metro bundle reached the real mobile Host 4 → main → Terminal 1 accessory UI.
  • Two rapid, separate Tab taps dispatched immediately. The cursor moved two tab stops with no delayed extra input. This supports the distinct-tap no-regression claim; Tab is non-repeatable, so this is not evidence for the held-repeat controller itself.

Before:

Terminal 1 before distinct taps

After two rapid Tab taps:

Terminal 1 after two distinct Tab taps

What remains unverified

Fresh native held-repeat proof is still blocked. Backspace was present in AX at x=0.9621, width=0.0818, giving a geometric center of x=1.003 outside the screen. The visible >> control is the live-input mode toggle, not an accessory pager, and tapping the right-edge overflow affordance did not expose Backspace. Frames from attempted edge holds that left Terminal 1 were rejected and are not attached.

Therefore this retry does not claim a fresh on-device pass for acknowledgement-paced repeats or the two-second post-release freeze. The deterministic repeat-controller tests and earlier paired-iOS evidence remain the support for that behavior.

No source or PR code changed during this retry. The pre-existing mobile/pnpm-lock.yaml working-tree blob remained d34739b64793cbe762c2f43b9d81eaa294e9038f.

Status remains: review-clean and required checks green; merge only as the separate held-accessory-repeat reliability fix. Do not treat it as resolving the unreproduced ordinary-tap lag in #13845.

@brennanb2025
brennanb2025 merged commit 4f14d6d into main Aug 28, 2026
18 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 30, 2026
…ablyai#14219)

* fix(mobile): backpressure accessory key repeats

* fix(mobile): keep accessory repeats on the pressed terminal

* fix(mobile): serialize accessory key presses

* fix(mobile): preserve queued accessory taps

* fix(mobile): fence queued taps across reconnects

* fix(mobile): recheck queued tap delivery context

* fix(mobile): stop accessory repeats after IME send failure

* fix(mobile): pace repeated live-input edits

* fix(mobile): dispatch accessory taps without ack delay

(cherry picked from commit 4f14d6d)
Jinwoo-H pushed a commit that referenced this pull request Sep 2, 2026
Rebuild app/h/[hostId]/session/[worktreeId].tsx as a 10-line route over
MobileSessionSurface + useMobileSessionController, restoring the 44 split
modules main deleted on this branch and re-applying the hybrid
operations-injection delta onto them.

Three behaviors main's own split had silently dropped are kept from the
branch instead: the accessory hold-to-repeat controller (#14219), the
relay-recovery input to classifyConnection, and the live MobileMarkdownReader
/ MobileDiffCommentLineRow components (main's split forked stale copies).

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ablyai#14219)

* fix(mobile): backpressure accessory key repeats

* fix(mobile): keep accessory repeats on the pressed terminal

* fix(mobile): serialize accessory key presses

* fix(mobile): preserve queued accessory taps

* fix(mobile): fence queued taps across reconnects

* fix(mobile): recheck queued tap delivery context

* fix(mobile): stop accessory repeats after IME send failure

* fix(mobile): pace repeated live-input edits

* fix(mobile): dispatch accessory taps without ack delay
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