Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix: fix agfs-server for windows (#16)

kkkwjxbbbdee90a0be
diff --git a/pyproject.toml b/pyproject.toml
index e5e7f39aa..8e3f16497 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "openviking"
-version = "0.1.5"
+version = "0.1.6"
description = "An Agent-native context database: Data in, Context out"
readme = "README.md"
authors = [
diff --git a/tests/vectordb/test_serializable.py b/tests/vectordb/test_serializable.py
deleted file mode 100644
index c61adb358..000000000
--- a/tests/vectordb/test_serializable.py
+++ /dev/null
@@ -1,104 +0,0 @@
-# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.
-# SPDX-License-Identifier: Apache-2.0
-"""测试新的 serializable 装饰器"""
-import unittest
-from openviking.storage.vectordb.store.data import CandidateData, DeltaRecord, TTLData
-
-
-class TestSerializableDecorator(unittest.TestCase):
- def test_candidate_data_serialization(self):
- """测试 CandidateData 的序列化和反序列化"""
- data = CandidateData(
- label=123,
- vector=[1.0, 2.0, 3.0],
- sparse_raw_terms=["term1", "term2"],
- sparse_values=[0.5, 0.8],
- fields='{"name": "test"}',
- expire_ns_ts=1234567890,
- )
-
- # 序列化
- serialized = data.serialize()
- self.assertIsInstance(serialized, bytes)
-
- # 反序列化
- restored = CandidateData.from_bytes(serialized)
- self.assertEqual(restored.label, 123)
- self.assertEqual(restored.vector, [1.0, 2.0, 3.0])
- self.assertEqual(restored.sparse_raw_terms, ["term1", "term2"])
- self.assertEqual(len(restored.sparse_values), 2)
- self.assertAlmostEqual(restored.sparse_values[0], 0.5, places=5)
- self.assertAlmostEqual(restored.sparse_values[1], 0.8, places=5)
- self.assertEqual(restored.fields, '{"name": "test"}')
- self.assertEqual(restored.expire_ns_ts, 1234567890)
-
- def test_delta_record_serialization(self):
- """测试 DeltaRecord 的序列化和反序列化"""
- record = DeltaRecord(
- type=DeltaRecord.Type.UPSERT,
- label=456,
- vector=[4.0, 5.0],
- sparse_raw_terms=["a", "b"],
- sparse_values=[0.1, 0.2],
- fields="new",
- old_fields="old",
- )
-
- serialized = record.serialize()
- restored = DeltaRecord.from_bytes(serialized)
-
- self.assertEqual(restored.type, DeltaRecord.Type.UPSERT)
- self.assertEqual(restored.label, 456)
- self.assertEqual(restored.vector, [4.0, 5.0])
- self.assertEqual(restored.fields, "new")
- self.assertEqual(restored.old_fields, "old")
-
- def test_ttl_data_serialization(self):
- """测试 TTLData 的序列化和反序列化"""
- ttl = TTLData(label=789)
-
- serialized = ttl.serialize()
- restored = TTLData.from_bytes(serialized)
-
- self.assertEqual(restored.label, 789)
-
- def test_default_values(self):
- """测试默认值"""
- data = CandidateData()
-
- serialized = data.serialize()
- restored = CandidateData.from_bytes(serialized)
-
- self.assertEqual(restored.label, 0)
- self.assertEqual(restored.vector, [])
- self.assertEqual(restored.fields, "")
-
- def test_empty_bytes(self):
- """测试空字节反序列化"""
- restored = CandidateData.from_bytes(b"")
- self.assertEqual(restored.label, 0)
-
- def test_schema_auto_generation(self):
- """测试 schema 自动生成"""
- # 验证 schema 和 bytes_row 已自动创建
- self.assertTrue(hasattr(CandidateData, "schema"))
- self.assertTrue(hasattr(CandidateData, "bytes_row"))
-
- # 验证字段数量
- self.assertEqual(len(CandidateData.schema.field_metas), 6)
-
- # 验证字段类型映射正确
- self.assertEqual(
- CandidateData.schema.field_metas["label"].data_type.name, "uint64"
- )
- self.assertEqual(
- CandidateData.schema.field_metas["vector"].data_type.name, "list_float32"
- )
- self.assertEqual(
- CandidateData.schema.field_metas["sparse_raw_terms"].data_type.name,
- "list_string",
- )
-
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/third_party/agfs/agfs-server/pkg/filesystem/pathutil.go b/third_party/agfs/agfs-server/pkg/filesystem/pathutil.go
index e4907ff3d..d5c37d2a7 100644
--- a/third_party/agfs/agfs-server/pkg/filesystem/pathutil.go
+++ b/third_party/agfs/agfs-server/pkg/filesystem/pathutil.go
@@ -1,7 +1,7 @@
package filesystem
import (
- "path/filepath"
+ "path"
"strings"
)
@@ -12,30 +12,32 @@ import (
// - Removes trailing slashes (except for root "/")
//
// This is used by most filesystem implementations (memfs, sqlfs, httpfs, etc.)
-func NormalizePath(path string) string {
- if path == "" || path == "/" {
+func NormalizePath(p string) string {
+ if p == "" || p == "/" {
return "/"
}
// Ensure leading slash
- if !strings.HasPrefix(path, "/") {
- path = "/" + path
+ if !strings.HasPrefix(p, "/") {
+ p = "/" + p
}
// Clean the path (resolve .., ., etc.)
- path = filepath.Clean(path)
+ // Use path.Clean instead of filepath.Clean to ensure consistency across OS
+ // and always use forward slashes for VFS paths
+ p = path.Clean(p)
- // filepath.Clean can return "." for some inputs
- if path == "." {
+ // path.Clean can return "." for some inputs
+ if p == "." {
return "/"
}
// Remove trailing slash (Clean might leave it in some cases)
- if len(path) > 1 && strings.HasSuffix(path, "/") {
- path = path[:len(path)-1]
+ if len(p) > 1 && strings.HasSuffix(p, "/") {
+ p = p[:len(p)-1]
}
- return path
+ return p
}
// NormalizeS3Key normalizes an S3 object key.
@@ -45,21 +47,22 @@ func NormalizePath(path string) string {
// - Cleans the path
//
// This is used specifically by s3fs plugin.
-func NormalizeS3Key(path string) string {
- if path == "" || path == "/" {
+func NormalizeS3Key(p string) string {
+ if p == "" || p == "/" {
return ""
}
// Remove leading slash (S3 keys don't have them)
- path = strings.TrimPrefix(path, "/")
+ p = strings.TrimPrefix(p, "/")
// Clean the path
- path = filepath.Clean(path)
+ // Use path.Clean instead of filepath.Clean
+ p = path.Clean(p)
- // filepath.Clean returns "." for empty/root paths
- if path == "." {
+ // path.Clean returns "." for empty/root paths
+ if p == "." {
return ""
}
- return path
+ return p
}
diff --git a/third_party/agfs/agfs-server/pkg/handlers/handlers.go b/third_party/agfs/agfs-server/pkg/handlers/handlers.go
index c5278963e..10a2aa23b 100644
--- a/third_party/agfs/agfs-server/pkg/handlers/handlers.go
+++ b/third_party/agfs/agfs-server/pkg/handlers/handlers.go
@@ -10,7 +10,7 @@ import (
"fmt"
"io"
"net/http"
- "path/filepath"
+ "path"
"regexp"
"strconv"
"time"
@@ -1002,9 +1002,8 @@ func (h *Handler) grepDirectoryStream(dirPath string, re *regexp.Regexp, callbac
for _, entry := range entries {
// Build full path
- fullPath := filepath.Join(dirPath, entry.Name)
- // Clean path to use forward slashes
- fullPath = filepath.ToSlash(fullPath)
+ // Use path.Join for VFS paths to ensure forward slashes on all OS
+ fullPath := path.Join(dirPath, entry.Name)
if entry.IsDir {
// Recursively search subdirectories
@@ -1070,9 +1069,8 @@ func (h *Handler) grepDirectory(dirPath string, re *regexp.Regexp) ([]GrepMatch,
for _, entry := range entries {
// Build full path
- fullPath := filepath.Join(dirPath, entry.Name)
- // Clean path to use forward slashes
- fullPath = filepath.ToSlash(fullPath)
+ // Use path.Join for VFS paths to ensure forward slashes on all OS
+ fullPath := path.Join(dirPath, entry.Name)
if entry.IsDir {
// Recursively search subdirectories
diff --git a/third_party/agfs/agfs-server/pkg/plugins/localfs/localfs.go b/third_party/agfs/agfs-server/pkg/plugins/localfs/localfs.go
index c0d287f73..c0df1b094 100644
--- a/third_party/agfs/agfs-server/pkg/plugins/localfs/localfs.go
+++ b/third_party/agfs/agfs-server/pkg/plugins/localfs/localfs.go
@@ -5,6 +5,7 @@ import (
"io"
"os"
"path/filepath"
+ "strings"
"sync"
"time"
@@ -54,10 +55,16 @@ func NewLocalFS(basePath string) (*LocalFS, error) {
// resolvePath resolves a virtual path to the actual local path
func (fs *LocalFS) resolvePath(path string) string {
- // Clean the path and ensure it starts with /
- cleanPath := filepath.Clean("/" + path)
- // Remove leading / and join with base path
- relativePath := filepath.Clean(cleanPath[1:])
+ // Remove leading slash to make it relative (VFS paths always start with /)
+ relativePath := strings.TrimPrefix(path, "/")
+
+ // Convert to OS-specific path separators
+ // On Windows, this converts "/" to "\"
+ relativePath = filepath.FromSlash(relativePath)
+
+ // Clean the path
+ relativePath = filepath.Clean(relativePath)
+
if relativePath == "." {
return fs.basePath
}
diff --git a/third_party/agfs/agfs-server/pkg/plugins/queuefs/queuefs.go b/third_party/agfs/agfs-server/pkg/plugins/queuefs/queuefs.go
index 970e17690..8b247a854 100644
--- a/third_party/agfs/agfs-server/pkg/plugins/queuefs/queuefs.go
+++ b/third_party/agfs/agfs-server/pkg/plugins/queuefs/queuefs.go
@@ -5,7 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
- "path/filepath"
+ "path"
"strconv"
"strings"
"sync"
@@ -388,19 +388,19 @@ var queueOperations = map[string]bool{
// parseQueuePath parses a path like "/queue_name/operation" or "/dir/queue_name/operation"
// Returns (queueName, operation, isDir, error)
-func parseQueuePath(path string) (queueName string, operation string, isDir bool, err error) {
+func parseQueuePath(p string) (queueName string, operation string, isDir bool, err error) {
// Clean the path
- path = filepath.Clean(path)
+ p = path.Clean(p)
- if path == "/" || path == "." {
+ if p == "/" || p == "." {
return "", "", true, nil
}
// Remove leading slash
- path = strings.TrimPrefix(path, "/")
+ p = strings.TrimPrefix(p, "/")
// Split path into components
- parts := strings.Split(path, "/")
+ parts := strings.Split(p, "/")
if len(parts) == 0 {
return "", "", true, nil
@@ -754,8 +754,8 @@ func (qfs *queueFS) getQueueControlFiles(queueName string, now time.Time) ([]fil
return files, nil
}
-func (qfs *queueFS) Stat(path string) (*filesystem.FileInfo, error) {
- if path == "/" {
+func (qfs *queueFS) Stat(p string) (*filesystem.FileInfo, error) {
+ if p == "/" {
return &filesystem.FileInfo{
Name: "/",
Size: 0,
@@ -772,7 +772,7 @@ func (qfs *queueFS) Stat(path string) (*filesystem.FileInfo, error) {
}
// Special case: README at root
- if path == "/README" {
+ if p == "/README" {
readme := qfs.plugin.GetReadme()
return &filesystem.FileInfo{
Name: "README",
@@ -784,7 +784,7 @@ func (qfs *queueFS) Stat(path string) (*filesystem.FileInfo, error) {
}, nil
}
- queueName, operation, isDir, err := parseQueuePath(path)
+ queueName, operation, isDir, err := parseQueuePath(p)
if err != nil {
return nil, err
}
@@ -793,7 +793,7 @@ func (qfs *queueFS) Stat(path string) (*filesystem.FileInfo, error) {
// Directory stat
if isDir {
- name := filepath.Base(path)
+ name := path.Base(p)
if name == "." || name == "/" {
name = "/"
}
@@ -823,7 +823,7 @@ func (qfs *queueFS) Stat(path string) (*filesystem.FileInfo, error) {
}
if !hasChildren {
qfs.plugin.mu.RUnlock()
- return nil, fmt.Errorf("no such file or directory: %s", path)
+ return nil, fmt.Errorf("no such file or directory: %s", p)
}
}
qfs.plugin.mu.RUnlock()
@@ -840,7 +840,7 @@ func (qfs *queueFS) Stat(path string) (*filesystem.FileInfo, error) {
// Control file stat
if operation == "" {
- return nil, fmt.Errorf("no such file: %s", path)
+ return nil, fmt.Errorf("no such file: %s", p)
}
mode := uint32(0644)