From 3043c1573f2294f7846f884a05e9b5adef99748c Mon Sep 17 00:00:00 2001 From: Matthew Pilot Date: Thu, 28 May 2026 05:24:12 +0000 Subject: [PATCH] fix: filter subdirectories before inbox cap check in evictInboxOverflow (PILOT-183) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit evictInboxOverflow counted subdirectory entries in the initial len(entries) <= cap short-circuit at line 307. If a mailbox had cap real files plus one subdir, the guard let us through — but after filtering IsDir() in the collection pass, len(files) == cap and the second check returned silently. Subdirs poisoned the eviction trigger, causing mailbox to grow unbounded. Fix: count only !e.IsDir() entries for the initial capacity guard, so subdirectories never inflate the file count. --- service.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/service.go b/service.go index f669950..0c1ec2c 100644 --- a/service.go +++ b/service.go @@ -304,7 +304,16 @@ func (s *Service) evictInboxOverflow(dir string) { slog.Debug("inbox evict: readdir", "dir", dir, "err", err) return } - if len(entries) <= cap { + // Only count regular files against the cap; + // subdirectories (e.g. conversation folders) must + // not poison the eviction trigger. + fileCnt := 0 + for _, e := range entries { + if !e.IsDir() { + fileCnt++ + } + } + if fileCnt <= cap { return } type aged struct {