Two false locks with the phone present: missing_after=30 sat below the realistic worst-case event gap (beacon counter rotation every 10s times 2-20% duty sampling, with frozen-RSSI dedupe collapsing catches inside one window), and the connect probe ran while our own discovery duty-cycling was active, where attempts stall or abort with le-connection-abort-by-local. Probe now stops discovery first and retries (2x6s); sample config and handoff document the sampling math. Local config additionally raises rssi_lock to -85, where nearby-phone readings were pinning.
109 lines
5.3 KiB
Markdown
109 lines
5.3 KiB
Markdown
# Handoff notes
|
||
|
||
Dated notes for picking this project back up: what happened, what was
|
||
learned, and which threads are still open. AGENTS.md carries the distilled
|
||
rules; this file carries the history behind them.
|
||
|
||
## 2026-11-06 — two more false locks: sampling math and probe contention
|
||
|
||
**Symptoms.** Two false locks while the user was present: 11:24:24 (RSSI
|
||
-64, strong, phone advertising) and 11:57:30 (RSSI -82 after 10 minutes
|
||
pinned at -78..-82).
|
||
|
||
**Root causes.**
|
||
|
||
1. *`missing_after = 30` sat below the realistic worst-case event gap.*
|
||
The beacon rotates its ServiceData counter every 10 s, but the daemon
|
||
only *samples* the radio (2-20% duty). When the RSSI is frozen (BlueZ
|
||
dedupe), catches within one rotation window dedupe to nothing, so
|
||
event gaps of 25-60 s are routine — e.g. 11:56:32 → 11:57:30 (58 s
|
||
gap) reached `missing_after` and triggered a probe.
|
||
2. *The connect probe ran while our own discovery duty-cycling was
|
||
active.* With the phone in range and advertising, the probe still
|
||
stalled for its whole window and BlueZ returned
|
||
`le-connection-abort-by-local` — controller contention between our
|
||
scan windows and the connection attempt. The probe is the last line
|
||
of defense and was not reliable under load.
|
||
|
||
**Fixes shipped.**
|
||
|
||
- Probe: 2 attempts × 6 s with a 1 s pause, and discovery is stopped
|
||
before probing so the connection attempt gets a clean radio.
|
||
- `missing_after = 60` with the companion app (30 s is not enough given
|
||
the sampling math; third-party beacons still warrant 120 s).
|
||
- Local config: `rssi_lock = -85` — nearby-phone readings pinned at
|
||
-78..-82 dBm sat exactly on the -80 threshold and made the weak-signal
|
||
path flap constantly. Watch desk readings via the sighting reports.
|
||
|
||
**Lingering observations.**
|
||
|
||
- Desk RSSI varies hugely day to day (-44..-65 one day, -52..-86 the
|
||
next): interference, phone position, TX power. The `rssi_lock`
|
||
threshold needs headroom against this variance.
|
||
- `le-connection-abort-by-local` at probe time is now expected only when
|
||
our 6 s timeout cancels the attempt (zbus drops the call → bluetoothd
|
||
aborts); the retry covers the transient case.
|
||
|
||
## 2026-11-05 — false-lock debugging session
|
||
|
||
**Symptoms.** The daemon flipped Present⇄Suspect every minute or so and
|
||
locked the screen three times in ~20 minutes while the phone sat on the
|
||
desk at -44..-65 dBm (rssi_lock is -80).
|
||
|
||
**Root causes, in order of discovery:**
|
||
|
||
1. *Duty math*: at the Present duty cycle (100ms window / 5s interval,
|
||
~2% radio), the ~1 Hz beacon was only caught every ~25-50s — at or
|
||
beyond `presence_timeout_secs` (30). Journal showed Present stretches
|
||
of 46s/71s/45s, then a Suspect flip the moment a 30s gap appeared.
|
||
2. *BlueZ RSSI dedupe*: `device_set_rssi()` early-returns when the value
|
||
is unchanged, so a stationary phone's event stream goes fully silent
|
||
(with `DuplicateData = true` and regardless of duty cycle). Silence
|
||
for `missing_after_secs` (60) → lock, e.g. 14:36:56 and 14:39:07, both
|
||
exactly 60s after the last event.
|
||
3. *Beacon pauses*: the phone's beacon app stops advertising entirely for
|
||
60-90s+ stretches (doze / battery optimization). During a pause the
|
||
phone is undetectable *and* unconnectable — this is why the first 3s
|
||
connect probe failed at 14:49:56 while the phone was in range.
|
||
|
||
**Fixes shipped:**
|
||
|
||
- `policy.rs`: Present escalates to the Suspect duty once the last
|
||
sighting ages past half of `presence_timeout_secs`, without leaving
|
||
Present (kills the flapping; freshness restored within seconds).
|
||
- `bluez.rs`: pre-lock connect probe (`probe_reachable`), now 10s; a
|
||
successful connection cancels the lock and returns to Present.
|
||
Probe outcomes are logged at INFO/WARN — every lock decision is now
|
||
explainable from the journal.
|
||
- Config guidance: `missing_after_secs = 120` (sample config and local
|
||
config) so a lock requires the phone to be silent *and* unconnectable
|
||
for 130s straight.
|
||
|
||
**Decision: stay scan-only.** The alternative — a persistent LE
|
||
connection held by the daemon (presence = link, immune to advertising
|
||
pauses, ~zero desktop scanning while connected) — was tested and is
|
||
viable: a manual connection held 60s+ through a silent stretch and the
|
||
daemon stayed Present with no scanning. It remains the guaranteed fix if
|
||
false locks recur. Watch out if adopting it: connecting to a dual-mode
|
||
phone registers the PC as an audio device on the phone (A2DP SEPs show
|
||
up), and the phone battery profile changes (probably better than 1 Hz
|
||
advertising, but unverified).
|
||
|
||
**Verification notes.** `bluetoothctl connect <mac>` is a quick manual
|
||
oracle for "is the phone connectable right now". Probe behaviour at INFO:
|
||
`probe: no connection within 10s, treating phone as out of range` vs
|
||
`probe: connect rejected: ...`; success logs `connect probe: phone in
|
||
range, not locking`.
|
||
|
||
**Open threads:**
|
||
|
||
- If false locks recur despite 120s + 10s probe: check the journal for
|
||
the probe outcome line, then reconsider the persistent connection.
|
||
- AdvertisementMonitor (README roadmap) removes the RSSI-dedupe class of
|
||
problems at the controller level; needs BlueZ ≥ 5.65 and
|
||
`Experimental = true`.
|
||
- v2 unlock (GATT + biometric-signed nonce, see README) — the probe and
|
||
the persistent-connection findings are groundwork for that design.
|
||
- MSRV/toolchain: project pins `rust-version = "1.85"` so Ubuntu 24.04
|
||
and 26.04 build identically; Cargo.lock is committed.
|