private guest survives the app closing — Restart=always resurrects it and the app-tied stop never reached systemd (ADR 0129 broken) #427

Closed
opened 2026-08-11 04:17:42 +00:00 by ben · 2 comments
Owner

What happened

After closing the operator app at the end of a founding drive (2026-08-10, ~20:53), the private guest VM kept running — hours later the qemu process and its user unit were still active with no app anywhere. ADR 0129 rules the exact opposite: the VM-mode guest is app-tied — closing the app stops the guest, the helper stopping the unit when its stdin closes.

The journal shows what actually happened at app close:

  • 20:53:52 — the guest's qemu exited cleanly (final console output, no failure status). No "Stopping ourcloud-guest.service" entry — the helper's administrative stop (disable --now) never reached systemd.
  • 20:53:54 — Scheduled restart job, restart counter is at 1 — the unit's Restart=always resurrected the guest one second later, and it has run ever since.

What I expected

Closing the app closes the VM (ADR 0129's own words: quit, window close, or crash — no Electron choreography needed).

Steps to reproduce

  1. Found a private-path community and let the drive reach a running guest.
  2. Close the operator app.
  3. systemctl --user is-active ourcloud-guest.service — active; pgrep qemu — the guest is still running (journal shows a restart rather than a stop).

Additional context

  • Two distinct defects compound here:
    1. The app-scoped user unit inherits Restart=always verbatim from the agent's system-scope posture (where "a crashed guest is resurrected" is right — ADR 0056's unconditional survival). Under ADR 0129's app-tied scope it means any guest exit that doesn't come through an administrative systemctl stop gets resurrected — the app-tied guarantee is structurally one race away from false. The user-scope unit likely wants no restart (or the stop path must always be the administrative one), while the agent's system scope keeps Restart=always.
    2. The stop-on-app-close never reached systemd on a real close. Whether the helper was killed before its stop ran or the stop failed, nothing was logged anywhere an operator (or agent) can find: the "best-effort and logged" promise has no observable log in a real launch — the launcher's captured output contains no helper lines at all. The stop path needs evidence that survives the app dying.
  • The clean qemu exit at the moment of app close (before the resurrect) is itself unexplained — worth understanding while fixing: something took the guest down without systemd knowing.
  • Reported during Ben's manual founding drive QA session 2026-08-10/11 (same sitting as #424/#425).
## What happened After closing the operator app at the end of a founding drive (2026-08-10, ~20:53), the private guest VM kept running — hours later the qemu process and its user unit were still active with no app anywhere. ADR 0129 rules the exact opposite: the VM-mode guest is app-tied — closing the app stops the guest, the helper stopping the unit when its stdin closes. The journal shows what actually happened at app close: - 20:53:52 — the guest's qemu exited cleanly (final console output, no failure status). **No "Stopping ourcloud-guest.service" entry** — the helper's administrative stop (`disable --now`) never reached systemd. - 20:53:54 — `Scheduled restart job, restart counter is at 1` — the unit's **`Restart=always`** resurrected the guest one second later, and it has run ever since. ## What I expected Closing the app closes the VM (ADR 0129's own words: quit, window close, or crash — no Electron choreography needed). ## Steps to reproduce 1. Found a private-path community and let the drive reach a running guest. 2. Close the operator app. 3. `systemctl --user is-active ourcloud-guest.service` — active; `pgrep qemu` — the guest is still running (journal shows a restart rather than a stop). ## Additional context - Two distinct defects compound here: 1. **The app-scoped user unit inherits `Restart=always`** verbatim from the agent's system-scope posture (where "a crashed guest is resurrected" is right — ADR 0056's unconditional survival). Under ADR 0129's app-tied scope it means any guest exit that doesn't come through an administrative `systemctl stop` gets resurrected — the app-tied guarantee is structurally one race away from false. The user-scope unit likely wants no restart (or the stop path must always be the administrative one), while the agent's system scope keeps `Restart=always`. 2. **The stop-on-app-close never reached systemd on a real close.** Whether the helper was killed before its stop ran or the stop failed, nothing was logged anywhere an operator (or agent) can find: the "best-effort and logged" promise has no observable log in a real launch — the launcher's captured output contains no helper lines at all. The stop path needs evidence that survives the app dying. - The clean qemu exit at the moment of app close (before the resurrect) is itself unexplained — worth understanding while fixing: something took the guest down without systemd knowing. - Reported during Ben's manual founding drive QA session 2026-08-10/11 (same sitting as #424/#425).
Author
Owner

