Skip to content

install-phone: a second install with the same work directory stops, instead of replacing the first one's images - #798

Merged
derekross merged 1 commit into
derekross:mainfrom
only21mil:build/install-phone-one-writer-2-r
Nov 15, 2026
Merged

derekross merged 1 commit into
derekross:mainfrom
only21mil:build/install-phone-one-writer-2-r

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

What and why

An AI agent found this reading the code. An install stages the image copy and the owner's files under fixed names in --work (root.simg, firstboot.conf, ...), one default directory for every run. With two installs waiting at "Type the phone's codename", the second replaces the first's files: confirming the first flashes the second owner's firstboot.conf while saying it set up the first owner.

Following #682's lock, an install or dry run holds an exclusive flock from before it reads the ramdisk or writes in the work directory until it exits. A second one with the same work directory stops there, before the phone, and says to let the first finish or give it its own --work DIR. --verify-only takes no part, so #682's sweep is unchanged. The lock file is .NAME.install.lock in the resolved work directory's parent (as make-bundle's since #664), so --work still ends empty. Its parent must be writable; a lock that can't be taken (a file system without flock) also stops the install. The kernel drops the lock, so an install killed outright keeps none out.

An AI agent made both runs (details block). Before, on main 12258d9, before the fix was written: alice's run says it set up alice; its image holds USERNAME=bob. After, on 84791fc: bob's run is refused; alice's image holds alice.

Regression test in tests/install-phone (a stand-in, not the reproduction): a second install, also through a symlink, is refused before it writes in --work, reads the ramdisk or asks anything, and sends the phone nothing; --verify-only passes beside it; a SIGKILLed install keeps none out. On main's tool it fails at "a second install with the same --work is refused". Details cover tests/install-phone-initramfs.

Device and build

  • Phone: none: the laptop-side installer only
  • Kernel release (uname -r): not applicable
  • Packages changed, with versions: none

Checks (no phone needed)

An AI agent ran these on 84791fc, on an x86_64 desktop running Ubuntu 26.04.

  • tools/pr-check origin/main passes
  • tests/all passes
  • tests/packages passes (or the packages I touched: ...): not run, no package changed
  • Each changed package has its version bumped, and the new version is in the commit subject: no package changed
  • Commits have area prefixes and bodies that say why; any AI help is a Co-Authored-By: or Assisted-by: trailer, never a Signed-off-by:

On the phone

  • I ran this on my own phone, booted into this build: no, the change is in the laptop-side installer
  • Runbook steps passed (plan, step, result): none, no plan step
  • What I did not test: no one, agent or person, tested what Not shown lists (details block)
  • Nothing in this change writes outside slot B and userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)
tools/phone-smoke report

Not applicable: a laptop-side installer change; nothing on the phone changes.

tests/install-phone-initramfs: the killed run of #682's case is now a --verify-only held in its lz4 by a stand-in and killed with SIGKILL; every other step and assertion is as it was, and #699's quiet job handling stays. On 84791fc the agent checked that the suite still fails without the exclusive check, with the shared lock let go after marking, without the mark check (also with the run's own directory spared), without the mark, and with a blocking exclusive lock.

84791fc is based on main 1a28cf3. The same steps give bob on main 6649b76 and alice on local merge d6e0910a; that merge is clean.

Setup: an x86_64 desktop running Ubuntu 26.04. An AI agent ran the real tools/install-phone in tests/install-phone's fixture, only fastboot faked, in bwrap with the checkout at /mnt, on a fixture built fresh for each commit. The agent's script prints only the ==> Preparing, ==> Done, ==> The files, user: and error: lines, without colour codes, and only the USERNAME line of the image fastboot got for userdata.

Steps: alice's and bob's installs on one --work → a --verify-only beside them → confirm alice's → read USERNAME → SIGKILL dave's at the codename → erin's install → read USERNAME

Before, 12258d91 (main, before the fix was written):

$ git rev-parse --short origin/main   # repo/tools/install-phone is this revision's
12258d91

