Skip to content

refactor(host,sandboxes): share guest client and primitives in host-core, use parking_lot, tighten VZ Sendable - #1855

Merged
nikhilunni merged 6 commits into
mainfrom
audit/p2-host-sandbox-reliability
Dec 2, 2026
Merged

nikhilunni merged 6 commits into
mainfrom
audit/p2-host-sandbox-reliability

Conversation

@nikhilunni

@nikhilunni nikhilunni commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Deduplicates guest-agent wire client and OS primitives across sandbox backends, and hardens host-agent/VZ reliability:

  • Shared guest client & primitives in engram-host-core: Extracts the duplicated engram-agentd wire client (guest_client.rs), ENGRAM_AGENTD_PORT, pidfd.rs, epoch_stream.rs, and POST_COPY_SEALED_FILE out of engram-sandbox-firecracker and engram-sandbox-vz into engram-host-core, removing engram-host-agent's direct imports of Firecracker internals.
  • Eliminate mutex poison panics: Switches std::sync::Mutex in engram-host-agent/src/blk_source.rs and capture_job.rs to parking_lot::Mutex (and fixes a capture-job task-handle race).
  • Tighter VZ Sendable<T> soundness: Removes unconstrained Deref in engram-sandbox-vz and gates access behind explicit queue-bound accessors (queue_bound.rs).
  • Typed session states: Replaces raw session-state string literals in engram-upgrade-drain with canonical SessionState.

Behavior notes

  • Capture-job race: start previously reserved the slot with a placeholder task, dropped the lock, spawned the real task, and then wrote its handle into whatever entry held the job id. A concurrent start for a newer epoch in that window aborted only the placeholder, and the older attempt's handle then overwrote the newer entry, so the older capture kept running. start now spawns and inserts under one lock; Tokio never polls a spawned task inline, and the task cannot touch the registry until the lock drops.
  • parking_lot: no caller recovered from poisoning (every site called .unwrap()). The guarded state is either one map or queue operation, or the ublk prefetch window, whose entries always map a chunk to that chunk's own bytes. A panic mid-section cannot make a later reader serve wrong data. With std poisoning, one panic made every later heartbeat or ublk read panic too.
  • VZ: the guest-listener delegate now duplicates the connection fd on the VM queue inside the callback, instead of sending the retained connection to a Tokio thread and reading fileDescriptor there. VZ exec errors from the probe, send, and cancel steps are now Unavailable (as on Firecracker) instead of Vm.
  • Upgrade drain: state names come from SessionState::as_str, so the mapping is byte-identical to the previous literals.

Validation

  • cargo fmt --all --check; cargo clippy --all-targets -D warnings for host-core, host-agent, sandbox-firecracker, sandbox-vz, upgrade-drain, dst-cosim, rootfs-materializer on macOS.
  • Linux cross-clippy (--target aarch64-unknown-linux-musl, -D warnings) for host-core, host-agent, sandbox-firecracker, upgrade-drain, dst-cosim. This found the missing HashMap import that failed every Linux lane.
  • cargo nextest run on the six crates above (macOS): 653 passed.
  • just vz-e2e (live VZ VMs): 11 passed.

🤖 Generated with Claude Code

nikhilunni and others added 6 commits December 1, 2026 16:38
The shared guest client move dropped the module-level HashMap import.
The only remaining non-test user is the cfg(target_os = "linux")
pss_samples field, so macOS clippy did not see the error and every
Linux lane failed to compile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lock special case

- vm.rs no longer re-exports Sendable; vsock_bridge imports it from
  queue_bound, its owner. The agentd port import moves into the import
  block, so the vsock port doc comment attaches to its constant again.
- agentd_request sends every request through guest_client::request.
  The StepClock arm rebuilt the same frame through step_guest_clock.
- The Sync SAFETY text states that Clone only retains, and the socket
  device lookup states why its wrapper is sound.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…trings

Resolve the coordinator's state name to a SessionState once, then match
on variants. The names come from SessionState::as_str, so the mapping is
unchanged: active evicts, parked resumes, pending/created/evacuating/
evicting wait, unreachable is reported, and other states are ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t-core

Also restore the pidfd module's statement of the two kernel properties
callers rely on: identity survives pid reuse, and the fd is readable at
process exit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sorting the list conflicts with a parallel change that adds a dependency
in the same block. The order has no effect on the build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nikhilunni
nikhilunni marked this pull request as ready for review December 2, 2026 21:54
@nikhilunni
nikhilunni merged commit ee3ba1e into main Dec 2, 2026
53 of 55 checks passed
@nikhilunni
nikhilunni deleted the audit/p2-host-sandbox-reliability branch December 2, 2026 21:54
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