Debugging State-Machine Defects in Complex Spatial Scanning Flows
A spatial scan can look like a simple sequence of capture, confirm, next room, and floor plan, while the real failures sit in room identity across pages. This article treats incomplete scans, camera sleep, overloaded result views, and reused buttons as state-machine and interaction-contract defects, then shows how to constrain transitions, trace code paths, and test failure cases.
Spatial scanning screens can look like a simple sequence: capture, confirm, move to the next room, and leave the floor plan. The hard part is whether a session that crosses several screens is still the same room. Common field failures include an incomplete scan marked as ready to continue, the camera sleeping when the user reaches a doorway and then asking them to return to the original room, a highlighted button changing “continue the current room” into “create a room,” and a result view so crowded with wall numbers that the important outline disappears. Changing copy or removing visual elements will not stop these failures from returning. The problem belongs to the state machine and the interaction contract, not to polishing a single screen.
Split the failures by state
A multi-room scan has at least four stages: capturing, localizing or relocalizing, waiting for the user to decide on the next room, and summarizing results. Each stage must answer three questions: what the current room identifier is, which recovery actions are allowed after this step fails, and whether success is judged by an area threshold, completeness, or merely by finishing the flow.
The first misleading case is a completion signal that is too broad. The system may have scanned only a fragment of a few tenths of a square meter, yet it still gives positive feedback that the user can enter the next room. The user assumes the geometry is closed. A better decision separates a fragment that can be stored temporarily from a room that meets the stitching threshold. Fragments may be kept, but the primary button’s copy, color, and icon must not look like success. Show the missing area and the number of unclosed edges, and change the primary action to “continue scanning this section” or “discard this section.”
The second case is a device lifecycle that is disconnected from screen state. The user walks to a doorway, the background camera sleeps or permission briefly fails, and the next frame tells them to return to the original room. This is usually not a sudden drop in localization quality. The session was not frozen across sleep: pose, scanned mesh, room identifier, and the room expected to continue were partly cleared, while recovery logic still interprets the event as “the user left the current room.” The screen should explicitly enter “capture paused.” On resume, it should continue the same session first, rather than running room-level relocalization again.
The third case is one button carrying several meanings. A highlighted “Next” can mean continue the current room, confirm moving to the next room, retry a failed step, or create a room, depending on context. One wrong tap creates a new session that cannot be stitched to the previous mesh. Any action that breaks session continuity needs a second confirmation, and it must not share control state with “retry the current operation.”
The fourth case is an overloaded result screen. More than twenty wall numbers drawn on a small floor plan cover wall lines and door openings. Labels should be grouped by default: organize them by room, expand numbers only when selected, highlight conflicting or unclosed walls first, and place the rest in a legend or sidebar list.
Why looking only at the interface misses the real defect
Screenshots can expose contrast, copy, and button placement, but not which room identifier a tap writes. A light review may suggest removing a small white 3D model in a corner, which barely affects the main path. Hidden defects often meet three conditions: the interface copy looks reasonable, the happy-path test passes, and the wrong branch appears only when timeout, sleep, and the back stack overlap.
A typical branch is localization timing out after about twenty seconds. The button still says “retry the current operation.” In the context of “scan the next room,” the handler does not restore the previous room’s continuation parameters. It runs new-room initialization instead. The user thinks they are retrying, while the data layer has already allocated an isolated room. Later stitching cannot find a shared wall, so the result screen can only pile up numbers. Other proposals that only change prompts may make the screen cleaner, but they never touch this branch, so tests will not catch it.
Trace from the button event to command dispatch, not from one piece of copy to another. Search especially for whether timeout, retry, create, room switch, and camera foreground/background branches share an entry point. If retry and create differ only in copy, the state machine is already untrustworthy.
Constrain the room session with an explicit state machine
Write the scanning flow as finite states instead of combining Boolean flags across screens. Core states can include idle, capturing a room, capture paused, localizing, localization timed out, waiting to confirm the next room, confirming a new room, and summarizing. Every transition must carry a room identifier and a reason code.
The structure below expresses constraints only. It is not an interface for any particular framework:
State: localization timed outAllowed:Retry localization -> localizing (room identifier unchanged; restore the last pose seed)Discard this section -> waiting to confirm the next room (mark this section incomplete)Forbidden:Entering new-room creation directlyMarking an incomplete fragment as successfully stitchableState: waiting to confirm the next roomAllowed:Continue the current room -> capturing a room (same identifier)Confirm a new room -> confirming a new room -> capturing a room (new identifier, and record adjacency intent with the previous room)
“Retry the current operation” should be bound to the command that failed, not to the most prominent business button on the current screen. If the failed command was “continue room A and localize,” the retry must carry A’s identifier, the existing mesh handle, and the pose from before the timeout. If those fields are missing, disable the button and explain that the session is invalid and recovery is possible only from a saved fragment. Do not silently create a room.
Camera sleep must not implicitly rewrite business state. On entering the background, emit “capture paused” and save the room identifier and the last valid pose. On returning to the foreground, only resume capture or prompt for authorization again. Allocate a new identifier only when the user explicitly chooses “this is another room.” Highlight styling means recommended, not a change of command type. Keep command type in a separate enumeration so one tap target does not reuse different meanings on different screens.
Separate the completion threshold from the display threshold. Internally, a 0.3-square-meter fragment can be saved for later scanning. Externally, “ready for the next room” must satisfy minimum completeness, closure error, and stitchability with existing rooms at the same time. If it does not, use a warning state rather than a success check.
Walk the code path once
Read the implementation along the call chain, not by screen file. Use a fixed checklist.
- Which flags the timeout callback sets, and whether it clears the room identifier.
- Whether the retry handler reads the previous command or the currently recommended next step.
- Where the only entry point for creating a room is, and whether timeout or pause branches can call it without confirmation.
- Whether stitching rejects a new identifier that has no adjacency record, or still draws its walls into the overall plan after failure.
- Whether anything writes camera stop as “the user left the room” instead of pause.
After finding “retry that actually creates,” fix three places together: the state machine must forbid that transition; the button must be disabled when parameters are incomplete; and the server or local store must reject an isolated room with no adjacency relationship from entering stitching. Changing only one of these can still present the bad state as something the user can continue.
Do not regress only the happy path. Cover at least these cases: tapping the primary button on an incomplete area, retrying after localization timeout, genuinely opening a new room after timeout, pressing Home during capture and returning, returning from the result screen to scan more, and two consecutive rooms sharing one wall. Each case should assert whether the room identifier changes, whether the fragment can be stitched, and whether the primary button copy matches the state.
Reduce noise in the result view and prompts
Once the flow is correct, still reduce cognitive load. Keep one primary action on a screen. Put dangerous or irreversible actions on secondary buttons with confirmation. During localization, explain the remaining wait and what happens after failure, so the user is not unsure at the twentieth second whether to retry or exit. By default, draw only the outline, door openings, and unclosed marks on the floor plan. Put wall numbers in a sidebar or switch them by room. Use color for state: in progress, incomplete, stitchable, and conflicting. Do not cover incomplete data with the same success color.
Log state transitions, not only taps. A useful record includes the old state, new state, room identifier, command type, whether a timeout occurred, and whether the camera was in the foreground. When a scan cannot be joined in production, first check whether the identifier was replaced with a new value at the retry instant, then decide whether the problem is geometry or session state.
Order of implementation
First freeze the room identifier and command enumeration so retry cannot call create. Then tighten completion judgment so an incomplete scan cannot enter the success path for the next room. Then handle camera pause and resume so sleep does not rewrite room ownership. Aggregate the result view and adjust copy last. The order cannot be reversed: improving labels while the state can still split rooms only makes the wrong result look better.
The quality of a complex interaction does not depend on whether one screen looks polished. It depends on whether, after failure, timeout, and foreground/background switches, the system still recognizes that this is the same room. Write down the transitions behind the buttons, test them fully, and forbid silent forks. That is what keeps users from walking back and forth at a doorway and staring at a pile of wall numbers they cannot correct.
