Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-8655: fix(agent): check Linux pidfd support before launching Pi (#10019)
Víctor Andrade690e85093edf
diff --git a/CLI_AND_DAEMON.md b/CLI_AND_DAEMON.mdindex e54fca4306..4e94291eff 100644--- a/CLI_AND_DAEMON.md+++ b/CLI_AND_DAEMON.md@@ -301,11 +301,14 @@ The daemon auto-detects these AI CLIs on your PATH:You need at least one installed. The daemon registers each detected CLI as an available runtime.-On macOS, Pi and Oh-My-Pi require kernel support for process identity signalling-to clean up detached tools safely. Each run checks this operation before launching-the runtime. An unsupported or denied operation fails startup with a compatibility-error instead of allowing work to start without the required cleanup capability.-This is a capability check, not a macOS version check. Existing runs blocked by+Pi and Oh-My-Pi require kernel support for process identity signalling to clean+up detached tools safely: on Linux, `pidfd_open` and `pidfd_send_signal` (kernel+5.3 or newer); on macOS, kernel-checked process identity signalling. Each run+checks these operations before launching the runtime. An unsupported or denied+probe operation, including one blocked by a sandbox, fails startup with a+compatibility error instead of allowing work to start without the required cleanup+capability. This is a capability check, not a kernel version check, and a passing+probe does not guarantee permission to signal every descendant process. Existing runs blocked byunconfirmed cleanup still require inspection and a manual rerun; the startup checkdoes not clear those blocks or establish that earlier background processes exited.diff --git a/server/pkg/agent/pi_cleanup_preflight_linux.go b/server/pkg/agent/pi_cleanup_preflight_linux.gonew file mode 100644index 0000000000..09cc0a9ec2--- /dev/null+++ b/server/pkg/agent/pi_cleanup_preflight_linux.go@@ -0,0 +1,34 @@+//go:build linux++package agent++import (+ "fmt"+ "os"++ "golang.org/x/sys/unix"+)++func checkPiCleanupSupport() error {+ if err := probePiPidfd(unix.PidfdOpen, unix.PidfdSendSignal); err != nil {+ return fmt.Errorf("this Linux environment cannot safely clean up Pi/omp processes; requires Linux 5.3+ with pidfd_open and pidfd_send_signal permitted: %w", err)+ }+ return nil+}++// probePiPidfd exercises both syscalls cleanup relies on against the daemon+// itself; signal 0 performs only the permission check.+func probePiPidfd(+ open func(pid int, flags int) (int, error),+ send func(fd int, sig unix.Signal, info *unix.Siginfo, flags int) error,+) error {+ fd, err := open(os.Getpid(), 0)+ if err != nil {+ return fmt.Errorf("pidfd_open: %w", err)+ }+ defer unix.Close(fd)+ if err := send(fd, 0, nil, 0); err != nil {+ return fmt.Errorf("pidfd_send_signal: %w", err)+ }+ return nil+}diff --git a/server/pkg/agent/pi_cleanup_preflight_linux_test.go b/server/pkg/agent/pi_cleanup_preflight_linux_test.gonew file mode 100644index 0000000000..f4fcb5d50f--- /dev/null+++ b/server/pkg/agent/pi_cleanup_preflight_linux_test.go@@ -0,0 +1,70 @@+//go:build linux++package agent++import (+ "errors"+ "os"+ "syscall"+ "testing"++ "golang.org/x/sys/unix"+)++func TestProbePiPidfd(t *testing.T) {+ // Stubs keep the test independent of the host kernel and seccomp profile,+ // and fail if the probe ever targets another process or sends a real signal.+ openedFD := -1+ openOK := func(pid, flags int) (int, error) {+ if pid != os.Getpid() || flags != 0 {+ t.Fatalf("pidfd_open(%d, %d), want own pid and flags 0", pid, flags)+ }+ // A real fd lets the probe's deferred close run normally.+ var p [2]int+ if err := unix.Pipe(p[:]); err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { unix.Close(p[1]) })+ openedFD = p[0]+ return p[0], nil+ }+ sendOK := func(fd int, sig unix.Signal, info *unix.Siginfo, flags int) error {+ if sig != 0 || info != nil || flags != 0 {+ t.Fatalf("pidfd_send_signal(sig=%d, info=%v, flags=%d), want probe-only call", sig, info, flags)+ }+ return nil+ }+ tests := []struct {+ name string+ open func(int, int) (int, error)+ send func(int, unix.Signal, *unix.Siginfo, int) error+ want error+ }{+ {"supported", openOK, sendOK, nil},+ // Linux < 5.3, as reported on 4.9.+ {"pidfd_open missing", func(int, int) (int, error) { return -1, syscall.ENOSYS }, sendOK, syscall.ENOSYS},+ {"pidfd_open denied", func(int, int) (int, error) { return -1, syscall.EPERM }, sendOK, syscall.EPERM},+ {"pidfd_send_signal missing", openOK, func(int, unix.Signal, *unix.Siginfo, int) error { return syscall.ENOSYS }, syscall.ENOSYS},+ {"pidfd_send_signal denied", openOK, func(int, unix.Signal, *unix.Siginfo, int) error { return syscall.EPERM }, syscall.EPERM},+ }+ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ openedFD = -1+ err := probePiPidfd(tt.open, tt.send)+ if openedFD >= 0 {+ if _, ferr := unix.FcntlInt(uintptr(openedFD), unix.F_GETFD, 0); !errors.Is(ferr, syscall.EBADF) {+ t.Fatalf("pidfd %d left open after probe", openedFD)+ }+ }+ if tt.want == nil {+ if err != nil {+ t.Fatalf("supported environment rejected: %v", err)+ }+ return+ }+ if !errors.Is(err, tt.want) {+ t.Fatalf("error=%v, want %v", err, tt.want)+ }+ })+ }+}diff --git a/server/pkg/agent/pi_cleanup_preflight_other.go b/server/pkg/agent/pi_cleanup_preflight_other.goindex ccfb37e016..b08459e736 100644--- a/server/pkg/agent/pi_cleanup_preflight_other.go+++ b/server/pkg/agent/pi_cleanup_preflight_other.go@@ -1,4 +1,4 @@-//go:build !darwin+//go:build !darwin && !linuxpackage agent