Repository navigation
Mobile: per-host connection log screen with one-tap diagnostics copy - #7984
Conversation
The rpc-client has always emitted a detailed connection lifecycle log (dials, timeouts, close codes, handshake steps, retries) via onLog, but only the pairing screen wired it up — for long-lived host connections everything went to console.log, invisible to users. Debugging reports like #7824/#6928 meant asking reporters for facts the app already knew. - connection-log-buffer: bounded (200/host) module-level ring buffer with referentially-stable snapshots for useSyncExternalStore; survives client swaps and provider remounts. - client-context: wire onLog for every shared host client. - connection-log screen: live per-host log (reuses the pairing ConnectionLog component), host picker, and a Copy Diagnostics button that bundles app/platform versions, endpoint (flagged if Tailscale), state, attempt count, last-connected, and the event log into one shareable blob. - troubleshoot: 'View connection log' entry point. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughAdds bounded per-host connection log storage and forwards RPC lifecycle logs into it. Adds a diagnostics report builder with coverage for populated and empty sessions. Introduces a connection-log screen with host selection, live log updates, empty states, and clipboard diagnostics copying. Exposes the screen from troubleshooting and registers a hidden-header navigation route. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: dfce37c1-4a1c-4f76-8142-7a875edbac6b
📒 Files selected for processing (8)
mobile/app/_layout.tsxmobile/app/connection-log.tsxmobile/app/troubleshoot.tsxmobile/src/diagnostics/connection-diagnostics-report.test.tsmobile/src/diagnostics/connection-diagnostics-report.tsmobile/src/transport/client-context.tsxmobile/src/transport/connection-log-buffer.test.tsmobile/src/transport/connection-log-buffer.ts
| useEffect(() => { | ||
| let stale = false | ||
| void loadHosts().then((loaded) => { | ||
| if (stale) { | ||
| return | ||
| } | ||
| setHosts(loaded) | ||
| setSelectedId((prev) => prev ?? loaded[0]?.id ?? null) | ||
| }) | ||
| return () => { | ||
| stale = true | ||
| } | ||
| }, []) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Add .catch() to the loadHosts() promise.
If loadHosts() rejects (e.g., Keychain access failure), the promise is unhandled. The troubleshoot screen handles the same call with try/catch; this screen should be consistent. The UI degrades gracefully (shows "No paired hosts."), but the unhandled rejection produces dev-mode warnings.
🛡️ Proposed fix
void loadHosts().then((loaded) => {
if (stale) {
return
}
setHosts(loaded)
setSelectedId((prev) => prev ?? loaded[0]?.id ?? null)
- })
+ }).catch(() => {
+ // Hosts list stays empty; screen shows "No paired hosts."
+ })📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| useEffect(() => { | |
| let stale = false | |
| void loadHosts().then((loaded) => { | |
| if (stale) { | |
| return | |
| } | |
| setHosts(loaded) | |
| setSelectedId((prev) => prev ?? loaded[0]?.id ?? null) | |
| }) | |
| return () => { | |
| stale = true | |
| } | |
| }, []) | |
| useEffect(() => { | |
| let stale = false | |
| void loadHosts().then((loaded) => { | |
| if (stale) { | |
| return | |
| } | |
| setHosts(loaded) | |
| setSelectedId((prev) => prev ?? loaded[0]?.id ?? null) | |
| }).catch(() => { | |
| // Hosts list stays empty; screen shows "No paired hosts." | |
| }) | |
| return () => { | |
| stale = true | |
| } | |
| }, []) |
| const copyDiagnostics = useCallback(async () => { | ||
| if (!selected) { | ||
| return | ||
| } | ||
| const report = buildConnectionDiagnosticsReport({ | ||
| hostName: selected.name, | ||
| endpoint: selected.endpoint, | ||
| state, | ||
| reconnectAttempts, | ||
| lastConnectedAt, | ||
| platform: `${Platform.OS} ${Platform.Version ?? ''}`.trim(), | ||
| appVersion: Constants.expoConfig?.version ?? 'unknown', | ||
| entries | ||
| }) | ||
| await Clipboard.setStringAsync(report) | ||
| setCopied(true) | ||
| setTimeout(() => setCopied(false), 2000) | ||
| }, [selected, state, reconnectAttempts, lastConnectedAt, entries]) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Handle Clipboard.setStringAsync rejection.
If the clipboard call rejects, copyDiagnostics rejects and the call site void copyDiagnostics() leaves it unhandled. The user gets no feedback (no "Copied", no error). Wrap the async operation so failures are surfaced or silently swallowed.
🛡️ Proposed fix
const copyDiagnostics = useCallback(async () => {
if (!selected) {
return
}
const report = buildConnectionDiagnosticsReport({
hostName: selected.name,
endpoint: selected.endpoint,
state,
reconnectAttempts,
lastConnectedAt,
platform: `${Platform.OS} ${Platform.Version ?? ''}`.trim(),
appVersion: Constants.expoConfig?.version ?? 'unknown',
entries
})
- await Clipboard.setStringAsync(report)
- setCopied(true)
- setTimeout(() => setCopied(false), 2000)
+ try {
+ await Clipboard.setStringAsync(report)
+ setCopied(true)
+ setTimeout(() => setCopied(false), 2000)
+ } catch {
+ // Clipboard unavailable; silently ignore so the user is not misled.
+ }
}, [selected, state, reconnectAttempts, lastConnectedAt, entries])📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const copyDiagnostics = useCallback(async () => { | |
| if (!selected) { | |
| return | |
| } | |
| const report = buildConnectionDiagnosticsReport({ | |
| hostName: selected.name, | |
| endpoint: selected.endpoint, | |
| state, | |
| reconnectAttempts, | |
| lastConnectedAt, | |
| platform: `${Platform.OS} ${Platform.Version ?? ''}`.trim(), | |
| appVersion: Constants.expoConfig?.version ?? 'unknown', | |
| entries | |
| }) | |
| await Clipboard.setStringAsync(report) | |
| setCopied(true) | |
| setTimeout(() => setCopied(false), 2000) | |
| }, [selected, state, reconnectAttempts, lastConnectedAt, entries]) | |
| const copyDiagnostics = useCallback(async () => { | |
| if (!selected) { | |
| return | |
| } | |
| const report = buildConnectionDiagnosticsReport({ | |
| hostName: selected.name, | |
| endpoint: selected.endpoint, | |
| state, | |
| reconnectAttempts, | |
| lastConnectedAt, | |
| platform: `${Platform.OS} ${Platform.Version ?? ''}`.trim(), | |
| appVersion: Constants.expoConfig?.version ?? 'unknown', | |
| entries | |
| }) | |
| try { | |
| await Clipboard.setStringAsync(report) | |
| setCopied(true) | |
| setTimeout(() => setCopied(false), 2000) | |
| } catch { | |
| // Clipboard unavailable; silently ignore so the user is not misled. | |
| } | |
| }, [selected, state, reconnectAttempts, lastConnectedAt, entries]) |
| export type ConnectionLogStore = { | ||
| append: (hostId: string, entry: ConnectionLogEntry) => void | ||
| get: (hostId: string) => readonly ConnectionLogEntry[] | ||
| subscribe: (hostId: string, listener: () => void) => () => void | ||
| } | ||
|
|
||
| export function createConnectionLogStore( | ||
| maxEntriesPerHost: number = MAX_ENTRIES_PER_HOST | ||
| ): ConnectionLogStore { | ||
| const entriesByHost = new Map<string, ConnectionLogEntry[]>() | ||
| const listenersByHost = new Map<string, Set<() => void>>() | ||
| // Why: useSyncExternalStore compares snapshots by reference — getSnapshot | ||
| // must return the SAME array until the data actually changes, or React | ||
| // loops re-rendering. Cache per host; invalidate on append. | ||
| const snapshotByHost = new Map<string, readonly ConnectionLogEntry[]>() | ||
| const EMPTY: readonly ConnectionLogEntry[] = [] | ||
|
|
||
| return { | ||
| append(hostId, entry) { | ||
| let entries = entriesByHost.get(hostId) | ||
| if (!entries) { | ||
| entries = [] | ||
| entriesByHost.set(hostId, entries) | ||
| } | ||
| entries.push(entry) | ||
| if (entries.length > maxEntriesPerHost) { | ||
| entries.splice(0, entries.length - maxEntriesPerHost) | ||
| } | ||
| snapshotByHost.delete(hostId) | ||
| const listeners = listenersByHost.get(hostId) | ||
| if (listeners) { | ||
| for (const listener of listeners) { | ||
| listener() | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| get(hostId) { | ||
| const cached = snapshotByHost.get(hostId) | ||
| if (cached) { | ||
| return cached | ||
| } | ||
| const entries = entriesByHost.get(hostId) | ||
| if (!entries || entries.length === 0) { | ||
| return EMPTY | ||
| } | ||
| const snapshot = Object.freeze([...entries]) | ||
| snapshotByHost.set(hostId, snapshot) | ||
| return snapshot | ||
| }, | ||
|
|
||
| subscribe(hostId, listener) { | ||
| let listeners = listenersByHost.get(hostId) | ||
| if (!listeners) { | ||
| listeners = new Set() | ||
| listenersByHost.set(hostId, listeners) | ||
| } | ||
| listeners.add(listener) | ||
| return () => { | ||
| const set = listenersByHost.get(hostId) | ||
| if (!set) { | ||
| return | ||
| } | ||
| set.delete(listener) | ||
| if (set.size === 0) { | ||
| listenersByHost.delete(hostId) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export const connectionLogStore = createConnectionLogStore() |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Find where hosts are removed/unpaired to verify a clear() call site is needed.
rg -nP -C3 'closeEntry|closeHost|removeHost|unpair|deleteHost' --type=ts mobile/src mobile/appRepository: stablyai/orca
Length of output: 14796
🏁 Script executed:
#!/bin/bash
rg -n "connectionLogStore|createConnectionLogStore|ConnectionLogStore|connection-log-buffer" mobile/src mobile/appRepository: stablyai/orca
Length of output: 1577
🏁 Script executed:
#!/bin/bash
sed -n '1,120p' mobile/src/transport/connection-log-buffer.ts
printf '\n---\n'
sed -n '80,120p' mobile/src/transport/client-context.tsx
printf '\n---\n'
sed -n '680,725p' mobile/app/index.tsx
printf '\n---\n'
sed -n '680,700p' mobile/app/h/[hostId]/index.tsxRepository: stablyai/orca
Length of output: 5936
Add a clear(hostId) path for deleted hosts. connectionLogStore keeps per-host entries in memory, but the host-removal flows only close the client. Add clear(hostId) here and call it from the delete flow so stale logs don’t accumulate across repeated pair/unpair cycles.
Clean auto-merge, no conflicts (109 files, +7490 from main). Brought in: - Codex WSL runtime status hooks (#7969); WSL/SSH agent path resolution past shell aliases (#7867); WSL source-control path separators (#7966); WSL GitLab-auth wake fix (#7967); WSL Codex usage RPC refresh (#7567/#7658) - Improve workspace cleanup list (#7053) + background removal - mobile: per-host connection log + Tailscale wedge recovery (#7984/#7980), wake slept agents on mobile worktree open (#7906) - Harden layout validation, watcher lifecycle, connection robustness (#7924) - Disable experimental worktree card style by default (#7977) Perf-branch structure preserved (clean auto-merge). typecheck 0 errors; lint 0 errors. CI is the release gate (local runs skipped per env lag). Co-authored-by: Orca <[email protected]>
…i#7984) The rpc-client has always emitted a detailed connection lifecycle log (dials, timeouts, close codes, handshake steps, retries) via onLog, but only the pairing screen wired it up — for long-lived host connections everything went to console.log, invisible to users. Debugging reports like stablyai#7824/stablyai#6928 meant asking reporters for facts the app already knew. - connection-log-buffer: bounded (200/host) module-level ring buffer with referentially-stable snapshots for useSyncExternalStore; survives client swaps and provider remounts. - client-context: wire onLog for every shared host client. - connection-log screen: live per-host log (reuses the pairing ConnectionLog component), host picker, and a Copy Diagnostics button that bundles app/platform versions, endpoint (flagged if Tailscale), state, attempt count, last-connected, and the event log into one shareable blob. - troubleshoot: 'View connection log' entry point. Co-authored-by: Orca <[email protected]>
Problem
The mobile rpc-client already emits a rich, human-readable connection lifecycle log via its
onLogoption — every dial, connect timeout, close code, E2EE handshake step, and retry, designed exactly for "'Connecting…' hangs forever, where is it stuck?". But only the pairing screen ever wired it up. For the long-lived host connections users actually report problems with (#7824, #6928), all of that went toconsole.log, which users can't see or share — so every report turned into a slow back-and-forth asking for facts the app already knew.Changes
connection-log-buffer.ts— bounded ring buffer (200 entries/host) retaining recent lifecycle events. Module-level so it survives client swaps (forceReconnect) and provider remounts; snapshots are referentially stable souseSyncExternalStoredoesn't re-render loop.client-context.tsx— passesonLogwhen creating each shared host client, so every connection's events are captured.app/connection-log.tsx— new screen: live per-host log (reuses the existing pairingConnectionLogcomponent), host-picker chips when multiple hosts are paired, current state + attempt count, and a Copy diagnostics button. Opening the screen acquires the host client, so it also kicks a dial and the log fills live.connection-diagnostics-report.ts) — one shareable text blob with app version, platform, endpoint (flagged(Tailscale)when tailnet), connection state, reconnect attempts, last-connected time, and the event log — everything we historically requested from reporters one message at a time.Notes
host:portonly — device tokens/keys never appear in log entries.Testing
tsc --noEmit,oxlint,oxfmt, and the max-lines ratchet all clean.Made with Orca 🐋