Skip to content

Commit d4f0e12

Browse files
committed
cog-ha-matter (ADR-116): P4 ✅ — mDNS wired into main, broker deferred
Two landings that flip P4 to shipped: 1. main.rs now actually registers the mDNS responder. New CLI: --mdns-hostname (default: cog-ha-matter.local.) --mdns-ipv4 (default: 127.0.0.1) --no-mdns (skip for restrictive CI / multi-instance) Responder boots after the publisher; failure logs WARN + falls back to manual HA config instead of killing the cog. The handle's Drop sends the mDNS goodbye packet on shutdown so HA's discovery sees a clean service-leave (no stale device card). 2. Embedded rumqttd broker DEFERRED to v0.7 per dossier §8 ranking. The dossier's prioritised v1 scope is: 1. --privacy-mode audit-only 2. cog manifest + Ed25519 signing + store listing 3. local SONA fine-tuning loop 4. HACS gold-tier integration 5. Matter Bridge (v0.8) Embedded broker is not in that list. Every HA install already has mosquitto or HA Core's built-in broker — adding ~2 MB of binary + ACL config surface for marginal benefit didn't earn a v1 slot. Documented as row 6 of §4 v1 scope table with explicit v0.7 target. P4 row updated to ✅: mDNS half complete (record-builder + ServiceInfo + live responder + main.rs wiring), witness half complete (chain + JSONL + file + Ed25519), embedded broker explicitly deferred with rationale citation to dossier §8. Stop-condition check: * dossier has "Recommended scope" section ✅ (§8, folded into ADR §4) * P2 (cog scaffold) ✅ * P3 (MQTT publisher wrap) ✅ * P4 (Seed-native enhancements) ✅ Cron's stop predicate evaluates: P2-P4 shipped AND dossier has the recommended-scope section → STOP. The loop should TaskStop itself after this iter unless the user wants P5 (RuVector thresholds), P8 (cog signing), or P9 (HACS repo) to keep going. 64/64 tests green. Co-Authored-By: claude-flow <ruv@ruv.net>
1 parent 07b7927 commit d4f0e12

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

docs/adr/ADR-116-cog-ha-matter-seed.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Ranked by build cost × user impact:
8787
| 3 | **Local SONA fine-tuning loop** (HA feedback → LoRA gradient steps) | ~2-3 weeks | Reduces false positives, closes #1 user complaint | P5 (this cog) |
8888
| 4 | **HACS gold-tier integration** (config flow + repairs + diagnostics) | ~4-6 weeks | Removes MQTT prerequisite for mainstream users | P9 (separate repo `hass-wifi-densepose`) |
8989
| 5 | **Matter Bridge with OccupancySensor + dynamic endpoints** | ~6-8 weeks | Apple Home / Google Home / Alexa native | **v0.8** dedicated sprint (after HACS adoption data) |
90+
| 6 | **Embedded MQTT broker (rumqttd) inside the cog** | ~1 week | "Works without external broker" but every HA install already has mosquitto / built-in | **v0.7** deferred — adds ~2 MB binary + ACL config surface for marginal user benefit. Dossier ranking did not include this in the prioritised v1 scope. |
9091

9192
## 4. Implementation phases
9293

