5 Commits
Author SHA1 Message Date
w3cjandClaude Opus 5.5 e4b44b5994 fix(lima): limactl shell never starts a stopped VM past devvm's checks
In a terminal, limactl shell of a stopped VM asks whether to start it, yes by default (Lima 2.3.0, reproduced under a pty), and that start is Lima's own: no proxy or sandbox-exec profile (no QEMU wrapper on Linux), no pins, and no folderChanged, so the project folder's mount, by path on Linux's 9p, follows a link put at the path or makes a folder that's gone again. devvm opens a shell (Shell) and runs an agent's login (Exec) on the terminal after bringUp, so a guest that powered itself off between the two got that question. This is the start path the self-check's restart was suspected of: that restart goes through startOnce, but limactl shell didn't.

The limactl builder, which every limactl command of devvm's goes through, now gives limactl shell --start=false, which Lima has had since 2.0.0-rc.0 (devvm's oldest is 2.2): a stopped VM's shell or command fails at once ("instance is stopped"), without asking, and devvm's next launch starts it with every check. devvm limactl, which passes its arguments on as given, is unchanged.

TestShellNeverStarts checks Exec's, Shell's and the builder's limactl shell, and fails without the change; the lima package's and the CLI scripts' expected limactl shell calls name the flag, their negative patterns too, so none turns vacuous. Docs: How it works' Lima page's A stopped VM's shell; the changelog's Security hardening gets the line, its summary widened to cover both of its lines, and the release page its section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 07:43:53 -07:00
w3cjandClaude Opus 5.5 6fd1d846d6 fix(lima): cache a Linux VM's project folder with 9p's none
Linux's 9p client loses data with Lima's default cache=mmap for a
writable share: a stat() during an extending write() takes the host's
stale size and writeback drops the data, so files reach the host empty
or cut to 4096 bytes even after fsync (Claude Code's Edit sets it off);
and on devvm's Ubuntu 26.04 guest kernel, a lock after a write makes the
next read return zeros, which breaks SQLite in any journal mode and
Gradle's daemon. macOS's vz VMs use virtiofs and aren't affected.

- New VMs on a Linux host record cache mode none in a new mount section
  of vm.json, and their project folder is made and started with it, as
  is the folder devvm clone off mounts. VMs whose state has no mode
  (0.1.0's, and every VM made before this) keep Lima's mmap untouched,
  with no limactl edit, and each launch warns (mount_cache_unchosen)
  until devvm mount-cache none.
- devvm mount-cache [none], with --json: none is the only mode devvm
  sets, so any other value is a usage error (mount_cache_invalid); a
  stopped VM gets it in its next start's one edit, a running one after
  the restart devvm offers. macOS refuses (backend_lacks), and so does a
  Linux VM whose folder isn't a 9p mount (mount_cache_no_choice). No -g
  or config.toml key: every new VM gets none.
- The start that changes the mode mounts the folder again in the guest,
  as cloud-init rewrites fstab only after systemd has mounted it, through
  the logged runner with a minute's limit (output pipes closed a second
  after), then checks it with mountpoint and findmnt, reading 4 KiB at
  most and only the last line: a folder left unmounted stops the VM and
  fails the start before its shell (mount_cache_unmounted), and so does a
  check that gets no answer (mount_cache_unchecked); one still mounted
  with the old mode is warned of (mount_cache_remount_failed), any mode
  but none or mmap named unknown. An interrupt meanwhile, on any tier,
  leaves a cleanup that stops the VM, the one stop then. A launch into a
  running VM asks the guest, in words, whether its folder is a mount
  point, and refuses one that isn't (project_unmounted) or whose check
  fails or gives no answer (project_unchecked). A stored mmap, from a
  build before none alone, reads as none chosen, and devvm clone off
  records none for its new mount; any other mode is refused naming
  vm.json.
- backend: FeatureMountCache (native on Linux, none on macOS, built on
  project-mount), Want.ProjectCache, Instance.ProjectCache, CacheModes.
- lima: mount rewrites keep only the sshfs and 9p settings devvm knows
  where they differ from Lima's defaults, and drop the rest for Lima to
  fill in, so lima.yaml never freezes a default; same() compares the
  cache where devvm sets one. Build VMs' writable output folders (tools,
  --from) get none.
- tools: an EROFS tool image that ends before its superblock does, or is
  shorter than its superblock says, as a build under mmap could leave
  one, counts as not built, so the next build makes it again; a build's
  short output is refused. The fakes' tool images are a page
  (backendtest.ToolImage).
