Skip to content

fix(mobile): stop held terminal keys when you switch terminals or leave the app - #31712

Merged
AmoabaKelvin merged 7 commits into
stablyai:mainfrom
nwparker:nwparker/mobile-monkey-accessory-repeat-lifecycle
Oct 28, 2026
Merged

AmoabaKelvin merged 7 commits into
stablyai:mainfrom
nwparker:nwparker/mobile-monkey-accessory-repeat-lifecycle

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​339 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​333
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88 $\color{#cf222e}{\Huge{\mathbf{−}}}$​38 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​50

ELI5

Hold a repeating terminal key, such as an arrow, then switch terminals or leave the app. The repeats can keep going or reach the wrong terminal. This fix stops the hold when its terminal or connection changes, and waits for the computer to accept one repeat before sending the next.

What Changed

  • Use the existing key-repeat controller instead of starting separate repeating timers.
  • Stop repeats when the terminal changes, the app loses focus, or it goes into the background.
  • Keep a slow connection from building up a queue of repeated keys.
  • Stop the hold when the key bar itself unmounts (an unmounting button never reports the finger lifting), and send each repeat through the current live-input mode so turning live input on mid-hold is respected.

Why

A key you held in one terminal should not keep acting after you move somewhere else.

Linked Issue

Maintainer-discovered regression. Bounded GitHub symptom and exact-file searches found no exact duplicate. Restores the pinned, acknowledgement-paced controller introduced in merged #14219 after the extracted selection hook stopped using it.

Visual Proof

Captured with the visual-proof skill. Before uses base 15246eb4a45; after uses this PR's standalone commit 514d883f824. The scenario passed asserted capture runs 3 times per version before representative screenshots were selected. The captures were visually inspected.

Evidence scope: production-hook harness. Explicitly labeled custom HTML rendering of real hook output with deterministic transport; not the native app or production terminal renderer. Captures hold across terminal switch with real accessory/send hooks; no native IME, touch, focus or AppState claim.

01-before.png 02-after.png
01-before.png 02-after.png

The hook/transport boundary harnesses are labeled in the captures. These are browser evidence where stated; they do not establish native keyboard, gesture, permission dialog, safe-area or real-network behavior. Full code regressions cover additional cases described above.

Testing

The combined review checkout aa6fe5dae109 contains this PR at 0ed9b095dd0d and the other mobile PRs reviewed together. Validation ran with ORCA_BACKGROUND_LAUNCH=1 on macOS.

  • Full mobile run: 11,493 passed, 2 failed, 6 skipped. Both failures were recording checks for the intentional new uncertain-paste warning. After updating only that golden, the affected two recording suites passed 1,197 tests, including both previously failing checks. This accounts for all 11,495 non-skipped tests; it is not a claim of a second clean full-suite invocation.
  • Production mobile typecheck and the test-typecheck ratchet passed (1,111 test files; 116 grandfathered).
  • Changed-code quality gate passed with zero new findings across eight code files, including React Doctor and design-system checks. Follow-up code formatting and lint checks passed.
  • Mobile web build and packaged asset verification passed. The package manager warned that its pre-script dependency refresh could not replace the shared node_modules symlink; the build and both asset verifiers nevertheless completed successfully.

An earlier attempt using the shared checkout’s newer Vitest crashed. The reported full run and recording recheck used the mobile package’s pinned Vitest 4.1.12 with four workers. These are combined-checkout results; separate CI must validate each PR against current main. Native-device coverage remains limited as described in Visual Proof and Review.

AI Disclosure

Risk-reduction checks

Second pass: Rechecked the actual repeat controller, slow-send backpressure, terminal replacement, app backgrounding, and refusal/disconnect recovery. No additional reproducible defect found in this pass.

Current PR head: 0ed9b095dd0d. Combined review head: aa6fe5dae109.

Carry-over (2026-10-28): rebased onto current main. The web held-press render check now expects the key bar's press to start the repeat controller without sending on its own, since the controller owns the first send. A second finger switching terminals mid-hold changes the active terminal, which cancels the hold and fails every later send's ownership check, so it is covered rather than a separate bug.

Review

Merge risk: Medium. Native held-touch and keyboard/IME lifecycle behavior still need device testing.

Previously reviewed by a separate agent team; this pass traced the production paths again and added failing-before regressions for the three newly reproduced defects.

Agent skill upstream boundary

  • Not applicable; this change copies no upstream skill-installer implementation.

Notes

Existing RPC methods and wire compatibility are retained. Review considered desktop host changes, remote execution authority, folder workspaces, and native/web consumers. Native simulator follow-up was limited after the three owned simulators became stuck shutting down; no unrelated simulator/process was reset.

Checklist

  • Focused change with a root-cause explanation.
  • Automated regression coverage and independent review.
  • Before/after proof attached with exact evidence scope.
  • Cross-platform and remote compatibility considered.
  • Required PR CI checks have passed.

@nwparker nwparker changed the title fix(mobile): restore lifecycle-safe terminal accessory repeat fix(mobile): stop held terminal keys when you switch terminals or leave the app Oct 22, 2026
@AmoabaKelvin
AmoabaKelvin force-pushed the nwparker/mobile-monkey-accessory-repeat-lifecycle branch from 0ed9b09 to b357506 Compare October 28, 2026 17:30
@AmoabaKelvin
AmoabaKelvin marked this pull request as ready for review October 28, 2026 19:42
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The accessory selection hook now uses a repeat controller and cancels active repetition when focus, app state, session ownership, connection, worktree, or terminal-root attachment changes. Accessory-key delivery checks client and target ownership, send permission, and delivery freshness, then returns a boolean result. Repeatable built-in keys start repetition without an immediate input and stop repetition when the component unmounts. New tests cover lifecycle cutovers, send outcomes, and held-press behavior.

Priority: Normal

Merge Risk: Low · up to 8167a

A held key can send unintended input after release on a slow connection; invalidate pending delivery before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: stopping held terminal keys when the terminal changes or the app loses focus.
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.
Description check Passed The description is complete and specific. It covers the user impact, implementation, rationale, testing results, visual evidence, risks, compatibility, and checklist status. The Linked Issue field has…
Full details: Description check

Explanation

The description is complete and specific. It covers the user impact, implementation, rationale, testing results, visual evidence, risks, compatibility, and checklist status. The Linked Issue field has no issue number, but the author identifies this as a maintainer-discovered regression, which matches the template's maintainer exception. The AI Disclosure section is empty, which is also permitted for internal contributors.

Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 7 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@AmoabaKelvin
AmoabaKelvin force-pushed the nwparker/mobile-monkey-accessory-repeat-lifecycle branch from e5f4e2a to 8167a5c Compare October 28, 2026 22:04
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found.

Summary

Replaces separate repeat timers with the existing controller.

  • Held accessory keys stay with their original terminal and stop when its context changes.

No actionable issues were found. This review checked code paths; it did not run tests or verify native touch behavior.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Key pressed] --> B[Capture terminal and connection]
  B --> C{Owner still current?}
  C -->|No| G[Stop]
  C -->|Yes| D[Apply live edit or send key]
  D --> E{Accepted and hold still active?}
  E -->|Yes| F[Wait before next repeat]
  F --> C
  E -->|No| G
  H[Release, blur, background, or owner change] --> G
