Skip to content

fix(mobile): stabilize terminal startup and Android window rendering - #20489

Closed
kargnas wants to merge 4 commits into
stablyai:mainfrom
kargnas:codex/mobile-terminal-rendering
Closed

kargnas wants to merge 4 commits into
stablyai:mainfrom
kargnas:codex/mobile-terminal-rendering

Conversation

@kargnas

@kargnas kargnas commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

On Android, Orca could miss the terminal's startup signal, freeze while parsing a large burst of output, or keep drawing into the old phone-sized area after a Fold/freeform-window resize. This change makes startup recoverable, feeds large output to xterm in bounded slices, and sizes the UI from the Activity's actual window.

What Changed

  • Terminal readiness (use-terminal-webview-controller.ts, shared by the native WebView and the page):
    • After the native WebView finishes loading (onLoadEnd), the controller sends one readiness ping, unless the document is already ready or a ping is already waiting for an answer. A missed web-ready no longer leaves the pane stuck until the 15 s watchdog reports no ready signal.
    • A pong counts as ready only when it reports terminalAvailable: true. The document fills that flag from its existing hasEngine() seam, so a document whose xterm script failed to load is not treated as ready.
    • Every web-ready still reaches the session, exactly as on main, so the session resubscribes whenever a new document announces itself. A pong announces the document only when nothing has announced it yet, which is the case of the post-load ping standing in for a dropped web-ready. A foreground-recovery pong for a document that was already announced stays silent, as it does on main. resetReadiness() clears that record for the next document.
    • The error overlay's Reload button now calls resetReadiness() before reload(), as the page's Reload already did. The dead document's queued commands and readiness therefore do not carry over into the next document, even if onLoadStart does not fire.
  • Large output: document/write-queue.ts splits any write over 4,096 UTF-16 code units into ordered slices and never cuts a surrogate pair. Shorter writes are pushed unchanged. Both paths still receive the status-dot-normalized text.
  • Android windowing:
    • The android-desktop-mode Expo config plugin makes the Activity handle density and smallestScreenSize changes, marks it resizeable, and adds the Samsung multi-display metadata.
    • The plugin also keeps React Native's DisplayMetricsHolder on the Activity's display and re-emits didUpdateDimensions on configuration change and resume.
    • react-native-screens 4.24.0 is patched with the 4.26 per-view density conversion.
  • Measured window bounds: WindowBoundsProvider measures the root view. Responsive layout, both drawers, onboarding, file preview and the terminal refit read useWindowBounds() instead of useWindowDimensions(). The page mounts no provider, so there it returns React Native's window dimensions exactly as before.
  • Command dock: painted with the existing colors.bgPanel token, so the unfolded bottom area no longer shows the white root background.

Rebase onto current main

This PR was squashed to one commit and rebased onto main, which had moved 773 commits and rewritten the terminal WebView into typed document modules plus a shared controller. Every fix above was rebuilt inside that new structure. Scope was dropped where main now covers it or already does it:

  • Subscribing before the first measure: dropped. fix(mobile): a terminal opens once at the phone's size, on the page and natively (OTA phase C follow-up) #22960 took the opposite, deliberate approach: a fresh document opens an empty terminal, measures, then subscribes, so the phone paints once.
  • Watchdog generation counter: dropped. armWebReadyWatchdog already clears the previous timer and only one timer is ever live, so the counter guarded no reachable path.
  • Foreground-recovery probe rewrite: dropped. main already replaces an unanswered foreground ping on each attempt.
  • Clearing consumed write-queue slots: already on main. Only the slicing is new here.
  • Terminal payload hash and route-parity pins: main removed the payload hash test. The route-parity test passes without changes because no route JSX changes remain.

The announcement rule also changed during review. The earlier branch announced each document at most once, which also dropped a real repeated web-ready. Only the pong is checked now, as described above.

Why

web-ready is a one-shot bridge event and can arrive before React Native attaches its message callback. The watchdog then reported no ready signal even though the document had loaded. A ping sent after the load makes that state recoverable, and requiring the engine flag keeps a document whose xterm failed to load from passing as ready.

Only the pong needs the "already announced" check. The document posts web-ready once, at startup, straight to the bridge without buffering, so it can never arrive after that document's pong. A repeated web-ready therefore always means a new document, and the session relies on it to resubscribe, for example after a reload that skipped onLoadStart. Deduplicating web-ready itself would have lost that resubscribe.

