Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d8b6ecc
feat(ios): expose native host telemetry to products
EnderOfWorlds007 Oct 20, 2026
411203d
fix(ios): use the agreed debug telemetry variant
EnderOfWorlds007 Oct 20, 2026
bad3dc4
fix(ios): keep host telemetry best effort
EnderOfWorlds007 Oct 20, 2026
0f12e1e
fix(ios): qualify TrUAPI host version lookup
EnderOfWorlds007 Oct 20, 2026
f175b27
fix(ios): call generated host version function
EnderOfWorlds007 Oct 20, 2026
88e27fb
Merge remote-tracking branch 'origin/main' into codex/pre-ios-host-te…
EnderOfWorlds007 Oct 21, 2026
ac385d0
fix(ios): use failable telemetry JSON conversion
EnderOfWorlds007 Oct 21, 2026
2c11c4a
fix(ios): stabilize telemetry bootstrap JSON
EnderOfWorlds007 Oct 21, 2026
9a027f3
fix(ios): log host telemetry bootstrap failures
EnderOfWorlds007 Oct 21, 2026
2da35d1
fix(ios): normalize host telemetry OS version
EnderOfWorlds007 Oct 23, 2026
2d7f127
fix(ios): avoid actor-isolated OS metadata
EnderOfWorlds007 Oct 23, 2026
4f28bc3
test(ios): avoid nested requirement macros
EnderOfWorlds007 Oct 23, 2026
dabb79e
feat(ios): report game reminder lifecycle to Sentry
EnderOfWorlds007 Oct 24, 2026
03bbc2b
fix(ios): count the Play tap as the open, match Android's reminder fi…
EnderOfWorlds007 Oct 24, 2026
bc4b841
style(ios): wrap the reminder event line to the 120-column limit
EnderOfWorlds007 Oct 24, 2026
9e62968
Merge remote-tracking branch 'origin/main' into codex/pre-ios-host-te…
EnderOfWorlds007 Oct 26, 2026
ab88afe
feat(ios): consolidate native host telemetry
EnderOfWorlds007 Oct 26, 2026
15331dd
refactor(ios): use game reminder diagnostics
EnderOfWorlds007 Oct 26, 2026
cfade2b
refactor(ios): build reminder diagnostics on host events
EnderOfWorlds007 Oct 26, 2026
4955936
fix(ios): drop stale reminder on past replacement
EnderOfWorlds007 Oct 26, 2026
fc76813
Merge origin/main into claude/ios-reminder-telemetry
EnderOfWorlds007 Oct 27, 2026
a840081
Merge remote-tracking branch 'origin/main' into codex/pr1678-game-rem…
EnderOfWorlds007 Oct 27, 2026
f0f9db6
fix(ios): match reminder recorder autoclosure
EnderOfWorlds007 Oct 27, 2026
6292db6
Merge origin/main into claude/ios-reminder-telemetry
EnderOfWorlds007 Oct 28, 2026
2fc760e
fix(ios): trim game reminder telemetry to diagnostics plumbing and sh…
EnderOfWorlds007 Oct 28, 2026
0e2a4f6
fix(ios): keep the alarm reminder alive while its booking test waits
EnderOfWorlds007 Oct 28, 2026
0566cc0
test(ios): split the game reminder center tests and share their doubles
EnderOfWorlds007 Oct 28, 2026
2e7f6dc
fix(ios): correct the reminder start doc and match the sibling observ…
EnderOfWorlds007 Oct 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ playground's Diagnosis, since dot.li serves no `Game` surface. Both CLI host
roles still install an in-memory `CliGameHost` that never rings anything. The
`truapi` runtime tests cover the product gate, the start-time check, a call
withdrawn before it reaches the host, the absence of any permission prompt, and
host failures. Android hosts with Sentry enabled report the reminder lifecycle
through `host.reminder.*` Sentry events without changing reminder delivery or
cleanup.
host failures. Android and iOS hosts with Sentry enabled report the reminder
lifecycle through `host.reminder.*` Sentry events without changing reminder
delivery or cleanup.

`Scanner` (`scan`) opens the host's own QR and barcode viewfinder (RFC
"Host-drawn scanner"). The Android app draws it. Both CLI host roles answer
Expand Down
63 changes: 32 additions & 31 deletions hosts/ios/Packages/IssueMonitoring/Sources/HostEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,41 @@ public struct HostEvent: Sendable, Equatable {
self.extras = extras
}

/// An event carrying the fields every host event shares; `tags` and `extras` add its own.
public static func make(
name: String,
origin: HostEventOrigin,
monotonicMilliseconds: Int,
tags: [String: String] = [:],
extras: [String: HostEventValue] = [:]
) -> HostEvent {
var sharedTags = tags
sharedTags["host.app_variant"] = origin.appVariant
sharedTags["host.platform"] = "ios"
sharedTags["host.native_app_version"] = origin.appVersion

var sharedExtras = extras
sharedExtras["host.app_build"] = origin.appBuild.map(HostEventValue.integer)
sharedExtras["event.monotonic_ms"] = .integer(monotonicMilliseconds)

return HostEvent(name: name, tags: sharedTags, extras: sharedExtras)
}

