<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: AI Flip Room</title>
    <description>The latest articles on DEV Community by AI Flip Room (@aifliproom).</description>
    <link>https://dev.to/aifliproom</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4158509%2F1e92bd6f-a6f7-4923-a214-4be8f82e7516.png</url>
      <title>DEV Community: AI Flip Room</title>
      <link>https://dev.to/aifliproom</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aifliproom"/>
    <language>en</language>
    <item>
      <title>Stamping a Virtually Staged label on listing photos in the browser, and the 12 rules where we refuse to</title>
      <dc:creator>AI Flip Room</dc:creator>
      <pubDate>Sun, 25 Oct 2026 19:55:10 +0000</pubDate>
      <link>https://dev.to/aifliproom/stamping-a-virtually-staged-label-on-listing-photos-in-the-browser-and-the-12-rules-where-we-52fn</link>
      <guid>https://dev.to/aifliproom/stamping-a-virtually-staged-label-on-listing-photos-in-the-browser-and-the-12-rules-where-we-52fn</guid>
      <description>&lt;p&gt;We build an AI virtual staging tool for listing photos. This post is about a small free tool next to it with no AI in it: pick your province or state and your MLS, then a photo, and the browser stamps a "virtually staged" label on it and saves a new JPEG. The photo never leaves the device.&lt;/p&gt;

&lt;p&gt;Stamping is the easy part. The harder part is that for 12 of the 32 MLS and regulator rules in the tool's data, the correct output is no label on the photo at all, and for 9 more it is "ask your MLS first".&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a label needs a rulebook
&lt;/h2&gt;

&lt;p&gt;Virtually staged listing photos have to be disclosed, and the rulebooks disagree about where. Four of the rules the tool quotes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The upstate New York Alliance MLSs require a text overlay reading exactly "Virtually Staged." on every staged photo since 1 September 2026; a caption or a line in the remarks alone is not acceptable.&lt;/li&gt;
&lt;li&gt;Florida's Stellar MLS wants the words in the photo description and the public remarks. Words on the photo itself are "strictly prohibited".&lt;/li&gt;
&lt;li&gt;Arizona's ARMLS does require a mark on the photo, but it is the MLS's own "Digitally Altered" watermark, applied in the MLS's listing system, and rule 8.23(e) bans any other text or watermark on the image.&lt;/li&gt;
&lt;li&gt;Tucson's MLSSAZ wants the disclosure "prominently placed along the top of the image".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The last two sit side by side in our &lt;a href="https://aifliproom.com/blog/virtual-staging-rules-arizona" rel="noopener noreferrer"&gt;Arizona rules article&lt;/a&gt;. A plain watermark tool would stamp all four photos and break two of the rules. So this one reads the rule before it touches the canvas.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rules as data, the decision as code
&lt;/h2&gt;

&lt;p&gt;The rules already existed as data: 32 options across 15 markets, built for our disclosure wording lookup. Each option records one of eight verdicts on words on the photo (required, banned, restricted, not-required, allowed, no-rule, not-addressed, unverified), the words the rule gives, and where each goes: the photo, the photo description field, the public remarks. Every sentence is copied verbatim from our published rules guides, and a separate guard checks 350 of those strings against the articles' text on every run.&lt;/p&gt;

&lt;p&gt;The label tool adds no facts. It turns each option into a plan with one of three modes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;NO_STAMP&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PhotoVerdict&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;banned&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;not-required&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CONFIRM&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PhotoVerdict&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;restricted&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;unverified&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;modeFor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;DisclosureOption&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;StampMode&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;NO_STAMP&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onPhoto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;verdict&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;no-stamp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;onPhoto&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;at&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;photo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="c1"&gt;// A mark is required on the photo, yet none of the rule's words go there: the MLS stamps its own watermark.&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onPhoto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;verdict&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;required&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;onPhoto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;no-stamp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CONFIRM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onPhoto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;verdict&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;confirm&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stamp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/** The one gate between the data and the canvas: a no-stamp plan never stamps; a confirm plan only once confirmed. */&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mayStamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;LabelPlan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;confirmed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;texts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stamp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;confirm&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;confirmed&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second &lt;code&gt;if&lt;/code&gt; in &lt;code&gt;modeFor&lt;/code&gt; is the ARMLS case. Its verdict is "required", which a naive mapping would turn into "stamp". But none of its words are placed on the photo: the data puts "Virtually staged" in the photo description field, because the mark on the photo is the MLS's job. Required, yet none of the rule's words on the photo, means refuse. There is no special case by id; it falls out of the data, and the guard names ARMLS in case the data changes shape.&lt;/p&gt;

&lt;p&gt;Across the 32 options the split today is 11 stamp, 9 confirm and 12 no-stamp: eight bans, three rules that send the label to the listing fields, and ARMLS.&lt;/p&gt;

&lt;p&gt;The words come from the same data, in order of how much say the rule has:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If the rule fixes exact words for the photo, those and nothing else. The Alliance plan offers only "Virtually Staged.", full stop included.&lt;/li&gt;
&lt;li&gt;Otherwise, any words the data places on the photo. Quebec's plan offers the regulator's example in French and in English; the French one, "Image générée par l'intelligence artificielle", is the longest label in the data at 45 characters.&lt;/li&gt;
&lt;li&gt;Otherwise, terms the rule fixes or lists for other places, then a fallback, then the rest. The fallback, "Virtually staged", comes from our disclosure FAQ: "Where no wording is prescribed, 'Virtually staged' is enough for a badge or a caption." The guard checks that sentence is still there.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The list is deduplicated case-insensitively, so a lowercase "virtually staged" reported for one MLS does not appear as a second choice next to the fallback.&lt;/p&gt;

