{"slug": "three-ai-agents-one-android-phone-and-a-clock", "title": "Three AI Agents, One Android Phone, and a Clock", "summary": "A developer built Corral, an open-source lease-based coordination system (v0.1.8) that lets multiple AI coding agents share a single Android device without colliding over adb. Instead of a lock file, Corral uses a SQLite lease table with a 30-minute default deadline, heartbeat renewal, and a FIFO queue, plus an identity chain (CORRAL_OWNER, /proc ancestry, then $USER) so the daemon can distinguish agents running under the same Unix user. The developer reports the hard part was handling agents that die while holding a device, which the expiring lease releases automatically.", "body_md": "Three coding agents sharing one Android phone is not an AI problem. It is a 1980s problem wearing a new hat. This is the devlog of the lease-based fix, including the parts that turned out to be harder than the interesting part.\n\nOriginally published at [https://hackernoon.com/three-ai-agents-one-android-phone-and-a-clock](https://hackernoon.com/three-ai-agents-one-android-phone-and-a-clock)\n\nThree coding agents were working in my repo at 3 a.m. Two were running instrumentation tests, one was taking screenshots. They all had `adb` on their PATH, and they all picked the same device, because of course they did.\n\nThe tests installed over each other. A screenshot captured a login screen from the wrong build. One agent force-stopped a process another was waiting on, then helpfully reported that the app had crashed.\n\nNone of this is an AI problem. It is a 1980s problem wearing a new hat: **a machine that is fine with one user and hostile to two**. A debug bridge, a serial port, a printer queue — anything with a single \"current state\" and no locking eventually meets a second caller.\n\nThis is the devlog of the thing I built to fix it, and of everything that turned out to be harder than the interesting part. The code is at [github.com/ciszkin/corral](https://github.com/ciszkin/corral): a daemon, a CLI, a Gradle gate and a Compose Desktop console around one SQLite lease table, with `v0.1.8` published.\n\nAn Android device is a singleton with no notion of ownership. `adb` will happily install, uninstall, force-stop, screenshot or shell into whatever is attached, from whoever asked. There is no lock, no queue, and no identity — the only thing standing between two agents and one phone is luck.\n\nWhat made it worse in my case was that the agents were *not* doing anything wrong. They were doing what I told them: run the tests, take a screenshot, iterate. The collision was structural. Add a second agent and you have a race that reproduces maybe one time in five, which is the worst rate possible: frequent enough to waste an afternoon, rare enough to look like a flaky test.\n\nSo the question was not \"how do I stop agents from being careless\". It was \"how do I give a singleton a queue, an owner and a deadline\".\n\nThe obvious fix is a lock file. It is also the wrong one, because a lock has no answer to the only question that matters:\n\nThe failure mode you must design for is not *two agents at once*. It is *one agent, gone*.\n\nAn agent that hits a token limit, crashes, or is simply killed by its harness leaves a lock file behind and no one to release it. The lock is held by a process that no longer exists, and every other agent waits forever on a dead owner.\n\nSo the primitive is a **lease**: a claim with a deadline. Default 30 minutes, renewed by a heartbeat, floored at 10 seconds so the heartbeat can keep up, capped at a day. When the holder stops renewing, the lease sweeps back into the pool and the queue moves on. A dead agent cannot hold a device, because the clock releases it.\n\nTwo details made that work in practice:\n\n`corral claim --model Pixel --os 14` means \"any that matches\", and the FIFO is over Everything else in the product is downstream of that one choice.\n\nEvery agent on my machine runs as `vitali`. Without a better idea, the daemon cannot tell Claude from Codex from a human typing `adb`, and my first design used `$USER` — which meant two agents could both \"prove\" they held the same lease.\n\nThe fix is an identity chain, resolved in this order:\n\n`CORRAL_OWNER` if the harness sets it (agent tiers flow in this way);`/proc` for `comm:pid:starttime` of the first non-shell ancestor;`user:$USER` as the floor.\nThat chain is why \"the holder\" survives `bash -c`, `make`, and Gradle forking a worker. It is also why the same identity appears in three places — the CLI, the adb wrapper, and an MCP server — and why they must agree byte for byte. They still disagree on a host without `/proc`, so the wrapper delegates to `corral owner` there and the JVM does the same walk. One reader, two front doors.\n\nHere is the uncomfortable part. My agents are cooperative. They use the CLI. But nothing stops an agent from typing `adb -s emulator-5554 install app.apk`, and on the day one does, a polite error message is worth nothing.\n\nSo the daemon installs gates in the places calls actually come from:\n\n`adb` — a two-line shim that asks the daemon before exec'ing the real binary.`platform-tools/adb`, daemon-healed if something overwrites it, because plenty of tooling calls adb by absolute path.`init.d` gate\nThat third one is the non-obvious layer, and it is the only one that can block an `installDebug` started from an IDE.\n\nThe honest count matters, so it is documented as what it is: **a POSIX install has three layers; a Windows install has two**, because the SDK shim is not installed there. An absolute-path call into `platform-tools\\adb.exe` is outside the gate on Windows, and the docs say so.\n\nNone of this is a security boundary. It is a guardrail for well-behaved machines with badly-behaved schedules. Saying that out loud, in the README and in `SECURITY.md`, saved me from a whole class of bug report where a \"bypass\" was really a misunderstanding.\n\nThis one still makes me smile. On Windows the daemon runs as a Scheduled Task, so install and uninstall have to answer a polite question: *is the task on this machine ours, someone else's, or absent?*\n\nGet it wrong in one direction and you hijack another user's task. Get it wrong in the other and you leave an orphan pointing at a launcher you just deleted. So the rule is conservative: read the task's XML, find `<Command>`, and only claim the task if that command is our launcher under our install root.\n\nThen a reviewer pointed the installer at an install root called `Jürgen`, on a stubbed Windows host.\n\nA non-ASCII path, one `schtasks` call, and the installer reported \"NOT started\" and left the task behind. The cause: the XML comes back in one of **four encodings** — UTF-16LE, UTF-16BE, UTF-8, or UTF-8 with a BOM — and the first fix I shipped was a hack: delete the NUL bytes and hope. That \"works\" for UTF-16 without touching the text, and silently corrupts anything else.\n\nThe real fix was to stop guessing and decode:\n\n```\ncase \"$bom\" in\n  FF\\ FE) iconv -f UTF-16LE -t UTF-8 … ;;   # then drop the decoded BOM\n  FE\\ FF) iconv -f UTF-16BE -t UTF-8 … ;;\n  EF\\ BB\\ BF) strip that leading BOM only ;;\n  *)      take it as UTF-8 ;;\nesac\n```\n\nTwo things I had to accept:\n\n`LC_ALL=C``<Command>` text is a path, and locale-dependent byte handling is how you lose a `ü`.` iconv`, a UTF-16 task is now unreadable even for an ASCII root, so install neither refreshes nor starts it. That is the safe direction, and it is written down. Git for Windows ships The tests grew eleven cases for this: two roots, four encodings, ASCII and non-ASCII foreign tasks, ours and a previous version's. All stubbed, because no CI runner offers a German Windows.\n\nSomewhere around the fortieth review I started auditing what the README *claimed* against what the code did. Twenty-two claims were false.\n\nNot typos. Things like:\n\n`v0.0.0-dev`.` corral doctor` reports the state of the gate\" — it reports the rules file; it cannot see the Gradle init script at all.\nThe lesson is not \"write better docs\". It is that **docs for an operator are a user interface**, and a wrong sentence costs exactly as much as a wrong line of code, except it never throws. The fix was to make the claims testable: a suite now greps the shipped docs for phrases that pin meaning, so a behaviour change cannot quietly leave a lie behind.\n\nThe console let you type the path to `scrcpy`. It saved it to `ui.conf`. It applied it to nothing — the launcher read only the process environment.\n\nThat is worse than a missing feature, because the UI *answered*. You set it, you clicked Save, it stayed saved, and the live view ignored it. The fix was small — resolve the saved value first, then the environment, then bare `scrcpy` — but the shape of it matters: the value is read **per launch**, not at construction, because the console keeps one launcher for its lifetime and the whole point is that a path saved now applies to the next live view.\n\nThe documentation audit is what found it. Which is the argument for auditing documentation: to check a sentence, you have to read the code that would make it true.\n\n`v0.1.0` is the first tagged release. Everything before it reported `0.0.0-dev`, which means the update path had **never once executed against a real release**.\n\nIt has two halves, and both are deliberately boring. The **check** is one unauthenticated GET to `releases/latest`, cached and off by a kill-switch; it changes nothing. The **apply** is the deliberate half, and it runs in a fixed order: download the zip, download its published `.sha256`, verify the two match, extract, run the bundle's own `install.sh`, restart the service unit. Nothing is extracted before the digest matches, and a host that cannot restart the unit is refused up front rather than left half-updated.\n\nSo I rehearsed it: a disposable container with systemd, a scratch GitHub repo, two releases, and one rule — no fake downloads, no injected fakes. Real `install.sh`, real `curl`, real `systemctl`.\n\nIt found two release blockers in the first hour.\n\n**Blocker one: the workflow could not build a release at all.** The step that resolves the version exported `CORRAL_VERSION` and `TAG`, but five later steps build `dist/corral-$VERSION.zip` — and `VERSION` was never exported. Under `set -u` that is:\n\n```\nline 14: VERSION: unbound variable\n```\n\nThe very command the release notes tell an operator to run. It had never been run, so it had never failed.\n\n**Blocker two: no apply could ever download anything.** GitHub answers a release-asset download with **302** to a CDN. The JDK's `HttpClient` does not follow redirects unless you ask. The *check* worked fine, because the API answers `200` directly — so the download was the only broken half, and every apply died at `HTTP 302` before the checksum gate could even run:\n\n```\nHttpClient.newBuilder()\n    .connectTimeout(…)\n    .followRedirects(HttpClient.Redirect.NORMAL)   // the whole bug, in one line\n    .build()\n```\n\nThe regression test serves a 302 from a loopback `HttpServer` and asserts the body lands. It fails without the fix, which is the only reason I trust it.\n\nA third thing the rehearsal taught me, a design smell rather than a bug: `CORRAL_REPO` is resolved **per process**. The daemon runs the update *check*; the CLI runs the **apply**. Set the variable on the daemon only, and `corral update` cheerfully offers a release that `corral update --apply` then fails to fetch. Both processes need it, and the docs now say so.\n\nAnd a fourth, the nicest property of the whole design: an existing `0.0.0-dev` install updated itself to the rehearsal release, in a container, with a restart, and came back healthy. That is the thing I could not have claimed before I watched it happen.\n\nI did not write this alone, and I did not review it alone. The shape that worked:\n\nThat is the whole machine. The load-bearing part is the reviewer: a **different** agent on a **different** model from the one that wrote the code, because an agent reviewing its own work is a very confident way to be wrong.\n\nFifty-two third-party review passes. Some found real bugs (the encoding, the redirect, an inert preference). Most found small ones. A few found nothing, which is also information: if every pass finds something, the thing finding them is too clever; if none does, it is not looking.\n\nThe rules that kept it honest:\n\n`git log` proving nothing is the only way to prove nothing was lost.\n`v0.1.8` is public, checksum-verified, and installs from a single zip on Linux and Windows. macOS has no installer yet. The update path is no longer theoretical — it has applied a real release to a real install, including one that started as `0.0.0-dev`.\n\nThe gates are guardrails for cooperative agents, and I say so in the docs. Signing is still an open question: the published `.sha256` proves the download was intact, not that the publisher was genuine, and that is a decision I have not made yet.\n\n```\n# Linux or Windows (Git Bash). macOS has no installer yet.\ncurl -LO https://github.com/ciszkin/corral/releases/download/v0.1.8/corral-0.1.8.zip\ncurl -LO https://github.com/ciszkin/corral/releases/download/v0.1.8/corral-0.1.8.zip.sha256\nsha256sum -c corral-0.1.8.zip.sha256          # PowerShell: Get-FileHash\nunzip corral-0.1.8.zip -d corral-0.1.8 && cd corral-0.1.8\n./install.sh --ui\nexport PATH=\"$HOME/bin:$PATH\"                # the installer writes corral to ~/bin\n\ncorral doctor                                  # rules file, adb shim, emulators, daemon\ncorral devices                                 # what the pool looks like\ncorral lease --model Pixel -- ./gradlew installDebug\n```\n\nJDK 17. Kotlin on the JVM, Ktor CIO, SQLite, and a Compose Desktop console. Four modules, five suites: module tests, an end-to-end, a wrapper integration suite, a demo suite and a 505-check installer sandbox. Apache-2.0.\n\nInstall the agent skill in one command:\n\n```\nnpx skills add ciszkin/corral#main -s corral -a claude-code -y\n```\n\nIf you run more than one coding agent against the same device pool, that is the problem I solved. And if you find a claim in the README that the code does not back up, that is a bug report I will take seriously — I have been on the wrong side of that one.", "url": "https://wpnews.pro/news/three-ai-agents-one-android-phone-and-a-clock", "canonical_source": "https://dev.to/ciszkin/three-ai-agents-one-android-phone-and-a-clock-3ih8", "published_at": "2026-11-25 10:36:33+00:00", "updated_at": "2026-11-25 10:43:07.132447+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-tools"], "entities": ["Corral", "adb", "Claude", "Codex", "Gradle", "SQLite", "Vitali"], "also_reported_by": [], "takeaway": "Use expiring leases with heartbeat renewal rather than lock files so a crashed or token-limited agent cannot hold a shared singleton device forever, and resolve agent identity via CORRAL_OWNER, then /proc comm:pid:starttime, then $USER.", "recommendation": {"advice": "Replace lock files with heartbeat-renewed leases for shared resources, and give each agent a distinct identity via CORRAL_OWNER or /proc ancestry so ownership checks survive bash -c, make, and Gradle forks.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/three-ai-agents-one-android-phone-and-a-clock", "markdown": "https://wpnews.pro/news/three-ai-agents-one-android-phone-and-a-clock.md", "text": "https://wpnews.pro/news/three-ai-agents-one-android-phone-and-a-clock.txt", "jsonld": "https://wpnews.pro/news/three-ai-agents-one-android-phone-and-a-clock.jsonld"}}