ANTIGRAVITY LABJP
Articles/Agents & Manager
Agents & Manager/2026-06-18Advanced

Handing Visual Regression to a Parallel Agent in Antigravity 2.0

A design for running a dedicated headless visual-regression agent alongside your main implementation agent using Antigravity 2.0's parallel orchestration — with a working harness and the reproducibility traps I hit in production.

antigravity374agents95visual-regression2testing11playwright3

Premium Article

Every time I add one more iPhone resolution, I get nervous that a layout is off by half a pixel somewhere. The wallpaper apps I run as an indie developer accumulate more screenshots as device support grows, and I used to end up comparing them one by one by eye. When I added the iPhone Air at 420×912 and the iPhone 17 Pro at 402×874, I missed a grid that was misaligned in exactly one spot until right before the App Store release.

Today, June 18, Gemini CLI folded into Antigravity CLI, and Antigravity 2.0's parallel orchestration became the working assumption for real projects. The third example Google gives for parallel execution is "another agent runs a headless visual regression test." For someone like me who had been relying on the human eye to the very end, that quiet capability turns out to matter. This article walks through the minimal harness for building that regression agent, plus the traps I hit running it in production.

Why pull visual regression into a separate agent

Visual regression testing — capture screenshots, compare them against approved baselines, stop when a diff appears — runs on a different clock than implementation. Run it while you are still writing code and you stall waiting; run it all at once afterward and you lose track of which change broke what.

What Antigravity 2.0 changes is that you can physically separate this inspection from the main implementation agent. While one agent rewrites a component, another keeps diffing against the previous commit's baseline. The time that implementation and inspection used to fight over inside one conversation now flows in parallel.

I think of this split the same way I learned to run four sites in parallel: keep the agent that generates content separate from the agent that runs the gates, and one stalling never freezes the other. Visual regression is the same. Put the "guardian of appearance" in its own process and the safety net runs continuously without dragging down implementation speed.

The minimal core: capture headless, diff against a baseline

Start with the pure core of visual regression, no parallelism or agents yet. It is a tiny harness that captures several viewports with Playwright and counts diff pixels with pixelmatch.

// vr/capture.mjs — capture a URL across multiple viewports
import { chromium } from "playwright";
import { mkdir } from "node:fs/promises";
 
// Real-device-like resolutions, using one of my app promo pages as the target
const VIEWPORTS = [
  { name: "iphone-air",       width: 420, height: 912 },
  { name: "iphone-17-pro",    width: 402, height: 874 },
  { name: "iphone-16-promax", width: 440, height: 956 },
  { name: "desktop",          width: 1280, height: 800 },
];
 
export async function capture(url, outDir) {
  await mkdir(outDir, { recursive: true });
  const browser = await chromium.launch(); // headless by default
  try {
    for (const vp of VIEWPORTS) {
      const page = await browser.newPage({
        viewport: { width: vp.width, height: vp.height },
        deviceScaleFactor: 2, // capture at Retina scale
      });
      await page.goto(url, { waitUntil: "networkidle" });
      await page.screenshot({ path: `${outDir}/${vp.name}.png`, fullPage: true });
      await page.close();
    }
  } finally {
    await browser.close();
  }
}

The diff side aligns the baseline and the new image to the same size, then compares pixels. pixelmatch returns the number of mismatched pixels, so we judge by the ratio against the total.

// vr/diff.mjs — return the diff ratio between baseline and current
import { PNG } from "pngjs";
import pixelmatch from "pixelmatch";
import { readFileSync, writeFileSync } from "node:fs";
 
export function diff(baselinePath, currentPath, diffOutPath) {
  const base = PNG.sync.read(readFileSync(baselinePath));
  const cur = PNG.sync.read(readFileSync(currentPath));
 
  // A size mismatch is itself "breakage" — fail immediately
  if (base.width !== cur.width || base.height !== cur.height) {
    return { changed: 1.0, reason: "dimension-mismatch" };
  }
 
  const { width, height } = base;
  const out = new PNG({ width, height });
  const mismatched = pixelmatch(
    base.data, cur.data, out.data, width, height,
    { threshold: 0.1, includeAA: false } // includeAA:false is the key to fighting flakiness
  );
  writeFileSync(diffOutPath, PNG.sync.write(out));
 
  const ratio = mismatched / (width * height);
  return { changed: ratio, reason: ratio > 0 ? "pixel-diff" : "identical" };
}

Wire those two together and you have the minimal regression loop: capture, compare, keep the diff image. Nothing special is needed up to here.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
If you have been catching layout breakage by eye, you can stand up an automatic screenshot-diff gate today
You will learn the three pillars of visual regression — headless capture, baseline management, threshold tuning — with copy-and-run code
You can wire a regression agent into Antigravity 2.0's parallel pipeline and keep a visual safety net without slowing implementation down
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Agents & Manager2026-04-16
Building an AI Test Pipeline with Antigravity Agents: Automating Quality Assurance in Production
Learn how to build a production-grade automated test pipeline using Antigravity's AI agents — from unit test generation to E2E testing with Playwright, complete with validation layers and CI/CD integration.
Agents & Manager2026-03-17
E2E Test Automation with Antigravity Browser Sub-Agent
A comprehensive, hands-on guide to E2E testing, visual regression testing, and CI/CD integration using Antigravity's Browser Sub-Agent powered by Gemini vision capabilities.
Agents & Manager2026-06-18
Three Boundaries I Draw Before Handing Work to an Antigravity 2.0 Agent
What to hand a background agent, and what to keep in your own hands. The three boundaries I actually drew while running solo-dev automation in parallel, and how to encode them so the lines hold.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →