diff --git a/docs/initiatives/standalone/544-inherit-channel-notify/PLAN.md b/docs/initiatives/standalone/544-inherit-channel-notify/PLAN.md deleted file mode 100644 index 98f01468..00000000 --- a/docs/initiatives/standalone/544-inherit-channel-notify/PLAN.md +++ /dev/null @@ -1,204 +0,0 @@ -# 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 (`MyMesh.cpp:3008-3013`, client side `meshcore_protocol.dart:586-592`) and is already true on radios that know only all/self/none. The owner's T1000-E is one. | Inherit needs a bit of its own. Per row 10b that is `caps2 0x80`. | -| 10 | `FIRMWARE_VER_CODE` **is rolling back to 14 and nothing may ride on it**. | Owner ruling relayed by FuchsiaCreek, Agent Mail 1401: "FIRMWARE_VER_CODE has conflicts to hell with 1.18.0 and needing to roll back to 14. No dependencies can ride on FIRMWARE_VER_CODE for Offband." Corroborated independently before the ruling arrived: `firmware-base` reads `22` while its own history line stops at #611 / `caps2 0x08` (`MyMesh.h:34`), and `caps2 0x10`, `0x20`, `0x40` plus sub-codes `0x0B`-`0x17` appear nowhere in it. [verified 2026-11-02 against the `firmware-base` checkout] | A `verCode >= N` gate is **not available to this feature**, and the pkt-hash precedent (`meshcore_protocol.dart:651`) is itself being retired. Capability signalling is caps bits, full stop. | -| 10b | So the signal is a **caps bit**, and `0x80` is the one left. | `0x01` scope, `0x02` matrix, `0x04` indicators, `0x08` pkt-hash, `0x10` tunes, `0x20` GPS, `0x40` screen (row 8). `0x80` is free. | Inherit takes `caps2 0x80`, which **exhausts caps byte 2**, so caps **byte 3** lands in this same work. No probe, no version floor. | -| 10c | Caps byte 3 goes at device-info offset **87**, not 85. | `MyMesh.cpp:3032-3036`: `offband_caps2` is written at 84, then `ui_led_enabled` at 85 and `ui_display_mode` at 86. [verified 2026-11-03] Read it the way byte 2 is read, length-gated: `frame.length >= 88 ? frame[87] : null` (`meshcore_connector.dart:7862-7863` is the byte-2 pattern). | Putting byte 3 at 85 would make every shipped client read a capability bitmask as the LED state, which is the exact mistake firmware's own comment at `MyMesh.cpp:2995-3000` warns about for byte 2. | -| 10d | The client ignores offsets 85 and 86 **today**, and has no `INDICATORS` constant. | No `uiLed` or `uiDisplay` reader anywhere in `lib/`; `meshcore_protocol.dart` has no `offbandCap2Indicators` for the `0x04` bit firmware sets at `MyMesh.cpp:3024-3026`. | Not this plan's scope, but it is the gap byte 3 gets appended past, so the offsets must be read from firmware's frame builder and not inferred from what the client currently parses. | -| 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 whose `caps2 0x80` is set but which still refuses `0x18` or scope `0x03` can say **why**, so that disagreement surfaces as a firmware bug instead of a dead control. | -| 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 advertises `caps2 0x80`. -- **`caps2 0x80`** as the capability bit, which exhausts caps byte 2, and therefore **caps byte 3**: a `parseOffbandCaps3` reading `frame.length >= 88 ? frame[87] : null`, length-gated and never version-gated, mirroring `parseOffbandCaps2` (`meshcore_connector.dart:7862-7863`). Absence means no byte-3 capabilities, never an error. -- `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. -- **Allocating any bit in caps byte 3.** This plan establishes the byte and its parser only, the way firmware's #508 established byte 2 all-zero. The first byte-3 bit belongs to whatever feature needs it next. -- The three shipped `FIRMWARE_VER_CODE` floors that break at 14 (block, caplog, pkt-hash). Separate fix, [#857](https://github.com/OffbandMesh/meshcore-client/issues/857). -- 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 without `caps2 0x80` and four with it; caps byte 3 reads from offset 87 and is `null` on a frame of 87 bytes or fewer, with 85 and 86 proven **not** to be mistaken for it; a DM decision is unchanged under Inherit (row 11). Red today on all but the DM case. Extends `test/connector/offband_device_ui_test.dart` and `test/connector/offband_caps2_test.dart`. | 4 | -| **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`, `offbandCap2ChannelNotify = 0x80` with its `firmwareSupports...` predicate taking **no** version argument, and `parseOffbandCaps3` at offset 87 (rows 10b to 10d). Checked by A1 and A2 going green. | 4 | -| **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 on `caps2 0x80` so it never appears on a radio that cannot do it (rows 4 and 10b), 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 | -|---|---|---| -| `caps2 0x80` clear, or caps byte 2 absent entirely | nothing: this is a definite answer | not a can't-tell branch. No Inherit row, no `0x18` traffic, behaviour identical to today. Listed so it is not mistaken for one. | -| `caps2 0x80` set, `0x18` GET sent, nothing back yet | what the radio's table holds | **stop**: loading row, no values shown, no 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 0x80` but refuses scope `0x03` or `0x19` with `0x7F` | why the bit and the behaviour disagree | **stop**: keep the previous value, show the refusal persistently, drop the control for this radio for the session. A bit that lies is a firmware bug and must surface as one, not be retried around. | -| Device-info frame is exactly 85, 86 or 87 bytes long | whether byte 3 is present | **stop**: `parseOffbandCaps3` returns `null`, same as byte 2 does on a short frame. Reading 85 or 86 as byte 3 would read the LED or display state as a capability mask (row 10c). | -| 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. - -- **Regression assertion, non-negotiable:** a test that sets `firmwareVerCode = 14` and asserts every gate this plan adds still returns `true` with its bit set. Row 10's ruling is only enforced if something fails when it is broken. - -- **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 advertise `caps2 0x80` behaves exactly as it does today, with no new UI and no new frames. -- **No gate this plan adds reads `FIRMWARE_VER_CODE`**, and a device reporting 14 behaves identically to one reporting 22. -- Caps byte 3 reads from offset 87, is `null` on any shorter frame, and holds no allocated bits yet. -- 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 | 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 | | - -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. - -**Settled, not re-asked.** Three questions were open in the draft of this plan and are now answered, so they are recorded here rather than put to you again: - -- **The capability signal is `caps2 0x80`**, and caps byte 3 lands in this work at offset 87. Settled by the Agent Mail 1401 ruling: capability signalling is caps bits. The draft had recommended a probe instead, on the reasoning that the version-code route was unsafe; the ruling reaches the same conclusion about the version code and picks the bit, which is better, because a bit needs no round trip and no "haven't heard yet" state. -- **Nothing rides on `FIRMWARE_VER_CODE`.** Same ruling. This plan adds no version floor, and the three shipped gates that already have one are a separate fix under [#857](https://github.com/OffbandMesh/meshcore-client/issues/857). -- **When the device and the cache disagree, the device wins.** That is #838 sync-is-truth Option A, decided and recorded. - -## 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. | -| The three shipped gates that go false at `verCode = 14`: block `>= 15`, caplog `>= 17`, pkt-hash `>= 22`. Verified inventory, including three more latent readers and the one at zero margin (`observer_config_client.dart:95,127`), is commented on the issue. | [#857](https://github.com/OffbandMesh/meshcore-client/issues/857). Its own build issue, tests and PR. Not folded into this plan, and not started: it changes user-visible behaviour on shipped features. | -| The client parses neither device-info offset 85 nor 86, and has no constant for the `caps2 0x04` indicators bit firmware already sets (row 10d). | Its own issue. Named here only because byte 3 is appended past those offsets. | -| 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. diff --git a/docs/initiatives/standalone/544-radio-channel-notify/PLAN.md b/docs/initiatives/standalone/544-radio-channel-notify/PLAN.md new file mode 100644 index 00000000..2998333a --- /dev/null +++ b/docs/initiatives/standalone/544-radio-channel-notify/PLAN.md @@ -0,0 +1,193 @@ +# Feature PLAN: radio channel notifications, independent of app notifications + +| | | +|---|---| +| **Feature** | [#544](https://github.com/OffbandMesh/meshcore-client/issues/544) · Citadel `meshcore-open-pmu` | +| **Serves** | Standalone. Closes research child [#545](https://github.com/OffbandMesh/meshcore-client/issues/545). Firmware half: [meshcore-firmware#606](https://github.com/OffbandMesh/meshcore-firmware/issues/606). | +| **Status** | Draft. Approved when this PR merges. | +| **Owner** | @Strycher | +| **Last updated** | 2026-11-03 | + +## At a glance + +- **What:** a second, independent per-channel notification control that sets the **radio's** buzzer, beside the existing per-channel control that sets the **phone's** notifications. +- **Why now:** the app's per-channel setting never reached the radio, and the shipped T1000-E guide documents that gap as a limitation. Firmware now stores a per-channel mode and answers `0xC5 0x18/0x19`. +- **How:** Epic A reproduces the gap as failing tests, Epic B the wire and sync, Epic C the two separate controls, Epic D the owner's paired hardware check. +- **Done when:** a channel's **radio** setting changes what the buzzer does with the phone disconnected, a channel's **app** setting changes what the phone does, and neither one moves the other. + +## The directive this is built to + +Owner, 2026-11-03: + +> "Rewrite, separate app notifications from radio notifications, so that they are separate controls and separate notifications. radio notifications set the channel setting in the radio and app notifications in the app. They are independent settings." + +Earlier, on why one merged value was wrong: + +> "I'm wondering if this should be separated between in-app/on-phone notifications (we have this already) and a separate setting for radio notifications (addition to the menu)." + +**Consequence: there is no bridging.** No Inherit option in the app's phone setting, no resolution function that reads one to answer the other, no precedence rule between them. Two stores, two controls, two outputs. + +## 1. Diagnosis + +| # | Finding | Evidence | Effect | +|---|---|---|---| +| 1 | The app's per-channel setting is **phone-only** and always was. | `ChannelNotifyMode { all, mentionsOnly, off }`, `lib/models/app_settings.dart:31`. Stored per radio then per PSK in `channelNotifyModesByRadio`, resolved at `lib/services/app_settings_service.dart:249-259`, written at `:265-299`. Rendered by `lib/widgets/channel_notify_mode.dart:14-34` from the Channels list and the channel chat menu. | It needs no change in behaviour. It becomes the **app** half of a labelled pair, nothing more. | +| 2 | Nothing in the client reaches the radio's per-channel notify. | No `0x18`/`0x19` sub-code exists in `lib/connector/`. Allocated sub-codes stop at `0x17` (`offband_screen_settings.dart:13-17`). | The radio half is entirely new client code. | +| 3 | Firmware has built it and the contract is settled. | FuchsiaCreek, Agent Mail 1406: `[0xC5][0x18][chan_idx]` GET, `[0xC5][0x19][chan_idx][mode]` SET replying with a re-read; `mode` 0 not set / 1 all / 2 mentions / 3 off; keyed by channel **slot index**; `OFFBAND_CAP2_CHAN_NOTIFY = 0x80` gated on `PIN_BUZZER`; built green on branch `epic/606-channel-notify`. | Build to this. It is not mine to redesign, and it is unpushed, so Epic D waits on the owner's firmware gate. | +| 4 | The encoding mirrors a surface that already ships. | `ChannelTune`: stored byte 0 means "no choice", any other value is `id + 1`, keyed by slot index, SET answered by a re-read, local state follows the reply and never the request. `lib/connector/offband_device_ui.dart:292-330`; send path `lib/connector/meshcore_connector.dart:1113-1145`; tests `test/connector/channel_tune_connector_test.dart`. | The radio half is a copy of a tested surface, not a new mechanism. | +| 5 | The client stores by **PSK**; the wire is keyed by **slot**. | #839 made the app 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 radio half keys by slot and needs no PSK bridge for its own store, but it must map a channel row to a slot to address it. A channel whose slot the radio has not reported cannot be addressed. | +| 6 | `caps2 0x80` fills caps byte 2, so **caps byte 3** arrives with it, at offset **87**. | FuchsiaCreek 1406, and firmware's own frame builder: `offband_caps2` is written at 84, then `ui_led_enabled` at 85 and `ui_display_mode` at 86 (`examples/companion_radio/MyMesh.cpp:3032-3036`). Read it length-gated, never version-gated. | A `parseOffbandCaps3` mirroring `parseOffbandCaps2` (`meshcore_connector.dart:7862-7863`). Reading byte 3 at 85 would parse the LED state as a capability mask. | +| 7 | The radio's **own** fallback is not the client's business, but the client must render the truth. | Per 1406: a channel with a mode set decides for itself; a channel with no mode falls back to the radio's device-wide scope; a device scope of `None` overrides even a set channel. The device-wide default is now `Self`. | The radio control cannot display the stored byte as if it were the effective behaviour. See §6 and decision 1. | +| 8 | The device-wide scope control already ships in the client. | Section header "Device notification scope" with All / Self / None rows, `lib/screens/settings/device_ui_view.dart:129` and `:195-210`; enum at `lib/connector/offband_device_ui.dart:194-210`. On the badge the same byte is the Setup row labelled "Sound" (`ui-new/BadgeScreens.cpp:1622`, cycled at `:1675-1689`). | The owner has said this control **may be deprecated** by per-channel settings. Firmware still ships it and still falls back to it, so this plan leaves it in place and does not design its removal. Flagged in §10. | +| 9 | DMs are not a channel, so nothing per-channel covers them. | The device-wide scope is what distinguishes DM-and-mention beeping from all-message beeping (`offband_device_ui.dart:195-197`). | Another reason this plan does not touch the device-wide control. Raised with firmware; not resolved here. | +| 10 | The shipped user guide documents the gap this closes. | firmware PR #1967's T1000-E guide: "The client's per-channel setting does not reach the radio… 'beep only when mentioned' is a whole-radio setting." | That text needs correcting when the firmware half merges. Firmware's to make, named here so it is not lost. | + +## 2. Scope + +**In:** +- A **new** per-channel radio control, writing `[0xC5][0x19][chan_idx][mode]` and reading `0x18`, gated on `caps2 0x80`. +- `parseOffbandCaps3` at device-info offset 87, length-gated. +- Per-radio client state for the radio modes, cleared on radio change like every other `0xC5` surface, written only from a device reply. +- Labelling both controls so it is obvious which output each one governs. +- New strings English-only, with the regenerated `untranslated.json` committed. + +**Out:** +- **Any change to the app's per-channel notify behaviour.** It keeps its store, its resolution and its three values. Only its label and placement change. +- **Any bridging between the two.** No Inherit in the app control, no shared resolution, no precedence. +- **The device-wide scope control**, including its possible deprecation (row 8) and the DM question (row 9). +- **Any bit in caps byte 3.** This establishes the byte and its parser only. +- The firmware half, and the guide correction in firmware PR #1967. +- **Killed by the owner's rulings, recorded so they are not re-proposed:** `NOTIFY_SCOPE_INHERIT = 3` (there is no firmware Inherit; "how would firmware inherit from firmware?"), the 4-byte `sha256(psk)` key, the width byte, collision escalation, CLEAR-then-repush, and a separate global gate byte. + +## 3. Epics + +Tasks are 3-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: the gap, as failing tests + +| Task | Pts | +|---|---| +| **A1 · The radio modes do not exist:** a `0x18` reply for slot 1 with mode 2 resolves to Mentions for slot 1; mode 0 resolves to "not set"; a reply for a slot with no channel is dropped, not applied to a guessed channel. Red today: no parser. New `test/connector/channel_notify_connector_test.dart`, shaped on `channel_tune_connector_test.dart`. | 3 | +| **A2 · Independence, asserted:** setting the app mode for a channel emits **no** `0x18`/`0x19` traffic, and a `0x19` reply does **not** change `channelNotifyModesByRadio`. This is the test that keeps the two from being re-merged later. | 3 | +| **A3 · Capability and byte 3:** the radio control is absent without `caps2 0x80`; caps byte 3 reads offset 87 and is null on a frame of 87 bytes or fewer, with 85 and 86 proven not to be mistaken for it. | 3 | +| **A4 · Epic verification** | 1 | + +### Epic B: the wire and the sync + +| Task | Pts | +|---|---| +| **B1 · The contract:** `offbandUiChannelNotifyGet = 0x18`, `offbandUiChannelNotifySet = 0x19`, a `RadioChannelNotify` value type with the 1-based encoding and an explicit unset, frame builders reusing `_channelByte`, `DeviceUiSurface.channelNotify`, `offbandCap2ChannelNotify = 0x80`, `parseOffbandCaps3`. | 4 | +| **B2 · Connector state:** a per-radio slot-to-mode map cleared in `_clearDeviceUiState`, `_handleDeviceUiReply` extended, suppression logged through `_deviceUiGateOpen`, request and set methods shaped on `requestChannelTune` / `setChannelTune` so state follows the reply and never the request. | 4 | +| **B3 · Read on connect:** once the channel table is known and the bit is set, GET each populated slot. A channel with no known slot is not addressed and is reported, not silently skipped. | 3 | +| **B4 · Epic verification** | 1 | + +### Epic C: two controls, clearly separate + +| Task | Pts | +|---|---| +| **C1 · The radio control:** a new per-channel affordance that writes the radio mode, gated on `caps2 0x80`, with the shipped "not saved until the radio replies" behaviour and a refusal shown with `persist: true`. Offers All / Mentions / Off / Not set. | 4 | +| **C2 · Labelling, so neither is mistaken for the other:** the existing control reads as the phone's notifications, the new one as the radio's sound. Both reachable from the same places the app control already is (`channels_screen.dart:534`, `channel_chat_screen.dart:476`), never merged into one row. | 3 | +| **C3 · Effective state, not the raw byte:** where the radio control shows what a channel will actually do, it composes the radio's rules from row 7 rather than displaying the stored mode. A channel set to All under a device scope of None is not shown as All. | 3 | +| **C4 · The #475 contract note, rewritten:** the two vocabularies stay distinct and are now two independent settings over two outputs. Plus the new English strings and the regenerated `untranslated.json`. | 3 | +| **C5 · Epic verification** | 1 | + +### Epic D: Integration Testing (owner, paired) + +| Task | Pts | +|---|---| +| **D1 · Independence on hardware:** set a channel's radio mode to Off and its app mode to All; the buzzer stays silent with the phone disconnected and the phone still notifies. Then the reverse. Needs a firmware image answering `0x18`/`0x19`. | 3 | +| **D2 · The negative test:** a radio without `caps2 0x80` shows no radio control and sends no `0x18`/`0x19`; the app control behaves exactly as it does today. | 3 | +| **D3 · Epic verification** | 1 | + +## 4. Order and dependencies + +A, then B, then C, then D. A is the red baseline; 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 and B3 both touch `lib/connector/meshcore_connector.dart`. C2 touches `channels_screen.dart`, `channel_chat_screen.dart` and `channel_notify_mode.dart`, which nothing else here touches. + +**Only Epic D depends on firmware.** A to C land on their own tests with no firmware change. D is a paired hardware test the owner runs; the firmware branch is unpushed and its PR is his gate. + +## 5. Grants and authorization + +| Term | Proposed | Why | +|---|---|---| +| **What merging this plan authorizes** | Building Epics A, B and C unattended, in order. | Each lands on tests needing 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. | +| **Epic verification** | Owner. | §7's command is the evidence each PR shows. | +| **Owner steps during the run** | None until Epic C merges. Then a paired image, a flash, and Epic D. | Nothing in A to C needs hardware. | +| **Stops** | Anything in §6. Also any sign the `0x18` contract does not match what a flashed image answers: that stops and goes to the owner. | | +| **Flash** | Not authorized by this plan. The owner flashes; I name the image. | Client session. | + +```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 two controls. 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, and the numbers are filled in here then. + +## 6. Can't-tell branches + +| Where | Can't tell what | Does | +|---|---|---| +| `caps2 0x80` clear, or caps byte 2 absent | nothing: that is a definite answer | not a can't-tell branch. No radio control, no `0x18` traffic, app control unchanged. Listed so it is not mistaken for one. | +| `caps2 0x80` set, `0x18` GET sent, nothing back | what the radio holds for this channel | **stop**: loading row, no value shown, no write offered. The scope surface already behaves this way (`device_ui_view.dart:180-190`). | +| A `0x18` reply names a slot with no matching channel | which channel it means | **stop**: drop it and log it. Never apply a mode to a guessed channel. | +| A channel row whose slot the radio has not reported | which slot to address | **stop**: do not write; surface it on the row. Silent non-delivery is the failure #839 was fixed to end. | +| `caps2 0x80` set but the radio refuses `0x19` with `0x7F` | why the bit and the behaviour disagree | **stop**: keep the previous value, show the refusal persistently, drop the control for this radio for the session. A bit that lies is a firmware bug and must surface as one. | +| Device-info frame is exactly 85, 86 or 87 bytes | whether byte 3 is present | **stop**: `parseOffbandCaps3` returns null, as byte 2 does on a short frame. Reading 85 or 86 would parse the LED or display state as a capability mask (row 6). | +| Radio connected, `0x18` answered, but the device-wide scope is unknown | what a channel with mode 0 will actually do | **stop**: show the channel as "not set" and do not claim an effective behaviour. The composition in row 7 needs both values; with one missing there is nothing truthful to display. | +| No radio connected, and the **app** control is read | nothing: the app store is local and complete | not a can't-tell branch. The app setting is independent and answers from its own store, exactly as it does today. | + +No fail-open branch is proposed. If one proves necessary it comes to the owner for a fail-open grant before the merge, not after. + +## 7. Verification + +- **Named command:** + +``` +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 test/services/app_settings_service_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 §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 the radio half is copied from, and a regression there means the copy was wrong. + +- **Independence assertion, non-negotiable:** A2 must fail if the two settings are ever wired together. Prove it fails before trusting it. + +- **Acceptance bar:** A1 to A3 fail before Epic B and pass after. D1 shows the two settings moving independently on real hardware with the phone disconnected for the radio half. Green tests alone do not meet the bar: the point is that two controls drive two outputs without touching each other. + +## 8. Done when + +- A channel's **radio** setting changes what the buzzer does, with the phone disconnected. +- A channel's **app** setting changes what the phone does, exactly as it does today. +- Changing either one leaves the other untouched, asserted by a test. +- The radio control appears only on radios advertising `caps2 0x80`, and such a radio behaves exactly as today without it. +- Caps byte 3 reads from offset 87, is null on a shorter frame, and holds no allocated bits. +- No gate this plan adds reads `FIRMWARE_VER_CODE` (#1065). + +## 9. Your choices + +| # | Question | Option A | Option B | Rec. | Your choice | +|---|---|---|---|---|---| +| 1 | What the radio control shows for a channel whose radio mode is **Not set**. | **Show the composed result** ("Follows the radio: mentions only"), computed from the device-wide scope per row 7. Truthful, and makes None-overrides-everything visible. Costs reading the scope on connect. | **Show "Not set"** and nothing more. Simpler, but a user with the radio muted sees "Not set" on a channel they explicitly set to All and cannot tell why it is silent. | ⭐ A | | + +**Settled, not re-asked:** the two settings are separate and independent (owner, 2026-11-03). The capability signal is `caps2 0x80` with caps byte 3 at offset 87. Nothing rides on `FIRMWARE_VER_CODE`. There is no firmware Inherit. + +## 10. Carried-in work + +| Item | Goes to | +|---|---| +| The firmware half: per-channel storage on the non-GUI variants and the `0x18`/`0x19` handler. Built green on `epic/606-channel-notify`, unpushed. | [meshcore-firmware#606](https://github.com/OffbandMesh/meshcore-firmware/issues/606). Epic D cannot run without it; Epics A to C do not wait on it. | +| Whether the device-wide notification scope is deprecated now that channels carry their own modes (row 8), and what then governs DM beeping (row 9). | Firmware's surface and the owner's call. This plan deliberately leaves the control in place and designs no removal. | +| The T1000-E guide text that documents the old gap (row 10). | firmware PR #1967's guide, corrected when the firmware half merges. | +| Retiring the GUI variants' own per-channel array. | Firmware, after #606; ChartreuseOtter layers the GUI onto the same byte. The client must not design around that array either way. | +| #545's deliverables are discharged here: the wire contract (§2), the decision matrix (§6 and row 7), the #475 note update (task C4), and settling with firmware (row 3). | Close #545 when this merges. | + +When this plan merges, each Epic and Task gets a GitHub issue and a Citadel task, per canon.