Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## [Unreleased]

## [0.8.1] - 2026-05-25

### Fixed

- **skills plugin**: guard skill cache with `sync.RWMutex` so parallel tool calls no longer crash with `fatal error: concurrent map writes` ([#53](https://github.com/thinktwiceco/agent-forge/issues/53))

## [0.8.0] - 2026-05-25
- [f9fe70a](http://github.com/thinktwiceco/agent-forge/commit/f9fe70ad04f1272d7e7d17d510c7cca041f5ed66) - chore(release): prepare release v0.8.0

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.0
0.8.1
12 changes: 12 additions & 0 deletions src/plugins/skills/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"sort"
"strings"
"sync"

agentforge "github.com/thinktwiceco/agent-forge/src"
"github.com/thinktwiceco/agent-forge/src/agents"
Expand Down Expand Up @@ -50,6 +51,7 @@ type Skill struct {
// skills, and inspect references on demand.
type SkillsPlugin struct {
dir string
mu sync.RWMutex
skills map[string]*Skill
}

Expand Down Expand Up @@ -90,6 +92,9 @@ func (p *SkillsPlugin) Hooks() map[core.Event]core.AgentHookFn {
// SystemPrompt implements core.PromptProvider.
// Returns a prompt section listing all discovered skills.
func (p *SkillsPlugin) SystemPrompt() string {
p.mu.RLock()
defer p.mu.RUnlock()

if len(p.skills) == 0 {
return ""
}
Expand Down Expand Up @@ -130,6 +135,9 @@ func (p *SkillsPlugin) Tools() []llms.Tool {

// loadSkills scans skills/ for SKILL.md-based skill packages.
func (p *SkillsPlugin) loadSkills() error {
p.mu.Lock()
defer p.mu.Unlock()

p.skills = make(map[string]*Skill)

entries, err := os.ReadDir(p.dir)
Expand Down Expand Up @@ -167,6 +175,10 @@ func (p *SkillsPlugin) getSkill(name string) (*Skill, error) {
if err := p.loadSkills(); err != nil {
return nil, err
}

p.mu.RLock()
defer p.mu.RUnlock()

skill, exists := p.skills[name]
if !exists {
return nil, fmt.Errorf("skill '%s' not found", name)
Expand Down
42 changes: 42 additions & 0 deletions src/plugins/skills/skills_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,48 @@ func TestSkillToolInstallRemoteSkill(t *testing.T) {
}
}

func TestGetSkill_ConcurrentNoRace(t *testing.T) {
root := t.TempDir()
skillDir := filepath.Join(root, "skills", "concurrent-skill")
if err := os.MkdirAll(filepath.Join(skillDir, "references"), 0755); err != nil {
t.Fatal(err)
}
writeTestSkill(t, skillDir, "concurrent-skill", "Concurrent access test", "Use when testing parallel skill lookups.")
if err := os.WriteFile(filepath.Join(skillDir, "references", "notes.md"), []byte("reference body"), 0644); err != nil {
t.Fatal(err)
}

plugin := NewSkillsPlugin(root)
tool := newSkillTool(plugin)

const workers = 32
var wg sync.WaitGroup
wg.Add(workers)
for i := 0; i < workers; i++ {
go func() {
defer wg.Done()
skill, err := plugin.getSkill("concurrent-skill")
if err != nil {
t.Error(err)
return
}
if skill.Name != "concurrent-skill" {
t.Errorf("unexpected skill name: %q", skill.Name)
}

refResp := tool.Call(nil, map[string]any{
"action": "load_skill_reference",
"name": "concurrent-skill",
"referencePath": "notes.md",
})
if !refResp.Success() || !strings.Contains(refResp.Data(), "reference body") {
t.Errorf("load_skill_reference response: success=%v data=%q err=%q", refResp.Success(), refResp.Data(), refResp.Error())
}
}()
}
wg.Wait()
}

func writeTestSkill(t *testing.T, dir, name, description, usage string) {
t.Helper()
if err := os.MkdirAll(dir, 0755); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/skills/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func (p *SkillsPlugin) handleListSkills() llms.ToolReturn {
if err := p.loadSkills(); err != nil {
return core.NewErrorResponse(fmt.Sprintf("failed to load skills: %v", err))
}

p.mu.RLock()
defer p.mu.RUnlock()

if len(p.skills) == 0 {
return core.NewEphemeralResponse("No skills found under skills/.")
}
Expand Down
Loading