Skip to content

#1037 Server Health: connection stats on the Servers page - #1041

Merged
ivanfenenko merged 2 commits into
mainfrom
feature/1037-server-health
Nov 14, 2026
Merged

ivanfenenko merged 2 commits into
mainfrom
feature/1037-server-health

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Records connection health for the active Connection Profile while the app is in the foreground, kept on the device for 7 days. It records:
    • a timed health ping every 30 s (global/health on v1, api/info on v2)
    • event-stream state changes
    • the cause of each drop, from a new observer hook on the foreground event stream (heartbeat stall, timeout, network, server, auth)
    • server restarts, detected when the v2 pid changes or the version changes
  • Servers page: the active server card gets a quick view with the status chip, current ping, a 30-minute sparkline and "Uptime · N reconnects today". Tapping it opens Server Health.
  • New Server Health screen (variant A from the prototype):
    • a header with the live ping and sparkline
    • a 1 h / 24 h / 7 d range picker
    • tiles for uptime, reconnects with median recovery time, error rate, and time between drops
    • latency, connection and reconnect charts
    • an error breakdown by cause
    • server info (version, protocol, last restart, restarts seen, event streams live)
  • Time with the app closed shows as "Not measured", never as downtime.
  • Design system, both platforms: adds OpenCodeSparkline, OpenCodeBandChart, OpenCodeStatusStrip, OpenCodeBarChart, OpenCodeChartCard, OpenCodeStatTile, OpenCodeProportionRow, plus an optional footer slot on OpenCodeListItem (existing call sites unchanged). All are on a new "Charts" gallery page.
  • Persistence:
    • Android: two Room tables, with an explicit Migration(1, 2).
    • iOS: its own SwiftData store, protected and excluded from backup, with an in-memory fallback.
    • Data is purged when a profile is removed and by Clear All Data.

Checks

  • Android:
    • ./gradlew :app:assembleDebug :app:assembleDebugAndroidTest passes.
    • :app:testDebugUnitTest for the serverhealth and ui.settings packages passes. This covers the new report-builder, monitor, pinger, format and view-model suites, plus additions to ConnectionSessionCoordinatorTest and DefaultForegroundEventStreamTest.
    • The full unit suite has 3 failures in code this PR doesn't touch:
      • 2 depend on the machine's locale (2,5s vs 2.5s)
      • 1 is a timing flake in SseRecoveryFaultOracleTest, which passes when run alone
    • ktlintCheck reports no violations in new code.
  • iOS:
    • The Debug simulator build passes.
    • The new Swift Testing suites pass: report builder, format, monitor, classification, SwiftData store, view model, text.
    • DefaultForegroundEventStreamTests, ConnectionSessionCoordinatorTests, ConnectionProbeServiceTests, SceneWorldSignalsTests, SseAttemptPolicyTests and OpenCodeListItemTitleHighlightTests pass. DefaultForegroundEventStreamTests.transportFailureBeforeHeadersKeepsTransportError failed once in a parallel run and passed when the suite ran alone; it waits on the shared diagnostic log.
  • Scenario harness: I ran both apps against the harness (opencode 2.3.0, detected as API v2). I forced an event-stream drop with the fault proxy, and restarted the harness during the Android run. Both apps recorded the reconnects, and Android detected the restart.

Evidence

Screenshots are in the evidence comment.

Issue

Fixes #1037

Risks / Follow-ups

  • v1 not checked live: the harness's opencode binary now answers as API v2, so the v1 global/health ping path is covered only by unit tests.
  • No migration test on a real database: the Room 1→2 migration has no instrumented test.
  • iOS store: SwiftData #Index needs iOS 18, so the store has no (profile, time) index. Data volume is small (about 10k rows per profile per week).
  • iOS ping timeout: iOS uses the probe session's 5 s request timeout. URLSession has no separate 3 s connect timeout.
  • Number formatting: ms, percent and durations use fixed . decimals, not localized formatting.
  • Latency axis labels: in the latency chart the max/mid labels can overlap the plot at the right edge.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Record ping latency, event-stream state changes, drop causes and server
restarts for the active Connection Profile while the app is open (7 days,
on device). Show a quick view on the active server card and a Server
Health screen with uptime, reconnects, error rate and latency charts.
Adds chart components (sparkline, band chart, status strip, bar chart,
chart card, stat tile, proportion row) and a list item footer slot on
both platforms.
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

iOS (iPhone 17e simulator) and Android (API 36 emulator), opencode 2.3.0 detected as API v2, scenario-harness data. One event-stream drop was forced with the fault proxy; the Android run also covered a harness restart.

Step iOS Android
Servers: quick view on the active card iOS quick view Android quick view
Server Health: header, range, tiles iOS top Android top
Charts (24 h) iOS charts Android charts
Errors and Server card iOS errors Android errors
1 h range iOS 1 h Android 1 h

@ivanfenenko ivanfenenko mentioned this pull request Nov 14, 2026
7 tasks done
@ivanfenenko
ivanfenenko marked this pull request as ready for review November 14, 2026 17:04

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: no finding that 2+ of 2 passes agreed on.

9 finding(s) from a single pass, not posted
  • ios/OpenCode Mobile/OpenCode Mobile/Data/Local/ServerHealth/SwiftDataServerHealthStore.swift:115 high: iOS health store ordering is nondeterministic on equal timestamps (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/ServerHealth/ServerHealthMonitor.swift:179 medium: iOS records stream failures while occupancy is Stopped (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/Data/Local/ServerHealth/SwiftDataServerHealthStore.swift:188 medium: Unknown persisted failure decodes to no failure on iOS (muse-spark-1.3-contributor)
  • android/app/src/main/java/dev/opencode/mobile/domain/serverhealth/ServerHealthMonitor.kt:1076 medium: Stream failure attributed to the wrong/previous profile during a profile switch (glm-5.3-flash)
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/ServerHealth/ServerHealthMonitor.swift:7256 medium: Stream failure recorded even while the stream is stopped (app backgrounded) (glm-5.3-flash)
  • android/app/src/main/java/dev/opencode/mobile/domain/serverhealth/ServerHealthMonitor.kt:959 low: Ping loop can keep pinging a profile the connection no longer uses (glm-5.3-flash)
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/ServerHealth/ServerHealthPinger.swift:7500 low: Ping cancellation misclassified when only the URLSession task was cancelled (glm-5.3-flash)
  • android/app/src/main/java/dev/opencode/mobile/di/ServerHealthModule.kt:466 low: Ping target defaults to v1 before protocol detection, producing false failures on v2 servers (glm-5.3-flash)
  • android/app/src/main/java/dev/opencode/mobile/domain/serverhealth/ServerHealthReportBuilder.kt:1360 low: meanTimeBetweenDrops computed as liveMs/drops, not time between drops (glm-5.3-flash)

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.111 · 1 pass(es) failed

@ivanfenenko
ivanfenenko merged commit 2e81a1a into main Nov 14, 2026
@ivanfenenko
ivanfenenko deleted the feature/1037-server-health branch November 14, 2026 19:29
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.

Server Health

1 participant