Skip to content

Merge dev into next-dev - #219

Merged
ps2 merged 11 commits into
next-devfrom
merge-dev-into-next-dev-214
Nov 10, 2026
Merged

ps2 merged 11 commits into
next-devfrom
merge-dev-into-next-dev-214

Conversation

@ps2

@ps2 ps2 commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Brings two dev changes into next-dev:

The merge has no conflicts. c79c2d7 was already recorded on next-dev by #215, so nothing from next-dev is reverted. The merged tree is identical to the build smoke-tested in the iOS Simulator against the pod simulator. That test covered a cold launch, a relaunch, two pod swaps in one app process, and background heartbeat cycles; every connect logged in and every command went through.

OmniTests: 218 run, 3 skipped, 0 failures.

Please merge with "Create a merge commit".

ps2 and others added 11 commits November 1, 2026 16:06
…ation

When the pod doesn't answer within the read timeout, readMessagePacket
cancelled the connection straight from the PeripheralManager queue. The
idle disconnect was moved off that queue in a715d9a because it raced
CoreBluetooth's teardown and wedged the next connect; this call was
missed. It also left commandConnectInFlight set, so the heartbeat probe
didn't re-arm after the disconnect. Route it through disconnectOnDemand.

Log the teardown and each peripheral configuration (duration, or the
error naming the step that timed out) as device events. A failed
configuration is ignored and the session's command then fails with
notReady; the nil disconnects in #199 are this
teardown, and these lines show where the time after a connect goes.
…s held

Routing the teardown through disconnectOnDemand cleared commandConnectInFlight
unconditionally, so with the app open (or a background Pod Keep Alive mode)
the drop no longer took the keep-alive reconnect path and the link stayed down
until the next command. Clear the flag only when the connection isn't held: a
held link reconnects as before, and an idle one re-arms the probe.

Also drop the comments saying a cancel from the PeripheralManager queue raced
CoreBluetooth and wedged the next connect. There's no evidence for it, and the
stuck-in-.connecting symptom is the InPlay link-layer wedge the eager watchdog
handles. The calls still go through managerQueue because the connect-on-demand
state lives there.
A cancel issued off managerQueue is suspected, without evidence, of wedging
the next connect. Record each cancel's time and whether it ran on
managerQueue, and when a connect sticks in .connecting (the eager watchdog
fires, or an on-demand connect times out) log a [stuckConnect] device event
with how long before it the last cancel ran and from which queue.

The forceful reconnect in PeripheralManager.reconnect still cancels from the
PeripheralManager queue, so field reports can compare the two.
…esponsive teardown in didDisconnect

logStuckConnect read lastCancel asynchronously, so on the eager watchdog
(already on managerQueue) the read ran after the watchdog's own cancel and
always reported it. It now reads synchronously when called on managerQueue.

disconnectUnresponsive no longer decides whether to keep commandConnectInFlight
when it cancels. It marks the teardown, and didDisconnect clears the flag if the
link isn't held at that moment. This closes the window where the app goes to the
background between the cancel and didDisconnect while the failing command
session is still counted: the flag stayed set and the probe didn't re-arm until
the next command.

Tag the unresponsive-pod and configuration device events.
The [stuckConnect] lines only existed to test whether a cancel from the
PeripheralManager queue wedges the next connect. Nothing in the field
reports points that way, so drop the bookkeeping and the comments that
still asserted it. The managerQueue helpers stay because the
connect-on-demand state lives there.
…er written

sendMessagePacket marks a message as possibly received before writing its
last packet. On Omnipod 5 a short message is a single packet, so a
missing characteristic after a failed discovery threw notReady before
anything was written, and the command was still recorded as
unacknowledged. notReady is only thrown before a write is issued, so
treat it as unsent: the session gets a certain failure and no pending
command to resolve.
…d disconnect

The device log couldn't say why the first exchange after a connect
failed in #199. Setup and login errors were
swallowed, and a disconnect didn't say who closed the link or what was
in progress.

- [connect] configured in Ns, with each step's time (services,
  characteristics, write size, hello, notifications, login), or
  configuration failed after Ns, with the error and the failing step. Login
  errors now reach this line instead of being logged only to os_log.
  Setup skipped on a fresh connection is logged too.
- [send] and [read] on a failed exchange: the error, the stage (CTS,
  packet i/n, data seq N, ...), whether the message was sent, what was
  done about it, the peripheral and central state, whether the
  characteristics are present, and the time since connect.
- [disconnect] on every disconnect: the error domain and code, or for
  our own cancels the reason (idle, unresponsive pod, background,
  watchdog, ...), with the time since connect, the phase (connect,
  setup, session name, idle) and the setup outcome.
- The retry after a dropped link says how setup went.

This replaces the [connectOnDemand] no response from pod line.
A pod that hangs up during a command, with the connection not held,
left commandConnectInFlight set: readMessagePacket saw the link already
down and skipped disconnectUnresponsive, so handleDisconnect took the
idle path with the flag still set and didn't arm the probe, and the idle
disconnect that would clear it needs a connected peripheral. With a
network CGM in the background nothing else issues a command, so the
heartbeat stopped.

handleDisconnect's decision now lives in DisconnectPolicy, which has no
CoreBluetooth dependency and is unit tested. A drop outside a command
session clears the flag. A drop during one leaves it to the session,
which may retry its connect, and when the last session ends with an
unheld link down, the flag is cleared and the probe armed. That replaces
unresponsiveTeardownPending, and keeps a cancelled probe's disconnect,
which can arrive after a command connect has started, from clearing the
flag under that connect.

Two device-log fixes: a connect that timed out was logged as a setup
failure at services, and a link iOS restored at launch was reported as
not connected.
…nect-queue

Log each connect's setup and every failed exchange and disconnect; don't mark unsent commands unacknowledged
* Unhook a replaced or forgotten PeripheralManager from BlePodComms

BlePodComms set itself as the delegate of each PeripheralManager it
adopted but never cleared it, so a pod's old manager (a pairing candidate
that lost out, or a pod that was forgotten) could still finish a queued
connect and call completeConfiguration(for:) on its own queue while
self.manager pointed at another manager. Session setup then ran against
self.manager and tripped its dispatchPrecondition.

Fixes #132

* Log in on the manager whose connect finished, and only for the current pod

Clearing a replaced manager's delegate stops new callbacks, but one that
has already started can still wait out the O5 write-size poll or
podStateLock while self.manager changes, and establishSession then built
the session on self.manager and trapped in sendMessagePacket. The session
is now established on the manager passed in, so it always runs on that
manager's queue, and completeConfiguration skips login when that manager
is no longer the pod's. Both skips are noted in the connect's setup log,
so a connect without a login no longer reads as setup ok with no login
step.
@ps2
ps2 merged commit 2a7ef46 into next-dev Nov 10, 2026
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