Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(daemon): skip duplicate SKILL.md in supporting files to prevent task prep failures (#3526)
MSandro996eb07dc5b0
diff --git a/server/internal/daemon/execenv/context.go b/server/internal/daemon/execenv/context.goindex 7ae1bc24ad..d1ddf1dc58 100644--- a/server/internal/daemon/execenv/context.go+++ b/server/internal/daemon/execenv/context.go@@ -365,7 +365,14 @@ func writeSkillFiles(skillsDir string, skills []SkillContextForEnv, manifest *si// it would mean the skill's bundled files list two entries// at the same path — that's an upstream data bug, not a// user-content collision, and we surface it.+ //+ // One common data bug is storing SKILL.md as both the primary+ // content (skill.Content) and as a supporting file. Skip the+ // duplicate so the agent still gets every unique file.for _, f := range skill.Files {+ if strings.EqualFold(f.Path, "SKILL.md") {+ continue+ }fpath := filepath.Join(dir, f.Path)if err := recordMkdirAll(filepath.Dir(fpath), 0o755, manifest); err != nil {return errdiff --git a/server/internal/handler/handler_test.go b/server/internal/handler/handler_test.goindex 69e48d1026..aa78b4ea40 100644--- a/server/internal/handler/handler_test.go+++ b/server/internal/handler/handler_test.go@@ -3609,3 +3609,189 @@ func TestAgentExplicitMentionStillTriggers(t *testing.T) {t.Fatalf("expected 0 tasks for Agent A (no self-trigger on own mention), got %d", got)}}++func TestCreateSkillSkipsSkillMdFile(t *testing.T) {+ if testPool == nil {+ t.Skip("no database available")+ }++ req := newRequest(http.MethodPost, "/api/workspaces/"+testWorkspaceID+"/skills", CreateSkillRequest{+ Name: "test-skill-create-skip-skillmd",+ Content: "# SKILL.md content",+ Files: []CreateSkillFileRequest{+ {Path: "README.md", Content: "readme"},+ {Path: "SKILL.md", Content: "should be skipped"},+ {Path: "helper.go", Content: "package main"},+ },+ })+ rec := httptest.NewRecorder()+ testHandler.CreateSkill(rec, req)++ if rec.Code != http.StatusCreated {+ t.Fatalf("expected 201, got %d: %s", rec.Code, rec.Body.String())+ }++ var resp SkillWithFilesResponse+ if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {+ t.Fatalf("unmarshal response: %v", err)+ }++ // Should only have README.md and helper.go, not SKILL.md+ if len(resp.Files) != 2 {+ t.Fatalf("expected 2 files, got %d", len(resp.Files))+ }+ for _, f := range resp.Files {+ if strings.EqualFold(f.Path, "SKILL.md") {+ t.Fatalf("SKILL.md should not be in response files")+ }+ }++ // Verify DB state directly+ ctx := context.Background()+ rows, err := testPool.Query(ctx, "SELECT path FROM skill_file WHERE skill_id = $1", resp.ID)+ if err != nil {+ t.Fatalf("query skill_file: %v", err)+ }+ defer rows.Close()++ var paths []string+ for rows.Next() {+ var p string+ if err := rows.Scan(&p); err != nil {+ t.Fatalf("scan path: %v", err)+ }+ paths = append(paths, p)+ }+ if len(paths) != 2 {+ t.Fatalf("expected 2 rows in skill_file, got %d", len(paths))+ }+ for _, p := range paths {+ if strings.EqualFold(p, "SKILL.md") {+ t.Fatalf("SKILL.md should not be stored in skill_file")+ }+ }+}++func TestUpdateSkillSkipsSkillMdFile(t *testing.T) {+ if testPool == nil {+ t.Skip("no database available")+ }++ // Create a skill first+ req := newRequest(http.MethodPost, "/api/workspaces/"+testWorkspaceID+"/skills", CreateSkillRequest{+ Name: "test-skill-update-skip-skillmd",+ Content: "# SKILL.md content",+ Files: []CreateSkillFileRequest{+ {Path: "README.md", Content: "readme"},+ },+ })+ rec := httptest.NewRecorder()+ testHandler.CreateSkill(rec, req)+ if rec.Code != http.StatusCreated {+ t.Fatalf("create skill: expected 201, got %d: %s", rec.Code, rec.Body.String())+ }++ var createResp SkillWithFilesResponse+ if err := json.Unmarshal(rec.Body.Bytes(), &createResp); err != nil {+ t.Fatalf("unmarshal create response: %v", err)+ }++ // Update with SKILL.md in files+ updateReq := newRequest(http.MethodPut, "/api/skills/"+createResp.ID, UpdateSkillRequest{+ Name: strPtr("updated-name"),+ Content: strPtr("updated content"),+ Files: []CreateSkillFileRequest{+ {Path: "README.md", Content: "updated readme"},+ {Path: "SKILL.md", Content: "should be skipped"},+ {Path: "new.go", Content: "package main"},+ },+ })+ updateReq = withURLParam(updateReq, "id", createResp.ID)+ updateRec := httptest.NewRecorder()+ testHandler.UpdateSkill(updateRec, updateReq)++ if updateRec.Code != http.StatusOK {+ t.Fatalf("update skill: expected 200, got %d: %s", updateRec.Code, updateRec.Body.String())+ }++ var updateResp SkillWithFilesResponse+ if err := json.Unmarshal(updateRec.Body.Bytes(), &updateResp); err != nil {+ t.Fatalf("unmarshal update response: %v", err)+ }++ if len(updateResp.Files) != 2 {+ t.Fatalf("expected 2 files after update, got %d", len(updateResp.Files))+ }+ for _, f := range updateResp.Files {+ if strings.EqualFold(f.Path, "SKILL.md") {+ t.Fatalf("SKILL.md should not be in updated response files")+ }+ }++ // Verify DB state+ ctx := context.Background()+ rows, err := testPool.Query(ctx, "SELECT path FROM skill_file WHERE skill_id = $1", createResp.ID)+ if err != nil {+ t.Fatalf("query skill_file: %v", err)+ }+ defer rows.Close()++ var paths []string+ for rows.Next() {+ var p string+ if err := rows.Scan(&p); err != nil {+ t.Fatalf("scan path: %v", err)+ }+ paths = append(paths, p)+ }+ if len(paths) != 2 {+ t.Fatalf("expected 2 rows in skill_file after update, got %d", len(paths))+ }+ for _, p := range paths {+ if strings.EqualFold(p, "SKILL.md") {+ t.Fatalf("SKILL.md should not be stored in skill_file after update")+ }+ }+}++func strPtr(s string) *string {+ return &s+}++func TestUpsertSkillFileRejectsSkillMd(t *testing.T) {+ if testPool == nil {+ t.Skip("no database available")+ }++ // Create a skill first+ req := newRequest(http.MethodPost, "/api/workspaces/"+testWorkspaceID+"/skills", CreateSkillRequest{+ Name: "test-skill-upsert-reject-skillmd",+ Content: "# SKILL.md content",+ })+ rec := httptest.NewRecorder()+ testHandler.CreateSkill(rec, req)+ if rec.Code != http.StatusCreated {+ t.Fatalf("create skill: expected 201, got %d: %s", rec.Code, rec.Body.String())+ }++ var createResp SkillWithFilesResponse+ if err := json.Unmarshal(rec.Body.Bytes(), &createResp); err != nil {+ t.Fatalf("unmarshal create response: %v", err)+ }++ // Try to upsert SKILL.md+ upsertReq := newRequest(http.MethodPut, "/api/skills/"+createResp.ID+"/files", CreateSkillFileRequest{+ Path: "SKILL.md",+ Content: "should be rejected",+ })+ upsertReq = withURLParam(upsertReq, "id", createResp.ID)+ upsertRec := httptest.NewRecorder()+ testHandler.UpsertSkillFile(upsertRec, upsertReq)++ if upsertRec.Code != http.StatusBadRequest {+ t.Fatalf("expected 400, got %d: %s", upsertRec.Code, upsertRec.Body.String())+ }+ if !strings.Contains(upsertRec.Body.String(), "SKILL.md is reserved") {+ t.Fatalf("expected error message about reserved SKILL.md, got: %s", upsertRec.Body.String())+ }+}diff --git a/server/internal/handler/skill.go b/server/internal/handler/skill.goindex fd925af7e5..8875357dc4 100644--- a/server/internal/handler/skill.go+++ b/server/internal/handler/skill.go@@ -458,6 +458,10 @@ func (h *Handler) UpdateSkill(w http.ResponseWriter, r *http.Request) {}fileResps = make([]SkillFileResponse, 0, len(req.Files))for _, f := range req.Files {+ // SKILL.md is reserved for the primary skill content (skill.Content).+ if strings.EqualFold(f.Path, "SKILL.md") {+ continue+ }sf, err := qtx.UpsertSkillFile(r.Context(), db.UpsertSkillFileParams{SkillID: skill.ID,Path: sanitizeNullBytes(f.Path),@@ -1844,6 +1848,10 @@ func (h *Handler) UpsertSkillFile(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusBadRequest, "invalid file path")return}+ if strings.EqualFold(req.Path, "SKILL.md") {+ writeError(w, http.StatusBadRequest, "SKILL.md is reserved for the primary skill content")+ return+ }sf, err := h.Queries.UpsertSkillFile(r.Context(), db.UpsertSkillFileParams{SkillID: skill.ID,diff --git a/server/internal/handler/skill_create.go b/server/internal/handler/skill_create.goindex 554ef54911..dc86842c6a 100644--- a/server/internal/handler/skill_create.go+++ b/server/internal/handler/skill_create.go@@ -3,6 +3,7 @@ package handlerimport ("context""encoding/json"+ "strings""github.com/jackc/pgx/v5/pgtype"db "github.com/multica-ai/multica/server/pkg/db/generated"@@ -46,6 +47,11 @@ func createSkillWithFilesInTx(ctx context.Context, qtx *db.Queries, input skillCfileResps := make([]SkillFileResponse, 0, len(input.Files))for _, f := range input.Files {+ // SKILL.md is reserved for the primary skill content (skill.Content).+ // Supporting files must carry additional assets, not duplicate the main file.+ if strings.EqualFold(f.Path, "SKILL.md") {+ continue+ }sf, err := qtx.UpsertSkillFile(ctx, db.UpsertSkillFileParams{SkillID: skill.ID,Path: sanitizeNullBytes(f.Path),