&lt;p&gt;Placement is data too, more crudely. A plan is top-only when one of its quoted rule sentences matches &lt;code&gt;/along the top of the image/i&lt;/code&gt;. A regex over prose is brittle, so the guard asserts that exactly one plan, MLSSAZ, is top-only. There the position picker offers only the three top positions, and a bottom choice carried over from another MLS moves to the top.&lt;/p&gt;

&lt;h2&gt;
  
  
  What refusing looks like
&lt;/h2&gt;

&lt;p&gt;For a no-stamp plan the tool shows the verdict and the rule's reasons, verbatim, then "The tool will not stamp this photo." and where the words go instead: for Stellar, "Virtually staged" in the photo description field and "One or more photo(s) was virtually staged." in the public remarks. The canvas element is not rendered at all.&lt;/p&gt;

&lt;p&gt;For a confirm plan (six rules that restrict text on photos, three rulebooks we have not read) there is a checkbox: "I checked with my MLS: a plain label on the photo is allowed." The tick is stored as the id of its plan, so ticking it for Alberta and switching to Texas's NTREIS does not carry it over.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mayStamp&lt;/code&gt; is the only gate. The component computes &lt;code&gt;allowed&lt;/code&gt; from it once, and both the drawing effect and the save handler return early without it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The canvas part
&lt;/h2&gt;

&lt;p&gt;The photo is read with &lt;code&gt;URL.createObjectURL&lt;/code&gt; into an &lt;code&gt;Image&lt;/code&gt; that never enters the DOM, drawn onto a canvas, and saved with &lt;code&gt;canvas.toBlob(cb, "image/jpeg", 0.92)&lt;/code&gt; through a temporary download link. No request carries it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Size cap.&lt;/strong&gt; Anything above 16,000,000 pixels is scaled by &lt;code&gt;sqrt(16,000,000 / (width × height))&lt;/code&gt;, because iOS Safari refuses larger canvases (around 16.7 million pixels, a reported figure we have not probed). A 6000×4000 photo comes out at 4899×3266: 16,000,134 pixels after rounding, a hair over our cap and under the browser's limit, so we left it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Text size.&lt;/strong&gt; The label scales with the shorter side of the image, so a portrait and a landscape photo get the same visual weight. Trimmed from &lt;code&gt;drawLabel&lt;/code&gt;, with the size lookup pulled out into &lt;code&gt;k&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;h&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;margin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.03&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;px&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// k = 0.035, 0.05 or 0.07: Small, Medium, Large&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;font&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;FONT&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;{px}&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;tw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measureText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;room&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;margin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;1.2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// the box's side padding is 0.6 * px on each side&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tw&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;room&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;tw&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;px&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;room&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;tw&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;font&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;FONT&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;{px}&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="nx"&gt;tw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measureText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a 12-megapixel 4032×3024 photo, Medium gives 151 px text and a 91 px margin. The shrink step is for long labels on narrow photos, such as the 45-character Quebec label at Large on a portrait shot. The text is white, semi-bold &lt;code&gt;system-ui&lt;/code&gt;, on a black box at 62% alpha, with an opacity slider from 50% to 100%.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EXIF orientation.&lt;/strong&gt; We wrote no orientation code. The tool relies on the browser applying the EXIF orientation when it decodes the image, so &lt;code&gt;drawImage&lt;/code&gt; gets an upright bitmap. We checked rather than assumed: a 300×200 JPEG tagged orientation 6 (rotate 90° clockwise), loaded in Chromium 152, reported 200×300 with the stored top half on the right, and the live tool drew it on a 200×300 canvas. We have not run the probe in Safari or Firefox.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EXIF stripping.&lt;/strong&gt; A canvas holds pixels, not metadata, so &lt;code&gt;toBlob&lt;/code&gt; writes a fresh JPEG. The same probe carried an EXIF block with a made-up camera make; the output started with a JFIF header, had no APP1 segment, and the make string was gone. Camera, location and date live in that segment. The price is a second JPEG generation at quality 0.92, plus the size cap.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we test
&lt;/h2&gt;

&lt;p&gt;The tool shipped with a guard of 283 checks in our regular QA run, in four groups:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Nothing invented.&lt;/strong&gt; One plan per data option, in order; every stamp word is the option's own or the fallback; verdicts and reasons verbatim.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Refuses where it must.&lt;/strong&gt; Each mode recomputed independently from its verdict; the eight bans, ARMLS and CRMLS named one by one; the Alliance's exact "Virtually Staged."; MLSSAZ as the only top-only plan; &lt;code&gt;mayStamp&lt;/code&gt; with and without the tick, and on hand-made plans: a no-stamp plan given words still does not stamp.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The photo stays on the device.&lt;/strong&gt; A static scan of the component's source for &lt;code&gt;fetch&lt;/code&gt;, &lt;code&gt;XMLHttpRequest&lt;/code&gt;, &lt;code&gt;sendBeacon&lt;/code&gt;, &lt;code&gt;WebSocket&lt;/code&gt;, &lt;code&gt;EventSource&lt;/code&gt;, dynamic &lt;code&gt;import()&lt;/code&gt;, http(s) URLs, analytics calls, workers and form submits; three allowed imports; &lt;code&gt;createObjectURL&lt;/code&gt; in, &lt;code&gt;toBlob&lt;/code&gt; as JPEG out; no label words typed into the component; the brand suffix off by default.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The page.&lt;/strong&gt; Title, canonical, structured data without a price, and links from the sitemap, the tools hub and the &lt;a href="https://aifliproom.com/blog/virtual-staging-rules" rel="noopener noreferrer"&gt;rules hub article&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The guard ships with a mutation job of 29 deliberate breaks, each named for the harm it would do: drop "banned" from the no-stamp list; let a confirm plan stamp without the tick; post the file to an API route when it is picked; &lt;code&gt;sendBeacon&lt;/code&gt; the blob on save; save as PNG; let a confirmation for one MLS carry over to another. At merge, all 29 turned the guard red.&lt;/p&gt;

