4.7 KiB
4.7 KiB
Mobile Terminal Output Streaming Findings
Date: 2026-04-28
Scope
The investigation was limited to mobile/. Server-side files under src/main/ were read for context only and were not modified.
Verified Findings
- The phone can connect to
ws://192.168.0.179:6768, list worktrees, list terminals, and callterminal.send. - The phone's saved host token is valid; a direct WebSocket probe from the desktop using the same token can call
worktree.ps,terminal.list,terminal.subscribe,terminal.send, andterminal.read. TerminalWebViewcan render text when the React Native side writes to it after xterm initializes. A temporary marker written afterinit()appeared visibly in the WebView.- Messages posted to the WebView before its page installs message handlers can be dropped. The mobile fix queues
init,write, andclearuntil the WebView reportsweb-ready. - The WebView also has an internal queue for writes that arrive after
web-readybut before xterm finishesinit(). - The selected physical-phone test worktree was
refs/heads/tasks-improvementsat/Users/jinwoohong/orca/workspaces/orca/pr-1172-review. - For that test worktree,
terminal.subscribeproduced an initialscrollbackevent with an emptylinesarray and no serialized buffer. - Sending commands to that test terminal returned
ok:true, but a direct WebSocketterminal.readfor the same handle still returned an empty tail and no livedatachunks were observed. - Creating a fresh terminal with
terminal.createin that same worktree also returned a writable handle, butterminal.sendfollowed by delayedterminal.readstill returned an empty tail. - Adding a mobile-side
terminal.readfallback did not make the current physical-phone test terminal display output, because the direct WebSocketterminal.readresponse formobile-output-testremainedtail: []andlastOutputAt: nullafterecho hi. - Calling
terminal.showbeforeterminal.sendonmobile-output-testreturned a connected/writable terminal with aptyId, but a delayedterminal.readstill returned an empty tail. - Root cause found after building a no-phone repro: daemon-backed PTYs were forwarding provider data to the desktop renderer, but not into
runtime.onPtyData. The runtime tail buffer andterminal.subscribelisteners are fed byruntime.onPtyData, so the phone saw accepted sends with no output. - Fix:
src/main/ipc/pty.tsnow forwardsprovider.onDataintoruntime.onPtyDatafor non-LocalPtyProviderproviders. Local PTYs already use the LocalPtyProvider configure hook, so the guard avoids duplicate local output. - After restarting Electron,
pnpm exec tsx mobile/scripts/test-subscribe.ts <deviceToken>passed: bothstreamSawMarkerandreadSawMarkerweretrue. - After the backend fix, the physical phone rendered the repro marker in
TerminalWebView. - Because of the empty tail/no live stream on that specific desktop terminal, the physical
lstest did not prove the WebView display path after real PTY output.
Changes Made
mobile/src/terminal/TerminalWebView.tsx- Added a native-side queue so WebView messages are not sent until the HTML reports
web-ready. - Added a WebView-side queue so writes wait until xterm finishes
init().
- Added a native-side queue so WebView messages are not sent until the HTML reports
mobile/src/transport/rpc-client.ts- Stored full stream request metadata so active streams can be replayed after reconnect.
- Avoided sending a subscription before the socket reaches
connected. - Fixed
terminal.unsubscribeto use the terminal handle assubscriptionId, matching runtime cleanup behavior.
mobile/app/h/[hostId]/session/[worktreeId].tsx- Clears and resubscribes when the worktree changes.
- Tracks the active terminal handle in a ref so stale handles are replaced when
terminal.listchanges. - Routes scrollback and live data into
TerminalWebView.
Useful Commands
agent-device devices --json
agent-device snapshot --platform android --serial R3CX105QXRH --json
agent-device fill @e33 "ls" --platform android --serial R3CX105QXRH --json
agent-device click @e34 --platform android --serial R3CX105QXRH --json
agent-device screenshot /tmp/mobile-terminal.png --platform android --serial R3CX105QXRH --json
orca terminal send --terminal term_926b8898-f843-461a-acd2-482f741327ad --text r --json
orca terminal read --terminal term_926b8898-f843-461a-acd2-482f741327ad --json
Next Debug Boundary
Do not repeat WebView readiness tests unless the WebView changes again; the WebView can render post-init writes. For future regressions, run the no-phone repro first. If it fails, debug the WebSocket/runtime/PTY bridge before touching the mobile UI. If it passes but the phone is blank, debug TerminalWebView or session-screen routing.