Large PTY bursts and scrollback replays were each submitted to xterm.write() as a single parse job. Slicing only the oversized writes keeps ordering and write boundaries, and the queue waits for xterm's write callback between slices, so no single burst holds the WebView thread.

On Samsung Fold freeform windows and in DeX, React Native 0.83 can mix the phone's display density with the Activity's, and useWindowDimensions() may keep reporting the display instead of the resizable root. Two layers need fixing:

  • the native density sync and the react-native-screens backport fix the density;
  • the measured root bounds fix the layout.

Linked Issue

Refs #18841. Closed in favor of #25502, #25503 and #20198; see the closing comment.

Related: #8592 (issue), #16018, #20198 (both still open). The Android density and windowing part overlaps those PRs. Terminal readiness, output slicing and the command-dock background are independent fixes, verified in the same Fold7 reproduction.

Visual Proof

Before, on a physical Galaxy Z Fold7 in a freeform window, the terminal left an unpainted black region after the window was resized:

Fold7 freeform terminal before

After, on the pre-rebase build, repeated changes to the freeform window's width left the terminal filling the resized window with no black region. No After capture is attached, and the rebased commit has no capture of its own.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Device evidence, pre-rebase commit:

  • On a physical Galaxy Z Fold7, I resized the freeform window from about 620 px to 1000 px while running timezone-cat and Codex.
  • The terminal kept filling the available width, and the captured logs contained no no ready signal or measure-fail event.
    Device evidence, commit d071ce4a (the same code as 4444eabbfb, which was rebased onto main 21f8e0f; the only conflict was an import line in mounted-bottom-drawer.tsx, where main switched to hostOs()):
  • A release APK (arm64) was installed on a physical Galaxy Z Fold7 (SM-F966N, Android 16) next to the existing Orca app, under a separate application id, and paired with mobile/scripts/mock-server.ts over adb reverse. The phone was folded, so this ran on the cover screen.
  • The terminal painted on first open, and logcat had no no ready signal or measure-fail line.
  • With Orca in a pop-up (freeform) window, am task resize changed the window four times (620, 1000, 600 and 1080 px wide, with different heights). Three wm size changes of the whole display were done before that. Each time the terminal refilled the window and rewrapped to the new width with no unpainted region, and the phone re-subscribed the terminal after each change (7 terminal.subscribe calls in the mock log; the mock does not log their size parameters).
  • Not re-tested on this commit: the unfolded inner screen, DeX, a real desktop host, Fold8 and iOS. Before the device run, npx expo prebuild --platform android --no-install and ./gradlew --no-daemon :app:compileDebugKotlin also passed.

Automated checks on this rebased commit:

  • After the rebase onto main 21f8e0f: mobile tsc --noEmit, check:tests-typecheck, the full mobile test suite, and the four mobile web closure suites (20 tests) pass. Ten suites first hit the 5 s timeout while the machine was heavily loaded; eight passed on a plain rerun and the other two with a longer timeout.
  • After the rebase onto main 31012ae (commit 7c705d4c7f): upstream's test: remove junk tests that assert source text instead of behavior #23815/test: remove assertion-free probes, copied inventories and export-shape checks #23816 junk-test cleanup deleted the source-text assertions this PR had updated (terminal-viewport-refit.test.ts, terminal-webview-text-zoom.test.ts), so the resolution keeps main's side there; _layout.tsx needed only the import block kept on both sides. Mobile tsc --noEmit, check:tests-typecheck, pnpm test (9659 passed, 6 skipped), and check:code-quality:changed pass.
  • After the greptile review fix (eb034f2e94): the document's pong now carries the same cellBox web-ready sends, and the controller stores it before announcing readiness, so a subscribe recovered through the post-load ping is viewport-fitted like the normal path. host-seams.test.ts pins the box on the wire and terminal-webview-cell-box.test.ts pins fitDimensions after a pong. Mobile tsc --noEmit, check:tests-typecheck, the terminal and session suites (259 files, 2492 tests), and check:code-quality:changed pass.
  • After afce2f8c2e: terminal-viewport-refit.ts was already at the mobile max-lines budget (300 lines, blanks and comments excluded), so this PR's one extra import failed oxlint. The iOS-resume and reconnect refit effects, which neither this PR nor feat(mobile): add Android opt-in to resize the terminal for the keyboard #23419 changes, moved unchanged into terminal-viewport-reassertion.ts; feat(mobile): add Android opt-in to resize the terminal for the keyboard #23419 adds the identical file. With the branch merged into current main (752871bd67), mobile oxlint, oxfmt --check, tsc --noEmit, check:tests-typecheck, the session-terminal closure test and pnpm test (9874 passed, 6 skipped) pass. The only failures are two tests in src/tasks/mobile-agent-launch-architecture.test.ts, which fail the same way on plain main locally.
  • pnpm --dir mobile exec tsc --noEmit: passed.
  • pnpm --dir mobile check:tests-typecheck: passed.
  • pnpm --dir mobile test: 893 files; 9,640 tests passed, 6 skipped.
  • pnpm --dir mobile lint and pnpm --dir mobile format:check: passed.
  • pnpm run check:code-quality:changed: 0 new findings across 25 files.
  • Mobile web closure suites (config/scripts/mobile-web-app-session-terminal-closure, page-closure-families, mobile-web-terminal-engine-closure, push-subsystem-closure): 21 passed. The session route gains the two window-bounds modules (4,251 → 4,253), recorded in that test's docstring.