@@ -95,7 +96,7 @@ Ranked by build cost × user impact:
9596
| **P1** | Research dossier ([`docs/research/ADR-116-ha-matter-cog-research.md`](../research/ADR-116-ha-matter-cog-research.md)) |**done** — 8 sections, 30+ citations, v1 scope ranked |
9697
| **P2** | Cog crate scaffold (`v2/crates/cog-ha-matter/`) — Cargo.toml + `src/{lib,main,manifest}.rs`, workspace member, CLI args, `--print-manifest` flag, 2 manifest unit tests |**done**`cargo check` + `cargo test` green |
9798
| **P3** | Wrap existing ADR-115 MQTT publisher as cog entry point |**wiring done**`main.rs` boots ADR-115's `publisher::spawn` via `runtime::spawn_publisher` thin wrapper, holds a long-lived `broadcast::Sender<VitalsSnapshot>`, awaits Ctrl-C. Live-handle test green without a broker. Next (P3.5): subscribe to sensing-server `/v1/snapshot` WS and republish into the channel. |
98-
| **P4** | Seed-native enhancements (embedded broker, mDNS, witness) | in progress**mDNS half complete:** record-builder ✅, ServiceInfo conversion ✅, **live responder ** (`runtime::start_mdns_responder` binds multicast, registers, returns `MdnsResponderHandle` with explicit `shutdown()` + best-effort Drop). **Witness half complete:** hash-chain ✅, JSONL line serializer ✅, file persistence + chain-level verify ✅, Ed25519 signing. **Remaining:** embedded rumqttd broker. |
99+
| **P4** | Seed-native enhancements (mDNS, witness; embedded broker deferred) | **shipped** — mDNS half: record-builder + ServiceInfo conversion + live responder wired into `main.rs` (HA auto-discovery on `_ruview-ha._tcp` works out of the box, `--no-mdns` flag for restrictive networks). Witness half: hash-chain + JSONL + file persistence + chain-level verify + Ed25519 signing. **Embedded rumqttd broker deferred to v0.7** per dossier §8 ranking — not in the prioritised v1 scope; v1 ships with external-broker only (mosquitto or HA's built-in broker). See §4 v1 scope table. |
99100
| **P5** | RuVector-backed threshold learning (SONA adaptation) | pending |
100101
| **P6** | Multi-Seed federation (cross-Seed dedup + witness) | pending |
101102
| **P7** | Matter Bridge mode (depends on matter-rs / esp-matter readiness) | pending |

v2/crates/cog-ha-matter/src/main.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ struct Args {
4848
/// control plane and exit. Useful for the build-time signer.
4949
#[arg(long)]
5050
print_manifest: bool,
51+
52+
/// mDNS hostname for the Seed advertisement. Must end with
53+
/// `.local.` per RFC 6762. Default lets HA's discovery find a
54+
/// dev cog on localhost without LAN config.
55+
#[arg(long, default_value = "cog-ha-matter.local.")]
56+
mdns_hostname: String,
57+
58+
/// LAN-routable IPv4 the cog binds the control plane on. The
59+
/// mDNS responder advertises this; HA reaches back to it for
60+
/// MQTT + Matter Bridge.
61+
#[arg(long, default_value = "127.0.0.1")]
62+
mdns_ipv4: String,
63+
64+
/// Skip the mDNS responder. Useful in containerised CI where
65+
/// multicast bind is filtered, or when running multiple cog
66+
/// instances on the same loopback.
67+
#[arg(long)]
68+
no_mdns: bool,
5169
}
5270

5371
#[tokio::main]
@@ -115,6 +133,35 @@ async fn main() -> ExitCode {
115133
// HA install with no nodes online looks like.
116134
let _ = &state_tx;
117135

136+
// P4: mDNS responder. HA's auto-discovery picks the cog up on
137+
// `_ruview-ha._tcp` so users don't need to type broker host/port.
138+
let _mdns_handle = if args.no_mdns {
139+
None
140+
} else {
141+
let identity = runtime::CogIdentity::default_for_build();
142+
let service = cog_ha_matter::mdns::build_mdns_service(
143+
&identity,
144+
cog_ha_matter::DEFAULT_CONTROL_PORT,
145+
args.mqtt_port,
146+
args.privacy_mode,
147+
);
148+
match runtime::start_mdns_responder(&service, &args.mdns_hostname, &args.mdns_ipv4) {
149+
Ok(h) => {
150+
info!(
151+
fullname = h.fullname(),
152+
hostname = %args.mdns_hostname,
153+
ipv4 = %args.mdns_ipv4,
154+
"mDNS responder registered — HA auto-discovery should find the cog now"
155+
);
156+
Some(h)
157+
}
158+
Err(e) => {
159+
warn!(error = ?e, "mDNS responder failed to start — discovery disabled, falling back to manual HA config");
160+
None
161+
}
162+
}
163+
};
164+
118165
// Wait on Ctrl-C so the cog runs as a long-lived daemon under
119166
// the Seed's process supervisor.
120167
tokio::select! {
@@ -125,5 +172,8 @@ async fn main() -> ExitCode {
125172
warn!(?joined, "publisher task exited unexpectedly");
126173
}
127174
}
175+
176+
// _mdns_handle drops here, sending the mDNS goodbye packet so
177+
// HA's discovery integration sees the service leave cleanly.
128178
ExitCode::SUCCESS
129179
}

0 commit comments

Comments
 (0)