Conversation
Add a package-level withMutexLock helper to global_helpers.go and have each logger's withLock method delegate to it, eliminating 4 identical lock/unlock bodies. Before: each of FileLogger, JSONLLogger, MarkdownLogger, and ToolsLogger contained an identical withLock implementation — 3 lines each, 12 total. After: each delegates to withMutexLock in one line; the canonical implementation lives in one place. Zero behaviour change: same mutex, same defer, same return path. Closes #2908 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the internal/logger package to remove duplicated mutex lock/unlock boilerplate by centralizing the common pattern in a single helper, while keeping the existing per-logger withLock methods unchanged for callers.
Changes:
- Added a package-level
withMutexLock(*sync.Mutex, func() error) errorhelper inglobal_helpers.go. - Updated
withLockimplementations inFileLogger,JSONLLogger,MarkdownLogger, andToolsLoggerto delegate to the shared helper.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/logger/global_helpers.go | Adds the shared withMutexLock helper used to standardize lock/unlock behavior. |
| internal/logger/file_logger.go | Replaces inlined mu.Lock()/Unlock() in withLock with the shared helper. |
| internal/logger/jsonl_logger.go | Replaces inlined mu.Lock()/Unlock() in withLock with the shared helper. |
| internal/logger/markdown_logger.go | Replaces inlined mu.Lock()/Unlock() in withLock with the shared helper. |
| internal/logger/tools_logger.go | Replaces inlined mu.Lock()/Unlock() in withLock with the shared helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Eliminates the four identical
withLockmethod bodies acrossFileLogger,JSONLLogger,MarkdownLogger, andToolsLoggerby adding a single package-levelwithMutexLockhelper toglobal_helpers.go, and having each per-type method delegate to it.Closes #2908
Root Cause
Each of the four logger types contained a verbatim copy of the same 3-line lock/unlock pattern:
Any future change to the locking strategy (tracing, timeout, different mutex type) would have required four identical edits.
Fix
Added one canonical helper to
global_helpers.go:Each per-type
withLocknow delegates in a single line:Trade-offs
defer, same return pathmufields aresync.Mutex(verified), so the*sync.Mutexparameter type is exactwithLockmethods are kept for readability at call sites; callers don't need to changeglobal_helpers.go(initGlobalLogger,closeGlobalLogger,withGlobalLogger)Test Status
go.modrequires Go ≥ 1.25.0, andproxy.golang.orgis blocked by the network firewall. Tests cannot be run locally.The change has been reviewed manually:
syncalready imported everywhere)withMutexLocktakes*sync.Mutex; all four loggermufields are exactlysync.Mutex✓global_helpers.goalready importssync, so no import changes needed ✓CI will validate build and tests on merge.