New or updated tests:

  • the pong carries the engine flag: the host-seams test and the bundled native-document test, which runs the real WebView script;
  • a missed web-ready recovered through the post-load ping, and an engine-less pong rejected;
  • a repeated web-ready reaching the session each time, and a new document announced after onLoadStart;
  • a foreground-recovery pong not re-announcing a document, whether web-ready or the post-load pong announced it;
  • the Reload-without-load-start path;
  • slicing without splitting a surrogate pair, and the normalized status dot reaching xterm both below and above the slice size;
  • the config plugin: idempotent manifest and MainActivity edits, and the patch registration.

mobile/pnpm-lock.yaml was regenerated with pnpm 10.24.0, which keeps the format main uses. Its diff is only the react-native-screens patch hash and the dependency keys derived from it. pnpm 12 would rewrite patchedDependencies and add supports-color peer suffixes across the whole file, so a reviewer on pnpm 12 should expect that churn if they regenerate.

AI Disclosure

OpenAI Codex (GPT-5.6 Sol and GPT-5.6 Luna) assisted with the original investigation, implementation and tests. The rebase onto current main and the review fixes were developed with Claude Code (Claude Opus 5.5). The author verified the original behavior on physical devices.

Review

  • Security: no permissions, network endpoints, credentials or host-execution paths were added.
  • Cross-platform:
    • The native configuration is Android-only.
    • The readiness edits live in the controller shared by TerminalWebView.tsx and TerminalWebView.web.tsx, so the page gets the same engine-checked pong. The page has no onLoadEnd and never pings on foreground, so it never receives a pong and its announcements are unchanged.
    • Adding resetReadiness() to the overlay Reload and the post-load ping are native-only changes in TerminalWebView.tsx; the page's Reload already reset readiness.
  • SSH/remote/local: pong.terminalAvailable travels between React Native and the document bundled with the same app build. It does not cross the host–client wire, so there is no mixed-version concern. Terminal RPCs and execution ownership are unchanged.
  • Agents/integrations: output handling is provider-neutral and applies equally to Codex, Claude Code and ordinary shell commands.
  • Performance:
    • Only writes over 4,096 UTF-16 code units are split, and queue order is unchanged.
    • Root-bound updates happen only when the measured size changes.
  • UI: the bottom background uses the existing mobile theme token. No new color or spacing value was introduced.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Native Android changes require a rebuilt APK.
  • If fix(mobile): correct text and layout scaling in Samsung DeX #20198 lands first, its density plugin and react-native-screens patch can replace the overlapping native part here. The measured-window and terminal fixes are still needed.
  • No README, environment-variable, API, deployment, privacy or remote-wire contract changed.

Author

X (Twitter): @kargnas

Checklist

  • This PR is small and focused (it bundles four related Android startup and window fixes; happy to split if preferred)
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason (Before is attached; After is described but not attached)
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (mobile typecheck, tests-typecheck, tests, lint and format pass; :app:assembleRelease was built for arm64 only, for the device run)

@kargnas
kargnas marked this pull request as ready for review September 13, 2026 17:27
@coderabbitai

coderabbitai Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: ec28c3ab-a826-468c-b538-8801c3f75216

📥 Commits

