on main help sign in
fix: clear regex cache on new session to prevent unbounded growth (#2161)
22ed1e5M1xA
internal/agent/tools/grep.go+11
@@ -64,6 +64,17 @@ func (rc *regexCache) get(pattern string) (*regexp.Regexp, error) {
64 return regex, nil
64 return regex, nil
65}
65}
66
66
67+// ResetCache clears compiled regex caches to prevent unbounded growth across sessions.
68+func ResetCache() {
69+ searchRegexCache.mu.Lock()
70+ clear(searchRegexCache.cache)
71+ searchRegexCache.mu.Unlock()
72+
73+ globRegexCache.mu.Lock()
74+ clear(globRegexCache.cache)
75+ globRegexCache.mu.Unlock()
76+}
77+
67// Global regex cache instances
78// Global regex cache instances
68var (
79var (
69 searchRegexCache = newRegexCache()
80 searchRegexCache = newRegexCache()
internal/ui/model/ui.go+2
@@ -24,6 +24,7 @@ import (
24 tea "charm.land/bubbletea/v2"
24 tea "charm.land/bubbletea/v2"
25 "charm.land/catwalk/pkg/catwalk"
25 "charm.land/catwalk/pkg/catwalk"
26 "charm.land/lipgloss/v2"
26 "charm.land/lipgloss/v2"
27+ agenttools "github.com/charmbracelet/crush/internal/agent/tools"
27 "github.com/charmbracelet/crush/internal/agent/tools/mcp"
28 "github.com/charmbracelet/crush/internal/agent/tools/mcp"
28 "github.com/charmbracelet/crush/internal/app"
29 "github.com/charmbracelet/crush/internal/app"
29 "github.com/charmbracelet/crush/internal/commands"
30 "github.com/charmbracelet/crush/internal/commands"
@@ -2986,6 +2987,7 @@ func (m *UI) newSession() tea.Cmd {
2986 m.promptQueue = 0
2987 m.promptQueue = 0
2987 m.pillsView = ""
2988 m.pillsView = ""
2988 m.historyReset()
2989 m.historyReset()
2990+ agenttools.ResetCache()
2989 return tea.Batch(
2991 return tea.Batch(
2990 func() tea.Msg {
2992 func() tea.Msg {
2991 m.com.App.LSPManager.StopAll(context.Background())
2993 m.com.App.LSPManager.StopAll(context.Background())