Skip to content

fix(mobile): harden terminal height refit (follow-up to #8647) - #8707

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/terminal-refit-followup
Jul 14, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/terminal-refit-followup

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #8647 (already merged) addressing two concrete risks + a perf issue raised in review. Client-only — no server schema or subscription-protocol changes, so desktop-first stays compatible.

Changes

1. Defer keyboard-visible height refits, and re-check at fire time (correctness). #8647 skipped a height change while the keyboard was visible and never re-fired it — on iOS the edge-to-edge keyboard doesn't change the frame height on close, so an over-fit that settled with the keyboard up could survive. A pure reducer (reduceTerminalFrameHeightRefit) now marks such changes pending and applies one correction when the keyboard closes. That correction is debounced 150 ms, so the reducer is re-consulted when the timer actually fires (refit-committed): if the keyboard reopened inside the debounce window it re-defers instead of reflowing mid-keystroke, and runs on the next close. Scoped via a height-originated flag so width/rotation and the forced reconnect/foreground re-asserts stay unguarded and always run.

2. Height layout callbacks no longer re-render SessionScreen (perf). Height now dispatches imperatively via notifyTerminalFrameHeight(...) instead of setTerminalFrameHeight state, so height-only layout bursts stay off React's render path for the ~5k-line SessionScreen. (Width stays on state — it changes rarely.)

3. Cache the updateViewport capability (efficiency + desktop-first compat). #8647 increased refit frequency; on an old desktop that returns method_not_found, each refit meant another failed probe before the legacy-resubscribe fallback. updateViewportCapabilityRef now records unsupported (narrow method_not_found-only predicate) so an old desktop probes once then goes straight to legacy resubscribe. Reconnect resets it so an in-place desktop upgrade is re-detected — mirroring the repo's GitCapabilityCache pattern. The cache is a hook-local ref, so "one probe" is per mounted session / reconnect epoch, not process-global.

Testing

  • vitest run src/terminal src/session → 705 passed; tsc --noEmit clean; oxlint + formatting clean.
  • Coverage is pure-reducer + source-assertion, not a mounted-hook render (the hook imports react-native, which is why this whole suite avoids mounting). The reducer tests exercise the keyboard-visible coalescing and the reopen-during-debounce re-defer (refit-committed); source assertions verify the imperative notify path, the fire-time re-check scoped to height refits, and that height no longer routes through setState. The "zero refits while typing / zero re-render / one probe per epoch" behavior follows from those decisions — it is not proven by an end-to-end timer/RPC test.

Ref #7350 — the base fix (#8647) targets this and is still pending on-device confirmation; this PR hardens the same path.

Addresses review feedback on #8647:

- Defer height refits while the keyboard is visible and coalesce every
  skipped layout change into one correction after the keyboard closes,
  via a pure reducer. Prevents an over-fit that settles with the keyboard
  up from surviving (on iOS the edge-to-edge keyboard doesn't change the
  frame height on close, so there was no later event to re-trigger it).
- Drive height layout callbacks imperatively (notifyTerminalFrameHeight)
  instead of setState, so height-only layout bursts no longer re-render
  SessionScreen.
- Cache the updateViewport capability (method_not_found -> unsupported):
  old desktops now get one unsupported probe then legacy resubscribe,
  instead of one probe per refit. Reconnect resets the cache so an
  upgraded desktop is re-detected.

No server schema or subscription-protocol changes; desktop-first stays
compatible.

Tests: 703 mobile terminal/session pass; tsc, oxlint, formatting clean.
@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The terminal viewport refit flow now uses imperative frame-height and keyboard-visibility notifications instead of local session state and refs. A reducer tracks keyboard-aware refit state and coalesces deferred frame-height changes. Window resize handling skips height-only refits while the keyboard is visible. The hook caches terminal.updateViewport capability responses, falls back to resubscription for unsupported desktops, and rechecks capability after reconnects. Tests cover reducer behavior, session wiring, resize deferral, and fallback ordering.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers changes and testing, but it omits most required template sections like Screenshots, AI Review Report, Security Audit, and Notes. Reformat the PR description to include Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes, and mention cross-platform review coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title matches the PR's main change: hardening mobile terminal height refit behavior.
✨ 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.

Close a race in the keyboard-deferral: a height refit deferred at
keyboard-close arms a 150ms debounce timer, and if the keyboard reopens
inside that window the timer still fired and reflowed the PTY mid-keystroke.

The timer callback now re-consults the reducer (new `refit-committed`
event) when the armed refit is height-originated: if the keyboard is
visible again it re-defers (pending) instead of reflowing, and runs on the
next keyboard close. Scoped via a height-originated flag so width/rotation
and the forced reconnect/foreground re-asserts stay unguarded and always run.

Tests: reducer coverage for the reopen-during-debounce re-defer + a wiring
assertion; 705 mobile terminal/session pass; tsc, oxlint clean.
@brennanb2025
brennanb2025 merged commit 8e17e75 into main Jul 14, 2026
2 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/terminal-refit-followup branch July 14, 2026 09:52
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
stablyai#8707)

* fix(mobile): harden terminal height refit (follow-up to stablyai#8647)

Addresses review feedback on stablyai#8647:

- Defer height refits while the keyboard is visible and coalesce every
  skipped layout change into one correction after the keyboard closes,
  via a pure reducer. Prevents an over-fit that settles with the keyboard
  up from surviving (on iOS the edge-to-edge keyboard doesn't change the
  frame height on close, so there was no later event to re-trigger it).
- Drive height layout callbacks imperatively (notifyTerminalFrameHeight)
  instead of setState, so height-only layout bursts no longer re-render
  SessionScreen.
- Cache the updateViewport capability (method_not_found -> unsupported):
  old desktops now get one unsupported probe then legacy resubscribe,
  instead of one probe per refit. Reconnect resets the cache so an
  upgraded desktop is re-detected.

No server schema or subscription-protocol changes; desktop-first stays
compatible.

Tests: 703 mobile terminal/session pass; tsc, oxlint, formatting clean.

* fix(mobile): re-check keyboard when a deferred height refit fires

Close a race in the keyboard-deferral: a height refit deferred at
keyboard-close arms a 150ms debounce timer, and if the keyboard reopens
inside that window the timer still fired and reflowed the PTY mid-keystroke.

The timer callback now re-consults the reducer (new `refit-committed`
event) when the armed refit is height-originated: if the keyboard is
visible again it re-defers (pending) instead of reflowing, and runs on the
next keyboard close. Scoped via a height-originated flag so width/rotation
and the forced reconnect/foreground re-asserts stay unguarded and always run.

Tests: reducer coverage for the reopen-during-debounce re-defer + a wiring
assertion; 705 mobile terminal/session pass; tsc, oxlint clean.
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