## 1. two installs with the same --work; a --verify-only beside them; the first confirmed
(terminal 1) $ repo/tools/install-phone --device testdev --images images --work work   # alice's answers
==> Preparing a local copy of the root image in work
    user:      alice (pin), host alice-phone, time zone UTC
(waiting at "Type the phone's codename")
(terminal 2) $ repo/tools/install-phone --device testdev --images images --work work   # bob's answers
==> Preparing a local copy of the root image in work
    user:      bob (pin), host bob-phone, time zone UTC
(waiting at "Type the phone's codename")
(terminal 3) $ repo/tools/install-phone --verify-only --device testdev --images images --work work
==> The files check out (the phone was not contacted)
exit=0
(terminal 1: testdev typed)
==> Done. The phone boots slot B; the first boot sets up alice (a few minutes).
exit=0
$ debugfs -R 'cat /etc/omamobile/firstboot.conf' <the userdata image fastboot got> | grep USERNAME
USERNAME=bob
(terminal 2: stopped with SIGTERM)

## 2. an install killed with SIGKILL at the codename, then the next one
(terminal 1) $ repo/tools/install-phone --device testdev --images images --work work   # dave's answers
==> Preparing a local copy of the root image in work
    user:      dave (pin), host dave-phone, time zone UTC
(waiting at "Type the phone's codename")
(terminal 1: the installer and its 1 child process(es) killed with SIGKILL)
$ ls -A work
authorized_keys
boot-update.conf
firstboot.conf
ramdisk
root.simg
verify.8Kw9uk
(terminal 2) $ repo/tools/install-phone --device testdev --images images --work work   # erin's answers
==> Preparing a local copy of the root image in work
    user:      erin (pin), host erin-phone, time zone UTC
(waiting at "Type the phone's codename")
(terminal 2: testdev typed)
==> Done. The phone boots slot B; the first boot sets up erin (a few minutes).
exit=0
$ debugfs -R 'cat /etc/omamobile/firstboot.conf' <the userdata image fastboot got> | grep USERNAME
USERNAME=erin

After, 84791fc7:

$ git rev-parse --short 84791fc7c6bccb05e2bf28711f53d792760124b1   # repo/tools/install-phone is this revision's
84791fc7

## 1. two installs with the same --work; a --verify-only beside them; the first confirmed
(terminal 1) $ repo/tools/install-phone --device testdev --images images --work work   # alice's answers
==> Preparing a local copy of the root image in work
    user:      alice (pin), host alice-phone, time zone UTC
(waiting at "Type the phone's codename")
(terminal 2) $ repo/tools/install-phone --device testdev --images images --work work   # bob's answers
error: another install is using the work directory work: let it finish, or give this one its own with --work DIR
exit=1
(terminal 3) $ repo/tools/install-phone --verify-only --device testdev --images images --work work
==> The files check out (the phone was not contacted)
exit=0
(terminal 1: testdev typed)
==> Done. The phone boots slot B; the first boot sets up alice (a few minutes).
exit=0
$ debugfs -R 'cat /etc/omamobile/firstboot.conf' <the userdata image fastboot got> | grep USERNAME
USERNAME=alice

## 2. an install killed with SIGKILL at the codename, then the next one
(terminal 1) $ repo/tools/install-phone --device testdev --images images --work work   # dave's answers
==> Preparing a local copy of the root image in work
    user:      dave (pin), host dave-phone, time zone UTC
(waiting at "Type the phone's codename")
(terminal 1: the installer and its 1 child process(es) killed with SIGKILL)
$ ls -A work
authorized_keys
boot-update.conf
firstboot.conf
ramdisk
root.simg
verify.uBybcx
(terminal 2) $ repo/tools/install-phone --device testdev --images images --work work   # erin's answers
==> Preparing a local copy of the root image in work
    user:      erin (pin), host erin-phone, time zone UTC
(waiting at "Type the phone's codename")
(terminal 2: testdev typed)
==> Done. The phone boots slot B; the first boot sets up erin (a few minutes).
exit=0
$ debugfs -R 'cat /etc/omamobile/firstboot.conf' <the userdata image fastboot got> | grep USERNAME
USERNAME=erin

