on main help sign in
fix: clear regex cache on new session to prevent unbounded growth (#2161)
commit22ed1e5d39ab871ae30219631c213dba6906556d authorM1xA <AnyCPU@users.noreply.github.com> dateTue 10 Feb 2026, 20:50 (8 months ago) parentd6643a6
2 files changed+13
internal/agent/tools/grep.go+11 internal/ui/model/ui.go+2
internal/agent/tools/grep.go+11
@@ -64,6 +64,17 @@ func (rc *regexCache) get(pattern string) (*regexp.Regexp, error) {
6464 return regex, nil
6565}
6666
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+
6778// Global regex cache instances
6879var (
6980 searchRegexCache = newRegexCache()
internal/ui/model/ui.go+2
@@ -24,6 +24,7 @@ import (
2424 tea "charm.land/bubbletea/v2"
2525 "charm.land/catwalk/pkg/catwalk"
2626 "charm.land/lipgloss/v2"
27+ agenttools "github.com/charmbracelet/crush/internal/agent/tools"
2728 "github.com/charmbracelet/crush/internal/agent/tools/mcp"
2829 "github.com/charmbracelet/crush/internal/app"
2930 "github.com/charmbracelet/crush/internal/commands"
@@ -2986,6 +2987,7 @@ func (m *UI) newSession() tea.Cmd {
29862987 m.promptQueue = 0
29872988 m.pillsView = ""
29882989 m.historyReset()
2990+ agenttools.ResetCache()
29892991 return tea.Batch(
29902992 func() tea.Msg {
29912993 m.com.App.LSPManager.StopAll(context.Background())