This was generated by AI during triage.

Triage: bug, ready-for-agent.

Verification: confirmed against the codebase, not just the report. ADR 0129 rules the user-scope private guest app-tied ("closing the app stops the guest", no autostart, no Electron choreography needed); ADR 0056 keeps the agent's system-scope guest on unconditional survival deliberately — these are two different scopes with two different intended lifecycles. The guest unit is rendered from one shared template: it already branches WantedBy by scope (default.target vs multi-user.target) but hardcodes Restart=always unconditionally for both scopes — the ADR 0056 crash-recovery reasoning bled into the ADR 0129 app-tied scope with no carve-out. Separately, the helper's stop-on-app-close routine is wired only into the normal path after its blocking stdio read loop returns; there is no signal handling (SIGTERM/SIGINT) anywhere in the helper, so a real app close/crash/process-group teardown can skip the stop entirely and leave nothing logged — matching the issue's "no helper output in the launcher's captured logs". No .out-of-scope/ entry and no GOTCHAS.md entry cover this failure mode; this is a new, previously unreported defect.

Agent Brief

Category: bug
Summary: The private-path guest's user-scope systemd unit can resurrect itself after the operator app closes, breaking ADR 0129's app-tied guarantee, because it shares an unconditional restart policy with the agent's system-scope guest and because the helper's administrative stop only runs on one exit path.

Current behavior:
Closing the operator app is supposed to stop the private guest (ADR 0129). In practice: the guest's qemu process can exit without the helper's administrative stop (disable --now) ever reaching systemd, and about a second later systemd's Restart=always resurrects the unit — it then runs indefinitely with no app attached, silently consuming resources on what's meant to be an app-scoped sandbox. This reproduces on a real founding drive: found a private-path community, let the guest come up, close the app, then check systemctl --user is-active and pgrep qemu — both show the guest still running.

Desired behavior:

  • The user-scope guest unit must never self-resurrect via systemd's restart accounting. Any exit that doesn't go through the app's own explicit stop path (administrative disable --now) should leave the unit stopped, full stop — matching ADR 0129's "closing the app stops the guest" with no exceptions carved out for crashes or unexpected exits.
  • The system-scope agent guest's existing unconditional-survival restart policy (ADR 0056) is unchanged — this fix must not affect that scope.
  • The helper's stop-on-app-close path must run on every process-termination path available to it (not only a clean blocking-read-loop return caused by stdin EOF), including termination signals and any process-group teardown the app triggers on quit/crash, so the administrative stop reliably reaches systemd.
  • Whether that stop succeeded or failed must be logged somewhere that survives the helper process exiting (e.g. retrievable via the system journal after the fact), per ADR 0100's honesty bar — today there is no observable trace either way.

Key interfaces:

  • The unit-rendering logic that already branches on scope (e.g. its WantedBy target) needs the restart policy added as a second scope-conditional axis, not a single shared constant.
  • The helper's process entry point needs to invoke the existing stop-on-exit routine from a signal handler (or equivalent termination hook), in addition to its current post-serve-loop call, so it's not solely dependent on a graceful stdin close.