Reviewing files that changed from the base of the PR and between 9a288ec0b4968ba08362461e0dbc00c102a7bb7e and d88b35d786bf233e0318b5f7c2bcfe301c0447e8.

📒 Files selected for processing (2)
  • mobile/app.json
  • mobile/src/session/mobile-session-route-parity.test.ts

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


📝 Walkthrough

Walkthrough

The mobile app adds Android desktop-mode configuration and display metric refreshes. It measures root window bounds and uses them across layouts, drawers, previews, and terminal refitting. Terminal WebView readiness now validates terminal availability, probes after load, suppresses duplicate notifications, and invalidates stale watchdogs. Large writes use bounded UTF-16-safe chunks. Tests and workspace configuration were updated.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to d88b3

No actionable current-head defect or merge-blocking risk is established by the reviewed evidence.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 28 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #18841 requires Orca Mobile to render correctly in Samsung DeX. The PR enables resizable Android desktop behavior, synchronizes display metrics, patches display-density conversion, and uses meas…
Out of Scope Changes check ✅ Passed The Android configuration, display-metric synchronization, density patch, measured bounds, responsive layout updates, and terminal readiness and rendering changes directly support issue #18841. Drawer…
Title check ✅ Passed The title clearly summarizes the main changes: stabilizing mobile terminal startup and Android window rendering.
Description check ✅ Passed The description is detailed and covers the required sections, changes, rationale, linked issues, testing, and review considerations. The visual proof is incomplete because it includes a before image b…
Full details: Docstring Coverage

Explanation

Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 28 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

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.

@pullfrog pullfrog 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.

ℹ️ No critical issues — one minor consistency suggestion inline, plus two nitpicks.

Reviewed changes

Full 32-file diff for the initial review; the readiness state machine, write-queue slicing, window-bounds context flow, and the Android density plugin were traced against the pinned RN 0.83.10 sources.

  • WebView readiness recovery: onLoadEnd sends a recovery ping; a pong is only accepted when terminalAvailable === true; onWebReady is deduped per document via webReadyNotifiedRef; the watchdog gets a generation guard so a cleared timer can't fire.
  • Write-queue slicing: writes over 4 KiB are split into 4 KiB chunks without cutting a surrogate pair; status-dot normalization still runs on the whole string before splitting, so chunking can't corrupt it.
  • Window bounds: new WindowBoundsProvider measures the root View and useWindowBounds() prefers measured bounds over useWindowDimensions(), with a fallback that preserves old behavior. All responsive/drawer/onboarding/file-preview/terminal-refit consumers migrated; context reaches Modal subtrees.
  • Android density/windowing: config plugin syncs DisplayMetricsHolder to the Activity display and emits didUpdateDimensions; [email protected] patch converts frames with the view's display density.
  • Removed behavior: measureViewportOnce deleted; cold-start measurement now relies on the bounded runTerminalViewportFitPass resubscribe after init. Path verified present and tested.
Technical details
# Review notes

## Verified
- `reactHost?.currentReactContext?.emitDeviceEvent(...)` and `DisplayMetricsHolder.setWindowDisplayMetrics/setScreenDisplayMetrics/getDisplayMetricsWritableMap` exist on the pinned RN 0.83.10 sources and are reachable from a `ReactActivity` subclass.
- `useWindowBounds` falls back to `useWindowDimensions()` when the provider has not measured, so consumers rendered outside the provider behave exactly as before.
- The slicing loop guards `end < normalized.length` before reading `charCodeAt(end)`, so the trailing `NaN` case cannot run.

## Not verified by CI
- The generated Kotlin is not compiled by any PR check; the author documents an unrelated Android release-build blocker.

## Nitpicks (no action required)
- `mobile/src/session/mobile-terminal-diagnostics.ts:79` `viewportMeasured()` now has no callers — its only caller was the deleted `measureViewportOnce`.
- `mobile/src/layout/window-bounds.tsx:34` `useMemo(() => measured, [measured])` is a no-op; `measured` can be passed directly.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread mobile/src/terminal/TerminalWebView.tsx Resolved

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Re-reviewed the 8cba333..dddb4cbe delta — one follow-up commit touching 3 files. It closes out the prior review's handleReload suggestion and both nitpicks, and adds no new behavior surface.

  • Reload now resets readiness: handleReload clears isWebReadyRef/webReadyNotifiedRef/pendingPingIdRef and re-arms the watchdog before reload(), matching handleContentProcessDidTerminate.
  • Removed dead diagnostics method: MobileTerminalDiagnostics.viewportMeasured() deleted; DiagnosticDimensions is still used by streamArmed, so no unused type is left behind.
  • Dropped no-op memo: WindowBoundsProvider now passes measured directly instead of wrapping it in useMemo.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@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: Advanced

