Part of duplicate code analysis: #1810
Summary
Four functions in internal/launcher/log_helpers.go repeat an identical if sessionID != "" { ... } else { ... } branching pattern for logging. A sessionSuffix() helper already exists but is only partially used — three of the four functions still manually fork every log statement.
Duplication Details
Pattern: if sessionID != "" log branches
// logTimeoutError (lines 101–112) — exact if/else on sessionID for log.Printf and logLauncher
if sessionID != "" {
log.Printf("[LAUNCHER] ❌ Server '%s' (session: %s) startup timed out after %v", serverID, sessionID, l.startupTimeout)
} else {
log.Printf("[LAUNCHER] ❌ Server '%s' startup timed out after %v", serverID, l.startupTimeout)
}
// ...
if sessionID != "" {
logLauncher.Printf("Startup timeout occurred: serverID=%s, sessionID=%s, timeout=%v", serverID, sessionID, l.startupTimeout)
} else {
logLauncher.Printf("Startup timeout occurred: serverID=%s, timeout=%v", serverID, l.startupTimeout)
}
// logLaunchSuccess (lines 117–125) — same pattern again
if sessionID != "" {
logger.LogInfoWithServer(serverID, "backend", "Successfully launched MCP backend server for session: server=%s, session=%s", serverID, sessionID)
log.Printf("[LAUNCHER] Successfully launched: %s (session: %s)", serverID, sessionID)
logLauncher.Printf("Session connection established: serverID=%s, sessionID=%s", serverID, sessionID)
} else {
logger.LogInfoWithServer(serverID, "backend", "Successfully launched MCP backend server: %s", serverID)
log.Printf("[LAUNCHER] Successfully launched: %s", serverID)
logLauncher.Printf("Connection established: serverID=%s", serverID)
}
Impact Analysis
- Maintainability: Every change to the session-aware log format must be applied in 4 places (8+ individual
if/else branches). The existing sessionSuffix() helper shows the right intent but is not consistently applied to all three log channels (logger.*, log.Printf, logLauncher.Printf).
- Bug Risk: Inconsistent format strings between session and non-session branches (e.g., missing session ID in one logger while present in another) could produce confusing log output.
- Code Bloat: ~35 extra lines of branching that could collapse into simple format-string composition.
Refactoring Recommendations
-
Extend sessionSuffix usage consistently — use it in all three log channels uniformly:
func (l *Launcher) logLaunchSuccess(serverID, sessionID string) {
suffix := sessionSuffix(sessionID)
logger.LogInfoWithServer(serverID, "backend",
"Successfully launched MCP backend server%s: server=%s%s", suffix, serverID, suffix)
log.Printf("[LAUNCHER] Successfully launched: %s%s", serverID, suffix)
logLauncher.Printf("Connection established: serverID=%s%s", serverID, suffix)
}
-
Consider a sessionKeyvals helper returning []any for structured loggers:
func sessionKeyvals(serverID, sessionID string) string {
if sessionID == "" {
return fmt.Sprintf("serverID=%s", serverID)
}
return fmt.Sprintf("serverID=%s, sessionID=%s", serverID, sessionID)
}
Implementation Checklist
Parent Issue
See parent analysis report: #1810
Related to #1810
Generated by Duplicate Code Detector · ◷
Part of duplicate code analysis: #1810
Summary
Four functions in
internal/launcher/log_helpers.gorepeat an identicalif sessionID != "" { ... } else { ... }branching pattern for logging. AsessionSuffix()helper already exists but is only partially used — three of the four functions still manually fork every log statement.Duplication Details
Pattern:
if sessionID != ""log branchesSeverity: Medium
Occurrences: 4 functions (
logLaunchStart,logTimeoutError,logLaunchSuccess,logLaunchError)Locations:
internal/launcher/log_helpers.golines 31–47 (logLaunchStart)internal/launcher/log_helpers.golines 97–113 (logTimeoutError)internal/launcher/log_helpers.golines 116–126 (logLaunchSuccess)internal/launcher/log_helpers.golines 70–95 (logLaunchError— usessessionSuffix()forlogger.*calls but still branches forlog.PrintfandlogLauncher.Printf)Code Sample:
Impact Analysis
if/elsebranches). The existingsessionSuffix()helper shows the right intent but is not consistently applied to all three log channels (logger.*,log.Printf,logLauncher.Printf).Refactoring Recommendations
Extend
sessionSuffixusage consistently — use it in all three log channels uniformly:Consider a
sessionKeyvalshelper returning[]anyfor structured loggers:Implementation Checklist
if sessionID != ""branches inlog_helpers.gosessionSuffix()or introduce a second helper for consistent key-value formattinglogLaunchStart,logTimeoutError,logLaunchSuccess, andlogLaunchErrormake test-unitto confirm no behaviour changeParent Issue
See parent analysis report: #1810
Related to #1810