Runs: one uninterruptible stage session no longer disables the runner

Start-up recovery used to fail the whole runner when any previously active
stage session could not be confirmed stopped. That run alone is now marked
interrupted with a diagnostic naming the session and error. A Pi owner whose
process and process group are gone counts as stopped without its quiescence
receipt (it crashed), as the Claude stage path already did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 00:23:39 +00:00
parent 3e267d4863
commit e649eced10
4 changed files with 83 additions and 3 deletions
+12 -2
View File
@@ -608,7 +608,9 @@ func piResult(data []byte) (string, error) {
}
// InterruptPi expires the retained lease. The explicit extension aborts tools and
// marks quiescence before shutting down; without that receipt recovery fails closed.
// marks quiescence before shutting down. An owner whose process and process
// group are both gone (a crash, a reboot) has nothing left to stop, so it
// counts as interrupted without that receipt; otherwise recovery fails closed.
func InterruptPi(ctx context.Context, reference string) error {
if !filepath.IsAbs(reference) {
return fmt.Errorf("invalid retained Pi reference")
@@ -623,6 +625,12 @@ func InterruptPi(ctx context.Context, reference string) error {
if json.Unmarshal(data, &owner) != nil || owner.PID <= 1 {
return errors.Join(fmt.Errorf("invalid retained Pi owner"), ErrStageCleanup)
}
gone := func() bool {
return errors.Is(syscall.Kill(owner.PID, 0), syscall.ESRCH) && errors.Is(syscall.Kill(-owner.PID, 0), syscall.ESRCH)
}
if gone() {
return nil
}
old := time.Unix(0, 0)
if err := os.Chtimes(filepath.Join(reference, "lease"), old, old); err != nil {
return err
@@ -630,7 +638,9 @@ func InterruptPi(ctx context.Context, reference string) error {
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
for {
if data, err := os.ReadFile(filepath.Join(reference, "quiescent")); err == nil && string(data) == "quiescent" && errors.Is(syscall.Kill(owner.PID, 0), syscall.ESRCH) && errors.Is(syscall.Kill(-owner.PID, 0), syscall.ESRCH) {
// The receipt is written just before a clean exit; a process that
// died without it is still gone.
if gone() {
return nil
}
select {
+28
View File
@@ -42,3 +42,31 @@ func TestPiReceiptRequiresProcessExit(t *testing.T) {
t.Fatal("confirmed process exit not accepted", err)
}
}
// A Pi owner that crashed never wrote its quiescence receipt; with its process
// and process group gone there is nothing left to stop, so recovery must not
// wait out its timeout and fail.
func TestPiOwnerGoneWithoutReceiptCountsAsInterrupted(t *testing.T) {
cmd := exec.Command("sleep", "5")
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
if err := cmd.Start(); err != nil {
t.Fatal(err)
}
pid := cmd.Process.Pid
if err := cmd.Process.Kill(); err != nil {
t.Fatal(err)
}
cmd.Wait()
dir := t.TempDir()
owner, _ := json.Marshal(map[string]any{"pid": pid})
for name, data := range map[string][]byte{"owner.json": owner, "lease": []byte("lease")} {
if err := os.WriteFile(filepath.Join(dir, name), data, 0600); err != nil {
t.Fatal(err)
}
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
if err := InterruptPi(ctx, dir); err != nil {
t.Fatal("a crashed owner was not accepted as gone:", err)
}
}