Skip to content

Linux VM: detached output, kept session logs, git in the guest, bundled Firecracker - #80

Merged
samifouad merged 5 commits into
mainfrom
claude/linux-vm-fixes
Oct 15, 2026
Merged

samifouad merged 5 commits into
mainfrom
claude/linux-vm-fixes

Conversation

@samifouad

@samifouad samifouad commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Fixes the Linux/Firecracker --vm problems found when testing on the ThinkPad (Arch, kernel 7.2.5, Firecracker v1.17.0), and ships Firecracker with the Linux x64 package.

What changed

  1. Detached --vm output was dropped. guestPty kept only one onData listener. The worker registers two (the output log, then the quiet detector), so the second replaced the first, and output.log and gild attach stayed empty. It now keeps a list of listeners. Output that arrives before the first listener is held for it, and an exit that comes before onExit is replayed. VmChild.onExit delegates to it, so a fast exit can't leave the session hanging. (src/isolation/session.ts, src/spawn-vm.ts)
  2. Output vanished when a detached session ended. DetachedHost.cleanup() deleted sessions/<id>/output.log. The log is now kept as ~/.gild/sessions/<id>.output.log:
    • It stays 0600 and is at most 8 MiB; the .1 rotation is dropped.
    • Only the newest 10 ended logs are kept, and a session that printed nothing (a failed start) leaves no log.
    • gild attach --watch <id> prints the kept log once the session has ended.
    • The worker now unlinks the socket and removes the session directory before announcing the exit, so a gild stop caller never sees them still there. This used to be a race; it showed up as a flake in the detach harness.
  3. Git in the guest refused /workspace ("detected dubious ownership"): mke2fs -d keeps the host uid while the agent runs as root. The guest env now carries GIT_CONFIG_COUNT/KEY_0/VALUE_0 = safe.directory=/workspace (guestGitEnvironment). Doing it in the env needs no image rebuild and covers vz too.
  4. Firecracker is bundled for Linux x64.
    • scripts/vendor-firecracker.mjs, run from bun run pack (so the release publish job runs it), downloads v1.17.0 x86_64. It requires the tarball to match both the pin in scripts/firecracker.json and Firecracker's published .sha256.txt, and checks each extracted file's hash.
    • The binary ships as bin/firecracker in @gildforge/cli-linux-x64, with LICENSE, NOTICE and THIRD-PARTY in vendor/firecracker/.
    • packed-packages.mjs checks the packed hashes and the exec bit, and refuses bin/firecracker in any other package.
    • Resolution order: vm.firecracker in isolation.json, then the binary next to the gild executable (defaultFirecracker), then PATH.
  5. Docs.
    • docs/VM.md: a table of which VM --vm uses (Multipass on macOS and Windows by default, vz only with a vm block in isolation.json), the bundling, and the design. Firecracker guests have no network by default, so the agent edits in the VM and the host commits and pushes; .git never syncs back; Multipass differs because it pushes from inside.
    • README, the spawn --vm help, and CHANGELOG under 0.6.14. package.json is not bumped.

Caching (AGENTS.md 7c): no server-rendered work here.

Evidence

Local gates, run on macOS from .github/workflows:

  • bun test --timeout 30000: 308 pass, 18 skip, 0 fail
  • bun run format:check: ok
  • npx tsc --noEmit: ok
  • bun run pack: verified firecracker 1.17.0: linux-x64
  • bun run test:install: verified npm pack: @gildforge/cli-linux-x64@0.6.13 (14 files), ok
  • bun run test:installed-pty: 105 pass
  • bun run test:install:revert: ok

Clippy: not applicable (no Rust changed).

Revert proofs:

  • session.ts reverted: the two new guestPty tests fail (Expected "EARLY Linux (none) 5.10", Received ""; exit not replayed).
  • Kept-log change reverted: detached session: stop fails with AssertionError: output not kept, and the prune test fails.
  • guestGitEnvironment dropped from guestEnvironment: the guest env test fails.
  • The real-git test reproduces the refusal with GIT_TEST_ASSUME_DIFFERENT_OWNER=1 and passes with the env.

Live on omarchy (x86_64, Firecracker via KVM). This branch's packages/cli-linux-x64 was copied over (bin/gild + bin/firecracker). ~/.local/bin/firecracker was moved aside, and nothing was on PATH (which: no firecracker):

  • The bundled binary ran: /home/sami/Projects/vmtest/pkg/bin/firecracker --api-sock …, and serial.log shows Running Firecracker v1.17.0.
  • Boot: microVM ready in 216–246 ms (image 19–29 ms), ~0.5 s for a whole true session. spawn --detach returns in 434 ms.
  • During the session, output.log and attach --watch both showed EARLY and Linux (none) 5.10.245+ … x86_64.
  • After it ended, lv1.output.log (0600) was kept, and gild attach --watch lv1 printed EARLY … LATE plus [lv1 has ended; its output is kept in …].
  • A guest script with no workaround printed STATUS_OK, Switched to a new branch 'guest/test', COMMIT_OK, and git log showed the guest commit. firecracker.txt synced to the host, and the guest .git was retained for recovery, as designed.

Notes

  • v0.6.13 has no VM image: https://releases.gild.gg/cli/v0.6.13/vm/manifest.json returns HTTP 404, so gild spawn --vm on Linux 0.6.13 fails with "no image was published for this version". The live test used isolation.json pointing at the 0.6.11 image (same guest protocol).
  • Server bugs (duplicate open PRs for one head; a bare 500 seen once) are filed as PR create: duplicate open PRs for the same head are accepted; a bare 500 seen once kit#4.

-claude

@samifouad
samifouad merged commit 89b5f11 into main Oct 15, 2026
4 checks passed
@samifouad
samifouad deleted the claude/linux-vm-fixes branch October 15, 2026 15:41

This branch was successfully deployed

1 active deployment
public-ci — 1eb27439 Deployed Oct 14, 2026 by samifouad via vz-helper #233
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.

1 participant