Skip to content

Refactor overlong functions in pkg/console/progress.go and pkg/cli/mcp_tools_privileged.go - #54705

Open
pelikhan with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-9919-1036865607-00e67a3a-01ae-4004-958f-35c042510885
Open

Refactor overlong functions in pkg/console/progress.go and pkg/cli/mcp_tools_privileged.go#54705
pelikhan with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-9919-1036865607-00e67a3a-01ae-4004-958f-35c042510885

Conversation

Copilot AI commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

One slice of the largefunc (max-lines=60) refactoring backlog: the lone pkg/console overflow plus the 6 findings clustered in pkg/cli/mcp_tools_privileged.go. No public API, MCP tool schema, or behavior changes.

pkg/console/progress.go

  • Update (61 lines) split into logUpdate, renderIndeterminate, and renderDeterminate, matching the three branches the function already had.

pkg/cli/mcp_tools_privileged.go

  • Tool description raw strings moved verbatim into package-level consts (logsToolDescription, auditToolDescription). largefunc counts a function's full source span, so these ~40-line literals dominated the registration functions' budgets.
  • Handler closures extracted into newLogsToolHandler, newAuditToolHandler, newAuditDiffToolHandler, collapsing each registerXTool to schema generation plus an mcp.AddTool call.
  • Handler bodies decomposed along existing seams: arg building (buildLogsCommandArgs, appendLogsFilterArgs, buildAuditCommandArgs, resolveAuditRunItems) and error/empty envelopes (buildLogsEmptyResult, buildLogsCommandError, buildAuditErrorResult, buildAuditDiffErrorResult).
  • Dropped the logs handler's inline copy of the gateway-deadline-detaching subprocess context in favor of the existing newMCPSubprocessContext helper already used by the audit tools — same semantics, ~35 fewer lines.
// before: 244-line registerLogsTool with an inline 193-line handler literal
mcp.AddTool(server, &mcp.Tool{
    Description: `Download and analyze workflow logs. ...`,  // ~40 lines
    InputSchema: logsSchema,
}, func(ctx context.Context, req *mcp.CallToolRequest, args logsArgs) (...) {
    // ...193 lines of arg building, subprocess plumbing, error envelopes
})

// after
mcp.AddTool(server, &mcp.Tool{
    Description: logsToolDescription,
    InputSchema: logsSchema,
}, newLogsToolHandler(execCmd, actor, validateActor))

The custom linters report no findings of any kind in the two touched files; the repo-wide make golint-custom still fails on the remaining backlog outside this slice.

Also reverts unrelated GH_AW_HARNESS_VERSION drift in three smoke-copilot*.lock.yml files that the environment regenerated, keeping the diff scoped to the two Go files.


Run: https://github.com/github/gh-aw/actions/runs/32552086004> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 28.1 AIC · ⌖ 8.19 AIC · ⊞ 9.5K ·

Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 12.3 AIC · ⌖ 8.33 AIC · ⊞ 7K ·
Comment /souschef to run again

Copilot AI linked an issue Aug 22, 2026 that may be closed by this pull request
9 tasks
Copilot AI and others added 3 commits August 22, 2026 03:31
…ools_privileged.go)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…privileged.go

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Copilot Request Refactor overlong functions in pkg/console/progress.go and pkg/cli/mcp_tools_privileged.go Aug 22, 2026
Copilot AI requested a review from pelikhan August 22, 2026 03:41
@pelikhan
pelikhan marked this pull request as ready for review August 22, 2026 03:55
Copilot AI balanced review requested due to automatic review settings August 22, 2026 03:55
@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Lean already. Ship. Reviewed diff per ponytail-review skill: pure mechanical function-extraction refactor. Handler closures and long string literals were pulled into named top-level functions/consts, each with exactly one caller and unchanged control flow. No reinvented stdlib, no unneeded deps, no speculative abstractions, no dead flexibility introduced.

Generated by Ponytail Reviewer for #54705

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the targeted largefunc backlog while preserving existing MCP and console behavior.

Changes:

  • Splits progress rendering and logging into focused helpers.
  • Extracts MCP descriptions, handlers, argument builders, and error-envelope helpers.
  • Reuses the shared MCP subprocess context helper.