Run ID: 4e8e1d02-5704-45eb-bb25-1f07fa55313b

📥 Commits

Reviewing files that changed from the base of the PR and between 8cba333a8154736b87bd0c2ebd5e7a27f45336ad and dddb4cbe102d807c97cf314d1514530777efe340.

📒 Files selected for processing (3)
  • mobile/src/layout/window-bounds.tsx
  • mobile/src/session/mobile-terminal-diagnostics.ts
  • mobile/src/terminal/TerminalWebView.tsx
💤 Files with no reviewable changes (1)
  • mobile/src/session/mobile-terminal-diagnostics.ts

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

Comment thread mobile/src/terminal/TerminalWebView.tsx Resolved

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Re-reviewed the dddb4cbe..2fdda2b delta — a single follow-up commit touching only TerminalWebView.tsx, closing the remaining gap in the error-overlay reload path. Prior review feedback was already addressed in dddb4cbe and both threads are resolved.

  • Cleared stale queues on overlay reload: handleReload now calls pendingMessages.clear() and writeCoalescer.clear() before reload(), so a reload that skips onLoadStart cannot replay commands queued for the dead document. This matches handleLoadStart and handleContentProcessDidTerminate, and both clear() implementations cancel their own pending timers/state, so the call is safe.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@kargnas
kargnas force-pushed the codex/mobile-terminal-rendering branch from 2fdda2b to 9a288ec Compare September 14, 2026 07:05
@kargnas
kargnas force-pushed the codex/mobile-terminal-rendering branch from 9a288ec to d88b35d Compare September 14, 2026 23:03
@kargnas
kargnas force-pushed the codex/mobile-terminal-rendering branch from d88b35d to 8b95809 Compare September 16, 2026 00:40
@kargnas
kargnas force-pushed the codex/mobile-terminal-rendering branch from 8b95809 to 70667cd Compare September 16, 2026 01:33
@kargnas
kargnas force-pushed the codex/mobile-terminal-rendering branch from 70667cd to 00c1e62 Compare September 16, 2026 03:07

@pullfrog pullfrog 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.

Important

The rebase conflict resolution in mobile/app/mobile-onboarding.tsx left three imports with no remaining users, and pnpm exec oxlint reports no-unused-vars errors on lines 1-2 — the Lint CI job will fail.

Reviewed changes

Re-reviewed the delta since the prior pullfrog review: the branch was rebased a fifth time (onto c33a4461) and the net change is confined to the import block at the top of mobile/app/mobile-onboarding.tsx.

  • Rebased onto a newer main: main extracted the local useReducedMotionEnabled hook into ../src/onboarding/use-reduced-motion, so the rebased file imports the shared hook instead of defining it locally.
  • Unused imports carried through the conflict: useEffect and AccessibilityInfo (only the deleted local hook used them) plus useWindowDimensions (superseded by useWindowBounds()) survive in the file, and oxlint fails on all three.
  • Route-parity pins still valid: commits 2-4 are byte-identical to the prior revision, and the new base's only mobile/src/session change is a doc comment in a file outside the pinned source family.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread mobile/app/mobile-onboarding.tsx Resolved