&lt;p&gt;The static scan has a known limit: it reads one file's source. The page, like every page on the site, loads our page-view analytics; the scan only says the photo path calls nothing. So we also checked the live page: choosing a rule and loading a photo added no entries to the browser's resource timing list. Orientation has no guard; it rests on the probe above.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does not do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is not legal advice. Rules change; the page says the MLS handbook and the broker are the final word.&lt;/li&gt;
&lt;li&gt;It does not apply an MLS's own watermark, fill in listing fields, or upload anything. Where the label belongs in a field, it shows the words and stops.&lt;/li&gt;
&lt;li&gt;It does not handle the unstaged original, which several rules want directly before, after or next to the staged photo.&lt;/li&gt;
&lt;li&gt;One photo at a time, one line of text, JPEG out. Photos above 16 megapixels come back smaller.&lt;/li&gt;
&lt;li&gt;The confirm checkbox is trust, not verification.&lt;/li&gt;
&lt;li&gt;The "AI Flip Room" suffix is opt-in and warns that many MLSs ban company names on photos, but it is not blocked per rule: an MLSSAZ user can still tick it.&lt;/li&gt;
&lt;li&gt;It knows the 15 markets our guides cover, five in Canada and ten in the US. A state outside them is not in the picker.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tool is at &lt;a href="https://aifliproom.com/tools/virtually-staged-label" rel="noopener noreferrer"&gt;aifliproom.com/tools/virtually-staged-label&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>canvas</category>
      <category>privacy</category>
    </item>
    <item>
      <title>The judge said the camera held still. It had not: measuring viewpoint drift in AI room renders</title>
      <dc:creator>AI Flip Room</dc:creator>
      <pubDate>Sat, 24 Oct 2026 22:11:10 +0000</pubDate>
      <link>https://dev.to/aifliproom/the-judge-said-the-camera-held-still-it-had-not-measuring-viewpoint-drift-in-ai-room-renders-4ac3</link>
      <guid>https://dev.to/aifliproom/the-judge-said-the-camera-held-still-it-had-not-measuring-viewpoint-drift-in-ai-room-renders-4ac3</guid>
      <description>&lt;p&gt;We build an AI virtual staging tool: a user uploads a photo of a room, an image model restyles it, and automatic checks compare the result with the original before anyone sees it. We described the three gates in an &lt;a href="https://dev.to/aifliproom/how-we-check-every-ai-generated-room-render-before-a-user-sees-it-3ek8"&gt;earlier post&lt;/a&gt;. This one is about the second gate alone, the one we could not get from a language model.&lt;/p&gt;

&lt;h2&gt;
  
  
  The failure
&lt;/h2&gt;

&lt;p&gt;The image model sometimes moves the camera. Not the furniture: the camera. The render comes back from a step back and to the left, or an angled bedroom shot is straightened to face the bed, or the frame has crept in toward the fireplace. The room in the picture is not the room in the photograph, which is exactly the complaint buyers have about &lt;a href="https://aifliproom.com/blog/house-does-not-look-like-the-listing-photos" rel="noopener noreferrer"&gt;a house that does not look like its listing photos&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Some MLS rule books require an unaltered image &lt;em&gt;with the same view&lt;/em&gt; beside an altered one (&lt;a href="https://aifliproom.com/blog/virtual-staging-rules-texas" rel="noopener noreferrer"&gt;the Texas rules, for example&lt;/a&gt;); a render shot from elsewhere cannot satisfy that.&lt;/p&gt;

&lt;p&gt;Our vision judge, a model that receives both images and answers a fixed list of yes/no questions, did not see it. Three rounds of hand-verified cases passed every check; one retry passed with every feature on the right wall and the room visibly shot from somewhere else. We gave the camera its own boolean; still blind. We blended the two images 50/50, double-exposure style, and asked whether the architecture doubled; not reliable either. Months later a stronger judge had the opposite problem, calling 13 of 43 in-place renders moved; its camera answers no longer count indoors.&lt;/p&gt;

&lt;p&gt;So: can a few hundred lines of plain image maths answer "did the camera move?" better than a model that describes rooms in paragraphs?&lt;/p&gt;

&lt;h2&gt;
  
  
  The measurement
&lt;/h2&gt;

