From b7e766ffe4e55152db823dbbac7c3f4b9d24d66d Mon Sep 17 00:00:00 2001 From: Leo Camus Date: Mon, 23 Nov 2026 04:34:29 +0000 Subject: [PATCH] fix(server): skip named pipes and sockets when packing a task archive writeTaskArchivePackage opened every entry of the staged workspace that is not a directory. Opening a FIFO blocks until a writer appears, so a named pipe left by a command (mkfifo backpipe for an nc relay) stopped the single archive worker in openat for good, with the task files already moved to staging and every later archive, restore and delete job queued behind it. A Unix socket failed the archive instead, and a device file was packed but refused by extractTaskArchivePackage on restore. Skip every entry that is neither a directory nor a regular file, as is already done for symlinks. --- CHANGELOG.md | 1 + server/task_archive_package.go | 6 ++ server/task_archive_special_unix_test.go | 70 ++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 server/task_archive_special_unix_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index b8e3766..c42cfc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project are documented in this file. The format is b ### Fixed +- **A named pipe in the task workspace no longer hangs the archive worker**: packing opened every non-directory entry, and opening a FIFO blocks until a writer appears, so the single archive worker stopped there and every later archive, restore and delete job waited behind it. A socket failed the archive instead, and a device was packed but refused on restore. The packer now skips every entry that is neither a directory nor a regular file, as it already did for symlinks. - **LLM connection-test logs stay one line**: the response body written by a connection test has CR and LF replaced with spaces before it is logged, so the body cannot start a second log record. - **Benchmark judge validation**: grading and the judge's falsification battery require one verdict per ground-truth ID, actual boolean decisions and gates, and matches to the supplied scanner findings. Invalid grading responses use the existing three-attempt budget and abort without writing scores, rather than counting duplicate IDs or truthy strings such as `"false"`. - **Live log subscribers can no longer crash the process**: a client disconnect closes its log channel. The sink now delivers a line while it still holds the subscriber lock, so that close cannot land in the middle of the send. diff --git a/server/task_archive_package.go b/server/task_archive_package.go index 496a740..a19b2e6 100644 --- a/server/task_archive_package.go +++ b/server/task_archive_package.go @@ -639,6 +639,12 @@ func writeTaskArchivePackage(path, payloadDir string, snapshot *pgdb.TaskArchive log.Printf("[task-archive] skipping symlink (unsupported by the archive, other files unaffected): %s", current) return nil } + if !entry.IsDir() && !info.Mode().IsRegular() { + // A named pipe, socket or device left by a command: opening a pipe blocks until + // a writer appears, tar refuses a socket, and the unpacker refuses the rest. + log.Printf("[task-archive] skipping a file that is not regular (unsupported by the archive): %s", current) + return nil + } header, err := tar.FileInfoHeader(info, "") if err != nil { return err diff --git a/server/task_archive_special_unix_test.go b/server/task_archive_special_unix_test.go new file mode 100644 index 0000000..79b0426 --- /dev/null +++ b/server/task_archive_special_unix_test.go @@ -0,0 +1,70 @@ +//go:build unix + +package server + +import ( + "net" + "os" + "path/filepath" + "syscall" + "testing" + + pgdb "github.com/Autumn-27/artex/db" +) + +// A named pipe or a socket left in the task workspace by a command must not +// make the archive unrestorable, nor stop the task from being archived. +func TestTaskArchiveSkipsSpecialFiles(t *testing.T) { + // A short root: a socket path is limited to about 100 bytes. + dataDir, err := os.MkdirTemp("/tmp", "arch") + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { os.RemoveAll(dataDir) }) + taskID := "42" + runDir := filepath.Join(dataDir, "tasks", taskID, "main") + if err := os.MkdirAll(runDir, 0o755); err != nil { + t.Fatal(err) + } + evidence := filepath.Join(runDir, "evidence.txt") + if err := os.WriteFile(evidence, []byte("task evidence"), 0o600); err != nil { + t.Fatal(err) + } + if err := syscall.Mkfifo(filepath.Join(runDir, "backpipe"), 0o600); err != nil { + t.Skipf("mkfifo: %v", err) + } + ln, err := net.Listen("unix", filepath.Join(runDir, "ctl.sock")) + if err != nil { + t.Skipf("unix socket: %v", err) + } + ln.(*net.UnixListener).SetUnlinkOnClose(false) + ln.Close() + + stage, err := stageTaskArchiveFiles(dataDir, 1, taskID, 7) + if err != nil { + t.Fatal(err) + } + archivePath := taskArchivePath(dataDir, 1, taskID) + snapshot := &pgdb.TaskArchiveSnapshot{FormatVersion: pgdb.TaskArchiveFormatVersion, TaskID: 42, ExplorationID: 7} + _, _, checksum, err := writeTaskArchivePackage(archivePath, stage.payload, snapshot) + if err != nil { + t.Fatalf("the task could not be archived: %v", err) + } + if err := stage.commit(); err != nil { + t.Fatal(err) + } + extracted := filepath.Join(dataDir, "restore") + if err := extractTaskArchivePackage(archivePath, checksum, extracted); err != nil { + t.Fatalf("the archive of the task cannot be restored: %v", err) + } + installed, err := installTaskArchiveFiles(dataDir, extracted, taskID, 1, ExecPrivilege{}) + if err != nil { + t.Fatal(err) + } + if err := installed.commit(); err != nil { + t.Fatal(err) + } + if got, err := os.ReadFile(evidence); err != nil || string(got) != "task evidence" { + t.Fatalf("restored %s = %q, %v", evidence, got, err) + } +}