8000 Apple CI: a notifications read that times out is no answer, not Denied (#128) by rleibman · Pull Request #140 · rleibman/thicket · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions docs/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ Go decision (see `08` §8.1) is made after S1, S2, S3 have reports.

## Decision log

- 2026-11-02 — **Apple CI: a notifications read that times out is "no answer", not Denied**
(#128). Every failed `apple.yml` run since #132 merged (5 of 5 checked: 41391530485,
41390412068, 41374569722, 41374441105, 41374248305) failed one step, `ios-gallery`, on
"notifications start Denied, not yet asked". `bin/verify-apple.sh` reboots the simulator
before each iOS step. Right after a boot, `getNotificationSettings` can take longer than
`notificationStatus()`'s 5 s cap, and the cap read as `denied`. Now the shim answers 4,
"no answer within 5 s". `ApplePermissions.status` still reports it as `Denied`, so the API
is unchanged and the main thread waits no longer. `AppleDevice.testing.notYetAsked` asks
again, up to about 60 s, and logs the codes it saw. Measured from a cold boot (iPhone 18 Pro
Max, load average 166 with three agents building): `4,4,4,4,4,3` in 28.7 s, and the check
then passed. The "macOS app has no window" failures that opened #128 stopped with #113's
60 s window poll; getting-started has passed in every run since. The one `http-ios` that was
killed silently (run 41122835117) has not recurred.

- 2026-11-01 — **The live camera preview: the owner took every recommendation in
`docs/17-camera-preview.md` §17.8.**
1. **An embedding point, not a built-in `WidgetKind`:** `Element.Platform` in `core`, handled
Expand Down
7 changes: 6 additions & 1 deletion modules/device-apple/shim/Sources/DeviceShim.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ private let granted: Int32 = 0
private let denied: Int32 = 1
private let restricted: Int32 = 2
private let notDetermined: Int32 = 3
/// UserNotifications did not answer in time. Not an answer: `ApplePermissions.status` reports it
/// as Denied, and a self-test asks again (#128). Right after a simulator boots, the first
/// settings read took longer than 5 s on 3 of 7 boots (measured in #118), and reading that as
/// Denied failed "notifications start not yet asked" on every Apple CI run that rebooted first.
private let unknown: Int32 = 4
private let unsupported: Int32 = -1

// MARK: - lifecycle
Expand Down Expand Up @@ -156,7 +161,7 @@ private func notificationStatus() -> Int32 {
status = s.authorizationStatus
done.signal()
}
if done.wait(timeout: .now() + 5) == .timedOut { return denied }
if done.wait(timeout: .now() + 5) == .timedOut { return unknown }
switch status {
case .authorized, .provisional: return granted
case .denied: return denied
Expand Down
5 changes: 3 additions & 2 deletions modules/device-apple/shim/include/thicket_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ void thk_dev_on_terminate(thk_dev_void_cb terminating, int64_t ctx);
usage key (iOS terminates an app that asks without one), or an app bundle (notifications).
A string that lives as long as the process. */
const char *thk_dev_permission_missing(int32_t permission);
/* The answer as it stands, without asking. Waits for UserNotifications' answer, a few ms,
so Scala marks the call blocking. */
/* The answer as it stands, without asking: 0 granted, 1 denied, 2 restricted, 3 not yet
asked, 4 UserNotifications did not answer within 5 s (#128). Waits for that answer, usually a
few ms, so Scala marks the call blocking. */
int32_t thk_dev_permission_status(int32_t permission);
/* Asks the user (the system shows its dialog only while the answer is not yet given) and calls
`answered` with the resulting status, always later, on the main thread. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ object ApplePermissions extends Permissions {
p: Permission
): PermissionStatus =
code match {
case 0 => PermissionStatus.Granted
case 2 => PermissionStatus.Restricted
case 1 | 3 => PermissionStatus.Denied
case _ =>
case 0 => PermissionStatus.Granted
case 2 => PermissionStatus.Restricted
// 4: UserNotifications did not answer in time (#128). Not an answer, so not Granted.
case 1 | 3 | 4 => PermissionStatus.Denied
case _ =>
throw UnsupportedOperationException(s"$p is not supported by thicket-device-apple")
}

Expand Down Expand Up @@ -164,7 +165,19 @@ object AppleDevice {
* refusal. A self-test needs the difference: a refusal left over from an earlier run answers at once, with no
* alert, and would pass a check of "Don't Allow" without one.
*/
def notYetAsked(p: Permission): Boolean = DeviceShim.thk_dev_permission_status(p.ordinal) == 3
def notYetAsked(p: Permission): Boolean = {
// 4 is "UserNotifications did not answer in time": right after a simulator boots, its first settings read can
// take longer than the shim's 5 s (#128). That is no answer, so ask again, up to about 60 s, rather than read it
// as a refusal. Measured from a cold boot under heavy load: 4,4,4,4,4,3 in 28.7 s, so about 60 s is allowed.
val started = System.nanoTime()
var codes = List(DeviceShim.thk_dev_permission_status(p.ordinal))
while codes.head == 4 && codes.size < 12 do codes = DeviceShim.thk_dev_permission_status(p.ordinal) :: codes
println(
s"[device] $p status codes ${codes.reverse.mkString(",")} in ${(System.nanoTime() - started) / 1000000} ms " +
"(3 not yet asked, 1 denied, 4 no answer within 5 s)"
)
codes.head == 3
}

/** How many location listeners `libthicketdevice.a` has (`thicket-location-apple`, #118): `CLLocationManager` is
* updating while this is not 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ object DeviceAbi {
"thk_dev_permission_status",
I32,
List(permission),
doc = "The answer as it stands, without asking. Waits for UserNotifications' answer, a few ms,\n" +
" so Scala marks the call blocking.",
doc = "The answer as it stands, without asking: 0 granted, 1 denied, 2 restricted, 3 not yet\n" +
" asked, 4 UserNotifications did not answer within 5 s (#128). Waits for that answer, usually a\n" +
" few ms, so Scala marks the call blocking.",
blocking = true
),
Fn(
Expand Down
Loading
0