&lt;p&gt;Six approaches, A to F in the research scripts, on a hand-labelled set that grew to 24 pairs across two rooms: five with the camera marked as moved, nineteen without.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A, edge correlation in the top strip.&lt;/strong&gt; Furniture rarely reaches the ceiling, so compare only the top 28% of the frame. Seven iterations later: 3 of 5 shifts caught with no false alarms; the two misses lived mid-frame (an arched window where the photo had three) and never reached the strip.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B, the ceiling line.&lt;/strong&gt; Trace where wall meets ceiling as a curve, one y per column, by dynamic programming over the vertical brightness gradient, and compare the original's curve with the render's. Clean on the first room. On the second, 8 false flags out of 11 good renders: art over a mantel and dark flush beams pulled the tracked line off the ceiling. Paint fools it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C and F&lt;/strong&gt;, block matching on edge maps and a vote-based re-tracker, never separated the set cleanly. &lt;strong&gt;E&lt;/strong&gt; was the double-exposure judge above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;D, a depth profile.&lt;/strong&gt; Run a monocular depth model on both images. In the upper band of the frame take, per column, how far the far wall reads, and compare the two profiles. Furniture changes the depth model's own normalisation between images, so the comparison is a robust affine fit, a rank correlation and a search for a sideways slide. Glass fools it: windows and mirrors are re-estimated differently each time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// one number per column: how far the far wall reads in the upper band&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;farFieldProfile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;depth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Float32Array&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Float32Array&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;med&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mad&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bandStats&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;depth&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// robust centre and spread&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prof&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Float32Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;W&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;W&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bandTop&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;bandBottom&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;depth&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;W&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;med&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;mad&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;prof&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;quantile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;FAR_Q&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// low percentile = farthest&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;medianFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prof&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;SMOOTH_WIN&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two failure modes do not overlap: paint is flat in depth, glass does not move the ceiling line. So the score is the smaller of the two normalised scores, and a render is flagged only when both channels fire:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;comb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rgbScore&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;T_RGB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;depthScore&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;T_DEPTH&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;verdict&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;comb&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;GREY_HI&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;shifted&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;comb&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;GREY_LO&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;grey&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ok&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the 24 pairs: 0 false flags, 5 of 5 shifts caught. The margin was thin: the worst good render scored 0.920, the weakest real shift 1.082. Hence a grey zone, logged and never failed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wiring it in
&lt;/h2&gt;

&lt;p&gt;The referee runs beside the vision judge on every indoor attempt, retries included; the depth call (about half a cent, three to seven seconds) hides behind the judge's call. "Shifted" counts as a geometry defect, the same class as a missing door, not a styling miss: the attempt is rejected, and when the cheap image model breaks geometry the pipeline escalates to a pricier one instead of rerolling. Everything fails open: if the referee errors or runs out of time, the camera is simply left unchecked and the other gates decide. A flaky referee must never block a paying user.&lt;/p&gt;

&lt;p&gt;Fail-open was where the bugs were. The check's 15-second wall used to fail open by resolving past a slow depth call, leaving the prediction running and billing us for a verdict we had abandoned; now it aborts the call. The original's reference had no wall at all, and the depth model is a shared one that scales to zero: a cold start rejected the whole QA stage, and a finished, already-paid render was thrown away as "Generation failed" after 55 seconds. In September, 8 of 26 live renders lost the camera check because the cold model did not start within 15 seconds (the 215 calls that did start waited at most 2.1 s). The render window has no slack for a sleeping model; the upload does, since a customer spends at least 30 seconds, typically about 60, choosing a style. So the reference is now computed at upload and stored as 1,536 numbers (ceiling curve, glare mask, depth profile); the referee never looks at the original again.&lt;/p&gt;

&lt;h2&gt;
  
  
  What live data said
&lt;/h2&gt;

&lt;p&gt;Was the referee too strict? Over 14 days in September, 78 customer renders went out as drafts. The referee had flagged the camera on 29 of them, but the camera was the &lt;em&gt;only&lt;/em&gt; failed check on 6, and those six scored 1.33 to 5.40 against a line at 1.08. All seven borderline flags (1.08 to 1.20) sat on renders that had also failed something else. Raising the line to 1.25 would have flipped 7 of 67 flags and un-drafted nothing.&lt;/p&gt;

&lt;p&gt;In the lab that month, four full-pipeline runs (345 attempts) produced 25 flags. Checked against the originals, 25 of 25 had really moved, 24 obviously, and none alone: every one also failed a door, window or layout check. The pricier model drifted at the same rate as the cheap one (8 of 104 versus 15 of 192). Camera drift is a symptom, not a class of defect: the model rebuilds the room as a catalogue photo. A wardrobe cut by the frame edge becomes a wall and the camera steps back behind it; an angled bedroom shot is straightened to face the bed; the frame zooms in toward the archway.&lt;/p&gt;

&lt;p&gt;Two fixes aimed at the model, both measured, both discarded. A prompt anchor saying the frame is fixed cut camera flags from 10 to 6, but clean renders fell from 15 to 12 and missing doors rose from 11 to 14; reverted. A second premium retry when only the camera had failed: the condition fired in 1 of 39 cells, and the retry gave 0 clean images in 12 throws, the camera returning five times, each with a new defect; not merged.&lt;/p&gt;

&lt;h2&gt;
  
  
  What still fails
&lt;/h2&gt;

&lt;p&gt;Then live pairs. Of 36 live drafts with a camera flag, 12 renders still existed (free-plan images expire) and one original; the rest were reconstructed from the stored reference curve and the door and window boxes. By eye: the model had moved the camera in 5 (plus one probable), the referee was wrong in 3, and 3 were arguable.&lt;/p&gt;

&lt;p&gt;All three errors were the same error. They scored 1.12 to 1.17, barely over the line, and each room had paint and glass together: a towel rail and a glass shower, a picture shelf and a full-height window. The ceiling-line channel locked onto the decor, the depth channel edged over on the glass, and the minimum rule, built on the assumption that the two deceivers do not meet, met them in one room. The one real soft shift in the set scored 1.10. No line separates 1.10 from 1.12; the calibration rooms simply had neither towel rails nor glass showers.&lt;/p&gt;

&lt;p&gt;One blind spot is by construction. A pan in a room with a flat ceiling barely changes the ceiling line's height, so the RGB channel stays quiet and the minimum discards the depth channel's alarm. Of 12 reviewed cases where the judge said moved and the referee said no, 7 were real, five of them vertical bedroom photos straightened to face the bed. One such render in 192 lab cells reached a user clean.&lt;/p&gt;