@kargnas
kargnas force-pushed the codex/mobile-terminal-rendering branch from b7480b7 to 59fae1f Compare September 16, 2026 06:34
@kargnas
kargnas force-pushed the codex/mobile-terminal-rendering branch from 59fae1f to cc03250 Compare September 17, 2026 00:04
@kargnas
kargnas force-pushed the codex/mobile-terminal-rendering branch from 75a59f1 to 98e4f04 Compare September 17, 2026 21:36
@kargnas
kargnas force-pushed the codex/mobile-terminal-rendering branch from 98e4f04 to d071ce4 Compare September 27, 2026 15:36

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Re-reviewed the rewrite since the prior pullfrog review. The branch is now one squashed commit (d071ce4a) rebased onto main@27b823f934, which had moved far ahead and rewritten the terminal WebView into typed document modules plus a shared controller. All four Android/mobile fixes were rebuilt inside that structure, and the readiness announcement rule changed: only a pong is gated on "not yet announced", so a repeated web-ready still reaches the session to resubscribe.

  • Readiness handshake rebuilt in the shared controller: probeWebReady pings the document on native onLoadEnd when nothing is ready and no ping is outstanding; a pong counts only when terminalAvailable === true; web-ready always announces, while a pong announces only until some document has announced. handleReload and handleContentProcessDidTerminate both call resetReadiness(), and the pong path stays silent for an already-announced document during foreground recovery.
  • Write-queue slicing: enqueueWrite slices writes over 4 KiB after status-dot normalization and never ends a slice on a high surrogate, preserving character integrity and FIFO order.
  • Measured window bounds: the new WindowBoundsProvider / useWindowBounds() resolve to the measured root bounds and fall back to useWindowDimensions() outside the provider; responsive layout, both drawers, onboarding, file preview and terminal refit were migrated.
  • Android density/windowing: the android-desktop-mode config plugin and the [email protected] patch are re-registered against the new lockfile; the command dock gains the colors.bgPanel background.

I ran the targeted mobile tests for the changed areas (readiness, write-queue, window-bounds, viewport refit, plugin) — all green — and traced the readiness/pong/probe state machine and the config-plugin injection against the pinned RN 0.83.10 sources. Could not construct a reachable double-announce or missed-announce on the named paths.

ℹ️ The Android native half is not verified on this head

mobile/plugins/android-desktop-mode.js generates Kotlin at prebuild time and no PR check compiles it; the react-native-screens patch is a native frame-density change. This same rebased commit was not rebuilt into an APK or device-tested, so the Android rendering behavior here rests on the pre-rebase device evidence.

Technical details
# Android native verification gap

## Affected sites
- mobile/plugins/android-desktop-mode.js — injected `MainActivity.kt` (applyActivityDisplayMetrics / onConfigurationChanged / onResume / emitActivityDimensions) is never compiled by a PR check.
- mobile/patches/react-[email protected] — native FabricEnabledViewGroup frame density.

## Required outcome
- Prebuild + `:app:compileDebugKotlin` (or a device run) for `d071ce4a` before merge, so the generated Kotlin is compiled at least once against the RN 0.83.10 / Expo 55 toolchain.

## Open questions for the human
- Was the Android build re-run for this rebased head, or is the pre-rebase Fold7 evidence still the only validation?

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@kargnas

kargnas commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

On the pullfrog note about the Android native half: I ran npx expo prebuild --platform android --no-install and ./gradlew --no-daemon :app:compileDebugKotlin on this head (d071ce4a). Both pass, so the plugin-injected MainActivity.kt and the patched react-native-screens compile against the current toolchain. The rebased commit is still not device-tested; the body now says so under Testing.

@kargnas
kargnas force-pushed the codex/mobile-terminal-rendering branch 2 times, most recently from 4444eab to 7c705d4 Compare September 29, 2026 11:18
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Patches native Android library and adds desktop-mode plugin.

The PR appears safe to merge; the previously reported recovery-size defect is fixed, with no new actionable issue identified.

Summary

The PR adds a post-load terminal readiness probe, slices oversized terminal writes, and adjusts Android display metrics and measured-window layout for resizable windows.

  • The latest change supplies the document’s cell box in a pong and stores it before announcing recovered readiness.
  • The previous cell-size finding is fixed and its thread is resolved.

Reviews (3) · Last reviewed commit: "fix: web-ready 대체 pong에 셀 박스 포함"

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Re-reviewed the 7c705d4c..eb034f2e delta — a single follow-up commit that closes the cell-box gap in the readiness-recovery path. All prior pullfrog threads are resolved.

  • Recovery pong carries the cell box: document/host-message-router.ts now answers a ping with cellBox: laidOutCellBox(scope)?.cellBox ?? null alongside terminalAvailable, so a pong that stands in for a dropped web-ready reports the box xterm laid out.
  • Controller stores it before announcing: the accepted-pong branch of use-terminal-webview-controller.ts sets cellBoxRef.current = readTerminalCellBox(msg) before confirmWebReady(...), so the recovered subscribe is fitted from the phone box rather than going out unmeasured and coming back at host size.
  • Tests pin both ends: host-seams.test.ts gives the terminal double a laid-out render service and asserts the box on the pong; native-document-bundle.test.ts pins cellBox: null when unmeasured; a new terminal-webview-cell-box.test.ts case drives post-load ping → pong → fitDimensions.

