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.
Originally published at https://hackernoon.com/three-ai-agents-one-android-phone-and-a-clock
Three 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.
The 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.
None 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.
This 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: a daemon, a CLI, a Gradle gate and a Compose Desktop console around one SQLite lease table, with v0.1.8 published.
The problem: a device with one current state
An 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.
What 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.
So 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".
The bet that shaped everything
The obvious fix is a lock file. It is also the wrong one, because a lock has no answer to the only question that matters:
The failure mode you must design for is not two agents at once. It is one agent, gone.
An 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.
So 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.
Two details made that work in practice:
-
The queue is by selector, not by name. Agents rarely care which device they get.
corral claim --model Pixel --os 14means "any that matches", and the FIFO is over waiters, not devices. - Waiting is capped. A queue wait clamps at 600 seconds. An agent that would wait 40 minutes is better off failing fast and telling its human, because an agent that waits silently looks identical to an agent that is working.
Everything else in the product is downstream of that one choice.
Every agent is the same user
Every 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.
The fix is an identity chain, resolved in this order:
-
CORRAL_OWNERif the harness sets it (agent tiers flow in this way); - the process ancestry — walk
/procforcomm:pid:starttimeof the first non-shell ancestor; -
user:$USERas the floor.
That 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.
Cooperation is not a security property
Here 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.
So the daemon installs gates in the places calls actually come from:
-
A PATH wrapper named
adb— a two-line shim that asks the daemon before exec'ing the real binary. -
An SDK shim at
platform-tools/adb, daemon-healed if something overwrites it, because plenty of tooling calls adb by absolute path. -
A Gradle
init.dgate, because the Android Gradle Plugin talks ddmlib over sockets and never executes theadbon your PATH at all.
That third one is the non-obvious layer, and it is the only one that can block an installDebug started from an IDE.
The 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.
None 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.
The installer could not recognise its own task
This 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?
Get 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.
Then a reviewer pointed the installer at an install root called Jürgen, on a stubbed Windows host.
A 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.
The real fix was to stop guessing and decode:
case "$bom" in
FF\ FE) iconv -f UTF-16LE -t UTF-8 … ;; # then drop the decoded BOM
FE\ FF) iconv -f UTF-16BE -t UTF-8 … ;;
EF\ BB\ BF) strip that leading BOM only ;;
*) take it as UTF-8 ;;
esac
Two things I had to accept:
-
Extraction runs under
LC_ALL=C, because the<Command>text is a path, and locale-dependent byte handling is how you lose aü. -
A task we cannot decode is not ours. On a host without
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 shipsiconv; a stripped-down MSYS2 that does not gets a refusal, not a wrong claim.
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.
My documentation was lying
Somewhere around the fortieth review I started auditing what the README claimed against what the code did. Twenty-two claims were false.
Not typos. Things like:
- "the tray icon parks the window on close" — except on GNOME and Wayland, where the code deliberately does not park, because the tray there is a fiction.
- "three enforcement layers" — true on POSIX, false on Windows.
- "an unknown version is omitted, never faked" — the console actually shows
v0.0.0-dev. - "
corral doctorreports the state of the gate" — it reports the rules file; it cannot see the Gradle init script at all.
The 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.
A setting that looked alive
The 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.
That 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.
The 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.
The release path had never run
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.
It 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.
So 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.
It found two release blockers in the first hour.
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:
line 14: VERSION: unbound variable
The very command the release notes tell an operator to run. It had never been run, so it had never failed.
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:
HttpClient.newBuilder()
.connectTimeout(…)
.followRedirects(HttpClient.Redirect.NORMAL) // the whole bug, in one line
.build()
The 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.
A 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.
And 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.
The loop that built it
I did not write this alone, and I did not review it alone. The shape that worked:
- One task per cycle, from a roadmap table with a status column I alone write.
- A separate agent implements, in its own checkout, and reports what it did.
- A different agent reviews the diff against the plan — and it is allowed to say no.
- A third agent verifies on a real Windows box for anything the Linux suite cannot see.
That 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.
Fifty-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.
The rules that kept it honest:
- Never merge with a red gate. A failing check is a fact, not an opinion.
- One retry, then park it. Two failures means the task is not ready to be a task.
-
Squash, and verify the content landed. After a squash the branch's commits are rewritten, so
git logproving nothing is the only way to prove nothing was lost. - Never delete work that has not landed. A dirty worktree is cheaper than a lost afternoon.
Where it actually stands
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.
The 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.
What I'd tell my past self
- Decide who owns identity before you write the first lease. Every later feature asks "is this yours?", and retrofitting identity is a rewrite.
- Put your gates where calls actually originate, not where your docs say they should.
- Treat docs as executable claims. Grep them in the suite, or they will rot into lies.
- A bounded lease beats a lock, every time, for anything that can die.
- Rehearse the boring path. The interesting code was reviewed 52 times; the boring path that had never run was broken in two places.
- Write the number you actually have. "Three layers" was a lie on Windows; "two on Windows" is less impressive and worth more.
Try it
# Linux or Windows (Git Bash). macOS has no installer yet.
curl -LO https://github.com/ciszkin/corral/releases/download/v0.1.8/corral-0.1.8.zip
curl -LO https://github.com/ciszkin/corral/releases/download/v0.1.8/corral-0.1.8.zip.sha256
sha256sum -c corral-0.1.8.zip.sha256 # PowerShell: Get-FileHash
unzip corral-0.1.8.zip -d corral-0.1.8 && cd corral-0.1.8
./install.sh --ui
export PATH="$HOME/bin:$PATH" # the installer writes corral to ~/bin
corral doctor # rules file, adb shim, emulators, daemon
corral devices # what the pool looks like
corral lease --model Pixel -- ./gradlew installDebug
JDK 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.
Install the agent skill in one command:
npx skills add ciszkin/corral#main -s corral -a claude-code -y
If 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.



Top comments (1)
The lease framing is the part I'd steal — a lock has no answer for 'one agent, gone,' and the 30-minute default with a heartbeat and a 10-second floor is exactly the right shape for agents that get killed by their harness. The queue-by-selector detail is smart too: agents rarely care which device they get, and capping the wait at 600 seconds so they fail fast instead of queuing for 40 minutes is a judgment call most people would get wrong. The Gradle init.d gate is the non-obvious layer for me — the Android Gradle Plugin talking ddmlib over sockets means a PATH shim alone would never catch an installDebug from the IDE. And auditing the README down to 22 false claims, including 'three enforcement layers' being false on Windows, is the kind of honesty that makes me trust the rest. One question: with the queue keyed by selector, what happens when an agent does need one specific device — say a Pixel 8 for a camera test — does the selector allow pinning a serial as a fallback, or would that break the FIFO fairness across waiters?