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 a SQLite lease table and an append-only audit log. The first tagged release was v0.1.0; the current one is linked below.
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 forever, because the clock releases it.
The TTL is the backstop, not the mechanism. A lease also carries the holder's pid, so when that process is gone the device is freed on the next sweep, not at the deadline. And because a killed CLI can leave a command still driving the phone, the lease carries the command's pids too: the device stays held while that command lives. SIGTERM/SIGINT/SIGHUP stop the command's tree before the lease goes back; SIGKILL cannot, so that case is bounded by the TTL rather than prevented — which is a sentence I would rather write than a guarantee I cannot keep.
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 "a Pixel on 14 or newer", 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.
ANDROID_SERIAL works if every caller cooperates, and nothing in an agent loop guarantees that: a harness spawns a shell, the shell spawns Gradle, Gradle spawns a worker, and the pin is one forgotten export away from being gone. Gradle Managed Devices and the cloud farms solve a different problem — sharding a test suite across devices — not arbitrating interactive sessions on the hardware already on your desk.
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 on macOS the wrapper delegates to corral owner, and on Windows the .bat twin delegates to corral gate; the JVM does the same walk in both cases. 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 bash shim that asks the daemon over HTTP before exec'ing the real binary. - An SDK shim at
platform-tools/adb, restored within a 10-second tick 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. So is a static adb build invoked by absolute path, a ddmlib client talking straight to the adb server on :5037, and scrcpy resolving its own adb.
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 (illustrative, not copy-paste):
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
0.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.
It keeps working, which is the part I did not expect. The review that shipped v0.1.4 found three more wrong claims and four imprecise ones — including corral devices described as printing a lease, when leases are in corral status.
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 was 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 a single unauthenticated GET to releases/latest, once a day, on by default, with no credentials; CORRAL_UPDATE_CHECK=off stops it without a restart. 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.
Then the first real update found three more. Closing the console window aborted the apply, because the download ran inside the console JVM and on GNOME/Wayland closing quits — so 0.1.2 made the apply a detached CLI process. The update row then sat stale while the daemon's first check was in flight. And updating to 0.1.2 briefly left two console windows open, because the old applier started a new console and never exited; 0.1.3 has the console replace itself, and only when the jar on disk really is the new version.
A rehearsal in a container found two blockers. One real user found three more. That ratio is the argument for rehearsing, and against believing a rehearsal.
The first five minutes on a clean machine
The next release is the one where I stopped testing my own machine. Three things broke for a stranger, and none of them were in the interesting code.
The installer delivered no agent skill. It copied skills/corral/SKILL.md only when ~/.agents/skills already existed — which it does on my machine, because I had been using it for months. On a clean host the directory was absent, so the installer skipped the copy while the README went on claiming the skill was installed. It now creates ~/.agents/skills/corral and links ~/.claude/skills/corral at it, because Claude Code reads the second path and not the first. One file, both layouts. On Windows it is a directory junction where MSYS cannot make a symlink, and never a copy — a copy goes stale.
opencode could not connect at all. It sends protocolVersion: 2025-11-25 in initialize and rejects a server that omits the field. The daemon omitted it. Bumping the MCP SDK was not enough: InitializeResult.protocolVersion has its own Kotlin default, and the daemon's codec runs with encodeDefaults off, so the field was dropped on the way out. A small converter registered ahead of the app's JSON converter is what actually fixed it. The bug was not in the protocol. It was in a serialization setting I had chosen for other reasons.
The README did not state its prerequisites. The first command a stranger ran failed, because nothing had told them they needed JDK 17 and an Android SDK with platform-tools/adb on PATH. The first screen now says both, and the deep material moved into a reference doc, which is a reference again rather than the front door.
And then the thing I should have built first: corral demo.
It spawns a second, isolated daemon whose device pool, screenshot bytes and emulator host are simulated inside the JVM. No phone, no adb, no Android SDK. Three fake devices — a Pixel 7, a Galaxy A54 over WiFi, and an emulator that takes six seconds to boot — with every human-readable name carrying (demo). It plays a thirty-second story: a grant, a refusal that names the holder and both forms that would have worked, a FIFO handoff, and an emulator that cannot be claimed until it finishes booting.