- The limactl stub lists QEMU's vmType, fills in 9p cache defaults on
  Linux, and answers the remount's check.
- Docs: backends/lima (the project folder's cache, when it changes,
  programs that map files for writing, SQLite), using/limits,
  using/clone, commands, internals/lima, internals/backends, the design
  note (both mmap bugs, why none alone, the remount, tool images, the
  e2e findings), the CLI reference and the cli skill.
- Tests: TestProjectCache, TestMountRoundTrip,
  TestStartSetsProjectCacheOnce (the remount's outcomes), TestCutShort,
  TestBuiltCutShort, TestGuestMountOptions, TestFilledMounts,
  TestUpCacheMode, TestWarnMountCache, TestCacheAtNextStart,
  TestSwitchCache, TestSetMountCache, TestCheckStateCache, the
  mount_cache CLI test, clone_switch and the 0.1.0 fixture on Linux, and
  e2e's projectMountCache (findmnt, a stat-while-write loop, SQLite's
  journals, a shared writable mmap refused, the opt-in switch of an
  unchosen VM, what mmap does reported, macOS unchanged).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-09 07:17:12 -07:00
w3cjandClaude Opus 5.5 ceda0bf925 feat(cli): --network TIER, devvm network TIER and the tier question
The command line names the four network tiers. --network TIER (open,
internet, allowlist or none) chooses a new VM's tier, checked before
anything runs (arg_not_choice). devvm network open|internet|allowlist|none
gives the folder's VM a tier through Net.SetTier, and devvm network -g
takes the tiers and ask. config.toml's and settings.json's network is ask
or a tier (settings.NetworkChoices, checked against netpolicy.TierNames
by a test, since settings can't import netpolicy).

The question on creation is Proxy.Choose(vm): net_about says what each
tier reaches, net_ask asks for one (Answer, AnsweredBy("--network")),
Enter or a refusal gives allowlist, and an answer that isn't a tier is
warned of (net_tier_unknown) and asked again. devvm setup's picker
offers ask and the four tiers (network_default_open, _internet,
_allowlist, _none). On an existing VM, --network is ignored with the
devvm network TIER command that changes it.

devvm network --json: policy is the tier or unenforced, and each policy
file whose denies alone apply (internet and none) has denies_only: true,
as the text output's "(denies only)", so a script can tell a file's
denies from all of its rules without knowing the tier rules.

Messages reworded: net_tier_backend (--network open), net_open_policy
(devvm network allowlist), net_about, net_ask, network_default*,
net_default_failed, network_failed, setting_already's and
widen_parent_vm*'s descriptions. safety/network's "Choosing a tier"
replaces its on/off section; docs, the cli skill, testscripts and e2e
use the new forms, and e2e's internet and none checks go through devvm
network.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 15:54:43 -07:00
w3cjandClaude Opus 5.5 0b82dc189f feat(vm): a moved folder's Claude Code history follows it
A folder move records the path the agents' state is under in the VM's
state (the moved section, set in recordMove under the VM's lock: the
first move's old path, kept through more moves, cleared by a move back).
The VM's next setup gets a moved file with both paths and their Claude
Code slugs (claudeMoved, claudeSlug), and guest/claude.sh's
claude_project_moved renames ~/.claude/projects/<old slug> to the new
one, or merges into it without replacing anything, and moves
~/.claude.json's projects entry (claude_json_project_move, kept on its
own for reuse). Once the setup succeeds, followed clears the section.

The slug is Claude Code's own rule (2.1.318's sanitizePath): every
UTF-16 unit but an ASCII letter or digit a dash; over 200, cut and
ended with "-" and abs(h*31+u, int32) in base 36.

Tests: TestClaudeSlug, TestClaudeMoved, TestClaudeProjectMoved,
TestMovedTo, TestFollowed, TestMoveHere's record and its clearing,
move.txtar, e2e project's moved checks. Docs: commands.md's moved
folder (Claude Code, Codex, opencode), internals overview.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 12:39:55 -07:00
w3cjandClaude Opus 5.5 e9ca7a4859 feat(vm): a moved or renamed project folder keeps its VM
A VM's files and machine are keyed by its name's hash, which stays; what
moves is the state's dir. The finder finds a folder's VM by the state
that records its path (finder.state: the path's hash first, then every
state, recorded), so a VM moved there is found from the new path alone,
and links by path (project.ForDir) match the recorded dir.