Acceptance criteria:

  • After closing the operator app on a running private-path guest, systemctl --user is-active ourcloud-guest.service reports the unit stopped/inactive and stays that way (no restart-counter increment in the journal), even after waiting past several of the unit's restart intervals.
  • pgrep for the guest's qemu process finds nothing after the app-close settles.
  • The system-scope agent guest's unit still restarts unconditionally on crash — existing coverage for that scope keeps passing unchanged.
  • A test asserts the two scopes render different restart policies (today's tests assert Restart=always identically for both).
  • Sending the helper a termination signal (not just closing its stdin) still results in the guest's administrative stop being attempted, with a log line recording success or failure.

Out of scope:

  • Root-causing why the qemu process exits cleanly at the moment of app close, before the resurrect fires — the issue flags this as unexplained and worth understanding, but the fix above (removing the resurrect + guaranteeing the stop path runs) makes the guest's end state correct regardless of that mechanism. Leave a note for a follow-up if the cause surfaces during investigation but don't block this ticket on fully explaining it.
  • ADR 0129's already-deferred HOx/seat-health wiring for the local-VM row — unrelated to this defect.
  • Any change to the system-scope agent guest's restart behavior (ADR 0056) — that scope is intentionally untouched.
> *This was generated by AI during triage.* **Triage:** `bug`, `ready-for-agent`. **Verification:** confirmed against the codebase, not just the report. ADR 0129 rules the user-scope private guest app-tied ("closing the app stops the guest", no autostart, no Electron choreography needed); ADR 0056 keeps the agent's *system-scope* guest on unconditional survival deliberately — these are two different scopes with two different intended lifecycles. The guest unit is rendered from one shared template: it already branches `WantedBy` by scope (`default.target` vs `multi-user.target`) but hardcodes `Restart=always` unconditionally for both scopes — the ADR 0056 crash-recovery reasoning bled into the ADR 0129 app-tied scope with no carve-out. Separately, the helper's stop-on-app-close routine is wired only into the normal path after its blocking stdio read loop returns; there is no signal handling (`SIGTERM`/`SIGINT`) anywhere in the helper, so a real app close/crash/process-group teardown can skip the stop entirely and leave nothing logged — matching the issue's "no helper output in the launcher's captured logs". No `.out-of-scope/` entry and no GOTCHAS.md entry cover this failure mode; this is a new, previously unreported defect. ## Agent Brief **Category:** bug **Summary:** The private-path guest's user-scope systemd unit can resurrect itself after the operator app closes, breaking ADR 0129's app-tied guarantee, because it shares an unconditional restart policy with the agent's system-scope guest and because the helper's administrative stop only runs on one exit path. **Current behavior:** Closing the operator app is supposed to stop the private guest (ADR 0129). In practice: the guest's qemu process can exit without the helper's administrative stop (`disable --now`) ever reaching systemd, and about a second later systemd's `Restart=always` resurrects the unit — it then runs indefinitely with no app attached, silently consuming resources on what's meant to be an app-scoped sandbox. This reproduces on a real founding drive: found a private-path community, let the guest come up, close the app, then check `systemctl --user is-active` and `pgrep qemu` — both show the guest still running. **Desired behavior:** - The user-scope guest unit must never self-resurrect via systemd's restart accounting. Any exit that doesn't go through the app's own explicit stop path (administrative `disable --now`) should leave the unit stopped, full stop — matching ADR 0129's "closing the app stops the guest" with no exceptions carved out for crashes or unexpected exits. - The system-scope agent guest's existing unconditional-survival restart policy (ADR 0056) is unchanged — this fix must not affect that scope. - The helper's stop-on-app-close path must run on every process-termination path available to it (not only a clean blocking-read-loop return caused by stdin EOF), including termination signals and any process-group teardown the app triggers on quit/crash, so the administrative stop reliably reaches systemd. - Whether that stop succeeded or failed must be logged somewhere that survives the helper process exiting (e.g. retrievable via the system journal after the fact), per ADR 0100's honesty bar — today there is no observable trace either way. **Key interfaces:** - The unit-rendering logic that already branches on scope (e.g. its `WantedBy` target) needs the restart policy added as a second scope-conditional axis, not a single shared constant. - The helper's process entry point needs to invoke the existing stop-on-exit routine from a signal handler (or equivalent termination hook), in addition to its current post-serve-loop call, so it's not solely dependent on a graceful stdin close. **Acceptance criteria:** - [ ] After closing the operator app on a running private-path guest, `systemctl --user is-active ourcloud-guest.service` reports the unit stopped/inactive and stays that way (no restart-counter increment in the journal), even after waiting past several of the unit's restart intervals. - [ ] `pgrep` for the guest's qemu process finds nothing after the app-close settles. - [ ] The system-scope agent guest's unit still restarts unconditionally on crash — existing coverage for that scope keeps passing unchanged. - [ ] A test asserts the two scopes render *different* restart policies (today's tests assert `Restart=always` identically for both). - [ ] Sending the helper a termination signal (not just closing its stdin) still results in the guest's administrative stop being attempted, with a log line recording success or failure. **Out of scope:** - Root-causing *why* the qemu process exits cleanly at the moment of app close, before the resurrect fires — the issue flags this as unexplained and worth understanding, but the fix above (removing the resurrect + guaranteeing the stop path runs) makes the guest's end state correct regardless of that mechanism. Leave a note for a follow-up if the cause surfaces during investigation but don't block this ticket on fully explaining it. - ADR 0129's already-deferred HOx/seat-health wiring for the local-VM row — unrelated to this defect. - Any change to the system-scope agent guest's restart behavior (ADR 0056) — that scope is intentionally untouched.
Author
Owner

Fixed and landed on origin/main (commit sandcastle: #427 app-tied guest stops staying up).

Two compounding defects, both closed:

  1. Shared restart policy — unitFile (internal/vm/manager.go) rendered Restart=always for both scopes; it now branches on scope: user-scope guest renders Restart=no (ADR 0129 app-tied — never self-resurrects), system-scope agent guest keeps Restart=always (ADR 0056, untouched). New TestRestartPolicyDiffersByScope asserts the two scopes render different policies; TestUserScope_DrivesUserSystemd amended to require Restart=no; install_test.go's system-scope Restart=always still passes.
  2. Stop only on stdin EOF — the helper now installs a SIGTERM/SIGINT handler (stopGuestOnSignal, app/helper/cmd/helper/guestlifecycle.go), so the administrative stop runs on every termination path a real app close/crash takes, not only a clean stdin drain. StopOnExit is idempotent across both paths via stopOnce and logs the stop's verdict once (ADR 0100 — the only durable evidence it ran). TestStopGuestOnSignal_StopsAndLogs + TestStopOnExit_IdempotentAcrossPaths.

Hazard recorded as GOTCHAS #13; STATUS.md header + milestone log updated.

Out of scope, still open: why qemu exits cleanly at app-close before the resurrect fires — the report flags this as unexplained; the fix makes the guest's end state correct regardless (no resurrect + the stop always reaches systemd).

Verified: go build ./..., go vet, and go test ./internal/vm/... ./app/helper/... ./internal/install/... all green under nix develop .#go-ci (plus the pre-push gate).

Fixed and landed on `origin/main` (commit `sandcastle: #427 app-tied guest stops staying up`). Two compounding defects, both closed: 1. **Shared restart policy** — `unitFile` (`internal/vm/manager.go`) rendered `Restart=always` for both scopes; it now branches on scope: user-scope guest renders `Restart=no` (ADR 0129 app-tied — never self-resurrects), system-scope agent guest keeps `Restart=always` (ADR 0056, untouched). New `TestRestartPolicyDiffersByScope` asserts the two scopes render *different* policies; `TestUserScope_DrivesUserSystemd` amended to require `Restart=no`; `install_test.go`'s system-scope `Restart=always` still passes. 2. **Stop only on stdin EOF** — the helper now installs a SIGTERM/SIGINT handler (`stopGuestOnSignal`, `app/helper/cmd/helper/guestlifecycle.go`), so the administrative stop runs on every termination path a real app close/crash takes, not only a clean stdin drain. `StopOnExit` is idempotent across both paths via `stopOnce` and logs the stop's verdict once (ADR 0100 — the only durable evidence it ran). `TestStopGuestOnSignal_StopsAndLogs` + `TestStopOnExit_IdempotentAcrossPaths`. Hazard recorded as GOTCHAS #13; STATUS.md header + milestone log updated. **Out of scope, still open:** *why* qemu exits cleanly at app-close before the resurrect fires — the report flags this as unexplained; the fix makes the guest's end state correct regardless (no resurrect + the stop always reaches systemd). Verified: `go build ./...`, `go vet`, and `go test ./internal/vm/... ./app/helper/... ./internal/install/...` all green under `nix develop .#go-ci` (plus the pre-push gate).
ben closed this issue 2026-08-11 05:57:27 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#427
No description provided.