The isolation is three thin seams — DeviceSource, ScreenshotSource, EmulatorHost — each implemented by the existing class with an override and no body change, so the real daemon takes exactly the path it took before. The demo never executes adb, emulator, gradle or scrcpy, never reads or writes ~/.corral, installs no gate and no service unit, and cannot take a lease on a real device. While it runs, PUT /api/config refuses the path-bearing settings with a 400, so a demo cannot be walked into the real paths.
Then I installed the published zip on a clean host, which is a thing I had never done — I had only ever installed from a tree I had been working in for months. Eight findings.
The installer put the CLI in ~/bin and never put it on PATH or said to, so the first command was command not found. With a distro adb on PATH it wrote the skill, the console, the launcher and the icons, then failed at mv /usr/bin/adb and left no CLI and no daemon; there is now a preflight that refuses before the first write. The systemd unit pinned an absolute JDK path, so changing the SDKMAN default broke the service until a reinstall.
Two were worse than inconvenient. The MCP endpoint reported its version as 0.3.0 — hardcoded, while every other surface said 0.1.4. Fifty-two review passes had not caught a made-up number in the one field whose whole job is to be a number. And the first corral devices printed daemon unreachable ... (null), because the JDK raises a ConnectException with no message on a closed port and Kotlin interpolated it faithfully.
There was also a data-loss bug that every review had missed: with CORRAL_ADB pointing at a directory that already held a foreign adb.real, both the daemon and the installer silently destroyed that binary. Both now park it as adb.real.corral-backup before stashing, and uninstall keeps and names every stash.
The last one I keep thinking about: the guard that compares the POSIX install path byte-for-byte against the base commit — the check protecting every Linux user — could pass vacuously when a sed address contained a slash. Two empty logs compared equal. It was green because it was comparing nothing. There is a non-vacuity row now.
And then I published a release whose bundled README still pointed at the release before it, which is how I learned that a publish step needs the same gate as a merge.
The loop that built it
I did not write this alone, and I did not review it alone. What I kept was the roadmap: one task per cycle, and a status column that only I write. An agent can propose a task, implement it, and report it finished. It cannot mark it finished. Everything below is safe to run because of that one column.
The shape that worked:
- One task per cycle, pulled from that table.
- 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, and the load-bearing part is the reviewer: a different agent, on a different model from the one that wrote the code. An agent reviewing its own work is a very confident way to be wrong.

Fifty-two passes by the first release, and more since. Some found real bugs — the encoding, the redirect, an inert preference. Most found small ones. Some found nothing, which is also information: if every pass finds something, the thing finding them is too clever; if none ever 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, then verify the content landed. A squash rewrites the branch's commits, so
git logproves nothing — diffing the tree against the base 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 — Windows verified on one machine, not a matrix. macOS has no installer: the daemon and CLI are portable Java, packaged and verified nowhere. 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. And corral demo means you no longer need a phone to decide whether any of this is useful.
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 — then rehearse it on a machine that has never seen your project. The interesting code was reviewed 52 times; the boring path that had never run was broken in two places, and the first five minutes on a clean host were broken in eight more.
- Write the number you actually have. "Three layers" was a lie on Windows; "two on Windows" is less impressive and worth more.
Try it
You do not need a phone. Install, then run corral demo: it boots a simulated pool inside the JVM and plays the whole story — grant, refusal, queue handoff, an emulator that cannot be claimed until it boots — in about thirty seconds.
Before you run it: install.sh puts an adb wrapper on your PATH, shims the SDK's platform-tools/adb (keeping the original as adb.real), and drops a Gradle init.d gate. ./install.sh --uninstall removes only what it installed and names anything you edited. It refuses an adb that is not the SDK's — a distro /usr/bin/adb — before writing anything, and with no adb at all it installs with a warning and points you at the demo.
# Linux, or Windows via Git Bash. macOS has no installer yet. curl -fsSLO https://github.com/ciszkin/corral/releases/download/v0.1.8/corral-0.1.8.zip curl -fsSLO 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" # ~/bin must precede the SDK, or adb resolves ungated The installer appends that line to ~/.bashrc/~/.zshrc when either exists; a shell that is already open needs it once.
corral demo # simulated pool; prints its URL. Ctrl-C stops it and cleans up. # from another shell, against the demo daemon: CORRAL_URL=http://127.0.0.1:8799 corral devices corral-ui --url http://127.0.0.1:8799 # with real devices attached (JDK 17+, platform-tools/adb on PATH): corral doctor # daemon + pool, wedged emulators, adb shim, gate rules, update state corral devices # what the pool looks like corral status # who holds what corral lease --model Pixel -- ./gradlew installDebug The agent skill ships with the installer and is also available as npx skills add ciszkin/corral#main -s corral -a claude-code -y. The MCP endpoint is one command: claude mcp add --transport http corral http://127.0.0.1:8798/mcp.
JDK 17+ (console verified on 17/Linux, 25/Windows). Kotlin on the JVM, Ktor CIO, SQLite, and a Compose Desktop console. Four Gradle modules and five test suites — module tests, end-to-end, wrapper integration, an installer sandbox and a demo suite — green on Linux CI. Windows is one host, not a matrix, and its POSIX-only cases are a documented baseline rather than a pass. Apache-2.0.
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.