/// The event for the app process finishing launch.
public static func processStarted(
origin: HostEventOrigin,
truapiHostVersion: String,
monotonicMilliseconds: Int
) -> HostEvent {
HostEvent(
make(
name: "host.process.started",
tags: tags(origin: origin, truapiHostVersion: truapiHostVersion).merging([
origin: origin,
monotonicMilliseconds: monotonicMilliseconds,
tags: [
"truapi.host_version": truapiHostVersion,
"host.os_version": origin.osVersion
]) { _, value in value },
extras: appMetadata(origin: origin).merging([
"app.launch_id": .string(origin.launchID.uuidString.lowercased()),
"event.monotonic_ms": .integer(monotonicMilliseconds)
]) { _, value in value }
],
extras: ["app.launch_id": .string(origin.launchID.uuidString.lowercased())]
)
}

Expand All @@ -45,31 +65,12 @@ public struct HostEvent: Sendable, Equatable {
truapiHostVersion: String,
monotonicMilliseconds: Int
) -> HostEvent {
HostEvent(
make(
name: "host.webview.created",
tags: tags(origin: origin, truapiHostVersion: truapiHostVersion),
extras: appMetadata(origin: origin).merging([
"host.session_id": .string(hostSessionID.uuidString.lowercased()),
"event.monotonic_ms": .integer(monotonicMilliseconds)
]) { _, value in value }
origin: origin,
monotonicMilliseconds: monotonicMilliseconds,
tags: ["truapi.host_version": truapiHostVersion],
extras: ["host.session_id": .string(hostSessionID.uuidString.lowercased())]
)
}
}

private extension HostEvent {
static func tags(origin: HostEventOrigin, truapiHostVersion: String) -> [String: String] {
var tags = [
"host.app_variant": origin.appVariant,
"host.platform": "ios",
"truapi.host_version": truapiHostVersion
]
tags["host.native_app_version"] = origin.appVersion
return tags
}

static func appMetadata(origin: HostEventOrigin) -> [String: HostEventValue] {
var extras: [String: HostEventValue] = [:]
extras["host.app_build"] = origin.appBuild.map(HostEventValue.integer)
return extras
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,37 @@ import Products
import SwiftUI
import Individuality

/// The AlarmKit calls a game reminder makes, so the reminder can be exercised without the system alarm store.
@available(iOS 26.1, *)
protocol GameAlarmManaging {
var isAuthorized: Bool { get }
func alarmIds() throws -> [UUID]
func scheduleGameAlarm(id: UUID, at date: Date, playIntent: GameAlarmPlayIntent) async throws
func cancel(id: UUID) throws
}

@available(iOS 26.1, *)
final class AlarmKitGameReminder: GameStartReminderServicing {
private let alarmManger: AlarmManager
private let alarmManger: GameAlarmManaging
private let settingsManager: SettingsManagerProtocol
private let keys: GameReminderStorageKeys
private let logger: LoggerProtocol
private let diagnostics: GameReminderDiagnostics
private let taskLock = NSLock()
private var lastTask: Task<Void, Never>?

init(
alarmManger: AlarmManager,
alarmManger: GameAlarmManaging,
settingsManager: SettingsManagerProtocol,
keys: GameReminderStorageKeys,
logger: LoggerProtocol = Logger.shared
logger: LoggerProtocol = Logger.shared,
diagnostics: GameReminderDiagnostics = GameReminderDiagnostics()
) {
self.alarmManger = alarmManger
self.settingsManager = settingsManager
self.keys = keys
self.logger = logger
self.diagnostics = diagnostics
}

func scheduleReminder(gameDate: Date, productId: ProductId) {
Expand Down Expand Up @@ -56,13 +68,15 @@ final class AlarmKitGameReminder: GameStartReminderServicing {
}

private func performScheduleReminder(gameDate fireDate: Date, productId: ProductId) async {
guard alarmManger.authorizationState == .authorized else {
guard alarmManger.isAuthorized else {
logger.debug("Not authorized, skipping schedule")
recordNotScheduled(.notAuthorized, gameDate: fireDate, productId: productId)
return
}

guard fireDate > Date() else {
logger.debug("Fire date is in the past, skipping")
recordNotScheduled(.startInPast, gameDate: fireDate, productId: productId)
performCancelReminder(alarmId: nil)
return
}
Expand All @@ -88,11 +102,21 @@ final class AlarmKitGameReminder: GameStartReminderServicing {
settingsManager.set(string: newAlarmId.uuidString, for: keys.alarmId)
settingsManager.set(value: Int(fireDate.timeIntervalSinceReferenceDate), for: keys.alarmFireDate)
logger.debug("Alarm scheduled \(newAlarmId) for \(fireDate)")
diagnostics.record(
GameReminderEvent(step: .scheduled, productId: productId, startsAt: fireDate, delivery: .alarm)
)
} catch {
logger.error("Failed to schedule AlarmKit alarm: \(error)")
recordNotScheduled(.failed, gameDate: fireDate, productId: productId)
}
}

private func recordNotScheduled(_ reason: GameReminderEvent.SkipReason, gameDate: Date, productId: ProductId) {
diagnostics.record(
GameReminderEvent(step: .notScheduled, productId: productId, startsAt: gameDate, skipReason: reason)
)
}

private func performCancelReminder(alarmId: UUID?) {
guard let alarmId = alarmId ?? settingsManager
.string(for: keys.alarmId)
Expand All @@ -114,8 +138,7 @@ final class AlarmKitGameReminder: GameStartReminderServicing {

private func isAlarmScheduled(id: UUID) -> Bool {
do {
let alarms = try alarmManger.alarms
return alarms.contains { $0.id == id }
return try alarmManger.alarmIds().contains(id)
} catch {
logger.error("Failed to fetch scheduled alarms: \(error)")
return false
Expand All @@ -127,6 +150,25 @@ final class AlarmKitGameReminder: GameStartReminderServicing {
at date: Date,
productId: ProductId
) async throws {
let playIntent = GameAlarmPlayIntent()
playIntent.alarmID = newAlarmId.uuidString
playIntent.productId = productId

try await alarmManger.scheduleGameAlarm(id: newAlarmId, at: date, playIntent: playIntent)
}
}

@available(iOS 26.1, *)
extension AlarmManager: GameAlarmManaging {
var isAuthorized: Bool {
authorizationState == .authorized
}

func alarmIds() throws -> [UUID] {
try alarms.map(\.id)
}

func scheduleGameAlarm(id: UUID, at date: Date, playIntent: GameAlarmPlayIntent) async throws {
let attributes = AlarmAttributes(
presentation: AlarmPresentation(
alert: .init(
Expand All @@ -143,12 +185,8 @@ final class AlarmKitGameReminder: GameStartReminderServicing {
tintColor: Color.accentColor
)

let playIntent = GameAlarmPlayIntent()
playIntent.alarmID = newAlarmId.uuidString
playIntent.productId = productId

_ = try await alarmManger.schedule(
id: newAlarmId,
_ = try await schedule(
id: id,
configuration: AlarmManager.AlarmConfiguration(
countdownDuration: nil,
schedule: .fixed(date),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Foundation
import AlarmKit
import AppIntents
import IssueMonitoring
import Keystore_iOS
import UIKit

@available(iOS 26.1, *)
struct GameAlarmPlayIntent: LiveActivityIntent {
Expand All @@ -16,7 +19,28 @@ struct GameAlarmPlayIntent: LiveActivityIntent {
@MainActor
func perform() async throws -> some IntentResult {
if let productId {
ProductOpener().open(productId: productId)
let diagnostics = GameReminderDiagnostics(recorder: IssueMonitoringFactory.createHostEventRecorder())

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.

I think we are polluting actual logic with diagnostics and at some point it will be hard to read. What about putting all the event assembly inside diagnostic? We could have different classes of diagnostics depending on use case. In that way actual production code will just contain diagnostic instance injected without with record function call. What do you think?

let startsAt = { storedStartsAt(productId: productId) }
diagnostics.record(
GameReminderEvent(
step: .tapped,
productId: productId,
startsAt: startsAt(),
appState: .init(UIApplication.shared.applicationState)
)
)

if ProductOpener().open(productId: productId) {
diagnostics.record(
GameReminderEvent(
step: .productOpened,
productId: productId,
startsAt: startsAt(),
openSource: .alarm,
appState: .init(UIApplication.shared.applicationState)
)
)
}
}

if let alarmIDString = alarmID,
Expand All @@ -26,4 +50,10 @@ struct GameAlarmPlayIntent: LiveActivityIntent {

return .result()
}

/// The fire date the alarm was booked with, read from the settings that booking persisted.
private func storedStartsAt(productId: String) -> Date? {
SettingsManager.shared.integer(for: GameReminderStorageKeys.product(productId).alarmFireDate)
.map { Date(timeIntervalSinceReferenceDate: TimeInterval($0)) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Foundation
import IssueMonitoring

/// Records the troubleshooting trail for a product's game reminder through the shared host-event path.
struct GameReminderDiagnostics: Sendable {
private let recorder: any HostEventRecording
private let origin: HostEventOrigin
private let monotonicMilliseconds: @Sendable () -> Int

init(
recorder: any HostEventRecording = NoopHostEventRecorder(),
origin: HostEventOrigin = .current,
monotonicMilliseconds: @escaping @Sendable () -> Int = HostEventClock.monotonicMilliseconds
) {
self.recorder = recorder
self.origin = origin
self.monotonicMilliseconds = monotonicMilliseconds
}

/// The event is built only when the recorder keeps it.
func record(_ event: @autoclosure () -> GameReminderEvent) {
recorder.record(event().hostEvent(origin: origin, monotonicMilliseconds: monotonicMilliseconds()))
}
}
Loading
Loading