docs(#545): plan of record for #544 Inherit per-channel notify, client half

Built to the owner's architecture ruling (AM 1399): one stored pref the
variant owns, not two. Re-grounded against firmware-base, which changed
three findings from the August design:

- the firmware table is already slot-keyed, range-checked, assertion-sized
  and persisted (GuiPrefs.h:26-27, GuiPrefs.cpp:39-41,76, MyMesh.cpp:1293,
  4687-4689), so the ruling's keying is what firmware already does
- the non-GUI alert path has no per-channel mode at all (MyMesh.cpp:1286-1296
  ifdef/else), so neither target has the pref the ruling reuses
- FIRMWARE_VER_CODE on firmware-base reads 22 while caps2 0x10/0x20/0x40 and
  sub-codes 0x0B-0x17 are absent from its history, so a version gate is unsafe

Kills the August design's sha256(psk) key, width byte, collision escalation,
CLEAR-then-repush and separate gate byte. Three decisions left for the owner
in section 9.
pull/1350/head
diffwireauto 4 weeks ago
parent ce8da46764
commit 0e4f02789d

@ -0,0 +1,189 @@
# Feature PLAN: Inherit, one channel notify pref the radio owns
| | |
|---|---|
| **Feature** | [#544](https://github.com/OffbandMesh/meshcore-client/issues/544) · Citadel `meshcore-open-pmu` |
| **Serves** | Standalone. Closes the research/design child [#545](https://github.com/OffbandMesh/meshcore-client/issues/545). Firmware half is [meshcore-firmware#606](https://github.com/OffbandMesh/meshcore-firmware/issues/606). |
| **Status** | Draft. Approved when this PR merges. |
| **Owner** | @Strycher |
| **Last updated** | 2026-11-02 |
## At a glance
- **What:** a 4th device-notify scope, **Inherit**, plus a per-channel notify mode the radio stores and the app sets over `0xC5` sub-codes `0x18` / `0x19`.
- **Why now:** the same user choice exists in two places that do not know about each other. The owner ruled there must be one, and the client half is the half that has to stop being a second source of truth.
- **How:** Epic A turns the gap into failing tests, Epic B builds the wire and the sync, Epic C makes one resolved value drive both the radio and the phone, Epic D is the owner's paired hardware check.
- **Done when:** with Public = Mentions, #skywarn = All, #wardriving = None set in the app, the T1000-E buzzer follows all three **with the phone disconnected**, and the phone's own notifications follow the same three values.
**The ruling this is built to**, relayed by FuchsiaCreek in Agent Mail 1399, verbatim:
> The way this is supposed to work is that the variant/board has a stored channel pref, all, mention, off, and for those with buzzer, sound/tone. Exposing a way for the GUI or for client to set it shouldn't result in 2 separate prefs for the same thing.
## 1. Diagnosis
What is true today, with evidence. Every Epic below traces back to a row here.
| # | Finding | Evidence | Effect |
|---|---|---|---|
| 1 | The pref **already exists twice**. | Client: `channelNotifyModesByRadio`, keyed device prefix to PSK to mode, `lib/services/app_settings_service.dart:249-299`. Firmware: `uint8_t notify_default` and `uint8_t channel_notify[kGuiMaxChannels]`, `src/helpers/gui/GuiPrefs.h:26-27`, persisted as `"nchan"` at `GuiPrefs.cpp:76`, consulted in the alert decision at `examples/companion_radio/MyMesh.cpp:1292-1293`. | Two sources of truth for one choice. This is exactly what the ruling forbids, and it is the whole feature. |
| 2 | The firmware copy is **GUI-only**, and the non-GUI path has **no per-channel mode at all**. | `MyMesh.cpp:1286-1296` is an explicit `#ifdef OFFBAND_GUI` / `#else`. GUI builds compute `alert` from `notify_on && notify_channels && channelMsgShouldNotify(text) && channelAlerts(channelMode(channel_idx), ...)`. The `#else` is bare: `const bool alert = channelMsgShouldNotify(text);`. The two targets are the QCC badge and the T1000-E; neither is an `OFFBAND_GUI` build. | The pref the ruling says to reuse **does not exist on the hardware this ships to**. Firmware must lift it out of that block. The client cannot do this and must not design around the GUI array. |
| 2b | But the firmware table is **already the shape the ruling describes**, which is why the ruling is cheap to honor. | Keyed by **slot index**: `channelMode(channel_idx)` at `MyMesh.cpp:1293`, and `_ui->notifyChannel(channel_idx)` at `:1297`. Range-checked with an All fallback: `GuiPrefs.cpp:39-41`. Sized by assertion, not by hope: `static_assert(MAX_GROUP_CHANNELS <= kGuiMaxChannels, "GuiPrefs::channel_notify must cover every channel slot")`, `MyMesh.cpp:4687-4689`, `kGuiMaxChannels = 40` at `GuiPrefs.h:16`. | The slot-index keying in the owner's ruling is **not a new choice**; it is what firmware already does. Sizing, validation and the out-of-range fallback are solved. Firmware's half is to move the table and answer two sub-codes, not to design it. |
| 3 | The device scope has **no Inherit**, and `0x03` is free. | `DeviceNotifyScope { all(0x00), self(0x01), none(0x02) }`, `lib/connector/offband_device_ui.dart:194-210`. | Adding the value is a one-line enum change. |
| 4 | The scope UI is **driven straight off the enum**. | `DeviceNotifyScope.values.map(...)` builds the rows, `lib/screens/settings/device_ui_view.dart:195`. | A 4th enum value renders a 4th row **on every radio**, including ones that cannot do it. The row must be filtered, not just added. See row 9. |
| 5 | `0x18` / `0x19` is the **next free sub-code pair**, colliding with nothing. | Client allocations: `0x01`-`0x04` scope and matrix (`offband_device_ui.dart:58-61`), `0x0B`-`0x0E` channel tune and GPS (`:65-71`), `0x0F`-`0x12` event tones, preview, slot read (`lib/connector/offband_tones.dart:14-17`), `0x13`-`0x17` screen settings (`lib/connector/offband_screen_settings.dart:13-17`), `0x7F` error. | The owner's allocation is the next pair in sequence. Nothing has to move. |
| 6 | **The exact encoding the ruling specifies already ships and is tested.** | `ChannelTune`: stored byte `0` means no choice, inherit the global; any other value is `id + 1`; keyed by channel **slot index**; the SET reply is a **re-read, not an echo**; local state follows the reply and never the request. `offband_device_ui.dart:292-330`, send path `lib/connector/meshcore_connector.dart:1113-1145`, tests `test/connector/channel_tune_connector_test.dart`. | Per-channel notify is a **copy of a shipped surface**, not a new mechanism. This is the strongest argument for building the ruling as written, and it is why the August design collapsed. |
| 7 | The client stores by **PSK**, the wire is keyed by **slot**. | #839 made the store PSK-keyed deliberately, with no bare-index fallback, because slot indices differ between radios: `app_settings_service.dart:246-258`. `Channel` carries both `index` and `pskHex`: `lib/models/channel.dart:12-24`. | The client must bridge PSK to slot from the **connected radio's own** channel table. A channel whose slot that radio has not reported cannot be pushed, and must not be guessed at. |
| 8 | `caps2` **`0x80` is the last free bit**. | `0x01` scope, `0x02` matrix, `0x04` indicators, `0x08` pkt-hash, `0x10` tunes, `0x20` GPS, `0x40` screen: `lib/connector/meshcore_protocol.dart:592-650`. Firmware agrees on `0x01`-`0x08`: `examples/companion_radio/OffbandConfigProtocol.h:337-351`. | Any new-bit option spends the last bit and forces a caps byte 3 for whatever comes next. |
| 9 | `caps2 0x01` **cannot** identify an Inherit-capable radio. | It is set wherever `PIN_BUZZER` is defined (`meshcore_protocol.dart:586-592`) and is already true on radios that know only all/self/none. The owner's T1000-E is one. | The client needs a signal that is not the scope bit. This is decision 1 in section 9. |
| 10 | `FIRMWARE_VER_CODE` **has drifted and cannot carry the gate**. | `firmware-base` reads `22`, and its own history line stops at #611 / `caps2 0x08`: `examples/companion_radio/MyMesh.h:34`. The client already ships `caps2 0x10`, `0x20` and `0x40` plus sub-codes `0x0B`-`0x17`, none of which appear in that line, and `firmware-base`'s `OffbandConfigProtocol.h` stops at `0x0A`. [verified 2026-11-02 against the `firmware-base` checkout] | A `verCode >= N` gate is **unsafe for this feature**: the number is not advancing with the contract. This rules out the option that would otherwise match the pkt-hash precedent (`meshcore_protocol.dart:651`). |
| 11 | DMs are **out of inheritance by spec**. | Owner, #544: DMs buzz under All, Self and Inherit; only None silences them. | Inherit changes channel behavior only. No DM path is touched, and a test asserts that. |
| 12 | The refusal path is already per-surface and already explains itself. | `0x7F` carries a reason byte precisely so "this board has no buzzer" and "unknown action" read differently: `offband_device_ui.dart:74-79`. Suppression logging is de-duplicated through `_deviceUiGateOpen`. | A radio that refuses `0x18` or scope `0x03` can say so, which is what makes the probe in decision 1 viable. |
| 13 | The August design's **separate global gate byte** is unnecessary. | GUI firmware already has two master switches above the per-channel mode, `notify_on` and `notify_channels` (`MyMesh.cpp:1292`), and the ruling's `0x00` unset value means "inherit the device scope", which the existing `0x01` / `0x02` scope already sets. | No gate byte on the wire. The device scope is the gate, and `0x00` is how a channel defers to it. One of the reasons the August design collapsed. |
## 2. Scope
**In:**
- `DeviceNotifyScope.inherit` (`0x03`) over the existing `0x01` / `0x02`, rendered **only** where the radio accepts it.
- `0x18` notify GET and `0x19` notify SET, keyed by **channel slot index**, mode **1-based**: `0x00` unset (inherit the device scope), `0x01` all, `0x02` mentions, `0x03` off. SET replies with a re-read, never an echo.
- The device's table becomes the **single source of truth** for the per-channel pref on any radio that answers `0x18`. The client's PSK-keyed store becomes that radio's cache, written only from a device reply.
- Sync on connect once the channel table is known, and on every user change.
- The PSK to slot bridge.
- **One resolved value** feeding both the radio's buzzer decision and the phone's notification gate, so the two can no longer disagree.
- New strings English-only, with the regenerated `untranslated.json` committed.
**Out:**
- **The firmware half**, all of it: lifting `channel_notify` out of `#ifdef OFFBAND_GUI`, storing it on non-GUI variants, honoring it in the buzz decision, and answering `0x18` / `0x19`. [meshcore-firmware#606](https://github.com/OffbandMesh/meshcore-firmware/issues/606).
- Any change to DM notification or buzzing.
- Per-channel **tune**. Already shipped on `0x0B` / `0x0C` and unrelated to notify.
- **The August design, killed by the ruling and recorded here so it is not re-proposed:** the 4-byte `sha256(psk)` channel key, the width byte, hash-collision escalation, CLEAR-then-repush, and a separate global gate byte. The ruling replaces all of it with the slot index and the 1-based mode byte.
## 3. Epics
Tasks are 3 to 4 points. Each Epic ends with a verification task and gets one PR. Epic A reproduces the diagnosis as failing tests before anything is built.
### Epic A: reproduce the two prefs as failing tests
| Task | Pts |
|---|---|
| **A1 · The client ignores the device's table:** a `0x18` reply for slot 1 with mode `0x02` must resolve to Mentions for that slot's PSK; `0x00` must resolve to "follow the device scope"; a reply for a slot with no matching channel must be dropped rather than applied to a guessed PSK. Red today: there is no `0x18` parser. New file `test/connector/channel_notify_connector_test.dart`, shaped on `channel_tune_connector_test.dart`. | 3 |
| **A2 · Inherit does not exist and must not leak:** scope `0x03` parses as Inherit; the scope list offers **three** rows on a radio that has not answered `0x18`, and four only once it has; a DM decision is unchanged under Inherit (row 11). Red today on the first two. Extends `test/connector/offband_device_ui_test.dart` and `test/connector/offband_caps2_test.dart`. | 3 |
| **A3 · Epic verification** | 1 |
### Epic B: the wire and the sync
| Task | Pts |
|---|---|
| **B1 · The contract:** `offbandUiChannelNotifyGet = 0x18`, `offbandUiChannelNotifySet = 0x19`, a `ChannelNotifyReply`, frame builders reusing `_channelByte`, `DeviceNotifyScope.inherit`, `DeviceUiSurface.channelNotify`. Checked by A1 and A2 going green. | 3 |
| **B2 · Connector state:** a per-radio slot to mode map cleared in `_clearDeviceUiState`, `_handleDeviceUiReply` extended to parse once and pass down, suppression logged through `_deviceUiGateOpen`, request and set methods shaped exactly on `requestChannelTune` / `setChannelTune` so state follows the reply and never the request. | 4 |
| **B3 · The bridge and the sync:** PSK to slot from the connected radio's channel table; on connect, GET every populated slot once the table is known; on a user change, SET then take the re-read. A channel with no known slot is **not pushed and is reported**, not silently dropped (row 7). | 4 |
| **B4 · One resolution:** a single function the phone gate and the UI both call, so the device's value wins wherever it exists and the cache stands alone only where it does not. This is the task that makes the two prefs one. | 3 |
| **B5 · Epic verification** | 1 |
### Epic C: the UI and the contract note
| Task | Pts |
|---|---|
| **C1 · The Inherit row:** added to the Button and buzzer pane, filtered by the signal from decision 1 so it never appears on a radio that cannot do it (row 4), with a subtitle that says what it follows. | 3 |
| **C2 · The channel selector writes through:** the existing 3-way selector on the Channels screen and the channel chat menu set the device when the radio speaks `0x18`, keeping the shipped "not saved until the radio replies" behavior; a refusal shows with `persist: true` rather than a 4-second flash, and the write is refused at the attempt with a reason, not hidden behind a disabled control. | 3 |
| **C3 · The #475 contract note, rewritten:** the device and app vocabularies stay distinct, but the per-channel pref is now **one value the device owns**. Plus the new English strings and the regenerated `untranslated.json`. | 3 |
| **C4 · Epic verification** | 1 |
### Epic D: Integration Testing (owner, paired)
| Task | Pts |
|---|---|
| **D1 · The owner's example on real hardware:** Public = Mentions, #skywarn = All, #wardriving = None set in the app; the T1000-E buzzer follows all three **with the phone disconnected**; the phone's notifications follow the same three. Needs a firmware image answering `0x18` / `0x19`. | 3 |
| **D2 · The negative test:** a radio that does not advertise the signal shows **no** Inherit row and sends **no** per-channel traffic; a radio that advertises the scope bit but refuses `0x03` keeps its previous scope and says why. | 3 |
| **D3 · Epic verification** | 1 |
## 4. Order and dependencies
A, then B, then C, then D. A is the red baseline the rest turns green. B owns the state C renders.
**Same files, so these do not run in parallel:** B1 and C1 both touch `lib/connector/offband_device_ui.dart`; B2, B3 and B4 all touch `lib/connector/meshcore_connector.dart`. C2 touches `lib/services/app_settings_service.dart`, `lib/screens/channels_screen.dart` and `lib/widgets/channel_notify_mode.dart`, which nothing else here touches.
**Epic D is the only part that depends on firmware.** Epics A to C land on their own tests with no firmware change, per the owner's standing rule: the client builds to the spec, firmware builds to the spec, and the owner tests the two together. D cannot be run by me at all, on any schedule, because it is a paired hardware test the owner runs.
## 5. Grants and authorization
What merging this plan authorizes, in words:
| Term | Proposed | Why |
|---|---|---|
| **What merging this plan authorizes** | Building Epics A, B and C unattended, in order. | Each lands on tests that need no radio and no firmware change. |
| **Merges** | 3, one per Epic (A, B, C). Epic D has no code and no PR. | Tasks are commits on the Epic branch, so there is no per-task PR. |
| **Epic verification** | Owner. | Section 7's command is the evidence each PR shows; the owner still approves each PR. |
| **Owner steps during the run** | None until Epic C is merged. Then: a paired image, a flash, and Epic D. | Nothing in A to C needs hardware, so there is nothing to babysit. |
| **Stops** | Anything in section 6. Also any sign that the `0x18` contract as written does not match what a flashed image actually answers: that stops and goes to the owner, it does not get worked around. | |
| **Flash** | Not authorized by this plan. The owner flashes; I name the image. | Client session, standing rule. |
```grant-terms
{
"epic_chain": [],
"chain": true,
"verification": { "mode": "owner" },
"merge": { "budget": 3, "basis": "one merge per code Epic: A the failing tests, B the wire and sync, C the UI and contract note. Epic D is the owner's paired hardware test and has no PR. Tasks are commits on the Epic branch, so there is no per-task merge." },
"flash": null,
"reset": null,
"expires_after_hours": 168
}
```
**`epic_chain` is empty on purpose.** The Epic issues do not exist yet; canon creates them when this plan merges. The numbers get filled in here then, the way #962's plan records its chain.
## 6. Can't-tell branches
| Where | Can't tell what | Does |
|---|---|---|
| `0x18` GET sent, nothing back yet | whether this radio speaks it | **stop**: loading row, no Inherit row, no per-channel push. The scope surface already behaves exactly this way (`device_ui_view.dart:180-190`). |
| A `0x18` reply names a slot with no matching channel | which channel it means | **stop**: drop the entry and log it. Never apply a mode to a guessed PSK. |
| A stored channel whose slot the connected radio has not reported | which slot to push to | **stop**: do not push; surface it on the channel row. Silent non-delivery is the failure mode #839 was fixed to end. |
| Radio advertises `caps2 0x01` but refuses scope `0x03` with `0x7F` | whether Inherit exists on this unit | **stop**: keep the previous scope, show the refusal persistently, drop the row for this radio for the session. |
| Two channels resolve to the same slot (duplicated PSK in the table) | which one is real | **stop**: push neither, report the clash. |
| A channel with **no** device-confirmed mode, on a radio that does not speak `0x18`, when the phone must decide whether to notify | what the user actually chose | **fail-open, needs grant**: resolves to **All** (notify), the already-shipped #839 default (`app_settings_service.dart:254-258`). It proceeds rather than stopping because the phone gate has to return something on every message. The direction is deliberate: All means a possibly unwanted notification, the alternative means a silently missed message. Marked rather than argued away, because it is a real fail-open and the direction is the owner's call. |
## 7. Verification
- **Named command:**
```bash
C:\Dev\flutter-meshcore\bin\flutter.bat test test/connector/channel_notify_connector_test.dart test/connector/offband_device_ui_test.dart test/connector/offband_caps2_test.dart test/connector/channel_tune_connector_test.dart
```
Plus `flutter analyze` on the touched files, `dart format` before every commit, and the full `flutter test` suite on each Epic's PR, because section 3 changes strings and string changes have broken asserts that `analyze` passed.
`channel_tune_connector_test.dart` is in the list deliberately: it is the shipped surface this one is copied from, and a regression there means the copy was wrong.
- **Acceptance bar:** A1 and A2 fail before Epic B and pass after. The owner's three-channel example in D1 behaves correctly with the phone disconnected, and D2's negative case shows no new UI and sends no new traffic. The bar is not met by green tests alone: the ruling is about there being one pref, so the proof is that changing it in the app changes what the radio does with no phone attached.
## 8. Done when
- Setting a channel's notify mode in the app changes what the **radio** does, with the phone disconnected.
- The app and the radio cannot hold different values for the same channel on a radio that speaks `0x18`.
- Inherit appears only on radios that accept it, and never on a radio that merely advertises the scope bit.
- A radio that does not speak `0x18` behaves exactly as it does today, with no new UI and no new frames.
- DMs behave exactly as before under All, Self and Inherit, and are silenced only by None.
- The #475 "never merge the vocabularies" note says what is actually true now.
## 9. Your choices
| # | Question | Option A | Option B | Rec. | Your choice |
|---|---|---|---|---|---|
| 1 | How does the client know a radio accepts Inherit and `0x18`? Row 9 rules out the scope bit; row 10 rules out a version-code gate. | **Probe.** Send `0x18` for slot 0 on connect. A real reply means supported, `0x7F` means not, silence means not yet (stop, show nothing). Costs one frame per connect and spends no capability bit. The loading-then-reply state machine it needs is already shipped on every `0xC5` surface. | **Spend `caps2 0x80`.** Unambiguous and needs no probe, but it is the **last free bit** (row 8) and the next capability after it forces a third caps byte. | ⭐ A | |
| 2 | `FIRMWARE_VER_CODE` on `firmware-base` reads 22 while three later `caps2` bits and sub-codes `0x0B`-`0x17` are absent from its history (row 10). | **Leave it.** Do not gate this feature on the number at all, and raise the drift with firmware separately as its own problem. | **Fix it first.** Ask firmware to re-base the number to match the shipped contract, then gate on `verCode >= N` the way pkt-hash does. Blocks this plan on another repo's merge. | ⭐ A | |
| 3 | On the first connect after this ships, a radio's table is empty (`0x00` everywhere) but the app already holds channel choices the user made. | **Push the app's existing choices up once per radio**, restricted to channels whose slot is known **and** whose device value is `0x00`, so a deliberate on-device choice is never overwritten. The user keeps what they configured. | **Take the radio's table as-is** and let the app's old entries fall away. Purest reading of "the radio owns the pref", but the user silently loses choices they already made in the app. | ⭐ A | |
Decision 3's Option B would be a silent loss of user settings, which is why A is the recommendation even though B is the simpler reading of the ruling.
**Already settled, not re-asked:** when the device and the cache disagree, the device wins. That is #838 sync-is-truth Option A, decided and recorded. This plan implements it; it does not revisit it.
## 10. Carried-in work
| Item | Goes to |
|---|---|
| Firmware must lift `channel_notify` out of `#ifdef OFFBAND_GUI` and store it on non-GUI variants (row 2), and answer `0x18` / `0x19`. Per row 2b this is a **move plus two sub-codes**, not a design: the table is already slot-keyed, range-checked, assertion-sized and persisted. | [meshcore-firmware#606](https://github.com/OffbandMesh/meshcore-firmware/issues/606). Named here because Epic D cannot run without it, not as a gate on Epics A to C. |
| `FIRMWARE_VER_CODE` drift on `firmware-base` (row 10). | Its own firmware issue. It is a contract-hygiene problem larger than this feature, and this plan deliberately does not depend on it. |
| The research/design child #545's four deliverables are discharged by this document: the wire contract (section 2), the decision matrix (sections 2 and 6, with the DM rule in row 11), the #475 note update (task C3), and settling with firmware (the ruling in At a glance). | Close #545 when this merges. |
| Retiring the duplicate GUI array once firmware owns the single pref. | Firmware's call, after #606. The client must not design around the array either way (row 2). |
When this plan merges, each Epic and Task gets a GitHub issue and a Citadel task, per canon.
Loading…
Cancel
Save

Powered by TurnKey Linux.