mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[GH-ISSUE #362] [Design Proposal] Shared resource holds across the sandbox lifecycle #92
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#92
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?
Originally created by @guozy18 on GitHub (Oct 12, 2026).
Original GitHub issue: https://github.com/kvcache-ai/AgentENV/issues/362
Affected component
Orchestrator / sandbox lifecycle, snapshot and volume content protection
Problem statement
Parent: Database design proposal. This proposal builds on Data model and interfaces; reclamation is covered by Online GC and historical data control, and SQL version coexistence by Database upgrades and compatibility.
Recording layer UUIDs, predecessor links, and content heads in SQL is not enough to protect a running sandbox. Prepared entries, VMs, fork results, paused state, and background readers may continue using the same source. Deleting a public snapshot or changing a volume backing must not remove bytes that these consumers still need.
Usage protection must follow the existing resource ownership chain without adding database access to every creation, derivation, pause, or exit. Protecting only the top-level request would let cancellation, cache eviction, or parent VM exit end protection before the actual I/O finishes.
Use case
The primary workload is many sandboxes publishing their own independent snapshots and restoring them occasionally, with little reuse across sandboxes. A benchmark where every request hits one popular template cannot establish an acceptable database cost: publishing a new S and preparing it for the first time on a node still require database operations.
A snapshot may also serve multiple VMs, derived children, or a long-lived paused consumer. The design must cover both low-reuse working sets and concurrent use of the same S. Cache TTL must not impose a lifetime limit on active consumers.
Current behavior and workarounds
SnapshotManager loads a catalog record and resolves it into runnable input. The snapshot catalog and publication pipeline manage publication through the shared Repository; local resource ownership keeps runtime files and ongoing tasks alive. Snapshot and volume publication already share a layer-storage pipeline. A volume retains its business identity while its backing layer list can change, and a sandbox snapshot captures a fixed copy of its volume layer lists. Local snapshots retain files in their publishing process, and promotion publishes shared artifacts while preserving the snapshot identity.
Local file ownership and byte caches cannot, by themselves, tell the database that remote dependencies are still in use. SQL protection also cannot replace the actual lifecycle of local files, devices, or in-flight I/O.
Desired behavior
manifest_refbefore reading the manifest or consuming managed artifacts. Load the immutable description under that protection, outside the SQL transaction. Subsequent consumers retain fixed inputs rather than being switched to a later public description.Proposed approach
Use the shared content-retention contract from the data-model proposal: immutable descriptions referenced by
manifest_ref, retained chain heads, layers identified by the unified existing UUID with fixed predecessor links, and active usage responsibilities. Do not expand every published snapshot into a complete snapshot-to-layer mapping or introduce another layer UUID.For the snapshot protocol below, S is a public snapshot and H is one shared usage hold tied to S. A sandbox ID is distinct from S. Multiple local responsibilities can share one H; SQL does not record a row for every VM. The detailed S/H logging and recovery rules describe this snapshot protocol; sharing the retention mechanism with volumes does not require every hold to occupy one generic table.
A volume ID remains a mutable business identity. Acquiring a volume backing must fix the selected content and retain it for the consumer, rather than following subsequent changes to that volume's current backing. Exclusive and read-only reservations retain their existing mount and writer-admission roles; they do not, by themselves, replace content protection. The concrete relation between volume records, fixed content, and holds is defined with the data model; this issue does not require a new volume-version ID.
Operations before and after
“Cold snapshot preparation” means the node has no reusable input for that snapshot. It is distinct from starting a sandbox directly from an OCI image.
Volume backing handoff and background readers
Suppose V currently retains
[A, B], and consumer P has acquired that fixed backing. Publishing[A, C]first establishes retention for the new backing, then changes V's current content. P continues to retain[A, B]; B becomes reclaimable only after P and every other old-content responsibility end. This is a content handoff, not an instruction to allocate a new volume-version ID or to change the volume's reservation semantics.Likewise, a snapshot captured from V must establish its own heads while the source remains protected. Restoring that snapshot into a new volume performs the reverse handoff. Afterwards, removing the original snapshot or volume cannot invalidate the new owner's content.
Background tasks retain the exact files and source responsibilities they use until their actual I/O ends. This includes startup recording, upload, P2P publication and serving, and external server-side copy. A UUID advertisement or metadata entry is not evidence that the corresponding reads have ended. If P2P serves an independently owned local copy, its own file lease can carry that responsibility; do not retain an unrelated remote hold after it is no longer needed. Conversely, cancellation or request completion cannot release a source still being read.
Rust pseudocode: extend the existing lease
Compose the local artifact lease and necessary source holds in the runnable input:
Store H logs durably outside temporary artifacts, and scan
holds/<H>separately from paused records. Log phases advance monotonically throughacquiring -> held -> releasing. A failed or uncertain Sync is not made durable merely because a read sees the value. Keep paused holds outside the backend's opaque payload so a corrupt payload does not discard source responsibilities.Resolve an uncertain initial acquisition using the original S/H. Reconstruct an already-delivered hold through read-only inspect. One H can support multiple derived inputs; the current public manifest reference cannot replace all of their saved recovery configurations. Cross-process consumers must establish one long-lived release owner; a short-lived proxy cannot release delivered protection when it exits.
Minimum prepared-cache contract
Repeated hits refresh access time, so T is not a deadline for revoking access after Delete. An expired Ready entry cannot grant new acquisition merely because the database is unavailable: new acquisition follows the cold Pin result, including retirement and connection failures. Cache TTL is distinct from the admission floor in Historical data control; neither expires active H.
SQL boundaries on cold and warm paths
Cold preparation resolves identity and performs Pin before fetching the protected manifest. Publication commits a manifest reference, retained heads, and any new layer records for the completed result. Final return performs Release. Rebuilding a hold from persistent records uses read-only inspect. Valid warm acquisition, fork, same-process pause/resume, and ordinary exit perform local handoffs only; measure background Release separately.
For low-reuse workloads, measure actual cold-preparation rates, SQL per preparation/publication, hold lifetimes, and connection waits. The prepared cache reduces repeated acquisition; it cannot eliminate the facts that independently published snapshots must record, or replace layer GC and historical-row cleanup. Measure publication work against new layers and retained heads as well as total chain length; inherited prefixes must not be re-registered as complete mappings.
Acceptance criteria
Compatibility and operational impact
Preserve existing volume ownership and lifecycle. Publication and GC must account for snapshot rootfs, memory, attached drives, embedded volume snapshots, and independent volume backings, as well as all actual consumers. VM state, startup packs/manifests, and AENV-owned registry publications remain part of the retention inventory even though they are not layer-chain nodes.
Alternatives considered
Non-goals
Do not change VM, block-device, or external-image semantics. Do not introduce a new volume product model, volume-version ID, or Local/promotion API. Do not prescribe a generic hold table, repeat the schema, layer-GC protocol, or admission-floor algorithm here, or replace online protection with a maintenance pause.
Contribution
I can provide more design details
Pre-submission checklist