Show a summary per file
File Description
pkg/console/progress.go Decomposes progress updates by rendering mode.
pkg/cli/mcp_tools_privileged.go Decomposes logs and audit tool registration and handling.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-08-22T00:00:00Z
review_event: REQUEST_CHANGES
top_themes:
  - validation regression in audit MCP handler
  - refactor safety on privileged MCP tools
files_reviewed:
  - pkg/cli/mcp_tools_privileged.go
  - pkg/console/progress.go
comment_count: 1

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 14.6 AIC · ⌖ 6.89 AIC · ⊞ 7K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes

This refactor is not behavior-preserving: the audit MCP handler no longer rejects variant without experiment, so an invalid request now leaks through to subprocess execution instead of failing fast as an MCP parameter error.

Blocking theme
  • Validation regressed in pkg/cli/mcp_tools_privileged.go: buildAuditCommandArgs appends --variant unconditionally, but the handler no longer enforces the documented variant requires experiment contract.

I did not find any other clearly blocking issue in the touched progress-bar extraction.

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 14.6 AIC · ⌖ 6.89 AIC · ⊞ 7K
Comment /review to run again

}

cmdArgs = appendRepoFlagFromEnv(cmdArgs)
cmdArgs := buildAuditCommandArgs(args, runItems)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactor dropped validation for variant without experiment, so the MCP tool now forwards an invalid flag combination to gh aw audit and turns what used to be a deterministic parameter error into a later subprocess failure.

💡 Why this matters and how to fix it

The tool description still says variant requires experiment, but newAuditToolHandler now only calls resolveAuditRunItems before building args. buildAuditCommandArgs appends --variant unconditionally, and there is no remaining guard that rejects variant by itself.

That is a correctness regression in the validation layer: callers now get a much weaker error path, and any client relying on MCP-level InvalidParams handling will break.

Add the explicit validation back before spawning the subprocess, e.g.

if args.Variant != "" && args.Experiment == "" {
    return nil, nil, newMCPError(jsonrpc.CodeInvalidParams, "variant requires experiment", nil)
}

Keeping this check in the handler preserves the previous contract and avoids wasting time on a doomed CLI invocation.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /codebase-design and /tdd — commenting (no blocking issues).

📋 Key Themes & Highlights

Key Themes

  • buildAuditErrorResult signature asymmetry: outputStr is accepted but not included in the error envelope, unlike the parallel buildLogsCommandError. Suggest either dropping it or making the two helpers consistent.
  • New testability opportunity: The extracted helpers (appendLogsFilterArgs, resolveAuditRunItems) are now independently testable; adding narrow unit tests would harden the refactor.

Positive Highlights

  • ✅ Pure mechanical extraction — no behaviour changes, all logic moved verbatim
  • ✅ Re-uses newMCPSubprocessContext instead of duplicating the gateway-deadline-detach pattern — good deepening
  • ✅ Constants for tool description strings is the right move; avoids off-by-one line-count issues with largefunc linting
  • progress.go splits are clean and the function names (logUpdate, renderIndeterminate, renderDeterminate) exactly match the three branches — easy to navigate

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 36.7 AIC · ⌖ 10.9 AIC · ⊞ 7.6K
Comment /matt to run again

if args.Runtime != "" {
cmdArgs = append(cmdArgs, "--runtime", args.Runtime)
}
return appendRepoFlagFromEnv(cmdArgs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/codebase-design] outputStr is passed to buildAuditErrorResult but is only used for logging its length — it's never included in the error envelope, unlike buildLogsCommandError which adds "stdout": outputStr to errorData. The asymmetry is subtle and now more visible since the function is extracted.

💡 Suggestion

If audit stdout is genuinely not useful in the error envelope, document that clearly at the call site or drop the parameter:

if execErr != nil {
    mcpLog.Printf("... stdout: %d bytes ...", len(stdout))
    return buildAuditErrorResult(execErr, runItems)
}

If it may be useful (e.g. partial JSON on failure), add "stdout": outputStr consistent with buildLogsCommandError.

@copilot please address this.

