Commit f586be2
fix(bulk): address third round of selector review feedback
A comprehensive review flagged two blocking issues plus a long list of
correctness, error-routing, and coverage gaps in the structural-selector
feature. Fixed:
Blocking:
- Root admission for aggregate expansion was not domain-constrained: a
scene assigned to a selected area was admitted as a root and expanded,
pulling entities from anywhere in the house into the dispatch (HA's
scene.entity_id attribute lists controlled targets, not structural
members). Scenes are now excluded from aggregate-root admission on
architectural grounds (not an integration-identity heuristic).
- A dynamic selector call's approval could be consumed by a DIFFERENT
invocation than the one that created it -- via a race (a concurrent
call's find() observing "approved" before the original waiter resumes)
or a later identical call reusing a stale approval within
approval_ttl_minutes, dispatching against re-resolved topology. Dynamic
entries are now bound to their creating invocation only.
Also fixed:
- A wildcard rule path with a literal tail (args.*.domain) was
over-classified as needing resolved-operations data by the previous
fix, regressing legitimate conditional selector rules back into an
unconditional gate. Narrowed to paths that can actually reach the
operations list.
- Stringified JSON arguments (Claude Desktop stdio sends these) bypassed
policy evaluation entirely: PolicyMiddleware reads raw
context.message.arguments before the tool's own Pydantic coercion runs,
so a rule targeting a nested field silently never matched. Normalized
once, before evaluation and hashing.
- _load_topology used a bare asyncio.gather; the first exception left the
other four awaitables orphaned. Now mirrors tools_areas.py's
return_exceptions=True + explicit re-raise pattern.
- Registry/visibility infrastructure failures were raised as the same
exception class as caller input errors, reaching the agent as
VALIDATION_FAILED and inviting a pointless selector rewrite against an
HA outage. Split into BulkSelectorInfrastructureError, routed through
create_connection_error.
- An unknown selector.domain (e.g. "lights") passed validation and
resolved to nothing, blaming exclusions/areas that were correct. Domain
existence is now checked against loaded states, and the empty-result
message distinguishes "no entities of domain X" from "all matches were
excluded or hidden".
- VALIDATION_FAILED had no DEFAULT_SUGGESTIONS entry, so ~14 selector
failure modes returned no actionable guidance.
- _parse_bulk_operations lost its security rationale comments
(include_input=False; why malformed rows are preserved) during an
earlier extraction.
Plus: NamedTuple returns instead of bare tuples, BulkSelectorResolution's
operations as a computed property (was a separately-tracked list that
could desync from resolved_entity_ids), _SELECTOR_KEYS derived from the
TypedDict instead of a parallel literal, a logger for the ~14 selector
failure modes, dispatch failures now attach the resolution to their error
context, dangling-member/cycle errors name their aggregate and parameter,
and the "exactly one of operations/selector" and "selector-only
parameter" validation messages now name the actual offender instead of a
collapsed generic message.
Test coverage added: scene exclusion, aggregate exclusion (only leaf
exclusion was tested before), unknown domain, domain-not-in-area vs
all-excluded-or-hidden, whitespace-padded IDs, orphaned-task-free
topology fetch failure, visibility-infrastructure routing, the wildcard
over-classification, stringified-argument policy bypass (pure-function
and end-to-end), the concurrent-approval race, and a real non-dry-run E2E
dispatch that verifies the excluded entity's live state never moves (the
only prior E2E test asserted the dry-run preview, never a real dispatch
or real post-dispatch state).
Deliberately deferred (documented in PR comment, not silently dropped):
a handful of narrower test-coverage gaps (exact MAX_SELECTOR_ENTITIES=100
boundary, individual selector-only-parameter-rejection cases, malformed
JSON body edge case) and a request to expose a hidden-vs-excluded
breakdown finer than the current warnings message.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent 5826100 commit f586be2
10 files changed
Lines changed: 1163 additions & 217 deletions
File tree
- src/ha_mcp
- policy
- tools
- tests/src
- e2e/workflows/core
- unit
- policy
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
213 | 217 | | |
214 | 218 | | |
215 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
19 | 70 | | |
20 | 71 | | |
21 | 72 | | |
| |||
216 | 267 | | |
217 | 268 | | |
218 | 269 | | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
227 | 274 | | |
228 | 275 | | |
229 | 276 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
19 | 25 | | |
20 | 26 | | |
21 | 27 | | |
| |||
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
118 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
119 | 128 | | |
120 | 129 | | |
121 | 130 | | |
| |||
125 | 134 | | |
126 | 135 | | |
127 | 136 | | |
128 | | - | |
| 137 | + | |
129 | 138 | | |
130 | 139 | | |
131 | 140 | | |
132 | 141 | | |
133 | 142 | | |
134 | 143 | | |
135 | 144 | | |
136 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
137 | 168 | | |
138 | 169 | | |
139 | 170 | | |
| |||
0 commit comments