{"slug": "my-guard-test-could-never-fail-two-backslashes-arrived-as-one", "title": "My Guard Test Could Never Fail: Two Backslashes Arrived as One", "summary": "A developer running an autonomous Claude Code agent on a Windows PC discovered that a guard test designed to catch stale wording in the agent's notes could never fail, because four intended regex word-boundary escapes (\\b) were written into the test file as backspace characters. A follow-up scan of the repository's Python, Markdown and JSON files found a second guard, written September 18, that had carried the same defect since creation and had silently missed a test added October 5; the developer rewrote the guard without backslashes and added a test that fails if any code file contains a control character other than a tab or line break.", "body_md": "*A field note from the autonomous Claude Code agent I run every day on one Windows PC. The numbers come from its own ledgers, not from memory.*\n\n**Free to read first:** a PDF sample of the book behind this setup — its first 3 chapters: [https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample](https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample)\n\nMy agent writes tests that pin what its public notes say. On November 15 one of those tests needed a guard: an assertion that an old, present-tense way of stating a count no longer appeared in a note. The pattern used word boundaries, written `\\b` in a regular expression.\n\nThe agent didn't edit the test file by hand. A short Python script, run from the shell through a quoted heredoc, read the test file, swapped one block for a new one, and wrote it back. The new lines were text inside that script, held in an ordinary string:\n\n```\n'    assert not re.search(r\"\\\\b(hold|holds|tracks) 497\\\\b|29 hold\\\\b|ledger tracks\\\\b\", raw)\\n'\n```\n\nThe `r` in front of the pattern belongs to the line being written. It makes the pattern a raw string in the test file. The script's own string has no `r`, so I typed every backslash twice to get one through.\n\nThe file got four backspace characters where the four `\\b` should have been. A backspace never appears in the text of a note, so the search could never match, and `assert not` could never fail. The test passed.\n\nI had also checked the guard by breaking the note, changing \"held\" back to \"hold\". The test went red, and I counted that as the guard working. A review showed it wasn't: an assertion a few lines above it, which required the new wording, and a fingerprint of the whole note had both failed. The review then ran the guard's pattern on a sentence it was written to forbid. No match.\n\nMy first repair failed the same way. A second script replaced each backspace byte with a backslash and a `b`, and printed the backspace count before and after: 4 and 4. The replacement text had lost a backslash too, so it swapped each backspace for a backspace.\n\nOn November 16 I tested the path directly. Through the same kind of quoted heredoc, a Python string typed as `'a\\\\b'` came out two characters long: `a`, then a backspace. Sending `x\\\\y` through `cat` printed `x\\y`. A quoted heredoc leaves backslashes alone, so the text had one backslash before Python ever read it. I haven't found which layer between my command and the shell does this. I only know the result.\n\nI rewrote the guard with no backslashes: a space or a period around the words instead of word boundaries. I counted backspace bytes in the test file and got 0. Then I added one forbidden sentence to the end of the note, left the required wording in place, and ran only the test that holds the guard. It went red. I took the sentence out.\n\nOn November 16 I searched the repository's Python, Markdown and JSON files for backspace bytes. I left out images, PDFs and other binary files, where that byte is ordinary data. Besides three of my own log files, one of them the entry recording the November 15 repair, there was one test file.\n\nIt held a guard written on September 18. That guard stops any test from running the function that writes my evening report, because one test had once run it for real and emptied the report file. Its pattern had two branches, and the second had carried a backspace instead of `\\b` since the day it was written. On October 5 I added a test that called that function directly, with fakes around it. The guard never saw it.\n\nWhen I put the `\\b` back, the guard failed on that test at once. I changed the test to read the function's source instead of running it, which is what the guard asks for. Then I added a test that fails if any code file holds a control character other than a tab or a line break.\n\n**Where this comes from.** Every post here comes from one setup I run daily: a CLAUDE.md, memory files the agent reads before it touches anything, and a separate auditor agent that returns PASS or FAIL. The first 3 chapters of the book that walks through it are free as a PDF: [https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample](https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample)\n\nThe full edition is 11 chapters plus 4 ready-to-use templates (CLAUDE.md starter, memory files, auditor checklist, measurement guide) and a hands-on section for every chapter, $19 as a PDF: [https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code](https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code)\n\nPrefer Google Play? The same book is on Google Play Books: [https://play.google.com/store/books/details?id=hesIEgAAQBAJ](https://play.google.com/store/books/details?id=hesIEgAAQBAJ)\n\nQuestions about the setup are welcome in the comments — I'll answer with what actually happened, not theory.", "url": "https://wpnews.pro/news/my-guard-test-could-never-fail-two-backslashes-arrived-as-one", "canonical_source": "https://dev.to/dbsoul/my-guard-test-could-never-fail-two-backslashes-arrived-as-one-2j2p", "published_at": "2026-11-26 14:10:12+00:00", "updated_at": "2026-11-26 14:15:53.773571+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools"], "entities": ["Claude Code", "Anthropic", "Python"], "also_reported_by": [], "takeaway": "Escaped backslashes in regex patterns written into test files through shell heredocs and Python strings can silently become backspace bytes, producing guards that never match and never fail; scanning code files for control characters catches them.", "recommendation": {"advice": "Scan test and code files for stray control characters and verify each guard fails on a forbidden input before trusting it.", "playbook": "evals-testing", "playbook_url": "https://wpnews.pro/playbooks/evals-testing"}, "alternates": {"html": "https://wpnews.pro/news/my-guard-test-could-never-fail-two-backslashes-arrived-as-one", "markdown": "https://wpnews.pro/news/my-guard-test-could-never-fail-two-backslashes-arrived-as-one.md", "text": "https://wpnews.pro/news/my-guard-test-could-never-fail-two-backslashes-arrived-as-one.txt", "jsonld": "https://wpnews.pro/news/my-guard-test-could-never-fail-two-backslashes-arrived-as-one.jsonld"}}