Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-6445: fix(daemon): keep skill cache failures from blocking skill loads (#7277)
Jamison-J0d036ee5aebb
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.goindex fcec46588d..60b20168c1 100644--- a/server/internal/daemon/daemon.go+++ b/server/internal/daemon/daemon.go@@ -6004,7 +6004,15 @@ func (d *Daemon) resolveSkillBundle(ctx context.Context, task *Task, ref SkillReif err := d.skillCache.WithRefLock(task.WorkspaceID, validationRef, func() error {return d.skillCache.Store(task.WorkspaceID, bundle)}); err != nil {- return SkillData{}, fmt.Errorf("store skill bundle cache: %w", err)+ if d.logger != nil {+ d.logger.Warn("skill bundle cache store failed; continuing with downloaded bundle",+ "workspace_id", task.WorkspaceID,+ "skill_id", bundle.ID,+ "source", bundle.Source,+ "hash", bundle.Hash,+ "error", err,+ )+ }}return bundle, nil}diff --git a/server/internal/daemon/skill_bundle_resolve_test.go b/server/internal/daemon/skill_bundle_resolve_test.goindex 50c50ae781..bf7db94cd5 100644--- a/server/internal/daemon/skill_bundle_resolve_test.go+++ b/server/internal/daemon/skill_bundle_resolve_test.go@@ -4,6 +4,7 @@ import ("context""encoding/json""errors"+ "io/fs""net/http""net/http/httptest""strings"@@ -233,6 +234,36 @@ func TestEnsureTaskSkillBundles_AcceptsServerSideSkillUpdate(t *testing.T) {}}+func TestEnsureTaskSkillBundles_CacheRemovalFailureDoesNotDiscardDownloadedBundle(t *testing.T) {+ bundle := makeResolvableSkillBundle("skill-1")+ ref := skillRefFromBundle(bundle)+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {+ w.Header().Set("Content-Type", "application/json")+ json.NewEncoder(w).Encode(map[string]any{"bundles": []SkillData{bundle}})+ }))+ defer server.Close()++ cache := NewSkillBundleCache(t.TempDir())+ cache.removeAll = func(string) error { return fs.ErrPermission }+ daemon := &Daemon{client: NewClient(server.URL), skillCache: cache}+ task := &Task{+ ID: "task-1",+ RuntimeID: "rt-1",+ WorkspaceID: "ws-1",+ Agent: &AgentData{ID: "agent-1", SkillRefs: []SkillRefData{ref}},+ }++ if err := daemon.ensureTaskSkillBundles(context.Background(), task); err != nil {+ t.Fatalf("cache removal failure must not discard a downloaded bundle: %v", err)+ }+ if len(task.Agent.Skills) != 1 || task.Agent.Skills[0].Hash != bundle.Hash {+ t.Fatalf("downloaded bundle was not attached to the task: %+v", task.Agent.Skills)+ }+ if _, ok := cache.Load(task.WorkspaceID, ref); ok {+ t.Fatal("bundle must not appear cached after the removal failure")+ }+}+func TestEnsureTaskSkillBundles_RejectsPluginHashDrift(t *testing.T) {defer noSleepRetry(t)()diff --git a/server/internal/daemon/skill_cache.go b/server/internal/daemon/skill_cache.goindex 9c288bbb4b..ef598c354a 100644--- a/server/internal/daemon/skill_cache.go+++ b/server/internal/daemon/skill_cache.go@@ -2,7 +2,9 @@ package daemonimport ("encoding/json"+ "errors""fmt"+ "io/fs""os""path""path/filepath"@@ -13,13 +15,20 @@ import ()type SkillBundleCache struct {- root string- mu sync.Mutex- locks map[string]*sync.Mutex+ root string+ rename func(string, string) error+ removeAll func(string) error+ mu sync.Mutex+ locks map[string]*sync.Mutex}func NewSkillBundleCache(root string) *SkillBundleCache {- return &SkillBundleCache{root: root, locks: make(map[string]*sync.Mutex)}+ return &SkillBundleCache{+ root: root,+ rename: os.Rename,+ removeAll: os.RemoveAll,+ locks: make(map[string]*sync.Mutex),+ }}func (c *SkillBundleCache) Load(workspaceID string, ref SkillRefData) (SkillData, bool) {@@ -64,10 +73,20 @@ func (c *SkillBundleCache) Store(workspaceID string, bundle SkillData) error {if err := os.WriteFile(filepath.Join(tmp, "bundle.json"), data, 0o644); err != nil {return err}- _ = os.RemoveAll(dir)- if err := os.Rename(tmp, dir); err != nil {+ if err := c.removeAll(dir); err != nil {return err}+ if err := c.rename(tmp, dir); err != nil {+ if !errors.Is(err, fs.ErrExist) {+ return err+ }+ if err := c.removeAll(dir); err != nil {+ return err+ }+ if err := c.rename(tmp, dir); err != nil {+ return err+ }+ }return nil}diff --git a/server/internal/daemon/skill_cache_test.go b/server/internal/daemon/skill_cache_test.goindex f688286bd5..a641d281c5 100644--- a/server/internal/daemon/skill_cache_test.go+++ b/server/internal/daemon/skill_cache_test.go@@ -1,7 +1,9 @@package daemonimport (+ "io/fs""os"+ "path/filepath""testing")@@ -22,6 +24,36 @@ func TestSkillBundleCacheLoadStore(t *testing.T) {}}+func TestSkillBundleCacheStoreRetriesRenameWhenDestinationExists(t *testing.T) {+ cache := NewSkillBundleCache(t.TempDir())+ bundle := testSkillBundle()+ ref := skillRefFromBundle(bundle)+ renameCalls := 0+ cache.rename = func(oldPath, newPath string) error {+ renameCalls+++ if renameCalls == 1 {+ if err := os.MkdirAll(newPath, 0o755); err != nil {+ return err+ }+ return &os.LinkError{Op: "rename", Old: oldPath, New: newPath, Err: fs.ErrExist}+ }+ return os.Rename(oldPath, newPath)+ }++ if err := cache.Store("ws-1", bundle); err != nil {+ t.Fatalf("Store: %v", err)+ }+ if renameCalls != 2 {+ t.Fatalf("rename calls = %d, want 2", renameCalls)+ }+ if _, ok := cache.Load("ws-1", ref); !ok {+ t.Fatal("expected cache hit after EEXIST recovery")+ }+ if _, err := os.Stat(filepath.Dir(cache.bundlePath("ws-1", ref))); err != nil {+ t.Fatalf("stat stored bundle directory: %v", err)+ }+}+func TestSkillBundleCacheRejectsCorruptBundle(t *testing.T) {cache := NewSkillBundleCache(t.TempDir())bundle := testSkillBundle()