Loading

Reviews (1) · Last reviewed commit: "test(mobile): pin the key bar's held pre..." · Reviewed by Greptile

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

⚠️ Outside diff range comments (1)

Minor · Invalidate the repeat on release and unmount. · use-mobile-session-accessory-selection.ts:68-72

mobile/src/session/use-mobile-session-accessory-selection.ts:68-72
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Invalidate the repeat on release and unmount.

startAccessoryRepeat() sends immediately and waits for the asynchronous live-input preflight. stopAccessoryRepeat() only advances the repeat generation, so it does not invalidate that in-flight preflight. After release or accessory-strip unmount, the preflight can still pass the unchanged owner-revision predicate and call sendTerminalLiveAccessoryRawBytes(...). This can send one terminal byte after the user releases the key or after its owning component disappears.

Make stopAccessoryRepeat() use the owner-invalidating cancellation path. Both onPressOut and the unmount effect already call this callback.

Suggested fix
-  const stopAccessoryRepeat = useCallback(() => accessoryRepeat.stop(), [accessoryRepeat])
-  const cancelAccessoryRepeat = useCallback(() => {
+  const stopAccessoryRepeat = useCallback(() => {
     repeatOwnerRevisionRef.current += 1
     accessoryRepeat.cancel()
   }, [accessoryRepeat])
+  const cancelAccessoryRepeat = stopAccessoryRepeat

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 926d7788-ca87-4a64-8fac-66f5524d60cc
Commits

Reviewing files that changed from the base of the PR and between e5f4e2a and 8167a5c.

Files selected for processing: 1
  • config/scripts/mobile-web-app/mobile-web-app-held-press-render.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@AmoabaKelvin
AmoabaKelvin merged commit 6434414 into stablyai:main Oct 28, 2026
38 checks passed
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.

2 participants