Repository navigation
[duplicate-code] Refactor: dedupe agent_output.json extraction in logs_metrics.go - #76976
Conversation
|
🔎 PR Code Quality Reviewer is reviewing code quality for this pull request... |
|
🚀 PR Specification Reviewer has started processing this pull request |
|
✂️ Ponytail Reviewer has started processing this pull request |
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the refactor consolidating safe-output artifact resolution and parsing.
No open issues 🎉
What changed in this PR
Refactors safe-output artifact extraction in gh-aw’s log analysis code, replacing duplicated loading and parsing logic with a shared helper.
Changes:
- Adds
forEachSafeOutputItem[I]for missing-tool, noop, and missing-data reports. - Centralizes artifact lookup in
resolveAgentOutputFile, retaining existing layout handling. - Enables verbose layout diagnostics in the shared resolver, including for skill-activation extraction.
| File | Description |
|---|---|
pkg/cli/logs_metrics.go |
Consolidates artifact resolution and JSON parsing while retaining report-specific filtering and construction. |
Review effort: Balanced (auto)
🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (>100 new lines) but does not have a linked Architecture Decision Record (ADR). 📄 Draft ADR committed:
📋 What to do next
Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision. 🧭 Scope noteThe change is a refactor within existing patterns. It adds no architectural choice beyond internal consolidation, so the gate fired on the volume rule alone. If the team judges this below the ADR bar, a maintainer can say so on this PR.
|
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /codebase-design and /tdd. The refactor is behavior-preserving on every branch I traced, and I found no correctness bugs. Two follow-ups are suggested in inline comments.
📋 Key Themes & Highlights
Key Themes
- Helper error model:
forEachSafeOutputItemreturns nothing and swallows read and parse failures. The extractors still returnnilerrors, as before, so this is not a regression. But it means the helper cannot serveextractSkillActivationsFromAgentOutput, which still duplicates the read/parse loop (aroundlogs_metrics.go:628) and is outside this diff. - Test coverage:
resolveAgentOutputFilenow owns four layout branches, and none of the extractor tests exercises the legacy directory, nested-file, or recursive path.
Positive Highlights
- ✅ Single resolver:
resolveAgentOutputFilenow honours its previously ignoredverboseparameter, removing the drift between the copies. - ✅ Generic
forEachSafeOutputItem[I]removes about 330 duplicated lines while keeping each per-item struct local. - ✅
go build ./pkg/clipasses and the targetedgo testrun for the log extractors passes. - ✅ Verbose messages keep their original wording, so the only visible change is the parse-error text, which the PR already notes.
Note: verification ran in this sandbox against the PR head, not in CI.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~5 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again
| // the new flattened layout first, then the legacy nested layout, and finally a | ||
| // recursive search. Returns an empty string when no file is found. When verbose | ||
| // is set, the layout that matched (or why a legacy layout was rejected) is reported. | ||
| func resolveAgentOutputFile(runDir string, verbose bool) string { |
There was a problem hiding this comment.
[/tdd] resolveAgentOutputFile now owns the flat, legacy-file, legacy-directory (with and without a nested file), and recursive-search branches, but no test references it or findAgentOutputFile by name, and none I found writes the directory or nested layout. Add a table test over these layouts plus malformed JSON and the no-file case, mirroring the differential harness described in the PR.
@copilot please address this.
| // legacy directory and recursive layouts), decodes each entry of its "items" array into I, | ||
| // and calls fn for every successfully decoded item. Read and parse problems are reported | ||
| // only when verbose is set, and processing continues without the failing file or item. | ||
| func forEachSafeOutputItem[I any](runDir string, run WorkflowRun, verbose bool, fn func(item I)) { |
There was a problem hiding this comment.
[/codebase-design] forEachSafeOutputItem swallows read and parse failures (they are logged only when verbose), so the extractors' error returns are always nil. extractSkillActivationsFromAgentOutput still needs those errors, so it cannot reuse this helper as written. Consider having the helper return an error (or accept an error-returning callback) so the last copy of the loop can be removed.
@copilot please address this.
| }) | ||
| if verbose { | ||
| fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("No safe output artifact found at %s for run %d", agentOutputJSONPath, run.DatabaseID))) | ||
| fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Found noop entry: "+item.Message)) |
|
🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:
Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering. Structured data{
"completed_task": 0,
"head": "f962496fe5898d2be782fe79b1e8b507db48fe96",
"kind": "requested",
"schema_version": "1",
"state": "9de73fc68db83d14741dbef8fc0604256ec967a5fcf563350182608e20ab1100",
"work": [
"42e5d572d9d75b7168fe7d0aeda0717cc07e65ed240f6d299e6fec661214f1ac",
"43282e7f5b3023b8c8cf9099eab79e7b99f650965f08b47d3df33cde5589879d"
],
"workflow": "pr-sous-chef"
}
|
…output-item-extraction-81256e46f849c011 Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Merged |
|
🎉 This pull request is included in a new release. Release: |
🔍 Duplicate Code Detected: agent_output.json extraction in
logs_metrics.goImplementation: Extracted the shared locate/read/parse loop into a generic helper
forEachSafeOutputItem[I]and made the existingresolveAgentOutputFilethe single resolver (it now honours its previously-unusedverboseparameter). Net change: +135 / −350 lines inpkg/cli/logs_metrics.go.Summary
extractMissingToolsFromRun,extractNoopsFromRunandextractMissingDataFromRuneach contained a ~110-line copy of the same logic: resolveagent_output.json(flat, legacyagent-outputdir/file, recursive fallback), read it, unmarshal{"items": [...]}, then decode each item. Only the per-item struct, the type check, and the report construction differed.resolveAgentOutputFilein the same file already duplicated the resolution part (minus verbose logging).Duplication Details
pkg/cli/logs_metrics.go:extractMissingToolsFromRun(≈ lines 281–410)extractNoopsFromRun(≈ lines 413–538)extractMissingDataFromRun(≈ lines 541–672)resolveAgentOutputFile(≈ lines 925–950, partial)pkg/**/*.go(non-test); this was the largest cluster.Impact Analysis
Validation
gofmt -l pkg/cli/logs_metrics.go: clean.pkg/cliin this sandbox: Go module dependencies could not be downloaded (TLS failure to proxy.golang.org), sogo build ./pkg/cli,make fmt,make agent-report-progressand the existinglogs_*_test.gotests were not run. Please rely on CI.console,constants,fileutil, copying the old functions fromHEADand the new ones from this change) over 7 layouts (flat, legacy file, legacy dir w/ nested file, legacy dir missing nested, recursive, malformed JSON, none) × verbose on/off, with mixed missing_tool/noop/missing_data/malformed items. Returned reports were identical in all cases, and verbose stderr output was identical, with one exception below.Behavior notes
missingToolItem.typeetc. instead of an anonymous.type). No tests reference this text.extractSkillActivationsFromAgentOutput(which callsresolveAgentOutputFile(runDir, verbose)) now emits the same verbose "Found ... " layout messages whenverboseis true; previously the parameter was ignored.Analysis Metadata
pkg/**/*.goplus manual review (Serena CLI was available but not needed for this exact-copy finding)pkg/cli/frontmatter_editor.go,pkg/cli/outcome_eval_generic.go,pkg/cli/pr_command.go,pkg/workflow/maintenance_workflow.go.