Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-6902 fix(agent): fix Pi v0.4.37 Windows session regression (#7843)
makesomethingshit438a30ef00d1
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 8f5378a993..05507c782d 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -672,6 +672,19 @@ jobs:# instead of passing as "ok".run: go test ./pkg/agent -v -run '^TestWindowsRunCollect' -count=1 -timeout=5m+ - name: Test Windows Pi session lock leaves the transcript readable+ if: ${{ needs.changes.outputs.backend == 'true' }}+ working-directory: server+ # #7840: the session lock claimed the transcript itself, and Windows+ # byte-range locks are mandatory. Pi's own read of the file we hand it+ # through --session failed with EBUSY, so every Pi/omp task on Windows+ # died ~0.5s after launch. Unix flock is advisory and never reproduces+ # it, which is exactly how the regression shipped; the tests are+ # windows-tagged and therefore run nowhere else today.+ # -v so a skip (a -run pattern that stops matching) is visible in the+ # log instead of passing as "ok".+ run: go test ./pkg/agent -v -run '^TestPiSessionFileLock' -count=1 -timeout=5m+- name: Test Windows OpenClaw npm shim interpreter resolutionif: ${{ needs.changes.outputs.backend == 'true' }}working-directory: serverdiff --git a/server/pkg/agent/pi_session_lock_windows.go b/server/pkg/agent/pi_session_lock_windows.goindex ff4e78fa3e..d1f52547dc 100644--- a/server/pkg/agent/pi_session_lock_windows.go+++ b/server/pkg/agent/pi_session_lock_windows.go@@ -10,10 +10,13 @@ import ()// tryLockPiSessionFile is the Windows equivalent of flock(LOCK_EX|LOCK_NB).-// FILE_SHARE_DELETE keeps a held lock from pinning the session directory when-// cleanup races a cancelled execution.+// Windows byte-range locks are mandatory, so locking the transcript itself+// would prevent Pi from reading the file it is supposed to append to. Lock a+// sidecar instead. FILE_SHARE_DELETE keeps a held lock from pinning the+// session directory when cleanup races a cancelled execution.func tryLockPiSessionFile(path string) (*os.File, bool, error) {- p, err := windows.UTF16PtrFromString(path)+ lockPath := path + ".lock"+ p, err := windows.UTF16PtrFromString(lockPath)if err != nil {return nil, false, err}@@ -22,14 +25,14 @@ func tryLockPiSessionFile(path string) (*os.File, bool, error) {windows.GENERIC_READ|windows.GENERIC_WRITE,windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE|windows.FILE_SHARE_DELETE,nil,- windows.OPEN_EXISTING,+ windows.OPEN_ALWAYS,windows.FILE_ATTRIBUTE_NORMAL,0,)if err != nil {return nil, false, err}- f := os.NewFile(uintptr(h), path)+ f := os.NewFile(uintptr(h), lockPath)overlapped := new(windows.Overlapped)err = windows.LockFileEx(windows.Handle(f.Fd()),diff --git a/server/pkg/agent/pi_session_lock_windows_test.go b/server/pkg/agent/pi_session_lock_windows_test.gonew file mode 100644index 0000000000..5629c16e71--- /dev/null+++ b/server/pkg/agent/pi_session_lock_windows_test.go@@ -0,0 +1,84 @@+//go:build windows++package agent++import (+ "os"+ "path/filepath"+ "testing"+)++func TestPiSessionFileLockDoesNotBlockTranscriptIO(t *testing.T) {+ t.Parallel()++ sessionPath := filepath.Join(t.TempDir(), "session.jsonl")+ content := []byte("{\"type\":\"session\"}\n")+ if err := os.WriteFile(sessionPath, content, 0o644); err != nil {+ t.Fatalf("create session file: %v", err)+ }++ claim, locked, err := tryLockPiSessionFile(sessionPath)+ if err != nil {+ t.Fatalf("lock session file: %v", err)+ }+ if !locked {+ t.Fatal("session-file lock was unexpectedly busy")+ }+ defer releasePiSessionFileLock(claim)++ transcript, err := os.OpenFile(sessionPath, os.O_RDWR, 0)+ if err != nil {+ t.Fatalf("open transcript while session is running: %v", err)+ }+ defer transcript.Close()++ got := make([]byte, len(content))+ if _, err := transcript.ReadAt(got, 0); err != nil {+ t.Fatalf("read transcript while session is running: %v", err)+ }+ if string(got) != string(content) {+ t.Fatalf("transcript = %q, want %q", got, content)+ }+ if _, err := transcript.WriteAt([]byte("X"), 0); err != nil {+ t.Fatalf("write transcript while session is running: %v", err)+ }+}++func TestPiSessionFileLockSerializesWriters(t *testing.T) {+ t.Parallel()++ sessionPath := filepath.Join(t.TempDir(), "session.jsonl")+ if err := os.WriteFile(sessionPath, nil, 0o644); err != nil {+ t.Fatalf("create session file: %v", err)+ }++ first, locked, err := tryLockPiSessionFile(sessionPath)+ if err != nil {+ t.Fatalf("acquire first lock: %v", err)+ }+ if !locked {+ t.Fatal("first lock was unexpectedly busy")+ }++ second, locked, err := tryLockPiSessionFile(sessionPath)+ if err != nil {+ releasePiSessionFileLock(first)+ t.Fatalf("attempt competing lock: %v", err)+ }+ if locked {+ releasePiSessionFileLock(second)+ releasePiSessionFileLock(first)+ t.Fatal("competing lock unexpectedly succeeded")+ }++ releasePiSessionFileLock(first)++ third, locked, err := tryLockPiSessionFile(sessionPath)+ if err != nil {+ t.Fatalf("reacquire lock after release: %v", err)+ }+ if !locked {+ t.Fatal("lock remained busy after release")+ }+ releasePiSessionFileLock(third)+}