&lt;p&gt;A second turned up in October, on 20 renders of hard amateur photos (close-ups, cluttered rooms). The referee caught 2 of 5 framing failures and missed 3, and in all three the camera had pulled straight back while the model drew in more room. The referee compares where the ceiling line and the far wall sit across the frame, not how large they appear; a pure pull-back changes scale, not position. Of the 15 renders that looked fine it flagged one, and a second look found a real shift there too. A cheap frame-scale comparison caught 2 of the 3 misses in the same set, with false alarms of its own, so it needs its own calibration, in a separate module, before it ships.&lt;/p&gt;

&lt;p&gt;The file is frozen; any edit means re-running the calibration. The proposed fix for the near-line errors, cross-checking the door and window boxes before a near-line "shifted" verdict, is written down and not yet done. Until then the referee is right far more often than the model it watches, and wrong in ways we can name.&lt;/p&gt;

&lt;p&gt;We build this at &lt;a href="https://aifliproom.com" rel="noopener noreferrer"&gt;AI Flip Room&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>computervision</category>
      <category>ai</category>
      <category>typescript</category>
      <category>imageprocessing</category>
    </item>
    <item>
      <title>42 of our 71 regression guards stayed green when we broke the code on purpose</title>
      <dc:creator>AI Flip Room</dc:creator>
      <pubDate>Sat, 10 Oct 2026 19:19:29 +0000</pubDate>
      <link>https://dev.to/aifliproom/44-of-our-70-regression-guards-stayed-green-when-we-broke-the-code-on-purpose-3jgf</link>
      <guid>https://dev.to/aifliproom/44-of-our-70-regression-guards-stayed-green-when-we-broke-the-code-on-purpose-3jgf</guid>
      <description>&lt;p&gt;We build an AI virtual staging tool: a user uploads a photo of a room, an image model restyles it, and a set of checks compares the result with the original before anyone sees it. We wrote about those checks in a &lt;a href="https://dev.to/aifliproom/how-we-check-every-ai-generated-room-render-before-a-user-sees-it-3ek8"&gt;previous post&lt;/a&gt;. This one is about the layer under that: the scripts that make sure the checks, the billing rules and the consent logic stay the way we fixed them.&lt;/p&gt;

&lt;p&gt;We call them guards. Each is a standalone Node script, &lt;code&gt;.mjs&lt;/code&gt; or &lt;code&gt;.mts&lt;/code&gt;, that asserts one behaviour and exits non-zero if it is gone. A fix ships with a guard. By late August we had about seventy, run together with &lt;code&gt;npm run qa&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then we asked each one a simple question: if we break the thing you protect, do you go red? For 42 of 71, the answer was no.&lt;/p&gt;

&lt;h2&gt;
  
  
  How we got there
&lt;/h2&gt;

&lt;p&gt;The first problem was not quality but running them at all. Until 22 August there was no runner; the list lived in a Markdown file that named 33 of the 78 scripts on disk. A runner that compares its list with the files actually present found one guard that was red (15 of 18 checks) with nobody noticing, 27 live guards that had not been run for months, and nine that were on disk but not in git.&lt;/p&gt;

&lt;p&gt;Now everything ran, and everything was green. That felt like proof. It was not.&lt;/p&gt;

&lt;p&gt;Two days later an independent review tried something small: in the error-tracker configuration it renamed the environment variable that carries the DSN, the kind of typo you make during a rename. All 55 checks of the guard watching that configuration stayed green. In production that typo means the error tracker is silently a no-op, the exact failure the guard existed to prevent.&lt;/p&gt;

&lt;p&gt;That was reason enough to do it to every guard.&lt;/p&gt;

&lt;h2&gt;
  
  
  The audit
&lt;/h2&gt;

&lt;p&gt;Method, by hand, one guard at a time: edit the production file so the guarded behaviour is really broken, run the guard, restore the file, write down the numbers. A hole counted only if the guard stayed green on a real break.&lt;/p&gt;

&lt;p&gt;Result: 42 holes across 71 guards, and 42 guards that stayed green on at least one real break and had to be rewritten (35 in the first batch, 7 of the last eight). These are two separate counts that happen to match: one guard can hide more than one hole, and a few weak guards only showed up while we were fixing the others.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Group&lt;/th&gt;
&lt;th&gt;Guards&lt;/th&gt;
&lt;th&gt;Holes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Error tracking, observability, infrastructure&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Image engine and render pipeline&lt;/td&gt;
&lt;td&gt;19&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Billing, consent, privacy, SEO&lt;/td&gt;
&lt;td&gt;28&lt;/td&gt;
&lt;td&gt;21&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The last eight (older zones, referrals, video, pins)&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;9 in 7 files&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;71&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;42&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Some individual findings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One guard had no checks at all. It printed a green tick and exited 0 whatever the code looked like.&lt;/li&gt;
&lt;li&gt;One check compared the position of two strings in a route file to assert that storage blobs are deleted before database rows (rows first would orphan a customer's files for good). The first string had been removed by a refactor more than three weeks earlier. &lt;code&gt;indexOf&lt;/code&gt; returned -1, -1 is less than anything, and the check had passed every run since.&lt;/li&gt;
&lt;li&gt;One guard tested a hand-written copy of the SQL instead of the production webhook.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The pattern behind most of the 42: the guards were written against text, not behaviour. We read the route file as a string and looked for names. Such a guard fails both ways: an honest refactor turns it red for nothing, and a real break slides past because the names are still there.&lt;/p&gt;

&lt;h2&gt;
  
  
  One guard, before and after
&lt;/h2&gt;

&lt;p&gt;The consent route does three things in order: write the user's choice to the auth provider, append to the audit log, unpublish their renders from the public showcase. The guard checked that order with &lt;code&gt;indexOf&lt;/code&gt; on the source. Nine checks, all green. The mutation that beat it, and the rewrite:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// production: awaited; a failure returns 500 to the user&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateUserMetadata&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="c1"&gt;// mutation: same call, same position in the file - all nine checks still green&lt;/span&gt;
&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateUserMetadata&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{});&lt;/span&gt;

