Files
w3cjandClaude Opus 5.5 de502f7840 fix(vm): rm's read of a --clone VM's clone gives up past 8 MiB or 2 minutes
readClone stopped keeping the VM's answer past cloneStateMax (8 MiB), but took the rest and waited for the command to end, with no time limit, so a VM that wrote without end, or never answered, kept devvm rm and devvm clone off waiting until Ctrl+C. The read of the agents' worktrees already had the bounds; workCheck.answer is now the one read for both, taken from agentTrees: at most cloneStateMax bytes, past which the bounded writer cancels the command, within answerWait (2 minutes, treesWait before), an interrupt returned as ctx's error. A failed, over-long or late answer is the check's failure, clone_check_failed or trees_check_failed, which keeps the VM and names the flag that skips the check, and a hostile one is parseCloneState's, as before. readClone fails before parsing on a bad answer, so its result is never a nil list (the nilaway baseline loses that line) and gosec sees its loop bounded by both lists.

On Lima the time limit didn't hold for either read: a cancelled limactl shell leaves its ssh child holding the command's output pipes, so os/exec's Wait waited for the VM's command to end. Exec now goes through the lima package's bounded (WaitDelay, a second), as the remount's commands do, so it ends a second after its context does; output a child held past limactl's own success is exec.ErrWaitDelay, an error, so an answer cut short is never taken as a whole one. That bounds every Exec, devvm paste's time limit and the history export included.

treeGlobs returns a list that's never nil: nilaway took its nil for one parseAgentTrees slices into, a false positive (agentTrees returns before it without patterns, and parseAgentTrees indexes pats only below nextRecord's len(pats)), which the CI job reported on main.

Tests that fail without the fix: TestWorkCheckBounded (TestAgentTreesBounded, now a table over both reads: an endless answer cancelled, a silent VM given up on after 2 minutes in a synctest bubble, an interrupt kept as the interrupt), whose clone case isn't cancelled and then deadlocks its bubble; TestExecHeldOutput, a real limactl stand-in that leaves a child holding its output, killed and after a success, which waits 30 s each, the success read as one, without bounded. TestParseAgentTrees checks treeGlobs with no patterns.

Docs: clone's --no-clone-check names a VM that doesn't answer within 2 minutes, How it works' deleting a VM gives the clone read's bounds, the Lima page's A command's output, the clone design note's cost and threat drop the wait that's gone, and internal/vm's map names answer. The changelog gets an If you use --clone block with the line, the release page its section under Fixes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 07:45:33 -07:00

71 lines
4.3 KiB
Go

// Package vm runs project VMs: what each of devvm's commands does to a
// folder's VM, below the command line.
//
// Env (env.go) is what they run with, the shared dependencies, and its
// parts, each made once by wire, which the commands reach without ever
// converting one type to another. The rest, by concern:
//
// - The start: start.go's starter.bringUp is every path's one start,
// with its requirements, confinementFor and hostChecks.
// - The finder: finder.go's target finds the VM a command acts on, as
// its need says; target.go is that VM, read once, and what a command
// does with it; move.go is a VM whose folder moved, devvm adopt VM.
// - The inventory: inventory.go reads every VM's state, backend and
// list in one place, with one failure policy.
// - Launch opens a shell in a folder's VM: a new one (up.go; parts.go,
// its toolchains, agents and layers, the picker, and setup's agents
// and layers; detect.go, what the folder's files call for), an
// existing one (existing.go), and ssh.go.
// - The agents: their mounts from devvm's agent store (agents.go's
// agentStore, the one reader of Dirs.AgentSettings, while
// secrets.LoginFile reads the logins); AgentImport (agentimport.go,
// devvm agent import, the one reader of the home's agent files);
// AgentLogin (agentlogin.go, devvm agent login: the agent's login in
// the VM, its forward, API keys); AgentSave (agentsave.go, devvm agent
// save: a VM's settings into the store after a diff, linediff.go, and
// a yes; agentsave_read.go, its fixed list and the checks on the VM's
// stream).
// - Lifecycle (lifecycle.go) stops, adopts, deletes and exports a VM;
// remake.go is the one remake, a VM made again from another image, for
// devvm layer add, devvm layer rm, devvm update and devvm clone, and
// home.go its home folder's copy.
// - Housekeeping (housekeep.go): images, shared tools, exports and
// leftovers, for devvm images, gc, space and retention; Exports
// (exports.go): the exports of agents' history, their .folder files,
// Newest.
// - Tools (tools.go): a VM's shared tools; Settings (settings.go,
// size.go, ports.go, sshagent.go, transparent.go, mountcache.go): its
// size, ports, SSH agent forwarding, .git protection, transparent mode
// and its project folder's cache mode; Net
// (network.go, secret.go): its network tier, network log, allowlist
// and secrets.
// - Links (links.go): links between VMs and published ports; Groups
// (groups.go): the links a group makes.
// - --clone (clone.go): the clone, its seed (cloneseed.go's seeder: the
// repos made in one command, then each repo's refs and pack sent
// through the backend's Exec, never git push; its uncommitted changes
// are cloneworktree.go's seedTree: the index normalised, each working
// copy read through a safefile root, folder by folder, never through a
// link, and the record of what went; its operation in progress and
// stash are clonestate.go's seedState, its settings and hooks
// cloneconfig.go's seedConfig, a partial clone's pack and warnings
// clonepartial.go's, each initialised submodule's own clone, recorded
// before its copy, clonesub.go's, Git LFS objects both ways, each
// checked against its oid, clonelfs.go's, saving a VM's stash entry
// clonesave.go's), rm's and a remake's check of the work lost with
// the VM's disk (clonecheck.go's workCheck: every repo read in one
// command, the seed's record read back, the VM's own stash entries
// fetched by commit; agenttrees.go: the agents' worktrees, which an
// export leaves out, read in one command, one question for both; each
// read bounded in size and time by answer) and
// devvm clone's switch; a workspace
// clone of a folder of repos (workspace.go: finding and choosing
// them, their seeds, devvm clone fetch and devvm clone add;
// workspacefiles.go: the folder's own files, copied once).
// - devcontainer.go: a devcontainer.json's mapping and commands; sync.go:
// the setup devvm sends to a VM.
// - Paste (paste.go): devvm paste, an image, a PDF or a copied file from this
// machine's clipboard into the VM's paste folder, devvm paste rm, and
// the launch's offer to delete what's left there.
package vm