From 20478f6e7d65cf640938736c59a0672b9703b2ba Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 31 Mar 2026 18:03:06 +0000 Subject: [PATCH 1/2] Initial plan From 8739507869800ec3be27e80ba209a9311d9e12be Mon Sep 17 00:00:00 2001 From: Landon Cox Date: Tue, 31 Mar 2026 13:49:38 -0700 Subject: [PATCH 2/2] refactor: deduplicate withLock() across logger types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add withMutexLock() helper in global_helpers.go and delegate all four identical withLock() methods to it. Zero behavior change — locking semantics are preserved exactly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- internal/logger/file_logger.go | 4 +--- internal/logger/global_helpers.go | 9 +++++++++ internal/logger/jsonl_logger.go | 4 +--- internal/logger/markdown_logger.go | 4 +--- internal/logger/tools_logger.go | 4 +--- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/logger/file_logger.go b/internal/logger/file_logger.go index 9038e9a9..da2c6079 100644 --- a/internal/logger/file_logger.go +++ b/internal/logger/file_logger.go @@ -59,9 +59,7 @@ func InitFileLogger(logDir, fileName string) error { // withLock acquires fl.mu, executes fn, then releases fl.mu. // Use this in methods that return an error to avoid repeating the lock/unlock preamble. func (fl *FileLogger) withLock(fn func() error) error { - fl.mu.Lock() - defer fl.mu.Unlock() - return fn() + return withMutexLock(&fl.mu, fn) } // Close closes the log file diff --git a/internal/logger/global_helpers.go b/internal/logger/global_helpers.go index 2bec733e..d702f94a 100644 --- a/internal/logger/global_helpers.go +++ b/internal/logger/global_helpers.go @@ -16,6 +16,15 @@ package logger import "sync" +// withMutexLock acquires mu, calls fn, and releases mu. +// This is the single implementation of the per-type withLock pattern +// used by FileLogger, JSONLLogger, MarkdownLogger, and ToolsLogger. +func withMutexLock(mu *sync.Mutex, fn func() error) error { + mu.Lock() + defer mu.Unlock() + return fn() +} + // closableLogger is a constraint for types that have a Close method. // This is satisfied by *FileLogger, *JSONLLogger, *MarkdownLogger, *ServerFileLogger, and *ToolsLogger. type closableLogger interface { diff --git a/internal/logger/jsonl_logger.go b/internal/logger/jsonl_logger.go index cbbb3631..ff14a148 100644 --- a/internal/logger/jsonl_logger.go +++ b/internal/logger/jsonl_logger.go @@ -70,9 +70,7 @@ func InitJSONLLogger(logDir, fileName string) error { // withLock acquires jl.mu, executes fn, then releases jl.mu. // Use this in methods that return an error to avoid repeating the lock/unlock preamble. func (jl *JSONLLogger) withLock(fn func() error) error { - jl.mu.Lock() - defer jl.mu.Unlock() - return fn() + return withMutexLock(&jl.mu, fn) } // Close closes the JSONL log file diff --git a/internal/logger/markdown_logger.go b/internal/logger/markdown_logger.go index aaa8e020..7a9d4ffa 100644 --- a/internal/logger/markdown_logger.go +++ b/internal/logger/markdown_logger.go @@ -71,9 +71,7 @@ func (ml *MarkdownLogger) initializeFile() error { // withLock acquires ml.mu, executes fn, then releases ml.mu. // Use this in methods that return an error to avoid repeating the lock/unlock preamble. func (ml *MarkdownLogger) withLock(fn func() error) error { - ml.mu.Lock() - defer ml.mu.Unlock() - return fn() + return withMutexLock(&ml.mu, fn) } // Close closes the log file and writes the closing details tag diff --git a/internal/logger/tools_logger.go b/internal/logger/tools_logger.go index b1f7952f..afd5b1b4 100644 --- a/internal/logger/tools_logger.go +++ b/internal/logger/tools_logger.go @@ -84,9 +84,7 @@ func InitToolsLogger(logDir, fileName string) error { // withLock acquires tl.mu, executes fn, then releases tl.mu. // Use this in methods that return an error to avoid repeating the lock/unlock preamble. func (tl *ToolsLogger) withLock(fn func() error) error { - tl.mu.Lock() - defer tl.mu.Unlock() - return fn() + return withMutexLock(&tl.mu, fn) } // LogTools logs the tools for a specific server