Skip to content

fix(mobile): re-fit terminal PTY when the frame height settles - #8647

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/mobile-terminal-bottom-bar
Jul 14, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/mobile-terminal-bottom-bar

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Ref #7350 — candidate fix. Could not reproduce in the emulator (timing-dependent), so this intentionally does not auto-close the issue: it needs confirmation on a real device / next TestFlight before closing.

Problem

On mobile, starting a Claude/Codex agent in a terminal renders the agent's input box behind the accessory / live-input bar — you can't see what you're typing. Leaving and re-entering the workspace fixes it (temporarily).

Root cause

The mobile terminal fits the PTY to rows = floor(frameHeight / cellHeight) with no bottom margin — by design the accessory/live-input dock sits below the terminal frame (terminal-webview-html.ts). But a freshly-created agent terminal fits before that dock has laid out, so the frame is briefly too tall and the PTY gets too many rows. Claude/Codex pin their input box to the bottom of the grid, so those extra bottom rows — the input box + status lines — render behind the dock.

The refit hook then re-fit only on width changes and deliberately ignored height-only changes, so the over-fit was never corrected. Leaving and re-entering worked around it because re-entry re-subscribes → re-measures against the now-settled layout.

Fix

Track the measured terminal-frame height and re-fit the PTY when it changes, mirroring the existing width path:

  • session/[worktreeId].tsx — add terminalFrameHeight state, set it in the frame's onLayout, pass it to useTerminalViewportRefit.
  • terminal-viewport-refit.ts — add a height-change effect that marks the viewport un-measured and re-fits (mirror of the width effect).

This makes the terminal self-correct when the dock settles — automatically doing what the manual leave/return did.

Why it's safe: Expo SDK 55's edge-to-edge IME overlays instead of resizing (see the keyboardHeight comment), so the frame height does not change on keyboard open/close on iOS or Android → the PTY is never reflowed while typing. The refit's existing row-count guard makes a height change that doesn't change the row count a no-op, so settled/jitter layouts don't churn the server PTY.

Testing

  • Added a behavioral test for the extracted decision helper (shouldRefitOnFrameHeightChange) — height transition, same-value no-op, and keyboard-open skip — plus structural tests for the wiring.
  • vitest run src/terminal src/session → 700 passed; tsc --noEmit clean; oxlint clean.
  • Emulator run (iOS Simulator, this branch, stable local host): app is stable and a freshly-created Claude terminal renders its input box correctly above the bar — no regression observed. But I could not reproduce the original bug in the emulator: the input renders correctly with and without the fix. This is a layout-timing race (the terminal's first fit vs. the accessory/live-input dock laying out) that the fast local simulator doesn't lose — matching the reporter's intermittent, "restart fixes it" report on TestFlight over a real/remote connection.
  • ⚠️ Not conclusively verified against the live bug. The fix is justified by root-cause analysis + the reporter's signature + tests, and is low-risk (only adds a guarded refit that can't regress the passing case: a row-count no-op when rows are unchanged, and a keyboard guard so it never reflows the PTY while typing). Authoritative check = a real device / next TestFlight: create a fresh Claude terminal and confirm the input box sits above the bar on first entry.

A freshly-created agent terminal fits its PTY to rows = floor(frameHeight
/ cellHeight) before the accessory/live-input dock has laid out, so the
frame is briefly too tall and the PTY gets too many rows. Claude/Codex
pin their input box to the bottom of the grid, so those extra bottom rows
— the input box and status lines — render behind the dock and you can't
see what you're typing. Leaving and re-entering the workspace worked
around it by re-measuring against the settled layout.

The refit hook previously re-fit only on width changes and deliberately
ignored height-only changes, so the over-fit was never corrected. Track
the measured frame height and re-fit on its change too, mirroring the
width path. Safe because Expo SDK 55's edge-to-edge IME overlays instead
of resizing, so the frame height doesn't change on keyboard toggle and
the PTY is never reflowed while typing; the refit's row-count guard makes
sub-row jitter a no-op.
@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The mobile session screen now tracks terminal frame height alongside width and passes both measurements and keyboard visibility to the terminal viewport refit hook. The hook detects non-keyboard height changes, invalidates the cached viewport measurement, and schedules a PTY refit. Tests cover the height decision logic, hook wiring, and session screen measurement updates.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary and testing, but it misses required template sections like Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections with screenshots or "No visual change", AI review details, security audit notes, and any platform-specific follow-up.
✅ 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 clearly summarizes the main change: refitting the mobile terminal PTY when the frame height settles.
✨ 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.

Address review on #8647:
- Extract shouldRefitOnFrameHeightChange (pure) and gate the height refit on
  keyboard-visible, so an IME that resizes the window (Android adjustResize)
  can never reflow the PTY while typing — no longer relies on the edge-to-edge
  no-resize assumption alone.
- Add a behavioral test for the decision helper (height transition, same-value
  no-op, keyboard-open skip) instead of only source-string assertions.
- Trim the added comments to 1-2 lines per AGENTS.md.
@brennanb2025
brennanb2025 merged commit e04ca97 into main Jul 14, 2026
2 checks passed
brennanb2025 added a commit that referenced this pull request Jul 14, 2026
* fix(mobile): harden terminal height refit (follow-up to #8647)

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.

* 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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…yai#8647)

* fix(mobile): re-fit terminal PTY when the frame height settles

A freshly-created agent terminal fits its PTY to rows = floor(frameHeight
/ cellHeight) before the accessory/live-input dock has laid out, so the
frame is briefly too tall and the PTY gets too many rows. Claude/Codex
pin their input box to the bottom of the grid, so those extra bottom rows
— the input box and status lines — render behind the dock and you can't
see what you're typing. Leaving and re-entering the workspace worked
around it by re-measuring against the settled layout.

The refit hook previously re-fit only on width changes and deliberately
ignored height-only changes, so the over-fit was never corrected. Track
the measured frame height and re-fit on its change too, mirroring the
width path. Safe because Expo SDK 55's edge-to-edge IME overlays instead
of resizing, so the frame height doesn't change on keyboard toggle and
the PTY is never reflowed while typing; the refit's row-count guard makes
sub-row jitter a no-op.

* fix(mobile): guard height refit against IME resize; test the decision

Address review on stablyai#8647:
- Extract shouldRefitOnFrameHeightChange (pure) and gate the height refit on
  keyboard-visible, so an IME that resizes the window (Android adjustResize)
  can never reflow the PTY while typing — no longer relies on the edge-to-edge
  no-resize assumption alone.
- Add a behavioral test for the decision helper (height transition, same-value
  no-op, keyboard-open skip) instead of only source-string assertions.
- Trim the added comments to 1-2 lines per AGENTS.md.
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