From ff6bda0fce8c52c9a8f83e5672079ec76bd1d005 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 20:43:28 +0000 Subject: [PATCH 1/2] Diagnostics capture the comparison ring's packets An export showed the second ring's requests and none of its replies, so an empty ring and dropped replies looked the same. DiagnosticsSubscriber now also reads ComparisonBus for packets and a few status lines; the packets are masked like the main ring's and marked "ring":"comparison". Claude-Session: https://claude.ai/code/session_01P1t1aUqSUPd3whKXmgVm7w --- .../diagnostics/DiagnosticsExporter.kt | 2 +- .../diagnostics/DiagnosticsSubscriber.kt | 40 +++++++++++++++---- .../java/com/pulseloop/ring/RingBLEClient.kt | 2 + .../DiagnosticsTransportMetadataTest.kt | 5 +++ 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/pulseloop/diagnostics/DiagnosticsExporter.kt b/app/src/main/java/com/pulseloop/diagnostics/DiagnosticsExporter.kt index f2675755..2ed0bbaf 100644 --- a/app/src/main/java/com/pulseloop/diagnostics/DiagnosticsExporter.kt +++ b/app/src/main/java/com/pulseloop/diagnostics/DiagnosticsExporter.kt @@ -17,7 +17,7 @@ import java.time.Instant */ object DiagnosticsExporter { /** The keys `RingBLEClient` stores in `raw_packets.decodedJSON` for each packet. */ - private val TRANSPORT_KEYS = setOf("characteristic", "generation", "attempt") + private val TRANSPORT_KEYS = setOf("characteristic", "generation", "attempt", "ring") /** * The transport facts of one stored packet, or null if it has none. Older rows may hold decoder diff --git a/app/src/main/java/com/pulseloop/diagnostics/DiagnosticsSubscriber.kt b/app/src/main/java/com/pulseloop/diagnostics/DiagnosticsSubscriber.kt index 66bc8b59..a3cff4a8 100644 --- a/app/src/main/java/com/pulseloop/diagnostics/DiagnosticsSubscriber.kt +++ b/app/src/main/java/com/pulseloop/diagnostics/DiagnosticsSubscriber.kt @@ -33,15 +33,39 @@ class DiagnosticsSubscriber( fun start(scope: CoroutineScope) { if (job != null) return job = scope.launch(start = CoroutineStart.UNDISPATCHED) { - PulseEventBus.events.collect { event -> - try { - record(event) - } catch (e: CancellationException) { - throw e - } catch (e: Exception) { - Log.e("Diagnostics", "Could not persist diagnostic event", e) - } + // The second ring's bus too (docs/ring-comparison.md): without it an export showed + // the comparison ring's requests and none of its replies, so "it sent nothing" and + // "we dropped what it sent" looked the same. Only the packets and a few status lines + // are taken; its readings still go nowhere but `comparison_readings`. + launch(start = CoroutineStart.UNDISPATCHED) { + ComparisonBus.events.collect { event -> safely { recordComparison(event) } } } + PulseEventBus.events.collect { event -> safely { record(event) } } + } + } + + private suspend fun safely(block: suspend () -> Unit) { + try { + block() + } catch (e: CancellationException) { + throw e + } catch (e: Exception) { + Log.e("Diagnostics", "Could not persist diagnostic event", e) + } + } + + private suspend fun recordComparison(event: PulseEvent) { + when (event) { + // Stored like the main ring's packets: masked on export by their own family's header, + // and marked `"ring":"comparison"` in their transport facts by the client. + is PulseEvent.RawPacket -> record(event) + is PulseEvent.SyncProgress -> + log(WearableLogCategory.SYNC, WearableLogLevel.INFO, "[comparison ring] Sync: ${event.stage}", deviceType = null) + is PulseEvent.BatteryLevel -> + log(WearableLogCategory.BATTERY, WearableLogLevel.INFO, "[comparison ring] Battery ${event.percent}%") + is PulseEvent.DeviceStateChanged -> + log(WearableLogCategory.CONNECTION, WearableLogLevel.INFO, "[comparison ring] Connection state: ${event.state.name}") + else -> { /* readings stay on the comparison bus */ } } } diff --git a/app/src/main/java/com/pulseloop/ring/RingBLEClient.kt b/app/src/main/java/com/pulseloop/ring/RingBLEClient.kt index 1f3e981b..55cfc52e 100644 --- a/app/src/main/java/com/pulseloop/ring/RingBLEClient.kt +++ b/app/src/main/java/com/pulseloop/ring/RingBLEClient.kt @@ -1591,6 +1591,8 @@ class RingBLEClient( put("characteristic", uuid) put("generation", forgetGeneration) if (attempt > 0) put("attempt", attempt) + // The second ring's packets share the diagnostics table; this says whose they are. + if (role == RingRole.COMPARISON) put("ring", "comparison") }.toString() // MARK: Scan callback diff --git a/app/src/test/java/com/pulseloop/diagnostics/DiagnosticsTransportMetadataTest.kt b/app/src/test/java/com/pulseloop/diagnostics/DiagnosticsTransportMetadataTest.kt index 10987f86..567e644a 100644 --- a/app/src/test/java/com/pulseloop/diagnostics/DiagnosticsTransportMetadataTest.kt +++ b/app/src/test/java/com/pulseloop/diagnostics/DiagnosticsTransportMetadataTest.kt @@ -11,6 +11,11 @@ class DiagnosticsTransportMetadataTest { assertEquals(expected, DiagnosticsExporter.transportMetadata(metadata)) } + @Test fun `the second ring's packets say so`() { + val metadata = """{"characteristic":"6e400003-b5a3-f393-e0a9-e50e24dcca9e","generation":1,"ring":"comparison"}""" + assertEquals(Json.parseToJsonElement(metadata), DiagnosticsExporter.transportMetadata(metadata)) + } + @Test fun `older rows with only decoder values do not export transport metadata`() { assertNull(DiagnosticsExporter.transportMetadata("""{"bpm":72}""")) assertNull(DiagnosticsExporter.transportMetadata(null)) From 9fb3f86c3132f0ca7c6a5a82945f71e4dc28ad9d Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 20:48:02 +0000 Subject: [PATCH 2/2] MCP socket test asks the server, not the freed port After the listener closes, its ephemeral port can be taken at once by another test's listener in the same run, so connecting to it to prove nothing listens there failed by chance on CI (PR #93). Claude-Session: https://claude.ai/code/session_01P1t1aUqSUPd3whKXmgVm7w --- app/src/test/java/com/pulseloop/mcp/McpServerSocketTest.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/test/java/com/pulseloop/mcp/McpServerSocketTest.kt b/app/src/test/java/com/pulseloop/mcp/McpServerSocketTest.kt index 8ad95f19..0a377f1e 100644 --- a/app/src/test/java/com/pulseloop/mcp/McpServerSocketTest.kt +++ b/app/src/test/java/com/pulseloop/mcp/McpServerSocketTest.kt @@ -42,7 +42,9 @@ class McpServerSocketTest { assertEquals(first, server.rebind(listOf(loopback, InetAddress.getByName("8.8.8.8")), 0)) // The address went away: nothing listens there any more. assertTrue(server.rebind(emptyList(), 0).isEmpty()) - assertFalse(runCatching { Socket().use { it.connect(first[0], 500) } }.isSuccess) + // Asked of the server, not of the port: the freed ephemeral port can be taken at once by + // another test's listener in the same run, so "nothing answers there" was a race. + assertFalse(server.isRunning()) // It came back: listening again, and answering. val again = server.rebind(listOf(loopback), 0) assertEquals(1, again.size)