Repository navigation
[repository-quality] Repository Quality Improvement Report - Debug-logging hygiene #76868
Closed
Replies: 1 comment
|
This discussion was automatically closed because it expired on 2026-11-12T13:04:12.116Z.
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
🎯 Repository Quality Improvement Report - Debug-logging hygiene
Analysis Date: 2026-11-11
Focus Area: Debug-logging hygiene (
pkg/loggerusage)Strategy Type: Custom (diversity roll 14, inside the 0–59 custom band)
Custom Area: Yes. Repository guidelines require
pkg/loggerfor debug output and promise zero-overhead disabled logging. Existing linters cover stdliblogand console-formatted stderr, but nothing checks logger namespace conventions or call-site cost.Executive Summary
The core logging discipline is sound. Production code has no stdlib
logusage, every package-level logger is referenced, and theconsolestderrandrawloginliblinters enforce the main rules. Three gaps remain.First, the logger documents "zero overhead (not even string formatting)" when disabled, but Go evaluates call arguments before the enabled check. About 21 production call sites build
strings.Join,json.Marshal, oryaml.Marshalarguments on every call, even whenDEBUGis unset. The cost is usually small, so this is a doc-accuracy and hot-path issue rather than a correctness bug.Second, verbose-gated
fmt.Fprintf(os.Stderr, ...)writes sit besideloggercalls in several functions. Inpkg/workflow/claude_logs.go, the only confirmed exact duplicate is line 142 (logger) and line 144 (stderr). Other verbose writes there have no matching logger call. Some writes are user-facing--verboseoutput and must stay; others may be developer diagnostics.Third, two production namespaces use hyphens, breaking the snake_case convention used elsewhere, and two debug messages carry a redundant literal
DEBUG:prefix. Task 3 is small and independent. Task 4 depends on Task 3. Task 1 needs a policy decision first.Full Analysis Report
Focus Area: Debug-logging hygiene
Current State Assessment
Metrics Collected:
loglogger.Newworkflow:mcp-config-custom,workflow:mcp-rendering)DEBUG:prefixpkg/workflow/time_delta.go)Join/Marshalargumentsos.Stderrwrites (adjacentif verbose {heuristic)os.Stderrwrites outsideconsole/loggerconsolestderrFindings
Strengths
logusage in production code. Therawloginlibandlogfatallibrarylinters guard this.pkg/parserand most ofpkg/workflowfollow a clearpackage:componentpattern.consolestderrlinter enforces console formatting for user-facing stderr.Areas for Improvement
pkg/workflow/git_helpers.go:63runsstrings.Join(args, " ")before every git invocation, even whenDEBUGis unset. Other sites are inpkg/cli/logs_download_artifacts.go(lines 109, 153, 241) andpkg/workflow/github_token.go:101.pkg/workflow/claude_logs.go,claudeLogsLog.Print("JSON array parse failed, trying JSONL format")at line 142 is followed by a--verbosefmt.Fprintf(os.Stderr, ...)of the same event at line 144. Verbose writes at lines 150, 155, 231, 278, and 321 have no exact logger counterpart. Classification is needed before any removal.pkg/workflow/mcp_config_custom.go:17usesworkflow:mcp-config-custom, andpkg/workflow/mcp_renderer_factory.go:36usesworkflow:mcp-rendering. A repository-wide grep found no references to these names outside the source files.pkg/workflow/time_delta.go:383and:423prefix messages withDEBUG:, although the namespace label already identifies the source.Detailed Analysis
Logger semantics. In
pkg/logger/logger.go,PrintfandPrintcheckl.enabledbefore formatting, so formatting is skipped when disabled. The caller's argument expressions are still evaluated first. The package docs (pkg/logger/doc.go) say "zero overhead (not even string formatting)", which is accurate only for simple arguments. The fix is either to guard expensive sites withlog.Enabled()(94 guards already exist in non-test code) or to reword the claim.Verbose output policy.
--verboseis a user-facing flag, so someos.Stderrwrites underif verbose {are intended output and should not move toDEBUG. The problem is only where the same information is also logged throughlogger, which means developers see it twice and the two channels can drift apart.Namespace convention. Non-test namespaces are overwhelmingly lowercase snake_case with colon separators. The two hyphenated names are the only production exceptions. Test-only namespaces such as
spec:slog-*andcli:drain3_*are out of scope.🤖 Tasks for Copilot Agent
NOTE TO PLANNER AGENT: Split the following tasks into individual work items. Task 4 depends on Task 3.
Improvement Tasks
Task 1: Classify and deduplicate verbose stderr writes in claude_logs.go
Priority: Medium
Estimated Effort: Small
Focus Area: Debug-logging hygiene
Description: In
pkg/workflow/claude_logs.go, classify the--verbosefmt.Fprintf(os.Stderr, ...)calls at lines 144, 150, 155, 231, 278, and 321. Only line 144 is confirmed to repeat aclaudeLogsLogcall (line 142). Classify each as user-facing--verboseoutput (keep) or developer diagnostic (remove only if it duplicates a logger call). Do not change user-visible--verbosebehaviour without noting it in the PR.Acceptance Criteria:
os.Stderrwrite inclaude_logs.gois classified as user-facing or developer-only, with the classification listed in the PR descriptionmake test-unitpasses, including the Claude log parser testsCode Region:
pkg/workflow/claude_logs.goTask 2: Make logger argument cost match the documented zero-overhead claim
Priority: Low
Estimated Effort: Small
Focus Area: Debug-logging hygiene
Description: About 21 logger calls build
strings.Join,json.Marshal, oryaml.Marshalarguments on every invocation. Either guard the expensive ones withif log.Enabled(), or reword the zero-overhead claim inpkg/logger/doc.goandpkg/logger/README.mdto say that caller-side argument evaluation still happens.Acceptance Criteria:
Join/Marshalargument is either guarded withEnabled()or documented as caller-evaluatedpkg/logger/doc.goandpkg/logger/README.mddescribe disabled-logging cost accuratelyDEBUG=cli:*andDEBUG=workflow:*output is unchangedmake test-unitpassesCode Region:
pkg/workflow/git_helpers.go:63,pkg/cli/logs_download_artifacts.go:109,153,241,pkg/cli/logs_artifact_set.go:211,219,pkg/workflow/github_token.go:101,pkg/logger/doc.go,pkg/logger/README.mdTask 3: Normalise hyphenated logger namespaces and redundant DEBUG prefixes
Priority: Low
Estimated Effort: Small
Focus Area: Debug-logging hygiene
Description: Rename
workflow:mcp-config-customtoworkflow:mcp_config_customandworkflow:mcp-renderingtoworkflow:mcp_rendering. Remove the literalDEBUG:prefix from the two messages inpkg/workflow/time_delta.goat lines 383 and 423. A repository-wide search found no references to the old namespaces outside the source files.Acceptance Criteria:
logger.Newnamespace contains a hyphenDEBUG=workflow:mcp_*enables the renamed loggerstime_delta.gomessages no longer include theDEBUG:prefixmake test-unitpassesCode Region:
pkg/workflow/mcp_config_custom.go:17,pkg/workflow/mcp_renderer_factory.go:36,pkg/workflow/time_delta.go:383,423Task 4: Add a guardrail for logger namespace convention
Priority: Low
Estimated Effort: Medium
Focus Area: Debug-logging hygiene
Description: Add a test that scans non-test Go files under
pkg/andcmd/forlogger.New("...")string literals and fails on any namespace that does not match^[a-z][a-z0-9_]*(:[a-z0-9_]+)+$. Exclude_test.gofiles andtestdata. Document the convention inpkg/logger/README.md. This depends on Task 3 so the test passes on first run.Acceptance Criteria:
pkg/logger/README.mddocuments the namespace conventionmake test-unitpassesCode Region:
pkg/logger/(new test file),pkg/logger/README.md📊 Historical Context
Previous Focus Areas
pkg/loggerusage)🎯 Recommendations
Immediate Actions (This Week)
Short-term Actions (This Month)
Long-term Actions (This Quarter)
--verbosestderr vsDEBUGlogging, then apply it across the roughly 463 verbose-gated writes inpkg/cliandpkg/workflow. Priority: Low📈 Success Metrics
DEBUG:prefixes in logger messages: 2 → 0Next Steps
Generated by Repository Quality Improvement Agent
Next analysis: 2026-11-12 — Focus area selected by diversity algorithm
All reactions