31 โ The Setup Layer¶
Scope. How a vacuum becomes configured and stays configured: the step machine the adapter declares, the drift signal that reopens a finished step, and the gate in front of every destructive operation. Room identity itself is 17 โ Room Identity; what a brand declares is 22 โ The Adapter Contract.
Setup is not a wizard that runs once. It is a set of predicates that are continuously re-evaluated, and any of them can go false again while the system is running.
1. The step machine is declared, not hardcoded¶
setup/drift.py::SETUP_STEP_IDS is a closed enum of the steps the framework understands, and
each brand declares which of them apply through its adapter's setup block. The framework iterates
whatever the adapter requires rather than assuming a map must be imported before rooms can be
saved.
The split of authority is worth noting because it is the opposite of the usual one:
- The adapter chooses which steps apply.
- The framework owns what each step means, including its display label โ
setup/drift.py::SETUP_STEP_LABELSis explicitly not adapter-overridable.
A brand that could rename a step could make two installs disagree about what "save rooms" means while both reported the same state. Choosing from a closed set cannot.
setup/status.py::get_setup_status evaluates the whole machine for the panel. It carries legacy
fields alongside the data-driven ones for the card that has not yet moved โ a compatibility surface
with an expiry, not a second source of truth.
2. Every operation reports; none of them raise¶
setup/workflow.py::add_vacuum and setup/workflow.py::import_active_map are the two atomic
operations, and both return an explicit result: a status of success, already-done, blocked or
error, a message, an operation payload, and next_actions โ what to do next.
Three properties are stated as requirements rather than emerging from the code: it never raises, it never silently no-ops, and it always tells the caller what to do next.
already_done is the one carrying the most weight. A setup step invoked twice is a normal event โ
a user clicks again, a card reloads, a service is called from an automation โ and collapsing that
into either success or error loses the distinction between it worked and it was already true.
The panel needs both to render honestly.
3. Drift is what reopens a finished step¶
The signal that save_rooms has gone stale is disagreement between the vacuum's reported rooms and
the configured ones. setup/drift.py::compute_room_drift returns that snapshot in four parts:
in-sync, new rooms, removed rooms, and transiently missing โ a category that exists precisely
so the third can be distinguished from the second.
setup/drift.py::update_drift_history runs on every discovery pass, incrementing missing-pass
counters and refreshing last-seen stamps. The thresholds are read per brand through
setup/drift.py::get_discovery_cadence.
The two directions are deliberately asymmetric:
| passes required | why | |
|---|---|---|
| a new room | one โ immediate | a room that appears is a fact; showing it early costs a glance |
| a removed room | three consecutive misses | a room that vanishes is usually an API glitch, and announcing a removal invites the user to act on it |
The asymmetry follows the cost of being wrong, not a preference for caution. A premature "new room" prompt is noise; a premature "room removed" prompt asks someone to clean up something that is still there. Both floors are clamped to at least one pass, so a brand cannot declare a zero-pass cadence and get instant removals.
A pass that discovers NOTHING is a third case, and it scores neither direction.
update_drift_history warns and returns without touching history when discovered_room_ids is
empty. The producer cannot tell the two readings apart โ run_discovery_pass flattens
discover_rooms_for_vacuum into a plain set, so "read the map, it lists no rooms" and "could not
read the map at all" arrive identically โ and treating that as a miss made a cold cache, an offline
vacuum or an unreachable cloud into positive evidence that every configured room was gone, three
passes from confirming it. Because missing_passes counts CONSECUTIVE misses, the guard neither
adds a strike nor clears the run already recorded: an unreadable pass is not an observation of the
rooms in either direction (C58, ruled 2026-08-24).
3b. A discovered room had one button, and it called the room a phantom¶
ISSUE #70. The drift panel lists new_rooms and offered exactly one action โ Reject as
phantom. Its hint read "Configure the matching map to include them", and that panel is
rendered inside the save_rooms step, whose editor is populated by
setup_get_map_rooms โ get_managed_rooms โ map_bucket["rooms"]. That is the MANAGED
set, so a never-managed room cannot appear there however fresh discovery is. The hint
named the one step structurally unable to carry it out.
The path that works is re-running Import Active Map:
import_active_map calls save_managed_rooms(enabled_room_ids=None) โ include every
discovered room โ and build_managed_rooms preserves existing per-room settings for
rooms still discovered. So adoption was always available, and nothing said so.
Add room is that call with a button on it, deliberately not a new write path โ but the call did not work, and the pre-release audit is what caught it.
import_active_map returned already_done for ANY map holding rooms, thirty lines above
its only save_managed_rooms call. A map reports a newly discovered room only when it
already holds configured rooms, so in the one scenario adoption exists for, the gate always
fired. The button was verified end to end at the wrong layer: the JS tests asserted the
import action was CALLED, never that a room arrived. Reachability, not correctness โ the
save it reached for was right and unreachable.
Two things had to change, and the second is the one that is easy to miss:
- Discovery runs before the gate, so the question is "is there anything here I do not already manage" rather than "does this map have rooms". Rejected ids are subtracted, or a dismissed phantom would reopen the map on every press.
- Adoption has to be stated. Lifting the gate alone stores the room
is_configured=False, enabled=Falseโbuild_managed_roomsdoes that on purpose, because a re-sync approves nothing new (R14/C60).is_configuredis the entity-creation gate AND whatcompute_room_driftsubtracts, so a "fixed" import would have adopted the room invisibly: no entities, still listed as newly discovered.adopted_room_idsis the third shape, and pressing Add room is the review the other two withhold.
And the button still did not render, which the second audit pass caught. The drift
row's map_id is enriched from _room_lookup, which walks MANAGED storage โ so a
genuinely new room, the only kind new_rooms ever holds, missed it and took the fallback
{"room_id": rid, "name": f"Room {rid}", "map_id": ""}. The card offers Add room only
when the row's map matches the active map, and "" == "B" is never true. The name was
discarded the same way: the vacuum reported "Study" and the row said "Room 3".
Neither fact needed inventing โ the map is the one the snapshot was scoped to, and the
name is in the discovery cache the same pass wrote. [DR-NEW-1] pins both.
The renderer suite could not see it, and that is the lesson worth keeping.
setup-adopt-room.test.mjs handed the renderer a row with a real map_id โ a shape the
backend only produces for a room ALREADY in storage. The fixture encoded the assumption
instead of testing it, so a green renderer suite and a green backend suite sat either side
of a button that never appeared. The fixture now carries a comment naming [DR-NEW-1] as
what holds it up.
The existing suite caught a regression in the fix, which is the argument for moving
discovery carefully: the relocated gate put "no rooms detected" in front of an
already-imported map for the first time, so a sleeping vacuum turned a settled map into
"complete a mapping run". An imported map answers from what it holds when the device says
nothing ([SW-10c]); only an empty one is blocked. A
bespoke adopt-one-room write would be a second route into the same store, free to diverge
from the first the moment either changed. [SAB-2] asserts the button reaches neither
save nor reject.
Offered only on the active map. import_active_map takes no map id โ "only the map
that is currently active on the device can be imported โฆ a hard limitation of the upstream
cloud API". A row for any other map says so instead of showing a button that would no-op,
and an UNKNOWN active map is treated as not-matching rather than assumed ([SA-2b]): a
permissive default puts the dead button back on every row.
setup/status.py emits active_map_id for this, resolved by the same call the drift
computation uses, so the id a row is compared against cannot disagree with the id the
drift was computed for.
4. A rejection belongs to one map, because ids do¶
setup/drift.py::reject_rooms hides a phantom room id the vacuum reports but which does not exist.
It is scoped to a single map, and the reason is a defect that shipped.
Rejection was stored as one flat list per vacuum, while the thing being rejected is per map.
Eufy reissues room ids from one on every map, so id 3 downstairs and id 3 upstairs are different
physical rooms. Rejecting a ghost downstairs therefore made the real room upstairs
unconfigurable โ permanently, and silently, because a rejected id never appears in new_rooms
for anyone to notice. Nothing in the record said which map a rejection was made on, so nothing
could tell the two apart.
setup/drift.py::rejected_room_ids is the single reader, and it resolves two backings on
purpose:
- the per-map store, which every new rejection is written to and which applies to its own map only
- the legacy flat list, which still applies to every map
Keeping the legacy list broad is the interesting half. A legacy id genuinely carries no map, and
inventing one would be a guess โ and it also matches what the user meant, because those entries
were recorded when only one map existed, so "every map" and "the map I was looking at" were the
same set. It is read but never appended to, so the ambiguity is frozen rather than growing, and
setup/drift.py::unreject_rooms is the way out of a legacy entry that blocks a real room upstairs.
The reporting superset is the wrong input for a decision¶
Calling the resolver without a map unions every map's rejections. That is a legitimate answer to "what has been rejected anywhere on this vacuum" and the right thing for a whole-vacuum status read.
โ It is the wrong input for any decision about a specific room, because over-reporting here hides a real room โ which is the original defect reproduced through the reporting path. Every production caller passes a map. A new caller that omits it will look correct, compile, and resurrect the bug.
5. Drift history belongs to one map too โ and for the opposite reason¶
room_drift_history was one flat dict keyed by room id, with no map dimension, while every
decision it feeds is per map. It therefore could not answer the only question asked of it, and
it failed in opposite directions depending on the brand:
- Roborock issues a distinct segment id per map. Another floor's rooms are absent from this map's configured set, so they surfaced as new rooms that do not exist here โ offered for rejection. Reported on a live two-floor install: "New rooms discovered [room], when [room] is a room on the non-active map. I'm offered 'reject as phantom'."
- Eufy reissues ids 1..N per map. A genuinely new id 3 upstairs is masked by the configured id 3 downstairs and never surfaces at all.
Scoping configured_ids to the active map moved the damage from the second symptom to the
first. Neither is fixable while the history cannot say which map an entry came from, so now it
says: setup/drift.py::_drift_history is the single accessor and every read and write goes
through it.
Legacy history is adopted only where attribution is certain¶
This mirrors the rejection split in ยง4 with one deliberate difference, and the difference is the point:
A rejection is a user decision and must survive, so the legacy flat list applies to every map forever. A drift counter is derived state that rebuilds itself within
removal_confirmation_passes/new_room_confirmation_passes, so an unattributable one is not worth a guess.
Attribution follows _resolve_rejection_map exactly: 0 maps โ nothing to attribute to;
1 map โ unambiguous, so the legacy entries migrate into it once and the flat dict is left
empty; 2+ maps โ the entry carries no map and inventing one would guess in the destructive
direction, because a wrong missing_passes removes a real room. Legacy is not adopted there;
per-map history rebuilds from the next pass.
Calling the accessor with no map on a multi-map vacuum yields an empty bucket, never a union. The union is what produced the report above.
Covered by [DR-MAPHIST-1] (the other map's rooms are not offered as new) and [DR-MAPHIST-2]
(a genuinely new room on its own map still is โ so "fix the false positive" and "delete the
feature" cannot be confused). Ablating _drift_history back to the flat dict turns
[DR-MAPHIST-1] red with new_rooms == [7, 8].
6. Destructive operations are gated by the backend¶
setup/protection.py::evaluate_map_protection assigns one of three levels, and the backend is
the single source of truth โ the panel only displays what it is told:
| level | gate |
|---|---|
| normal | one click |
| elevated | a confirmation click |
| high | a typed token that must match the map's display name exactly |
Putting the level in the backend means the same rule applies to a service call from an automation as to a button in the card. A protection level the panel computed would protect only the panel.
setup/delete.py::delete_map evaluates protection before touching anything, and refuses with a
requires_confirmation result rather than an error when a token is needed and absent โ the same
report-don't-raise contract as ยง2.
Deletes are integration-only and never touch upstream cloud data. The scope of the destructive operation is the integration's own record of a map. That boundary is what makes the protection levels a proportionate answer rather than an insufficient one.
7. Common wrong assumptions¶
| assumption | reality |
|---|---|
| setup completes once | every step is a predicate that is continuously re-evaluated and can go false again โ ยง3 |
| an adapter can define its own steps | it selects from a closed set; the framework owns the semantics and the labels โ ยง1 |
| a missing room means a removed room | it means transiently missing until it has been missed three consecutive passes โ ยง3 |
| new and removed rooms are symmetric | they are not, and the asymmetry follows the cost of a wrong prompt โ ยง3 |
| rejecting a phantom id is harmless | before it was map-scoped it silently disabled the same id on every other map โ ยง4 |
| the unscoped rejection read is a convenient default | it is a reporting superset, and using it for a per-room decision reproduces the defect โ ยง4 |
| the card enforces confirmation | the backend does; the card renders it โ ยง5 |