Skip to content

Mobile: per-host connection log screen with one-tap diagnostics copy - #7984

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/mobile-connection-log
Jul 9, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/mobile-connection-log

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The mobile rpc-client already emits a rich, human-readable connection lifecycle log via its onLog option — 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 to console.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 so useSyncExternalStore doesn't re-render loop.
  • client-context.tsx — passes onLog when 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 pairing ConnectionLog component), 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.
  • Copy diagnostics (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.
  • Troubleshooting screen — "View connection log" entry point under Run diagnostics.

Notes

Testing

  • New unit tests: buffer per-host isolation, cap eviction, snapshot stability, listener unsubscribe; diagnostics report content for Tailscale and never-connected cases.
  • Full mobile suite: 1284 passed / 2 skipped; tsc --noEmit, oxlint, oxfmt, and the max-lines ratchet all clean.

Made with Orca 🐋

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]>
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary and testing, but it omits required Screenshots, AI Review Report, and Security Audit sections. Add the missing template sections and include the required AI review, cross-platform check, security audit, and screenshots or a no-visual-change note.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: a per-host connection log screen with diagnostics copying.
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.
✨ 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.

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dfce37c1-4a1c-4f76-8142-7a875edbac6b

📥 Commits

Reviewing files that changed from the base of the PR and between 73f1bbf and cb6328a.

📒 Files selected for processing (8)
  • mobile/app/_layout.tsx
  • mobile/app/connection-log.tsx
  • mobile/app/troubleshoot.tsx
  • mobile/src/diagnostics/connection-diagnostics-report.test.ts
  • mobile/src/diagnostics/connection-diagnostics-report.ts
  • mobile/src/transport/client-context.tsx
  • mobile/src/transport/connection-log-buffer.test.ts
  • mobile/src/transport/connection-log-buffer.ts

Comment on lines +34 to +46
useEffect(() => {
let stale = false
void loadHosts().then((loaded) => {
if (stale) {
return
}
setHosts(loaded)
setSelectedId((prev) => prev ?? loaded[0]?.id ?? null)
})
return () => {
stale = true
}
}, [])

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.

🩺 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.

Suggested change
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
}
}, [])

Comment on lines +64 to +81
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])

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.

🩺 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.

Suggested change
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])

Comment on lines +12 to +84
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()

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.

📐 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/app

Repository: stablyai/orca

Length of output: 14796


🏁 Script executed:

#!/bin/bash
rg -n "connectionLogStore|createConnectionLogStore|ConnectionLogStore|connection-log-buffer" mobile/src mobile/app

Repository: 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.tsx

Repository: 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.

@Jinwoo-H
Jinwoo-H merged commit 9c111fd into main Jul 9, 2026
3 checks passed
Jinwoo-H added a commit that referenced this pull request Jul 10, 2026
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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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