Links: the regression test, tests/install-phone at 84791fc; #682, whose lock this follows.

Not shown (no one, agent or person, tested these):

  • a phone
  • a network-mounted home
  • a real file system that rejects flock (the failure is simulated in the offline test)
  • a killed install whose child lives on (it holds the lock until it ends)

Generated with Claude Opus 5.5 in T3 Code Nightly

The image copy and the other staged files have fixed names in --work
(root.img, root.simg, firstboot.conf, authorized_keys, boot-update.conf,
ramdisk/), and every install uses the same default work directory. With
two installs waiting at "Type the phone's codename", the second had
replaced the first one's files, so confirming the first flashed the
second owner's firstboot.conf while it said it set up the first owner;
and either one's exit removed the other's files.

An install or a dry run now holds an exclusive flock until it exits,
taken before it reads the ramdisk or writes in the work directory, and a
second one with the same work directory stops there, before the phone:
"another install is using the work directory DIR: let it finish, or give
this one its own with --work DIR". The lock file is beside the resolved
work directory, .NAME.install.lock in its parent (as make-bundle's lock
is beside the bundles), so two spellings of one directory lock one file
and the directory still ends empty. It is kept after the run, since
unlinking it could let two runs lock different inodes. The work
directory's parent must be writable: if the lock file can't be created
there, the install stops with a message naming it. A lock that can't be
taken for any other reason (a file system without flock) stops the
install too, with "can't lock the work directory DIR", rather than going
ahead unlocked. The kernel drops the lock with the run's last process,
so an install killed outright keeps none out. The lock is python3's
fcntl, as derekross#682's is: the bundle ships the installer alone. --verify-only
takes no part and still runs beside an install, so derekross#682's sweep is
unchanged.

tests/install-phone: a second install with the same --work, and one
through a symlink to it, is refused within a time bound, before it
writes in --work or reads the ramdisk (a mktemp and an lz4 that note
their calls are never run) and before any question, and sends the phone
nothing; the waiting install's staged files are unchanged and it flashes
its own owner; --verify-only passes beside it; after a SIGKILL of a
waiting install (and its child) the next one installs; the work
directory ends empty with the lock beside it; an unwritable parent is
refused; and a python3 stand-in whose flock on the lock fails refuses
the install before any question, staging write or fastboot call. It
fails on main's tool at "a second install with the same --work is
refused".

tests/install-phone-initramfs: derekross#682's case ran two full installs in one
--work, which this forbids. Its killed run is now a --verify-only held
in its lz4 by a stand-in and killed with SIGKILL; every assertion keeps
its meaning, and the suite still fails without the exclusive check,
with the shared lock let go after marking, without the mark check (also
with the run's own directory spared), without the mark, and with a
blocking exclusive lock.

Tested: tools/pr-check, tests/install-phone,
tests/install-phone-initramfs, tests/install-guided, tests/all. Not
tested: a phone; a network-mounted home; a real file system that
rejects flock (the failure is simulated in the test).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derekross

Copy link
Copy Markdown
Owner

Thank you, @only21mil. The scenario in your description is a nasty one (the first owner's install flashing the second owner's answers while telling the first it set them up), and the fix is the right size. I checked the order: the lock is the first thing that writes in --work, so a second run stops before any question and before fastboot devices, and nothing about which partitions are written, the codename or the dry run changes. Because bash holds the descriptor, the lock lasts until the installer and its short-lived children end, and install-phone starts nothing that outlives it.

I also checked it against the guided installer's new keep-awake hold (#814), which landed after you branched. That hold starts after install-phone has finished and runs from the guided installer itself, so the two don't meet, and tests/install-guided passes on your branch merged with today's main, as do tests/install-phone and its new cases. With the lock block taken out, your test fails where you said it would.

One behaviour change I want to note, not change: a --work whose parent directory isn't writable (a USB stick's mount point, say) now stops with your "can't create the lock file" message, where it used to work. The message says what to do, so I'm happy with it. I'll merge this as it is.

@derekross
derekross merged commit fb29444 into derekross:main Nov 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants