mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[PR #380] [MERGED] refactor(sandbox): give Firecracker sandbox resources a single owner and split start paths #390
Labels
No labels
bug
documentation
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/AgentENV#390
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/AgentENV/pull/380
Author: @yingdi-shan
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/16/2026
Merged by: @yingdi-shan
Base:
main← Head:refactor/firecracker-sandbox-resources📝 Commits (4)
89a10f4refactor(sandbox): own Firecracker host resources in SandboxResources0004991refactor(sandbox): share Firecracker rootfs attach and boot-arg append3f616abrefactor(sandbox): split Firecracker start_resume into stagescc945b5refactor(sandbox): move guest volume helpers out of FirecrackerSandbox📊 Changes
5 files changed (+784 additions, -697 deletions)
View changed files
📝
src/sandbox/firecracker/mod.rs(+1 -0)➕
src/sandbox/firecracker/resources.rs(+159 -0)📝
src/sandbox/firecracker/sandbox.rs(+434 -697)➕
src/sandbox/guest_volumes.rs(+189 -0)📝
src/sandbox/mod.rs(+1 -0)📄 Description
What
Restructure
src/sandbox/firecracker/sandbox.rs, which has had the most churn and the most bug fixes in the repository, in four commits that each keep behavior the same:SandboxResources(resources.rs): the ~10 acquired host resources (network slot, ublk devices, prefetch task, extension hook guard, …) move out ofFirecrackerSandbox's separateOptionfields into one owner. It has a single orderedrelease()used bystop()and aDropfor abnormal drops.attach_user_rootfs()replaces the two copies of the rootfs overlaybd device setup instart_fresh/start_resume, including the release-on-symlink-failure path.append_boot_arg()replaces four copies of the boot-arg appendmatch.start_resumebecomes a sequence of named stages (adopt_warm_firecracker,prepare_resume_drives,create_pack_recording_mem_device/acquire_shared_mem_device,attach_new_volume_drives).allocate_network_slot,spawn_firecrackerandinit_envd_instanceare shared withstart_fresh.src/sandbox/guest_volumes.rs: the envd-driven guest mount, sync and fsfreeze helpers move out of the Firecracker sandbox impl, unchanged, into a module that doesn't depend on any backend.Why
The release order and the "store the handle before the next
?" rule were enforced only by comments and by keeping two hand-written teardown paths in sync.ff822fe(#42), a network slot leaked when setting the egress policy failed, is an example of what that structure allows. With one owner, a handle stored inSandboxResourcesis always released, and the release order lives in one place.Related issue
None. This came out of a code-quality review of the highest-churn files.
Scope and non-goals
src/sandbox/firecracker/changes, plus the newsrc/sandbox/guest_volumes.rsand itsmodline. No public types are touched.orchestrator/service.rs, which can come in a follow-up.Design and behavior changes
The goal is no behavior change. Small, intentional differences:
start_resumetracing span still identifies the path.start_freshapplies the egress policy right after allocating the slot, before it reads the slot's boot arg and netns path (both are plain getters).The
stop()release order (rootfs → tools → dedicated mem → extra drives → stop hook → network → prefetch → shared mem) and theDropbehavior are unchanged.FirecrackerSandbox::dropreleases resources explicitly before the work dir and Firecracker process fields drop, as it did before.Compatibility and operations
Validation
make fmtmake clippymake test-unit(the agentenv parts were run; see below)make -C services test(required whenservices/changes)maketargetCommands and results:
The firecracker unit tests (
cargo test -p agentenv --lib firecracker::, 99 tests) andcargo clippy -p agentenv --lib --tests -D warningspassed after each commit.Skipped checks and reasons:
snapshot_oss_e2e_testneeds an object-storage service, and the change does not touch repository or publication code.make test-unitoutside agentenv (envd, linux-cap, aenv, ublk crates, install scripts) were not run; this PR does not touch them.services/is unchanged, so its tests were not run.Risks and reviewer notes
SandboxResources::release()with the oldstop()body. Commit 1 is easiest to review on its own.prepare_resume_drivesnow returns the(slot, drive)pairs for launch-time volumes that must be bound after snapshot load. That replaces thehas_new_volume_attachmentsflag that was checked in two places.Checklist
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.