When the folder has no VM, the finder looks through the states for one
made for this folder at another path (moveHere, move.go; the match is
here.movedFrom): the same folder identity (device, inode, birth time),
the folder this user's, its identity unique (platform.UniqueFolderID:
an ID with a birth time, and on macOS APFS or HFS+), another recorded
path that's gone on the folder's device or only a symlink to here, its
creation finished, not a --clone VM. One match is offered: in a terminal
move_vm, [y/N]; without one vm_moved_here, naming devvm adopt; devvm
adopt --force moves it without asking. Several matches warn
(vms_moved_here) and move none. Never automatic.

The move (finder.move) refuses a folder no new VM may have
(checkUnsafe), holds the creation locks of the VM and of the folder's
would-be new VM, checks again that no state records the folder and
that the folder is still the one asked about (move_folder_changed),
stops a running VM as devvm stop does, then records the path and
identity under the VM's lock, refusing a state that changed meanwhile
(create_running); vm_adopted says so. .git protection's record is kept:
.git, its identity and its uchg locks move with the folder.

The project folder's mount is now part of backend.Want (Want.Project,
Instance.Project, Apply), so the next start mounts the folder where it
is: Lima's wantEdits rebuilds .mounts in its one edit when the project
mount or the agent folders differ (mount.project). A VM running with
another path asks to restart (Y/n) and otherwise warns
(next_start_folder, folder_next_start).

A new VM at the old path can't use the moved VM's folder, so newName
takes the first of the path's names whose VM folder holds no state
(project.Nth: the hash of the path, then of the path and n).

devvm adopt [VM]: with VM (by name or alias, as devvm rm VM), moves a
VM whose folder is gone or not connected to this folder, for a copy on
another disk (a new inode, never matched on its own): adopt_move_vm
[y/N], --force, adopt_move_refused without either; refuses a --clone VM
(adopt_clone), a lost machine (rm_vm_lost), an unfinished VM, a folder
still there (adopt_folder_there) and a folder with a VM of its own
(adopt_has_vm). It clears .git protection's record, as the copy's .git
is another.

rm_vm_state_mismatch is gone, as a dir needn't hash to the name any
more: devvm rm VM acts as devvm rm only on the folder's own VM
(finder.folderVM), and a VM whose state names a folder with another VM
of its own is refused as one whose folder is there.

macOS's FolderID has the folder's birth time too, as Linux's has.

Security review (security-audit skill, focused, with an independent
read): inode reuse needs a unique identity (birth time; APFS/HFS+ on
macOS), the same device (in the ID) and the old folder gone; another
user's folder never matches (its owner checked); a copy has a new inode
and never matches; links and groups go by name and stay, and links by
path take the recorded dir, a move refused when another VM records it;
a symlinked cwd is resolved first, and a symlink at the old path counts
only when it resolves here; .git protection's record stays for a move
and is cleared for a copy; agents' mounts are unchanged (only the
project mount changes); a VM can rename only folders inside its own
mount, which it already writes. Fixed from the review: a folder swapped
at the path while devvm asked was moved to (now move_folder_changed);
macOS device:inode could collide with a later volume given the same
device number (birth time added); a running VM kept the old path's
share, which a new folder made there would reach (the move stops it
first); a move to the home folder or into devvm's own folders (now
checkUnsafe). FolderID's format change makes VMs and .git records made
before it look like other folders (adopt them, or make them again).

Tests: TestMovedFrom (table: gone/present, same/different device and
inode, a non-unique ID, another user's, a clone, unfinished),
TestMovedAway (gone, a folder, symlinks here/elsewhere/dangling),
TestMoveHere (refused, no, yes, found by its dir, stopped, the new
mount at start, a restart for a running old mount, a new VM at the old
path by its next name), TestMoveFolderChanged, TestAdoptMoved,
TestMoveHereSeveral, TestAdoptVM, TestUniqueFolderID, ForDir and Nth in
project, wantEdits' moved project, the conformance start's moved
project; move.txtar (refused, no, yes, found, Lima's mounts edit, a new
VM at the old path, adopt VM of a copy); rm_vm.txtar's hand-edited
dir; e2e project: mv, refused, a yes in a terminal (script), the home
file kept, the new path mounted alone, moved back with adopt --force.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 09:30:05 -07:00