Multi-Room Scanning Interactions: Debugging the State Machine Before Touching the UI
Complex spatial scanning is far more than "press capture a few more times." This article walks through how to model scanning sessions, room identity, fragments, and camera lifecycle as an explicit state machine; identifies four high-frequency defect classes (overly loose completion conditions, lifecycle/guidance mismatches, hidden retry branches, and result-page information overload); and explains how to review state transitions before editing code, keep interaction logic and scanning decisions properly separated, persist data per room, and validate behavior with concrete acceptance cases.
Scanning Is a State Machine, Not a Sequence of Button Presses
Complex spatial scanning is not simply “press capture a few more times.” As users walk through a space collecting geometry, the system must simultaneously maintain the sensor session, the current room, confirmed fragments, and the final floor plan. The checkmarks, buttons, and highlights on screen are, at their core, outputs of state transitions. Changing interface copy or button colors first usually masks the underlying logic errors rather than fixing them.
First, Collapse the Flow into Checkable States
A continuous scan typically moves through these stages: start capture, scanning, single-room save, cross-space relocation, and 2D floor-plan confirmation. Each stage should answer only three questions:
- Which operations are currently allowed?
- What conditions must hold to leave this stage?
- If something fails, which state do we return to?
It is better to model states explicitly as a finite set instead of scattering them across multiple booleans. For example: “scanning,” “insufficient fragments,” “this room is saved,” “waiting for relocation,” “relocation failed,” and “results editable.” When crossing rooms, also carry the room identifier and fragment ownership, so the system does not rely on the view stack to infer “am I still in the previous room.”
A simple illustrative structure could look like this:
state: scanning | fragment_saved | relocating | plan_readyroomId: current logical roomfragments: list of fragments assigned to roomscamera: active | suspended
There are only a few key invariants:
- If area or coverage is too low, the system must not enter “can go to the next room.”
- When the camera is suspended, the user must not be pushed into a new-room creation flow for a different room.
- Every retry must carry the original roomId; it must never implicitly allocate a new room.
- Annotations on the result page exist by default to support verification, not to fill the drawing with labels.
Four High-Frequency Defect Classes
1. Completion conditions that are too loose. A tiny, incomplete fragment of a few tenths of a square meter still gets a green “complete” checkmark that guides the user to the next room. Users will assume the geometry is closed, but subsequent stitching lacks overlapping regions. Completion conditions should examine coverage, trajectory continuity, and closure quality together—not just “did the user press save.”
2. Lifecycle contradicting the guidance. When the camera suspends automatically near a doorway, the UI still asks the user to return to the previous room. If the highlighted button’s semantics are “continue the current room,” a tap on the wrong path creates a new space, and fragments before and after can no longer be stitched together. Suspension, resumption, and permission interruption should each enter a well-defined recovery state, and both the copy and the button target must reference the same roomId.
3. Hidden branching in retries. The screen says “scan again,” but the implementation may create a new session, clear ownership, or reset local coordinates. This is the easiest defect to miss: visually it is just one button, but in code it is an initialization that is not bound to the old room. During review, follow the click handler all the way to persistence and coordinate alignment—do not stop at the view hierarchy.
4. Information overload on the result page. Twenty-plus wall numbers laid out across the floor plan make it impossible to discuss spatial relationships with clients on site. Wall numbers, dimensions, and openings should be layered: by default show only room outlines and key dimensions, and expand numbering only when verifying a specific wall segment. Annotations are view state and must never feed back into scan state.
Do a Design Review Before Changing Code
Complex pages should not be modified by opening the project and editing right away. A more reliable order is:
- Use the same set of on-site screenshots to describe the phenomena.
- Have a code-reading assistant tool draw the state transitions and exception branches first.
- Confirm the plan manually before making changes.
The screens must at minimum cover: scan start, scanning in progress, single-room save, cross-space relocation, and the 2D result—so everyone is discussing the same path.
During review, split the problems apart; don’t get sidetracked by “the picture looks nicer.” Page noise reduction, comparison images, and annotation layers address readability. Whether rooms get split apart, or whether suspension returns to the original session, addresses correctness. No matter how good the former is, it cannot prove the state machine is correct. A fixed review checklist could be:
- Which state transition does each exit button correspond to?
- Does each transition carry the room identifier and fragment list?
- Which operations are forbidden when area or coverage is insufficient?
- Which state do camera suspension, process recovery, and relocation failure each land in?
- Are the three semantics—retry, create new, and merge—consistent between code and copy?
- Does the result page’s default layer obscure spatial relationships?
If an analysis tool only proposes visual changes but fails to point out paths such as “a retry can split a room apart,” consider the review incomplete rather than the plan approved. The whole value of complex interactions and state machines lies in tracing call chains to find branches like these—branches that never appear in a single static mockup.
Keep the Boundaries Firm During Implementation
The interaction layer should only display the current state and collect user intent; it must not decide “you can go to the next room.” Put that decision in the scanning session module: inputs are coverage, trajectory, and camera lifecycle; the output is the set of allowed actions. Buttons being grayed out, the copy, and the actual transition then come from the same source, eliminating the split where the checkmark lights up but the backend cannot stitch.
Persist data per room, not per click. Store fragments, poses, and user confirmations separately. Creating a new room must be an explicit action. A retry should only append to or replace that room’s unconfirmed fragments, and it should record the failure reason for later replay. When cross-space relocation fails, keep the already-saved rooms; do not roll back the whole task.
Raw session trajectories, keyframes, and operation logs belong in object storage and logging services, correlated by task ID. When “the user tapped retry but got a new room” is reported, you can replay the state sequence using the same task ID instead of relying on screenshots and memory. When using cloud storage and logs, retaining the room identifier, state name, and operation name is enough; there is no need to keep detailed geometry long-term on the client.
How to Validate
Lock down transitions with scripts or manual cases instead of judging by how pretty the final floor plan looks. At minimum:
- Extremely small, incomplete fragments cannot be marked complete.
- After camera suspension, the user can only resume the original room or explicitly abandon it.
- After tapping retry, the room count is unchanged and fragments remain stitchable.
- Only tapping “create new” adds a room.
- The result page does not fill the screen with wall numbers by default; when expanded, the numbers match the wall segments.
Area-estimation bias that runs large can be tracked separately; it is mostly related to scale calibration and loop closure and should not be conflated with interactive-state defects.
For engineering teams, continued investment in tooling that can read code and reason about state constraints pays off: API smoothness affects efficiency, but what determines whether an on-site tool is trustworthy is whether hidden branches are found. Review states first, then modify the UI, and complex scanning flows will stop falling apart into mismatched rooms in front of your clients.
