qm icon indicating copy to clipboard operation
qm copied to clipboard

AWS MicroVM: exec hangs 4–9 min then 502 when the VM is paused but reports RUNNING

Open songofroland opened this issue 3 days ago • 1 comments

We run QM 0.1.20 on AWS with Lambda MicroVM sandboxes. In us-west-2, execute (and skill file syncs) keeps hanging for 4–9 minutes and then fails with microVM exec failed (502). The VM reports RUNNING the whole time.

What we see

  • On Dec 2 at 11:31:36 UTC, a subagent ran a trivial curl against the agent API. It hung for 271 s. Core logged three 502s at 11:36:04: orchestrator: provision, eager provision and list skills to prune, all from execRaw (aws-microvm-api.ts:361).
  • In the guest, dmesg shows nothing between 11:24:55 and 11:35:55. Then the platform agent runs drop-memory-caches.sh, and kill-connections.sh runs at 11:36:03. So the VM was paused, the resume only started about 4.5 min after our request arrived, and the resume killed the in-flight exec, which is where the 502 comes from.
  • GetMicrovm showed RUNNING throughout (idlePolicy 600/600, autoResumeEnabled true). The same exec run afterwards returns in about 1 s.
  • The first exec on a freshly launched VM hit the same thing (308 s).
  • Frequency: tool calls of 120 s or more went from about 1/day to 12 (Nov 29), 28 (Nov 30) and 53 (Dec 1). That's about 50 exec 502s in 24 h in us-west-2. Our second deployment on the same QM version in us-east-1 had zero in the same period. So the pause itself looks like AWS-side behaviour, possibly region-specific. I'm filing it here because QM can't currently recover from it.

Why QM waits so long

ensureRunning returns immediately when the state is RUNNING and only resumes on SUSPENDED. execRaw then waits up to timeoutSec + 15 s for the proxy. A paused-but-RUNNING VM therefore costs the full proxy timeout before anything happens, and the user sees the agent stall for minutes on ls.

Suggestion

Before an exec (or on the first exec after the body has been idle for N seconds), do a short /health probe, a few seconds at most. If it doesn't answer, call resume (or wait for the daemon) and retry the exec once, rather than waiting for the 502. A 502 from the proxy on an exec marked retrySafe could also be retried automatically.

Happy to share more logs if useful.

songofroland avatar Dec 02 '26 13:12 songofroland

Thanks for the detailed writeup! Took a look and couldn't reproduce the stall. About 50 microVMs over 45 minutes in us-west-2 and us-east-1, with idle gaps up to ~11 minutes, fresh launches and a real suspend and resume, all answered exec right away.

The empty 502 looks like it comes from the platform's ingress proxy rather than the VM. The guest daemon never returns 502, and the same exec sent right after goes through. We see the same empty 502 now and then on our own deployments, on health checks and snapshots.

#4246 handles the drop. QM now sends an exec once more after a 502, but only when a marker file shows the command never started. If it did start, the error says so instead of a bare 502. It doesn't shorten the wait before the 502, so I'll leave this open.

If you can share a microVM ID and a UTC timestamp from one of the stalls, that's probably worth an AWS support case on the proxy side. Lmk if it keeps happening once this lands.

16francej avatar Dec 03 '26 20:12 16francej