&lt;span class="c1"&gt;// rewritten guard: cut out the statement itself, not a name near it&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ROUTE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;client.users.updateUserMetadata&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ROUTE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ROUTE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lastIndexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ROUTE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;write is awaited, not fired in the background&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sr"&gt;/^await client&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;users&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;updateUserMetadata&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stmt&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nf"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a failed write is not swallowed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;catch&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stmt&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nf"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;and not silenced with void&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="sr"&gt;/^void&lt;/span&gt;&lt;span class="se"&gt;\b&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stmt&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Under the mutation the order of the three calls did not move, so the old checks passed. The meaning was gone: the write is fire-and-forget, the failure is swallowed, the audit log records "revoked", the user believes they opted out, and the showcase keeps publishing because the provider still says "allowed".&lt;/p&gt;

&lt;p&gt;The rewrite is still text, but the text of the statement itself, and the mutation that defeated the old version is now a permanent check. Where the code can be imported, we go further: the guard loads the real function through a loader and runs it over a table of inputs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The runner
&lt;/h2&gt;

&lt;p&gt;Every one of those experiments was a throwaway script, fifty lines each, and each hit the same traps: CRLF on the Windows working copy versus LF in git, a snippet that matched twice, a "mutation" that deleted a line and could not be reverted by an empty pattern (one stayed in the code and was caught on a second pass).&lt;/p&gt;

&lt;p&gt;On 28 August it became one tool. A job is JSON: the guard command plus named substitutions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"guard"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node tmp/qa/geometry-escalation-proof.mjs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mutations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"file"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"src/lib/draft-rank.ts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"a judge that errored no longer ranks last - an empty verdict beats a checked image"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"from"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"  if (input.errored) return Number.MAX_SAFE_INTEGER - 1;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"to"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="s2"&gt;"  void input.errored;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"file"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"src/app/api/generate/route.ts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"escalation became unconditional - furniture-placement failures go to the expensive engine too"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"from"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"if (!economyMode &amp;amp;&amp;amp; lastGeometryBroken &amp;amp;&amp;amp; attempt &amp;lt; MAX_ATTEMPTS) {"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"to"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="s2"&gt;"if (!economyMode &amp;amp;&amp;amp; attempt &amp;lt; MAX_ATTEMPTS) {"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The loop is short; the rules around it are what we paid for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;runGuard&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="nf"&gt;fail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;guard is already red; it proves nothing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;          &lt;span class="c1"&gt;// 1. green before&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;bad&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;empty replacement is a deletion, not a mutation&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;original&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;rx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;g&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;                      &lt;span class="c1"&gt;// rx() tolerates \r?\n  // 3&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;hits&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;hits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;bad&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;snippet must occur exactly once&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;// 4&lt;/span&gt;
  &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;rx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stillGreen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;runGuard&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;stillGreen&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;bad&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GUARD STAYED GREEN&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;good&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;assertEveryFileRestoredByteForByte&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;                                         &lt;span class="c1"&gt;// 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mutations are named and semantic on purpose. Classic mutation testing flips operators automatically; we write each mutation as a sentence about how a customer would get hurt, because that sentence also documents why the guard exists. The trade-off is coverage: we test only the breaks we thought of.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the mutations found in production code
&lt;/h2&gt;

&lt;p&gt;The day the runner was born, a run on a new guard did something we did not expect. The function that decides whether a payment-return URL is stale had an explicit "payment time is in the future" branch. Six mutations turned the guard red. The seventh, removing that branch, changed nothing: a future timestamp gives a negative age, and a negative age is never above the threshold. The branch was a crutch the guard could not tell from working code. We removed it and wrote the reason above the function.&lt;/p&gt;

&lt;p&gt;In the same session, 35 mutations across seven fixes found three guards checking the wrong thing: a parser that stopped at the first closing brace and broke on a nested object (four of six mutations passed on obviously broken code); a "the catch block logs" check that stayed green when the log left one branch because a neighbouring branch still had one; and a scanner for prototype-key guards that cleared a whole file if the guard appeared anywhere in it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it stands
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;93 mutation jobs, 867 mutations, in the repo next to the guards.&lt;/li&gt;
&lt;li&gt;171 guards in the runner's list, 12 named skips (they cost money, run on a calendar or need a fresh build); the list is compared with the disk on every commit.&lt;/li&gt;
&lt;li&gt;Written rule: a new guard without a mutation run counts as not written.&lt;/li&gt;
&lt;li&gt;The pre-commit hook checks only the registry, in 0.08 seconds. The full run takes minutes, needs the network and a database, and can go red from someone else's outage; a hook like that gets &lt;code&gt;--no-verify&lt;/code&gt; on the first urgent fix, and a bypassed hook is worse than none. The full run stays manual and mandatory before a merge.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What still fails
&lt;/h2&gt;

&lt;p&gt;Hand-written mutations come from the same person who wrote the guard, with the same blind spots. On 5 October a mutation named "only seven articles left in the links block" removed 5 of 17 links and the guard stayed green. The mutation was too weak, not the guard; it now removes every link. Nothing finds weak mutations except somebody noticing.&lt;/p&gt;

