{"slug": "my-ai-wrote-a-bug-that-would-have-let-strangers-fake-your-safety-check-in", "title": "My AI Wrote a Bug That Would Have Let Strangers Fake Your Safety Check-In", "summary": "A developer built Afterlife Kit, an open-source offline-first app skeleton for #Kiroween using Kiro, a spec-driven AI IDE, and documented four bugs the AI agent introduced that were caught by property-based tests before release. The failures included a hybrid logical clock that could issue duplicate timestamps, a relay paging scheme that dropped edits from the longest-offline device, an overdue alarm measured from the last check-in instead of the next checkpoint's ETA, and ECDSA check-ins vulnerable to public-key swapping under another member's id. The fixes included the textbook HLC receive rule, keying batches by server arrival time, and deriving self-certifying member ids from the signing key.", "body_md": "It's 6:41 PM on Halloween. Maya is somewhere on Blackwood Ridge. Her phone shows no service.\n\nAt home, Mom's phone shows nothing either. Every app they own died the second the signal did.\n\nThat's the moment I built for. Afterlife Kit is an open-source skeleton for apps that keep living when the network dies. I built it for #Kiroween with Kiro, a spec-driven AI IDE. This is the story of the four bugs the AI wrote, and how the specs caught every one before a user ever could.\n\nMost apps treat the server as the truth and your phone as a window onto it. Lose the window and you lose everything.\n\nAfterlife Kit flips that: **the device is the truth.** Every change is written to an operation log on the phone (IndexedDB) the instant you tap. When *any* phone catches a bar of signal, the changes travel through a ~100-line relay and merge on every other phone.\n\nTwo very different apps run on the same skeleton:\n\n| 🦇 **Ghost Trail** | 🕯️ **Ledger After Dark** | \n|---|---|\n| Group safety check-ins for no-signal hikes | Credit ledger for corner shops | \n| Real topo map, downloaded for offline use | Photo receipts on every entry | \n| Overdue alarm on every synced phone | Reminders on SMS, WhatsApp, LINE, WeChat | \n| Every check-in signed by the phone's own key | 10 languages, Arabic and Urdu right-to-left | \n\nI didn't start in a chat box. I started in:\n\n.kiro/\n\n├── steering/   product.md · tech.md · structure.md   ← the rules every agent run follows\n\n├── specs/\n\n│   ├── sync-core/    requirements (EARS) · design · tasks\n\n│   └── ghost-trail/  requirements (EARS) · design · tasks\n\n└── hooks/      tests on save · typecheck on stop · secret guard · boundary review\n\nRequirements are written in EARS, so they're testable sentences:\n\n*WHEN now > the next checkpoint's ETA + 15 min grace **THE SYSTEM SHALL** mark the member overdue.\n\nThe design turns those into **correctness properties**, and each property becomes a [fast-check](https://fast-check.dev) test that throws hundreds of random histories at the code.\n\nThen I let Kiro's agent loose, headless, on a cheap model, one spec phase per run. A hook re-ran the property tests on every file save, and another blocked the agent from finishing while the types were broken.\n\nThe agent's code passed every example test. The properties did not pass.\n\nThe hybrid logical clock (HLC) is the heartbeat of the merge. Kiro's version could hand two phones the **same timestamp**, so a merge could silently pick the wrong value.\n\nOne property, *\"receive always produces a clock strictly greater than both inputs\"*, failed in three steps. The fix was the textbook HLC receive rule.\n\nThis one scared me. Three replicas, one with a clock 3 ms behind:\n\n```\nreplica 2 writes + pushes → replica 0 pulls (cursor jumps ahead)\nreplica 1 writes (older clock) + pushes → replica 0 pulls → never sees it 💀\n```\n\nThe relay was paging by the *phones'* clocks. The phone that was offline the longest (the exact user this kit exists for) lost its edits. The spec said to key batches by **server arrival time**. The property made the gap impossible to miss.\n\n```\nCP0 at 11:00, CP1 at 12:00. Hiker checks in at CP0 at 11:00. On time.\nnow = 11:12 → \"OVERDUE\" 🦇🦇🦇\n```\n\nThe agent measured lateness from the *last check-in*, not the *next checkpoint's ETA*. Every hiker would have triggered a bat-swarm alarm 15 minutes after every check-in. Kiro's own seven properties passed. Three more properties written straight from the requirement text failed instantly.\n\nRequirement 5 says **\"Only you can check in as you.\"** Kiro implemented ECDSA signatures and five properties, all green.\n\nI added a sixth: *a check-in is valid only if the signing key belongs to that member id.* It failed immediately. Ids were random, so anyone who could edit the shared member list could swap their own public key under Maya's id and sign \"I'm OK\" **as her**. On a safety app.\n\nThe fix: make ids self-certifying.\n\n```\nid = base64url(SHA-256(`${crv}:${x}:${y}`)).slice(0, 22)\n```\n\nSwap the key and you're out. Every phone checks it before trusting a signature.\n\nBecause it's Kiroween:\n\nThe whole thing (sync engine, two apps, 40 tests, 29 property checks) ran on Kiro's free credits. The specs did the thinking, so the model only had to type.\n\n*Built for #Kiroween 2026 (Skeleton Crew). Map data © OpenStreetMap contributors, OpenTopoMap.*", "url": "https://wpnews.pro/news/my-ai-wrote-a-bug-that-would-have-let-strangers-fake-your-safety-check-in", "canonical_source": "https://dev.to/atomiccninja/my-ai-wrote-a-bug-that-would-have-let-strangers-fake-your-safety-check-in-1g16", "published_at": "2026-11-28 10:06:34+00:00", "updated_at": "2026-11-28 10:14:59.594842+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-safety", "artificial-intelligence"], "entities": ["Kiro", "Afterlife Kit", "Ghost Trail", "Ledger After Dark", "fast-check", "IndexedDB", "EARS"], "also_reported_by": [], "takeaway": "Writing EARS requirements as correctness properties and running them with fast-check on every save caught four agent-written bugs—duplicate HLC timestamps, relay paging by device clock, overdue alarms measured from the last check-in, and swappable ECDSA keys—that example tests missed.", "recommendation": {"advice": "Convert each requirement into a property test and gate the coding agent on it, since example tests passed while properties exposed duplicate timestamps, dropped offline edits, and key-swapping check-ins.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/my-ai-wrote-a-bug-that-would-have-let-strangers-fake-your-safety-check-in", "markdown": "https://wpnews.pro/news/my-ai-wrote-a-bug-that-would-have-let-strangers-fake-your-safety-check-in.md", "text": "https://wpnews.pro/news/my-ai-wrote-a-bug-that-would-have-let-strangers-fake-your-safety-check-in.txt", "jsonld": "https://wpnews.pro/news/my-ai-wrote-a-bug-that-would-have-let-strangers-fake-your-safety-check-in.jsonld"}}