Skip to content

feat(qemu): pause() and in-place reset() — paused marker, CLI verbs (#375) - #376

Draft
mobileskyfi wants to merge 3 commits into
mainfrom
feat/375-pause-reset
Draft

mobileskyfi wants to merge 3 commits into
mainfrom
feat/375-pause-reset

Conversation

@mobileskyfi

Copy link
Copy Markdown
Contributor

Closes #375.

What

  • chr.pause() / quickchr pause <name> — QEMU monitor stop under the machine lock. QEMU, its sockets and every NIC's carrier stay up (a hung switch, not a pulled cable). A /^error/i reply is PROCESS_FAILED and sets no marker. An already-held guest only gets the marker. A stopped machine is MACHINE_STOPPED and leaves clean state.
  • chr.reset({ wait, timeoutExtra }) / quickchr reset <name> [--no-wait] [-T <s>] — monitor system_reset on that machine only: same QEMU PID, every socket kept, RouterOS cold-boots, REST-ready by default (same wait and BOOT_TIMEOUT capture as continue(), now shared in waitAfterResume()). Far-end carrier is not touched; MANUAL shows set --link on the peers around it.
  • New paused marker on MachineState, separate from frozen (doc comment says how they differ). continue() clears both. finalizeStoppedState(), markMachineStopped(), clean(), the device-mode relaunch and _launchExisting clear it with the pid. status stays "running".
  • list/get: (paused) in the table, a Paused: line in the detail view, paused in --json.
  • CLI dispatch, per-command help, top-level help, bash/zsh/fish completions (pause/reset complete running machines), lock op names.

Decisions to review

  • Reset of a paused (or frozen) machine resumes it. After system_reset, QEMU leaves a held guest in paused (prelaunch). reset() checks info status and sends cont, then clears both markers. A reset always ends with RouterOS booting. Staying held would add nothing that a pause() after the reset doesn't already give, and reset() could not keep its REST-ready promise.
  • exec/rest against a paused machine: fail fast, not documented waits. rest(), exec() (every transport) and qga() throw a new MACHINE_PAUSED code at once. They read the marker from machine.json, so a handle made before a quickchr pause in another process still sees it. shutdown() of a paused guest power-cuts at once and reports forced (with a requestError that says why) instead of waiting out its timeout.
  • pause() never touches frozen; pausing a frozen machine sets paused beside it.

Docs

MANUAL (pause, reset sections with the #364 grounded facts: frozen clock, SIGSTOP vs. watchdog, backpressure; the library table and interface; the error-code table), qemu.instructions.md (durable QEMU facts), DESIGN.md (decision record), CHANGELOG.

Tests

  • Unit test/unit/pause-reset.test.ts (fake monitor that models run state): pause sets the marker and leaves frozen alone; idempotent pause; stop error; dead pid; continue clears; a stale handle sees the on-disk marker; rest/exec/exec --via console/qga fail fast; reset sends cont only for a held guest and clears both markers; reset error keeps the marker; no-user-NIC refusal; stop, shutdown and status refresh clear the marker.
  • Unit test/unit/cli-pause-reset.test.ts: list markers (table/detail/json), usage errors, exec → MACHINE_PAUSED, help text, option forwarding.
  • Integration test/integration/pause-reset.test.ts: two CHRs on a socket link. Pause keeps the peer's carrier (checked every 1 s for 4 s) while pings get 0 replies; guest requests are refused in under 2 s; continue returns REST-ready and pings flow; reset keeps the same PID, and a RAM :global is gone afterwards (a real reboot) while the disk config survives; resetting a paused machine resumes it; stop clears the marker.

Runs

  • Linux x86_64 / KVM, RouterOS 7.25.2: bun test test/unit/ 2184 pass / 0 fail; bun run check clean (the one biome warning was already there); integration pause-reset 1/1 pass (95 s); frozen-continue 4/4 pass (regression for the continue() refactor).
  • macOS (Morpheus): running now; results and the clock-freeze answer will be posted here.

Follow-ups

🤖 Generated with Claude Code

…375)

- chr.pause() / quickchr pause: monitor `stop` under the machine lock; NICs
  keep carrier, the guest clock stops. Idempotent; sets a new `paused`
  marker (never `frozen`).
- chr.reset() / quickchr reset [--no-wait] [-T]: monitor `system_reset` in
  place (same QEMU PID and sockets), REST-ready by default. A paused or
  frozen guest is resumed by the reset and both markers are cleared.
- continue() clears `paused` as well as `frozen`; stop/clean/relaunch/status
  refresh clear it with the pid.
- rest()/exec()/qga() fail fast with the new MACHINE_PAUSED code;
  shutdown() of a paused guest power-cuts at once and reports `forced`.
- list/get show `(paused)`, a `Paused:` detail line and `paused` in --json;
  help, completions, MANUAL, DESIGN, qemu.instructions, CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mobileskyfi
mobileskyfi marked this pull request as draft December 2, 2026 13:13
@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@mobileskyfi mobileskyfi left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 101 focused unit tests and the RouterOS 7.25.2 Linux/KVM integration test passed. The inline findings cover pause state after cross-process resume and monitor failures, reset’s effect on live links at timeout, and CLI paths that miss the paused state. I reproduced the stale-handle, monitor-reply, and CLI argument cases with local fixtures.

Comment thread src/lib/quickchr.ts Resolved
Comment thread src/lib/quickchr.ts Resolved
Comment thread src/lib/quickchr.ts Resolved
Comment thread DESIGN.md Resolved
Comment thread src/cli/index.ts Resolved
Comment thread MANUAL.md Resolved
Comment thread src/cli/index.ts Resolved
Comment thread src/lib/quickchr.ts Resolved
Comment thread test/unit/pause-reset.test.ts Resolved
…s, reset keeps QEMU on timeout

- assertNotPaused: the on-disk record wins in both directions, so a handle
  that saw `paused` stops refusing once another process resumes the VM.
- pause/reset/continue: `info status` must parse and every `stop`/`cont`/
  `system_reset` needs the final prompt; `/^error/i` replies fail; the
  marker is set only once QEMU reports the guest held.
- buildAndSpawnQemu clears `paused` and sets `frozen` from the launch before
  any pid or record is saved; the foreground exit also drops the old pid.
- snapshot.load: a failed loadvm resumes the guest only if it was running.
- reset: a REST-wait timeout keeps QEMU and its links up (BOOT_TIMEOUT with
  the report), instead of the continue-style stop.
- CLI: `get` prints a paused report instead of live reads; `qga` refuses a
  paused machine; `continue`/`reset` refuse a valueless --timeout-extra/-T.
- Tests: exact monitor sequences, strict-reply cases, reverse stale handle,
  snapshot-load on a paused guest, spawn markers, CLI get/qga/-T, and a RAM
  sentinel across the live paused reset. snapshot-budgets stub grows `info status`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t pause survives without a reboot

- Morpheus (Intel Mac, HVF, QEMU 11.1.1): the first `stop` after a boot does
  not freeze guest time, and a first pause of 20 s or more crashes the guest
  kernel on `cont` (RouterOS reboots in the same QEMU). Later pauses freeze the
  clock as on KVM. Linux/KVM re-checked: a 30 s first pause straight after boot
  is clean. Documented in MANUAL and qemu.instructions; follow-up #377.
- pause-reset integration: a RAM :global set before pause() must survive
  continue(), so a resume that came back through a reboot fails the test.

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

Copy link
Copy Markdown
Contributor Author

macOS grounding (Morpheus)

Environment: macOS 26.6.2, Intel x86_64, HVF (-accel hvf -cpu host), QEMU 11.1.1, Bun 1.4.4, CHR 7.25.2 x86, run at a41abe3.

Result
Unit pause-reset, cli-pause-reset, continue 29 pass
Integration pause-reset.test.ts 1 pass (135 s)
Integration frozen-continue.test.ts 4 pass (86 s)

Probe (quickchr pause / continue / reset on one machine):

  • pause took 0.36 s; list showed (paused); exec failed with MACHINE_PAUSED in 0.32 s.
  • reset: same PID and uptime restarted (22.7 s from running, 17.7 s from paused). From paused it came back running with no (paused) marker.
  • pause then stop: stopped, no marker, no PID.
  • Does stop freeze the guest clock on HVF? Only after the first resume. The first pause after each boot is not frozen: on cont the guest sees the whole pause at once. A first pause of 3 or 10 s was harmless. At 20 and 30 s the guest kernel failed and RouterOS rebooted inside the same QEMU (same PID, kernel failure in previous boot, continue ≈ 27.7 s), and continue still reported success. Every later pause in the same boot (five 30 s pauses) froze the clock as on KVM: uptime +2–3 s over 33–34 s of wall time, guest clock 32 s behind, continue in 2.4–3.0 s.

Linux/KVM re-check: a 30 s pause straight after boot (uptime 21 s) kept a RAM :global, and uptime moved 2 s across about 32 s of wall time. KVM does not have this problem.

What changed (0e7760a):

  • MANUAL (pause) and qemu.instructions.md now give the HVF caveat. MANUAL no longer says pause can never trigger a reboot.
  • The integration test sets a RAM :global before pause() and checks that it survives continue(), so a resume that came back through a reboot fails the test. Its pause is still about 5 s, below the HVF threshold, so the test passes on both platforms.
  • The mechanism, a possible mitigation (a short primer stop/cont on HVF), detecting a reboot inside continue(), and Apple Silicon/TCG coverage are tracked in macOS/HVF: a first pause() ≥20 s after boot crashes the guest kernel on continue #377.

Linux/KVM at 0e7760a: pause-reset 1/1 pass, frozen-continue 4/4, disk 3/3, unit suite 2194/0. A macOS re-run at the new head is in progress.

@mobileskyfi

Copy link
Copy Markdown
Contributor Author

macOS re-run at 0e7760a (Morpheus, Intel x86_64 with HVF):

  • Unit tests in pause-reset, cli-pause-reset, continue and snapshot-budgets: 43 pass, 0 fail.
  • Integration tests pause-reset and frozen-continue: 5 pass, 0 fail.
  • No machines or QEMU processes were left behind.

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.

feat(qemu): pause() and in-place reset() — paused marker, CLI verbs

2 participants