Skip to content

feat(fire_vmm): let exec wait for a booting VM's agent - #200

Open
markovejnovic wants to merge 1 commit into
mainfrom
feat/exec-wait-for-agent
Open

markovejnovic wants to merge 1 commit into
mainfrom
feat/exec-wait-for-agent

Conversation

@markovejnovic

Copy link
Copy Markdown
Contributor

Why: an exec on a VM whose guest agent isn't listening yet answers :agent_unavailable at once, so a caller that boots a VM and runs something in it has to poll. usher (hypervm.sh) polls every 250 ms. With #199's spans, a production login reads:

Step Duration
create_vm 50 ms
two refused execs 0.3 and 0.7 ms
two sleeps between them 500 ms
the real exec 94 ms

The agent came up somewhere between 300 and 550 ms into boot, but the poll quantised it to 250 ms steps.

What: exec takes :wait_for_agent (ms). With it, an exec on a VM still booting probes the VM's vsock every 2 ms until the agent answers or the wait runs out, then runs as before. :timeout starts once the agent answers, so the command keeps its own deadline. Without the option exec is unchanged.

The probe is Relay.agent_listening?/2: the relay's own RelayDialer handshake, closed once firecracker answers OK. While nothing in the guest listens on 1024, firecracker refuses the CONNECT at once, so a probe costs a Unix-socket connect and one line. The 2 ms interval bounds what the wait adds after the agent comes up.

The wait gets its own span, Hyper.Node.FireVMM.Agent.wait_for_agent (vm_id, wait_ms), so a trace shows how long each VM took to bring its agent up.

Why poll and not a push from the guest: the guest agent is baked into each image when it's loaded (OciLoader), so a guest-initiated "I'm up" over vsock would only reach images loaded after it ships. It would also need a host listener on every VM (today the guest-services one, on port 1100, runs only for VMs that have services), plus a fallback for old agents. Probing works for every existing image and lands within 2 ms of the agent coming up.

Tests: agent_wait_test.exs runs a real Relay against a fake firecracker that refuses every CONNECT until the guest "boots":

  • an exec that waits answers once the agent comes up, within 100 ms of it and not when the wait runs out;
  • an exec that doesn't wait is refused at once, as before;
  • a wait that runs out first is :agent_unavailable after about that long, not a hang.

Each test fails when the code is broken: dropping the wait fails the first and third tests, and a 250 ms probe interval fails the first one's bound.

Checked locally:

  • Done: format, compile --warnings-as-errors in dev and test, credo --strict, and the agent, relay and Hyper suites (59 tests and properties).
  • Not run: dialyzer and the full mix check, which can't run on a Mac (the suidhelper stamp compiler). CI is the gate for those.

An exec on a VM whose guest agent is not listening yet answers
:agent_unavailable at once, so a caller that boots a VM and runs
something in it has to poll. usher polls every 250 ms, and in
production that poll is most of a login: the agent comes up a few
hundred milliseconds into boot, each refused exec costs under a
millisecond, and the sleeps between them cost up to 250 ms.

Nothing tells the host when the agent starts listening, but firecracker
refuses a CONNECT to a guest port nothing listens on at once, so
probing is cheap: a Unix-socket connect and one line. exec takes
:wait_for_agent (ms), and probes the VM's vsock every 2 ms until the
agent answers or the wait runs out, then runs as before, with :timeout
starting once the agent answers. Without the option exec is unchanged.

The wait is its own span, Hyper.Node.FireVMM.Agent.wait_for_agent, so
a trace shows how long each VM took to bring its agent up.
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown

Test Results

    4 files  ±0    366 suites  +2   5m 56s ⏱️ +13s
1 739 tests +3  1 739 ✅ +3    0 💤 ±0  0 ❌ ±0 
2 421 runs  +6  1 739 ✅ +3  682 💤 +3  0 ❌ ±0 

Results for commit 6627be1. ± Comparison against base commit d1840b0.

This branch has not been deployed

No deployments
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