{"slug": "my-ai-agent-diagnosed-its-own-bug-the-diagnosis-was-plausible-specific-and-wrong", "title": "My AI agent diagnosed its own bug. The diagnosis was plausible, specific, and wrong.", "summary": "A developer's AI agent misdiagnosed a Core Web Vitals issue on their blog, attributing a layout shift (CLS 0.303) to missing image dimensions when in fact 91% of images had incorrect dimensions. The developer emphasizes that a wrong diagnosis can be more costly than no diagnosis, as it misdirects attention, and advocates for measuring before fixing and labeling inferences in logs.", "body_md": "Article pages were shifting during load. Lighthouse reported **CLS 0.303**, where anything\n\nabove 0.1 counts as poor.\n\nMy ops agent wrote the cause into its log:\n\nArticle pages CLS 0.303, caused by\n\n`.prose img`\n\nmissing`width`\n\n/`height`\n\n.\n\nFixing requires fetching intrinsic dimensions for 125 images — separate task.\n\n**That diagnosis looks entirely correct.** Images without declared dimensions give the browser\n\nnothing to reserve space with, so content jumps when they load. It's the canonical cause of\n\nlayout shift; every article about CLS leads with it.\n\nWhen I sat down to fix it the next day, I did one thing first: **I counted how many images\nwere actually missing dimensions.**\n\nThe answer was **4**. The other **155 already had them.**\n\nNot in the physics — image dimensions genuinely do affect CLS. It went wrong by **applying a\nfamiliar cause without checking the scene.**\n\nThe real problem: those 155 images had dimensions, and the dimensions were **wrong**.\n\nThese posts were written in 2017. The HTML looks like this:\n\n```\n<img src=\"https://i.imgur.com/KXKbv0d.jpg\" width=\"500\" height=\"500\">\n```\n\nThe author meant *\"display this at 500×500.\"* They did **not** mean *\"this image is 500×500.\"*\n\nThe image is actually **1361×738**.\n\nSo here's the sequence:\n\n`width=\"500\" height=\"500\"`\n\n, reserves a square based on that 1:1 ratio**Wrong dimensions are worse than no dimensions.** Without them, the browser knows it doesn't\n\nknow. With wrong ones, it confidently reserves the wrong space.\n\nI fetched intrinsic dimensions for all 119 unique image URLs and compared:\n\n**145 of 159 were wrong. 91%.**\n\nIf the log had said \"cause unknown,\" I'd have investigated.\n\nInstead it gave me something **plausible, specific, and immediately actionable.** Following it,\n\nI'd have added dimensions to those 4 images, watched CLS barely move, and started suspecting\n\nsomething else entirely — **continuing to search from an already-misled starting point.**\n\n**A wrong diagnosis costs more than no diagnosis, because it consumes the attention you would\notherwise have spent doubting.**\n\nThe shape of the mistake is worth naming: it **treated the common cause as this case's cause.**\n\nMissing dimensions genuinely is the most likely explanation for CLS, so it was a good guess.\n\nThe failure wasn't the guess. It was **not spending one command to test the guess before\ncommitting to it.**\n\nThat command takes under ten seconds:\n\n```\n# how many images have no width/height?\ngrep -o '<img[^>]*>' *.md | grep -vc 'width='\n```\n\nWorth stating plainly, because it reads that way if I don't.\n\nThe same system wrote that log, and in the same pass it got a lot right: it recorded the exact\n\nCLS figure, identified the affected selector, filed the work as its own task, and left a note in\n\nthe status file saying *\"new articles must always carry real width/height so this doesn't\naccumulate again.\"*\n\n**That preventive note was correct. The diagnosis was wrong. Both came from the same thinking.**\n\nPeople do this constantly. A familiar symptom triggers the most common cause, and subsequent\n\nobservations get bent toward it. The difference is that **a system writes its guess down as a\nconfident single line, files it, and tomorrow you read that line as an established fact.**\n\n**1. Measure before fixing.**\n\nNot the severity — I already had that (CLS 0.303). Measure **whether the cause I assume actually\nholds here.** It's usually one command. Ten seconds would have redirected this entire task.\n\n**2. Separate \"measured\" from \"inferred\" in the log.**\n\n`CLS 0.303`\n\nand `selector .prose img`\n\nwere measured. `because they lack width/height`\n\nwas\n\ninferred. They sat on the same line and read as equally reliable the next morning. Inferences\n\nnow have to be labelled as inferences.\n\n**3. When corrected, amend the original diagnosis explicitly.**\n\nThe log now says *\"the original diagnosis was wrong\"* rather than quietly swapping in the right\n\nanswer. **Next time I need to know more than the correct answer — I need to know how I got it\nwrong.**\n\nThere's a tail to this.\n\nAfter replacing every declared size with the real one, one page went from 0.303 to **0.212**.\n\nNot zero.\n\nAnother round of digging: that 0.212 was **manufactured by the local environment.** The images\n\nare on imgur, imgur's hotlink protection rejects a localhost referer, the images fail, the\n\nbrowser renders alt text at a different size, and the layout shifts again.\n\n**Measured in production: 0.**\n\nSo the same number got explained once by a wrong diagnosis and produced once by a wrong\n\nenvironment. Both times I nearly acted on it.", "url": "https://wpnews.pro/news/my-ai-agent-diagnosed-its-own-bug-the-diagnosis-was-plausible-specific-and-wrong", "canonical_source": "https://dev.to/wisplu/my-ai-agent-diagnosed-its-own-bug-the-diagnosis-was-plausible-specific-and-wrong-7gm", "published_at": "2026-08-25 17:09:19+00:00", "updated_at": "2026-08-25 17:45:38.780040+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools"], "entities": ["Lighthouse", "CLS", "AI agent", "Imgur"], "alternates": {"html": "https://wpnews.pro/news/my-ai-agent-diagnosed-its-own-bug-the-diagnosis-was-plausible-specific-and-wrong", "markdown": "https://wpnews.pro/news/my-ai-agent-diagnosed-its-own-bug-the-diagnosis-was-plausible-specific-and-wrong.md", "text": "https://wpnews.pro/news/my-ai-agent-diagnosed-its-own-bug-the-diagnosis-was-plausible-specific-and-wrong.txt", "jsonld": "https://wpnews.pro/news/my-ai-agent-diagnosed-its-own-bug-the-diagnosis-was-plausible-specific-and-wrong.jsonld"}}