&lt;p&gt;Many guards still read source text. Executed guards are better, but much of our logic sits in route handlers tied to auth and a database, and extracting it just to test it is a refactor we have not earned yet. Text guards are honest only as long as their mutation set is.&lt;/p&gt;

&lt;p&gt;There is no CI. The guards run on a laptop before a merge.&lt;/p&gt;

&lt;p&gt;And the first finding of all: 42 of 71 is not a number about carelessness. Every guard was written in good faith after a real bug. A green check is a claim, and until something tries to make it red, it is an unverified one.&lt;/p&gt;

&lt;p&gt;We build this at &lt;a href="https://aifliproom.com" rel="noopener noreferrer"&gt;AI Flip Room&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Correction, 11 October: an earlier version said 44 of 70. The table adds up to 71 guards and 42 holes, and 42 guards had to be rewritten; the headline mixed two counts. Thanks to Arhan Canli for doing the sums in the comments.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>testing</category>
      <category>node</category>
      <category>typescript</category>
      <category>ai</category>
    </item>
    <item>
      <title>How we check every AI-generated room render before a user sees it</title>
      <dc:creator>AI Flip Room</dc:creator>
      <pubDate>Sat, 03 Oct 2026 02:05:35 +0000</pubDate>
      <link>https://dev.to/aifliproom/how-we-check-every-ai-generated-room-render-before-a-user-sees-it-3ek8</link>
      <guid>https://dev.to/aifliproom/how-we-check-every-ai-generated-room-render-before-a-user-sees-it-3ek8</guid>
      <description>&lt;p&gt;Image models are very good at restyling a room and quietly bad at leaving the room alone. Ask for a Japandi living room and you get beautiful furniture, and sometimes also:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a window that moved, shrank, or appeared over a kitchen sink where the photo shows a solid wall;&lt;/li&gt;
&lt;li&gt;a closet door that came back as a curtain, a sliding screen, or plain wall;&lt;/li&gt;
&lt;li&gt;a sofa parked across the only archway;&lt;/li&gt;
&lt;li&gt;a new doorway at the frame edge, or a niche carved into a flat wall;&lt;/li&gt;
&lt;li&gt;a camera that slid sideways;&lt;/li&gt;
&lt;li&gt;or the opposite: a picture that is almost exactly the photo you uploaded.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our users put these images in property listings, where a staged photo may change the furniture but not the windows, walls or doors (&lt;a href="https://aifliproom.com/blog/virtual-staging-disclosure-rules" rel="noopener noreferrer"&gt;why that line exists&lt;/a&gt;). So every render is checked automatically before anyone sees it. Here is how, and what building it taught us.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline at a glance
&lt;/h2&gt;

&lt;p&gt;For an indoor room, each render goes through three gates in parallel:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;A vision-model judge&lt;/strong&gt; compares the original photo with the render and answers a fixed list of yes/no questions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A mechanical camera check&lt;/strong&gt; measures whether the viewpoint moved, with no language model involved.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A crop-level presence check&lt;/strong&gt; looks at each door, window and staircase found in the original, at full resolution.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If all three pass, the render is served. If not, we retry. If nothing passes, the user gets the best attempt, clearly marked as a draft.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gate 1: a judge that only answers booleans
&lt;/h2&gt;

&lt;p&gt;The judge gets the original and the render, both downscaled, and must return a fixed JSON object. We use structured output with a schema, so it cannot reply in prose. An earlier version asked for "only JSON" and scraped it out with a regex; when the output got long or cut off, the parse failed and the gate silently did nothing.&lt;/p&gt;

&lt;p&gt;Indoors there are 16 checks, outdoors 9. Indoors they cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Openings:&lt;/strong&gt; every door is still a door you could open; every passage has clear floor to walk through.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Windows:&lt;/strong&gt; same count, position, size and shape; none invented; not hidden behind a tall wardrobe; the same view outside.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The room shell:&lt;/strong&gt; ceiling, fireplace, no carved niches, features on the same walls, solid frame edges, no new rooms or corridors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Finish consistency:&lt;/strong&gt; no half-repainted rooms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content rules:&lt;/strong&gt; no people, and no photo or realistic portrait of a person in the wall art.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Camera:&lt;/strong&gt; same viewpoint, same room depth.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Outdoors: buildings, fence line and gates, terrain (no new pool), mature trees, background, and a usable driveway.&lt;/p&gt;

&lt;p&gt;A simplified, illustrative verdict:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"doors_preserved"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"openings_clear"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"windows_ok"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"window_unblocked"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"walls_uniform"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"frame_edges_solid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"no_faces_in_art"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"fail_reasons"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sofa end stands on the archway floor"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A render passes only if every counted boolean is true; the reasons feed logs and the retry prompt. Most of the work went into the wording:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Say what must pass.&lt;/strong&gt; Restyling is the product, so the instructions list what is expected (new floors, paint, wallpaper, fixtures) and say "unsure means pass". The exception is a short list where unsure means fail, led by a window that may not have been in the original. An invented window is the worst defect a listing photo can have.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One question per field.&lt;/strong&gt; While the frame-edge rule was a sub-clause of a broader "no phantom architecture" check, new doorways at the frame edge got through. Its own boolean made the model actually look.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Naming things primes the judge.&lt;/strong&gt; An early niche check listed which shelves were allowed, and the judge started flagging every shelf. The current wording is purely geometric: is this flat wall still one plane?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Allow "nothing to compare".&lt;/strong&gt; The "same view through the window" check kept firing on originals with blinds drawn or glass blown out to white. That case is now an explicit pass.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wording is measurable.&lt;/strong&gt; The old wall-art wording wrongly failed 10 of 16 good frames (stylised line drawings counted as faces). The rewrite failed 0 of 16 and still caught all 5 real portraits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gate 2: measuring the camera instead of asking about it
&lt;/h2&gt;

&lt;p&gt;Early on, the vision model was close to blind to viewpoint changes: renders shot from a visibly different spot passed every neural check. Later, a stronger judge had the opposite problem: on 43 renders where the camera had not moved, it said it had 13 times. So indoors the judge's camera answers no longer decide pass or fail. A measurement does, with two channels:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Ceiling line.&lt;/strong&gt; We trace the wall/ceiling boundary as a curve (dynamic programming over the vertical brightness gradient) and compare the original's curve with the render's.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Depth profile.&lt;/strong&gt; A monocular depth model estimates both images. Per column we take how far the far wall reads, then compare the profiles with a robust fit, a rank correlation and a search for a sideways shift.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each channel is fooled by something different. Paint fools the ceiling line (dark beams, art on a mantel). Glass fools depth (windows and mirrors are estimated differently each time). Paint is flat in depth, and glass does not move the ceiling line, so we flag a shift only when &lt;strong&gt;both&lt;/strong&gt; agree: the minimum of the two normalised scores.&lt;/p&gt;

&lt;p&gt;On 24 hand-labelled pairs from two rooms, this caught 5 of 5 real shifts with 0 false flags. The margin was thin, so a grey zone around the threshold is logged, not failed. Outdoors there is no ceiling to trace, so the mechanical check is off and the judge's camera question stays in charge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gate 3: crops, because a door is 80 pixels wide
&lt;/h2&gt;

&lt;p&gt;At the judge's resolution a front door is a thin strip. So doors, windows and stairs are detected at upload, and after each render a model is asked about each crop at full resolution: is it still there? A mechanical channel also measures whether a window drifted or widened. On 87 labelled pairs, the crop judge caught 7 of 10 broken renders with no false alarms on the 75 clean ones; the mechanical channel caught the other 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  When a render fails
&lt;/h2&gt;

&lt;p&gt;Retries depend on the kind of defect.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Placement defects&lt;/strong&gt; (a blocked passage, a face in the art, half-painted walls) are retried on the same image model with the judge's reasons added to the prompt.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Geometry defects&lt;/strong&gt; go to a second, pricier image model. We measured a same-model retry fixing broken geometry about one time in five. In an earlier bake-off the two models were clean on 18 and 17 of 20 renders, and 19 of 20 together: their failures barely overlap.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The geometry retry gets a fixed, count-based instruction ("same set of openings, not one more, not one less"), never the judge's description of the defect. When a retry prompt named an arched opening at the left edge, the retry model painted exactly that.&lt;/p&gt;

&lt;p&gt;If nothing passes, the user still gets the best attempt, under a "rough draft" banner. On paid plans the first four rejected drafts in a rolling week don't use a render; the free plan gets one. The cap is deliberate: a draft is a real, downloadable image, so unlimited forgiveness would be a free image farm.&lt;/p&gt;

&lt;p&gt;The checks fail open. If the judge itself errors or times out, the user is not blocked: the image is served flagged, and an unverified render is not charged as a draft.&lt;/p&gt;

&lt;h2&gt;
  
  
  The near-copy trap
&lt;/h2&gt;

&lt;p&gt;At first, "best attempt" meant the one with the fewest failed checks. The attempt that breaks the least is often the one where the model barely did anything. In one real case the first attempt was a convincing industrial restyle that failed on geometry, and the user was served the second: their old room, old wallpaper and all, plus a pair of lamps. The ranking was paying the model for doing nothing.&lt;/p&gt;

&lt;p&gt;The fix is a change meter: shrink both images to a tiny thumbnail and count how much of the frame visibly changed. No model call, and we calibrated it on 110 real renders and 10 synthetic near-copies (recompressed, blurred, brightened, shifted, a couple of lamp-sized patches). The ranking now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// simplified&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;draftRank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Attempt&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;checkerErrored&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;LAST&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;rank&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;failedChecks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasPeopleOrRealFacesInArt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;rank&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;HARD_BAN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isNearCopy&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;intensity&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;rank&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;NEAR_COPY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;rank&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// lowest is served&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A light restage is exempt, because there the user asked us to keep the room.&lt;/p&gt;

&lt;h2&gt;
  
  
  Picking the judge model with a calibration set
&lt;/h2&gt;

&lt;p&gt;The judge runs on every attempt, so a cheaper model is tempting. We keep a calibration set of 31 hand-labelled frames and run every candidate on it twice. A cheaper model at under half the price per call missed 6 defects per run against our current judge's 3. On 46 live renders with 8 defects marked by eye, it caught 0 and 1 across two runs; the current judge caught 6. A newer model wasn't clearly better either: fewer misses (2 vs 3), twice the false alarms (4 vs 2). We kept the current judge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Ask the judge narrow yes/no questions, not one "is this good?".&lt;/li&gt;
&lt;li&gt;Where geometry can be measured, measure it, with channels whose failure modes don't overlap.&lt;/li&gt;
&lt;li&gt;Calibrate every wording change and model swap on a labelled set, twice.&lt;/li&gt;
&lt;li&gt;Design the failure path as carefully as the check: ranking, draft label, who pays.&lt;/li&gt;
&lt;li&gt;"Least broken" can mean "least changed". Measure change directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We build this at &lt;a href="https://aifliproom.com" rel="noopener noreferrer"&gt;AI Flip Room&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>computervision</category>
      <category>nextjs</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
