Files
devvm/testdata/script/move.txtar
T
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

85 lines
2.9 KiB
Plaintext

# A moved or renamed project folder keeps its VM, only after a yes in a
# terminal or devvm adopt --force: without either every command on the
# folder's VM refuses, naming devvm adopt. Once moved, the VM is found by
# the folder its state records, from the new path alone, and its next
# start mounts the folder there. devvm adopt VM moves a VM whose folder
# is gone to a copy of it, which is never offered on its own.
project web
exec devvm --network open
vm_name WEB web
exec devvm stop
cd $WORK
mv web site
cd site
# Without a terminal: refused, nothing changed.
stub_reset
! exec devvm
stderr '^devvm: vm_moved_here vm=devvm-web-[0-9a-f]{14} was=/\S*/web$'
! exec devvm stop
stderr '^devvm: vm_moved_here vm=devvm-web-[0-9a-f]{14} was=/\S*/web$'
stub_calls
! stdout 'limactl (start|stop|edit|clone|delete)'
vm_state $WEB_dir/vm.json
stdout '^dir=/\S*/web$'
# A no in a terminal: the folder has no VM.
ttyin -stdin $WORK/no.txt
! exec devvm stop
stderr '^move_vm vm=devvm-web-[0-9a-f]{14} was=/\S*/web \[y/N\] devvm: no_vm dir=/\S*/site$'
vm_state $WEB_dir/vm.json
stdout '^dir=/\S*/web$'
# A yes: the VM's state records this folder.
ttyin -stdin $WORK/yes.txt
exec devvm stop
stdout '==> vm_adopted dir=/\S*/site vm=devvm-web-[0-9a-f]{14}$'
stdout '==> already_stopped vm=devvm-web-[0-9a-f]{14}$'
vm_state $WEB_dir/vm.json
stdout '^dir=/\S*/site$'
grep '"moved": \{\s*"from": "/\S*/web"\s*\}' $WEB_dir/vm.json
# Found by that folder from then on, asking nothing; its start mounts the
# folder where it is now, in the one edit, and its setup moves the agents'
# state from the old path, clearing the record.
stub_reset
exec devvm
! stderr 'vm_moved_here|move_vm'
stub_calls
[darwin] stdout '^limactl edit --tty=false devvm-web-[0-9a-f]{14} --set \.mounts = \[\{"location":"/\S*/site","writable":true\}'
[linux] stdout '^limactl edit --tty=false devvm-web-[0-9a-f]{14} --set \.mounts = \[\{"location":"/\S*/site","writable":true,"9p":\{"cache":"none"\}\}'
stdout '^limactl shell --workdir /\S*/site devvm-web-[0-9a-f]{14}\n\z'
exec tar -xOf $STUB_DIR/sync.tar moved
stdout '^moved_from=''/\S*/web''\nmoved_to=''/\S*/site''\nclaude_from=''-\S*-web''\nclaude_to=''-\S*-site''\n\z'
! grep '"moved"' $WEB_dir/vm.json
exec devvm ls --json
stdout '"folder": "/\S*/site",'
# A new folder at the old path gets a VM of its own, by another name.
cd $WORK
mkdir web
cd web
exec devvm --network open
exec devvm ls
stdout -count=2 '^devvm-web-[0-9a-f]{14} '
# devvm adopt VM: a copy of the folder, as on another disk, is another
# folder, never offered; adopt moves the VM there once its folder is gone.
cd $WORK
exec cp -R site copy
cd copy
! exec devvm stop
stderr '^devvm: no_vm dir=/\S*/copy$'
! exec devvm adopt $WEB --force
stderr '^devvm: adopt_folder_there dir=/\S*/site vm=devvm-web-[0-9a-f]{14}$'
rm $WORK/site
exec devvm adopt $WEB --force
stdout '==> vm_adopted dir=/\S*/copy vm=devvm-web-[0-9a-f]{14}$'
vm_state $WEB_dir/vm.json
stdout '^dir=/\S*/copy$'
-- yes.txt --
y
-- no.txt --
n