cd /news/ai-agents/three-ai-agents-one-android-phone-an… · home › topics › ai-agents › article
[ARTICLE · art-176011] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Three AI Agents, One Android Phone, and a Clock

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.

recommendation

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.

more in playbook: Designing agent systems
by read11 min views2 publishedNov 25, 2026

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.

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 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:

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.

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_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. 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.

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:

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 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.

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:

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.

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:

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. 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.

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.

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.

I did not write this alone, and I did not review it alone. The shape that worked:

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:

git log proving nothing is the only way to prove nothing was lost. 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.

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.

── more in #ai-agents 4 stories · sorted by recency
── more on @corral 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/three-ai-agents-one-…] indexed:0 read:11min 2026-11-25 · —