cmdArgs = append(cmdArgs, "--runtime", args.Runtime)
}
if args.Firewall {
cmdArgs = append(cmdArgs, "--firewall")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] The extracted helpers — especially appendLogsFilterArgs (flag-to-arg mapping) and resolveAuditRunItems (precedence/fallback logic) — are now top-level package functions and directly unit-testable without a full MCP harness. Adding narrow table-driven tests for these would lock in the refactored behaviour and prevent future regressions.

@copilot please address this.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-executed refactor. The extracted helpers (buildLogsCommandArgs, buildLogsEmptyResult, buildLogsCommandError, resolveAuditRunItems, buildAuditCommandArgs, buildAuditErrorResult, buildAuditDiffErrorResult, and the new*ToolHandler constructors in both files) are faithful extractions with no behavioral changes.

All return values (effectiveCount, timeoutValue, cmdArgs) from buildLogsCommandArgs are correctly threaded back into the caller for logging and subprocess timeout. LGTM.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 42.3 AIC · ⌖ 8.97 AIC · ⊞ 6.2K

Documents the decision to decompose overlong registration functions and
handler closures in pkg/cli/mcp_tools_privileged.go and
pkg/console/progress.go to satisfy the largefunc (max-lines=60) linter.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot this PR still needs forward progress before maintainer review.

  • A blocking review says the audit MCP handler regressed validation: variant should still require experiment in pkg/cli/mcp_tools_privileged.go.
  • Please restore that fast-fail validation, rerun the focused Go validations for the touched code, and leave a concise maintainer handoff.
  • After the fix, refresh the branch if needed and run the pr-finisher skill.

Run: https://github.com/github/gh-aw/actions/runs/32552086004

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 28.1 AIC · ⌖ 8.19 AIC · ⊞ 9.5K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot this PR still needs forward progress before maintainer review.

  • A blocking review says the audit MCP handler regressed validation: variant should still require experiment in `pkg/cli/mc...

Fixed in f17546d: audit now rejects variant without experiment before subprocess execution, with regression coverage. Focused tests, build, lint, unit tests, and workflow recompilation pass; full make test initially hit an unrelated Cobra concurrent-map-write flake, then the full pkg/cli suite passed on retry. CI is stale after this agent push and needs maintainer re-triggering.

Copilot AI requested a review from gh-aw-bot August 22, 2026 04:59
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot this PR still needs forward progress before maintainer review.

  • A blocking review was previously addressed, but the PR still needs a final maintainer-ready handoff on the current head.
  • Please refresh the branch if needed, confirm the current head still includes the validation fix and passing focused reruns, and run the pr-finisher skill.
  • Leave a concise maintainer handoff with exact validations rerun and whether any CI still needs human re-triggering.

Run: https://github.com/github/gh-aw/actions/runs/32553383419

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 12.3 AIC · ⌖ 8.33 AIC · ⊞ 7K ·
Comment /souschef to run again

Copilot AI commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot this PR still needs forward progress before maintainer review.

  • A blocking review was previously addressed, but the PR still needs a final maintainer-ready handoff on the current head....

Current head 186d0df is refreshed with main and retains f17546d’s --variant requires --experiment fast-fail plus its no-subprocess regression test. Reran: make fmt, make build, focused go test ./pkg/cli -run 'TestAuditTool_(VariantWithoutExperimentFails|ExperimentVariantFlags|ExperimentFlagWithoutVariant|FailsWhenNoRunIDProvided)$' -count=1, make lint, make test-unit, and make recompile — all passed. make test again hit the unrelated full-suite Cobra concurrent map writes failure in pkg/cli (and impacted-test base detection cannot find origin/main in this shallow checkout). Run 32553383419 succeeded but is for main, not this head; CI must be human-retriggered for 186d0df before merge.

@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

  • Category: refactor
  • Risk: medium
  • Priority score: 38/100 (impact 10, urgency 20, quality 8)
  • Recommended action: batch_review
  • CI status: failing
  • Batch: batch-1

Generated by 🔧 PR Triage Agent · auto · 82.9 AIC · ⌖ 6.65 AIC · ⊞ 8.3K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[lint-monster] function-length refactoring backlog

4 participants