mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[PR #108] [MERGED] Fix sandbox lifecycle bugs and improve network policy handling #183
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#183
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/108
Author: @LSX-s-Software
Created: 8/3/2026
Status: ✅ Merged
Merged: 8/3/2026
Merged by: @LSX-s-Software
Base:
main← Head:fix/sandbox-lifecycle📝 Commits (4)
e025555fix(sandbox): slot resource leak caused by a failure to set egress policy6fee769fix(orchestrator): handle artifact root allocation error4a2589efix(orchestrator): make network policy and custom extension param updates cancellation-safea28c065feat(network): make egress policy update atomic📊 Changes
7 files changed (+295 additions, -32 deletions)
View changed files
➕
src/image/cache/mock.rs(+54 -0)📝
src/image/cache/mod.rs(+4 -0)📝
src/orchestrator/service.rs(+66 -13)📝
src/orchestrator/tests.rs(+108 -2)📝
src/sandbox/firecracker/sandbox.rs(+5 -2)📝
src/sandbox/network/iptables_util.rs(+0 -7)📝
src/sandbox/network/policy.rs(+58 -8)📄 Description
What
Fixes three sandbox lifecycle bugs (network-slot leak on egress-policy failure, unhandled artifact-root allocation error during pause, and cancellation-unsafe network/custom-extension updates) and makes egress policy replacement atomic via a single
iptables-restoretransaction.Why
Several lifecycle paths left the sandbox in an inconsistent state on failure or cancellation:
set_egress_policycall dropped the network slot before it was attached toself.network_slot, leaking the underlying network resources.allocate_artifact_rootfailure during pause occurred after the handle/route were already detached, with no rollback of image refs or sandbox state.replace_sandbox_network_policyandpatch_sandbox_custom_extension_paramswere not wrapped in the cancellation-safe execution path used by other lifecycle operations (create/fork/delete/pause/resume/snapshot), so a client disconnecting mid-request could leave the update half-applied.USER_EGRESS_CHAINand installed new rules as two separateiptables-restoreinvocations, leaving a brief window with inconsistent (or no) egress rules.Related issue
Closes #42
Closes #99
Scope and non-goals
Included: sandbox network-slot leak fix, pause artifact-root allocation error handling, cancellation-safety for network policy/custom extension param updates, atomic egress policy replacement.
Excluded: no serialization for concurrent network policy/custom extension param updates.
Design and behavior changes
FirecrackerSandbox:network_slotis now assigned toself.network_slotbeforeset_egress_policyis invoked, so a failed call still leaves the slot reachable by the normal cleanup path instead of being dropped in place.OrchestratorService::pause_sandbox_inner:allocate_artifact_rootis now called before detaching the sandbox handle/route (while it does not mutate the backend). On allocation failure, image refs forRuntimeImageOwner::PausedSandboxare released and the state machine is rolled back fromPausingtoRunning.run_lifecycle_operationrenamed torun_cancellation_safe;replace_sandbox_network_policyandpatch_sandbox_custom_extension_paramsare now split into public wrapper +_innerimplementation and routed throughrun_cancellation_safe, so a caller cancelling the request no longer aborts the update mid-flight — the background task still runs to completion.build_user_egress_commandsnow takes areplace: boolflag; when replacing, aFlushChaincommand is prepended to the same command batch sent toapply_iptables_commands, so flush + rule installation happen as a single atomiciptables-restoretransaction. The standaloneflush_table_chainhelper was removed as it's no longer needed.Compatibility and operations
Validation
make fmtmake clippymake test-unitmake -C services test(required whenservices/changes)maketargetCommands and results:
Skipped checks and reasons:
services/unchanged, somake -C services testskipped.Risks and reviewer notes
Checklist
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.