carlos / platform Public

instances: instance-stop R1 P2s: witness asserts outcomes, wording

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev feac4029cca441b0b2ea91bea065e46d749aba92 parent dcb0050
4 files changed, +18 −13
  • docs/superpowers/specs/2026-11-08-instance-stop-execstop-528-design.md +7 −5
  • internal/host/execstop_probe_rootrunner_linux_test.go +4 −4
  • internal/instanceexec/stop_linux.go +6 −3
  • internal/provision/testdata/plan14-root-reads-instance-stop-execstop-528.tsv +1 −1

CI passed — run details

diff --git a/docs/superpowers/specs/2026-11-08-instance-stop-execstop-528-design.md b/docs/superpowers/specs/2026-11-08-instance-stop-execstop-528-design.md
index ca4e6d982..7ae5d4f2b 100644
--- a/docs/superpowers/specs/2026-11-08-instance-stop-execstop-528-design.md
+++ b/docs/superpowers/specs/2026-11-08-instance-stop-execstop-528-design.md
@@ -69,11 +69,13 @@ The phases, kept apart:
- **Graceful wait:** up to 18 s from the helper's SIGTERM.
- **Kill request:** SIGKILL through the pidfd.
- **Observed exit:** the pidfd polls readable, up to 1 s later.
-- **Completed unit stop:** systemd's own phases and `ExecStopPost`. These
- are not bounded by the helper. A main process stuck in an uninterruptible
- wait leaves systemd in its kill phase, exactly as today. The activator's
- unit observer already holds such a stop as unproven (`unitproc.go`) and
- does not release it.
+- **Completed unit stop:** systemd's own phases and `ExecStopPost`, not
+ bounded by the helper. A main process stuck in an uninterruptible wait
+ with its SIGKILL pending does not keep systemd waiting forever: its
+ kill-phase timer runs out, it runs `ExecStopPost`, and the unit ends
+ failed with processes left. The safeguard is the activator's unit
+ observer (`unitproc.go`). It holds the stop as unproven while the unit's
+ cgroup is populated, and does not release the instance.
### How the helper finds and signals the main process
diff --git a/internal/host/execstop_probe_rootrunner_linux_test.go b/internal/host/execstop_probe_rootrunner_linux_test.go
index b234515a5..d9c16ac18 100644
--- a/internal/host/execstop_probe_rootrunner_linux_test.go
+++ b/internal/host/execstop_probe_rootrunner_linux_test.go
@@ -781,7 +781,7 @@ func TestRootInstanceStopExecStop(t *testing.T) {
launch("ignore")
o := cycle()
t.Logf("verdict: C ignores SIGTERM: %+v", o)
- if o.terms != 1 || o.stop < instanceexec.StopBudget-time.Second || o.stop > 20*time.Second+500*time.Millisecond || o.result != "signal" {
+ if o.terms != 1 || o.stop < instanceexec.StopBudget-time.Second || o.stop > 20*time.Second+500*time.Millisecond || o.result != "signal" || o.mainCode != "2" || o.mainStatus != "9" || !o.record {
t.Errorf("ignore-SIGTERM stop not bounded as designed: %+v", o)
}
@@ -855,7 +855,7 @@ func TestRootInstanceStopExecStop(t *testing.T) {
stopWith = nil
undrop("61-runtime.conf")
t.Logf("verdict: G RuntimeMaxSec: %+v", o)
- if o.terms != 1 || !o.drained || o.result != "timeout" || killedOrDumped(o.mainCode) {
+ if o.terms != 1 || !o.drained || o.result != "timeout" || killedOrDumped(o.mainCode) || o.mainStatus != "0" || !o.record {
t.Errorf("RuntimeMaxSec expiry: %+v", o)
}
@@ -886,7 +886,7 @@ func TestRootInstanceStopExecStop(t *testing.T) {
o = cycle()
undrop("62-stall.conf")
t.Logf("verdict: J manager timeout before the helper signals: %+v", o)
- if o.terms != 0 || o.stop < 2500*time.Millisecond || o.stop > 8*time.Second {
+ if o.terms != 0 || o.stop < 2500*time.Millisecond || o.stop > 8*time.Second || o.result != "timeout" || o.mainCode != "2" || o.mainStatus != "9" || !o.record {
t.Errorf("timeout before signalling: %+v", o)
}
@@ -898,7 +898,7 @@ func TestRootInstanceStopExecStop(t *testing.T) {
o = cycle()
undrop("63-short.conf")
t.Logf("verdict: K manager timeout after the helper's SIGTERM: %+v", o)
- if o.terms != 1 || o.stop < 2500*time.Millisecond || o.stop > 8*time.Second {
+ if o.terms != 1 || o.stop < 2500*time.Millisecond || o.stop > 8*time.Second || o.result != "timeout" || o.mainCode != "2" || o.mainStatus != "9" || !o.record {
t.Errorf("timeout after signalling: %+v", o)
}
diff --git a/internal/instanceexec/stop_linux.go b/internal/instanceexec/stop_linux.go
index d1a8857a1..fb9e0412a 100644
--- a/internal/instanceexec/stop_linux.go
+++ b/internal/instanceexec/stop_linux.go
@@ -19,9 +19,12 @@ import (
// sometimes takes the unit's main process for "not our child", and then a
// KillMode=mixed stop SIGKILLs it straight after its SIGTERM. This runs
// first: one SIGTERM to the main process (the trampoline, which forwards
-// it to the app), a wait for its exit, and SIGKILL at StopBudget. By the
-// time systemd's own SIGTERM phase begins the main process is gone, so
-// the app gets exactly one SIGTERM whatever systemd thinks of its parent.
+// it to the app), a wait for its exit, and SIGKILL at StopBudget. When it
+// has seen the exit, systemd's own SIGTERM phase finds no main process to
+// signal, so the app gets exactly one SIGTERM whatever systemd thinks of
+// its parent. When it has not (a process stuck in the kernel with its
+// SIGKILL pending), systemd's phases run on as before and the activator's
+// populated-cgroup check decides when the stop is complete.
//
// It runs as root in the host PID namespace (a "+" command gets no
// PrivatePIDs= of its own), so $MAINPID names the right process. It reads
diff --git a/internal/provision/testdata/plan14-root-reads-instance-stop-execstop-528.tsv b/internal/provision/testdata/plan14-root-reads-instance-stop-execstop-528.tsv
index 1e9efb1e3..f44c7313c 100644
--- a/internal/provision/testdata/plan14-root-reads-instance-stop-execstop-528.tsv
+++ b/internal/provision/testdata/plan14-root-reads-instance-stop-execstop-528.tsv
@@ -13,4 +13,4 @@ internal/instanceexec/stop_linux.go procCgroup legacy accepted-legacy accepted-l
@coverage . 1523897095768fb1b0c71a56056bd9182e52b71a961b07d001e034631c6deba3
@coverage internal/host b9e219bc73844a2926892b6e254ec64312ec4fa03d0df38fb955e1774884cb9d
@coverage internal/host/units 649e7fe2ece8a3acf4a202d64d0936a65077b287b8cdc307c13dc940db6f5c6f
-@coverage internal/instanceexec c3d90f88e9ea83bba9aa27fde8db60b7ad4633825520a85d3478c378ec4ef7d4
+@coverage internal/instanceexec fa59150895c4932e6287b0f2ad2f37cad2167b6513293f326cee9bc7b42ac1bf