I ran the four affected mobile suites (46 tests) green, and confirmed the new cell-box case fails without the controller line, so it is real coverage rather than a snapshot of the current output.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Recover a missed terminal web-ready with a post-load ping whose pong must
report a loaded xterm engine. That pong announces the document only when
no web-ready has, so a foreground-recovery pong never re-announces it,
while every real web-ready still reaches the session. The error overlay's
reload now resets readiness.

Slice document writes larger than 4 KiB so one PTY burst or replay no
longer holds the WebView thread, without splitting surrogate pairs.

Measure the root view for responsive layout, drawers, onboarding, file
preview and terminal refits, keep React Native's display metrics on the
Activity's display in Android freeform/DeX windows, backport
react-native-screens' per-view density conversion, and paint the command
dock with the panel token.
web-ready가 유실돼 post-load pong이 준비 신호를 대신할 때 셀 박스가
빠져, 프레임이 이미 측정된 상태면 첫 구독이 뷰포트 없이 나가 초기
스크롤백 스냅샷이 호스트 크기로 직렬화됐다. web-ready와 같은 박스를
pong에 실어 복구 경로의 첫 구독도 폰 크기로 맞춘다.
upstream main의 의존성 갱신(76b1a90)과 리베이스 충돌을 해소하면서 lockfile이
patchedDependencies 선언과 어긋났다. pin된 pnpm 12.8.1로 --lockfile-only 재생성.

Tested: pnpm install --lockfile-only (supply-chain 정책 통과)
terminal-viewport-refit.ts가 모바일 max-lines 예산(빈 줄과 주석을 뺀 300줄)에
이미 붙어 있어서, 이 PR이 더한 import 한 줄 때문에 oxlint가 실패했다. 이 PR도
#23419도 건드리지 않는 iOS 복귀와 재연결의 강제 refit effect 두 개를 동작 변경
없이 terminal-viewport-reassertion.ts로 옮겼다. AGENTS.md가 max-lines 예외를
금지하므로 예외는 추가하지 않았다.

Constraint: 모바일 oxlint max-lines 300(빈 줄·주석 제외)이며 파일별 예외 추가는 금지된다
Rejected: 코드 줄 합치기 | oxfmt가 되돌리고 의미 없는 변경만 남는다
Directive: #23419에도 같은 내용의 같은 파일을 넣었으므로 먼저 머지되는 쪽의 변경과 동일하게 맞춘다
Tested: oxlint, tsc --noEmit, vitest src/terminal과 키보드 상태 테스트 654개 통과

@pullfrog pullfrog 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.

ℹ️ No critical issues — one documentation nitpick.

Reviewed changes

Incremental re-review of the c2a9767552..afce2f8c2e delta: a single refactor commit that moves the iOS-resume and reconnect viewport-refit effects out of terminal-viewport-refit.ts into a new module.

  • Split out useTerminalViewportReassertion: the iOS AppState resume refit and the reconnect connState refit effects moved verbatim into terminal-viewport-reassertion.ts and are invoked unconditionally from useTerminalViewportRefit. The moved code is byte-identical and both effects keep equivalent dependency sets, so there is no behavioral change; the split brings the refit file back under the max-lines cap after the useWindowBounds import was added.

ℹ️ Nitpicks

  • config/scripts/mobile-web-app-session-terminal-closure.test.mjs:469: the recorded session-route closure total (4,251 -> 4,253 modules, 1,049 -> 1,051 local) predates terminal-viewport-reassertion.ts. That module is value-imported by terminal-viewport-refit.ts, which is in the session route's closure (MobileSessionRouteScreen.tsx → useMobileSessionController → useMobileSessionKeyboardState → useTerminalViewportRefit), so the head now measures 4,254 / 1,052. Worth re-recording the extra module beside the window-bounds addition so the paragraph stays the durable count it is meant to be.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@kargnas

kargnas commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Closing this in favor of smaller PRs, as the "small and focused" checklist item asks:

I'm not refiling the measured-window layout or the command-dock background for now. All of my device evidence for them was gathered together with the density part, so I can't show what they fix on their own. If Fold pop-up windows still lay out at the old size once #20198 lands, I'll open a separate issue with new evidence.

@kargnas kargnas closed this Oct 5, 2026
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