Map: core / engine protocol
core/src/protocol.rs is the frame algebra and its two transports;
core/src/engine.rs is the --engine child that answers one of them;
core/src/wire.rs is the duplex byte channel both ride; core/src/hatch.rs
is a wire-seat child’s spawn machinery. The why is
engine-protocol; this page only points at symbols.
core/src/protocol.rs
PROTOCOL_VERSION(currently 7) — checked atAttach; a mismatch refuses.HATCH_ACK— the guest’s one-byte readiness signal, written fromhatch.rs; lives here for platform neutrality, not because it is ever aFrame.Frame— the whole wire enum:Attach,Detach,Dispatch,Probe,Event,Session,Control,Answer,Ping,Pong.Run/Program— one dispatch’s payload: the policy fields plusProgram::Source/Program::Hook.Event— engine→front-end, inside a dispatch’s window:Surface,Enquiry,Report.SessionEvent— engine→front-end with no dispatch to ride:Attached/Refused(String)(the attach verdict) andDeferredSurface(Vec<FOValue>)(a detached worker’s batch).EnquiryError— message plus status, the wire shape of a refused enquiry;no_desk()is the fixed wording for a host with nothing to answer.Control/Winsize/TerminalEndpoint— the out-of-band control frame and the attach-time terminal conveyance (TerminalEndpoint.leaseis#[serde(skip)]).Report/Diagnostics/Ending— the terminal frame:Static { diagnostics }orRan { ending, captured, trail };Ending::Stoppedcarries no platformcfg— the wire type is data, identical everywhere, only its producer (render_ending) is Unix.render_ending/RunReport::into_report— project the engine’s ownrun::Ending/RunReportonto these wire shapes, rendering a caught error to a string against theSourceDb.Severed— why no further frame will cross:Refused/Closed/Silent/Faulted,Displayed as the sentence a front-end shows; the privatesever()is first-cause-wins, andWireTransport::severlets a front-end declare aFaultedpeer dead itself.ProbeError—Rejected(a program error: an unknown class, a probe mid-run) orSevered.Hosttrait — one run’s whole host-facing surface:surface,enquire,fork;impl Host for ()is the mute host every callerless dispatch installs.Transporttrait —dispatch,probe,control,events,severed,attach,detach,answer,set_deferred_sink;IdentityTransportandWireTransportare its two instances.dispatch_to_report— mint aDispatchId, calltransport.dispatch, drainevents()to that dispatch’s ownReport, forwardingSurface/Enquirytohost;Result<Report, Severed>.answer_probe— the one probe-reading decoder both transports share (worker-count,binding-count,leased-binding-count,env-var,cwd,grant-depth,largest-binding-bytes,workers).ControlSender— out-of-bandCancel/Suspend/Resume/Resize;newtrips the identity transport’s own foreground scope,new_wirewrites aControlframe through the severance cell.EventReceiver— the front-end’s single-drainer event queue; itsstashhands back an event a probe’s or a desk’s pre-drain read past, in arrival order, rather than dropping it.IdentityTransport/EngineInner/SessionLock— the in-process transport: one poison-recovering mutex around theShell, and adispatch_threadstampcheck_not_reentrantasserts against before every session-lock door (shell_mut,with_shell,dispatch,probe,attach,detach,set_deferred_sink).IdentityDesk— the identity binding’sEnquiryDesk: drains queuedSurfaceevents before callinghost.enquire, so a handler can never outrun its own run’s earlier output.WireTransport— the out-of-process transport.newis Unix-only: spawns a same-host--enginechild on a socketpair, no heartbeat (a same-host death is a kernel-guaranteed EOF).adoptdrives an existing stream — the guest-VM path — under aLivenessticker.severed()reads the cause;await_attached()blocks on the reader’sAttached/Refusedverdict or its ownpatiencedeadline.spawn_wire_reader/spawn_heartbeat— the reader severs before droppingevent_tx, on every exit path; the heartbeat pings onLiveness::interval, seversSilentpastLiveness::deadline, and never takes the write lock on that path.write_through— the one write doorWireTransport::writeandControlSender’s wire arm both share: on error, severs and shuts the channel down before the lock releases.
core/src/engine.rs
EngineInstaller— one compiled-in boot recipe (tag,boot: fn() -> Shell,narrow: GrantNarrower); onlytagcrossesAttach, never the function.run_engine— adopts fd 3 as the wire channel and callsengine_session.engine_session— the engine’s whole protocol life: readAttach,resolve_installer, boot, apply a hatch seed if any, writeAttached/Refused, then the reader loop; returns the process exit code.resolve_installer— the version check plus the installer-table lookup, aResultso the refusal path is testable without exiting.WireDesk— the wire engine’sEnquiryDesk: writesEvent::Enquiry, parks aslotsmap keyed byEnquiryIduntilFrame::Answerfills it or the run’s own cancel scope fires.Dispatch— the engine’s one-run-or-probe rendezvous; claiming it is the only way to mint one, so “engine busy” (written back to a second dispatch) can never be raised without a run genuinely in flight; itsDroplowers the busy flag on every exit, unwind included.Patience/HOST_SILENCE_DEADLINE— the engine’s own read-silence and write-stall deadlines, armed once the firstPingarrives; production always runsPatience::default, a test gets a brisker one.- The teardown settle — on any loop exit: cancel the in-flight run and the
durable root,
hatch::teardown_hatched(), then pollbusyunderSETTLE_TIMEOUT/SETTLE_POLLbefore exiting, so no run is abandoned mid-report.
core/src/wire.rs
WireStream—UnixStreamon Unix,TcpStreamon Windows: std’s owner of a connected stream socket, never a statement about address family (vm-managerhands backAF_VSOCK/AF_HYPERVsockets through the same type).WireChannel— length-prefixed JSON framing (subprocess_codec) over oneWireStream;pair()(a socketpair on Unix, a loopback accept on Windows),from_stream,try_clone.poll_readable— wait for a frame or a timeout without blocking insideread_frame; howengine_sessionnotices a silent front-end with no dedicated thread.set_write_deadline— bounds everywrite_frameon every clone of the channel (SO_SNDTIMEOlives on the shared file description), turning a stalled write into the same fatal error a severed pipe already gives.
core/src/hatch.rs
A wire-seat spawn is one exchange: the guest binds an ephemeral port for one spawn and the host dials in — see engine-protocol’s hatch section for the why.
listen_for_hatch— waits on a caller-bound listening descriptor for the one dial that hatches a child; checks the dialler’s eight token bytes, and packs the parent’s scrubbedShellinto anEngineSeedon the caller’s own thread.hatch_over— re-execs this binary (--enginein production) with the dialled connection on fd 3 and a seed socketpair named byRAL_ENGINE_SEED_FD; writes the framed seed while the child drains it, and answersHATCH_ACKonly oncespawn()has returned and the seed has crossed.HATCH_ACK(defined inprotocol.rs, written from here) — the byte that says the child exists and already holds its whole seed; neither it nor the token is aFrame, so a hatch never touchesPROTOCOL_VERSION.seed_from_env— the child’s own take: readsRAL_ENGINE_SEED_FD, striking the var as it takes the fd, before the engine waits forAttach.apply_seed— hydrates the taken seed’s scope and context into the booted shell, then narrows its capabilities through the installer’sGrantNarrower.GrantNarrower—fn(&Capabilities, &str, &str) -> Result<Capabilities, String>, a field ofEngineInstallerrather than a registered hook: core has no base-tag lexicon of its own, so a seeded child’s ceiling is always stated by the host that boots the engine.HATCHED/teardown_hatched/sweep_hatched— the process-global table of spawned-but-unreaped hatch children, swept bywaitpidat the next hatch and again at engine teardown (a hatched child closes its seed channel on hydration, not on death, so onlywaitpidtells running from gone).
The seed a hatch carries is EngineSeed — transport’s
core/src/child_eval.rs section.
See also
engine-protocol (the why — the channel table, the
laws of an enquiry, the two bindings, liveness and severance),
transport (subprocess_codec’s framing, EngineSeed,
and the pipeline-helper IPC this protocol shares its codec with),
agent (RunHost, the wire-seat spawn that dials
a hatch), synod (WireTransport::adopt over a guest VM’s
virtual socket).