Skip to content

Refactor action pin warnings and agentdrain helpers - #51674

Merged
pelikhan merged 6 commits into
mainfrom
copilot/refactor-consolidate-warn-once
Aug 10, 2026
Merged

Refactor action pin warnings and agentdrain helpers#51674
pelikhan merged 6 commits into
mainfrom
copilot/refactor-consolidate-warn-once

Conversation

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

pkg/actionpins combined unrelated pin-data, resolution, mapping, and warning concerns in one file, while repeating warning deduplication. pkg/agentdrain had event/template helpers separated from their related functionality.

  • Action pin structure

    • Split actionpins.go into focused types, data, references, resolution, mapping, and warning files.
    • Preserved existing public APIs and pin-resolution behavior.
  • Warning deduplication

    • Centralized stderr warning/info emission in PinContext.emitOnce.
    • Covers unresolved pins, fallback pins, action mappings, and invalid/valid container mappings.
ctx.emitOnce(key, message, console.FormatWarningMessage)
  • Agentdrain organization
    • Moved event flattening, tokenization, and stage sequencing into event.go.
    • Moved template parameter extraction beside template similarity/merge logic in cluster.go.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 16.4 AIC · ⌖ 5.39 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 13 AIC · ⌖ 6.68 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.2 AIC · ⌖ 6.75 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Run: https://github.com/github/gh-aw/actions/runs/31375792022> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 17.8 AIC · ⌖ 5.46 AIC · ⊞ 8.5K ·

Comment /souschef to run again

Copilot AI and others added 2 commits August 10, 2026 03:54
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] Refactor actionpins to consolidate warn-once block and split file Refactor action pin warnings and agentdrain helpers Aug 10, 2026
Copilot AI requested a review from pelikhan August 10, 2026 03:57
@pelikhan
pelikhan marked this pull request as ready for review August 10, 2026 05:03
Copilot AI balanced review requested due to automatic review settings August 10, 2026 05:03
@github-actions

github-actions Bot commented Aug 10, 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 10, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • api.individual.githubcopilot.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.individual.githubcopilot.com"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 10, 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 10, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Lean already. Ship. This PR is a mechanical file split (actionpins.go and agentdrain files broken into focused files) plus consolidation of duplicated warning-dedup logic into a single emitOnce helper. No new abstractions, no speculative flexibility, no unnecessary dependencies were introduced — the diff nets roughly +29 lines total, mostly package boilerplate for new files. Nothing found to cut.

Generated by Ponytail Reviewer for #51674

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 action pin resolution into cohesive files, centralizes warning deduplication, and colocates agentdrain helpers with related functionality.

Changes:

  • Split pkg/actionpins by responsibility while preserving APIs.
  • Added centralized PinContext.emitOnce warning deduplication.
  • Reorganized agentdrain event and template helpers.
Show a summary per file
File Description
pkg/actionpins/actionpins.go Removed monolithic implementation.
pkg/actionpins/types.go Houses public types and interfaces.
pkg/actionpins/data.go Handles embedded pin loading and lookup.
pkg/actionpins/references.go Contains reference parsing and formatting.
pkg/actionpins/resolve.go Contains pin-resolution logic.
pkg/actionpins/mappings.go Handles action and container mappings.
pkg/actionpins/warnings.go Centralizes deduplicated message emission.
pkg/actionpins/actionpins_internal_test.go Tests warning initialization and deduplication.
pkg/agentdrain/event.go Groups event formatting and sequencing helpers.
pkg/agentdrain/mask.go Retains masking-specific functionality.
pkg/agentdrain/cluster.go Colocates template parameter extraction.
pkg/agentdrain/miner.go Removes relocated template helper.
pkg/agentdrain/coordinator.go Removes relocated event sequencing helper.

Review details

Tip

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

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

@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, correct refactoring. The monolithic actionpins.go is split into focused files (types.go, data.go, references.go, resolve.go, mappings.go, warnings.go) with all public APIs preserved. agentdrain helpers are reorganised similarly. One intentional behaviour change: invalid container-pin mapping warnings are now deduplicated via emitOnce, matching the existing deduplication for valid-mapping notifications. The new test TestApplyContainerPinMapping_DeduplicatesInvalidWarnings correctly covers this. No blocking issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 40.1 AIC · ⌖ 9.95 AIC · ⊞ 5.4K

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Test Quality Score: 100/100 — Excellent

Analyzed 2 test(s): 2 design, 0 implementation, 0 violation(s).

📊 Metrics (2 tests)
Metric Value
Analyzed 2 (Go: 2, JS: 0)
✅ Design 2 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 2 (100%)
Duplicate clusters 0
Inflation No (1.56:1)
🚨 Violations 0
Test File Classification Issues
TestPinContextEmitOnce_InitializesAndDeduplicates pkg/actionpins/actionpins_internal_test.go behavioral_contract / design_test / high_value Minor: assertions lack descriptive failure messages
TestApplyContainerPinMapping_DeduplicatesInvalidWarnings pkg/actionpins/actionpins_internal_test.go behavioral_contract / design_test / high_value Minor: assertions lack descriptive failure messages

Notes

Both tests cover deduplication invariants — verifying that a warning is emitted to stderr exactly once per unique key. This replaces the older TestInitWarnings_InitializesAndPreservesMap test (which tested internal map initialization) with stronger behavioral coverage.

  • Build tag (go/redacted):build !integration present ✓
  • No Go mock library usage ✓
  • Test inflation ratio: 28 added test lines / 18 added production lines (warnings.go) = 1.56:1 ✓

Minor: assert.Equal and assert.True calls omit descriptive failure messages. Not a hard violation but aids readability when CI fails.

Verdict

Passed. 0% implementation tests (threshold: 30%). No violations.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 34.6 AIC · ⌖ 6.94 AIC · ⊞ 7.6K ·
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.

✅ Test Quality Sentinel: 100/100. 0% implementation tests (threshold: 30%).

@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 /tdd and /codebase-design — 3 minor observations, no blocking issues.

📋 Key Themes & Highlights

Key Themes

  • Missing t.Parallel(): Two new tests omit t.Parallel(), breaking the file's consistent pattern and slowing the test suite.
  • Empty slice allocation: extractParams uses []string{} where var params []string is idiomatic and avoids a heap allocation on the zero-value path.

Positive Highlights

  • ✅ Clean split of a 595-line monolith into focused, well-named files (types.go, data.go, references.go, resolve.go, mappings.go, warnings.go)
  • PinContext.emitOnce is a neat encapsulation — eliminates 4 separate if !ctx.Warnings[key] / fmt.Fprintln / ctx.Warnings[key] = true blocks
  • ✅ Invalid container mapping warning is now deduplicated (was emitted on every call in old code) — correct behavior improvement, well-tested
  • agentdrain helpers (FlattenEvent, Tokenize, StageSequence) move to event.go alongside their natural home; extractParams lands correctly in cluster.go
  • ✅ Public APIs unchanged — pure internal reorganization

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 86 AIC · ⌖ 7.64 AIC · ⊞ 7.1K
Comment /matt to run again

}
}

func TestApplyContainerPinMapping_DeduplicatesInvalidWarnings(t *testing.T) {

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] Missing t.Parallel() — same pattern break as TestPinContextEmitOnce_InitializesAndDeduplicates; the new dedup test should also be marked parallel to match the file's established convention.

💡 Suggested fix
func TestApplyContainerPinMapping_DeduplicatesInvalidWarnings(t *testing.T) {
	t.Parallel()
	ctx := &PinContext{

@copilot please address this.

Comment thread pkg/agentdrain/cluster.go
params := []string{}
for i, tok := range template {
if tok == paramToken && i < len(tokens) {
params = append(params, tokens[i])

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] params := []string{} allocates an empty non-nil slice even when nothing matches. Idiomatic Go uses var params []string to defer allocation, which also aligns with the pattern used elsewhere in the package.

💡 Suggested fix
var params []string
for i, tok := range template {

Callers using len(params) == 0 are unaffected; the only observable difference is the avoided heap allocation.

@copilot please address this.


initWarnings(ctx)
func TestPinContextEmitOnce_InitializesAndDeduplicates(t *testing.T) {
ctx := &PinContext{}

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] Missing t.Parallel() — all sibling tests in this file call t.Parallel() at the top of the function body, but this new test omits it, slowing the suite and breaking the established convention.

💡 Suggested fix
func TestPinContextEmitOnce_InitializesAndDeduplicates(t *testing.T) {
	t.Parallel()
	ctx := &PinContext{}

@copilot please address this.

@github-actions

Copy link
Copy Markdown
Contributor

Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (697 new lines in pkg/actionpins and pkg/agentdrain) but does not have a linked Architecture Decision Record (ADR).

Draft ADR committed: docs/adr/51674-split-actionpins-into-focused-files-with-emit-once.md — review and complete it before merging.

This PR cannot merge until an ADR is linked in the PR body.

What to do next
  1. Review the draft ADR committed to your branch at docs/adr/51674-split-actionpins-into-focused-files-with-emit-once.md — it was generated from the PR diff
  2. Complete the missing sections — add context the AI could not infer, refine the decision rationale, and list the real alternatives you considered
  3. Commit the finalized ADR to docs/adr/ on your branch
  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-51674: Split actionpins into focused files with emitOnce

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

Why ADRs Matter

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What did you decide? Why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number (e.g., 51674-split-actionpins-into-focused-files-with-emit-once.md for PR #51674).

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · sonnet46 · 102.2 AIC · ⌖ 26.6 AIC · ⊞ 8.7K ·
Comment /review to run again

@github-actions

Copy link
Copy Markdown
Contributor

Great work on this refactoring! 🎉 Your PR cleanly consolidates the duplicated warn-once blocks in pkg/actionpins and splits the 595-line file into focused, single-responsibility files (types.go, data.go, resolve.go, warnings.go, etc.). The emitOnce method on PinContext is a solid improvement that removes the nil-map footgun and makes the emit-once pattern explicit.

The changes to pkg/agentdrain are equally well-organized — moving event helpers into event.go, template parameter extraction into cluster.go alongside related template operations, and StageSequence to types.go. Tests are updated and the diff is tight and focused.

This PR demonstrates the kind of incremental, targeted refactoring that keeps the codebase maintainable. The ADR documentation is a nice touch for future maintainers.

Ready for review! 👍

Generated by ✅ Contribution Check · auto · 55.6 AIC · ⌖ 4.16 AIC · ⊞ 8.8K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Quick triage nudge for this PR.

Please refresh the branch if GitHub can update it cleanly, review the maintainer-facing feedback below, and run the pr-finisher skill before handing this back.

Open review context (newest first):

  • github-actions review: extractParams still uses []string{} on the zero-value path; consider switching to var params []string if that feedback is still unaddressed.
  • github-actions review: two new tests were noted as missing t.Parallel(); please confirm whether that maintainer-facing suggestion still needs a follow-up commit.
  • no failed checks were listed in the compact candidate snapshot.

Branch refresh was requested.
Run: https://github.com/github/gh-aw/actions/runs/31359323746

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 16.4 AIC · ⌖ 5.39 AIC · ⊞ 8.5K ·
Comment /souschef to run again

@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

Category: refactor · Risk: medium · Priority: medium · Score: 62/100

Score breakdown

  • Impact: 22/50 (internal refactor, 14 files touched, no behavior change)
  • Urgency: 15/30 (mergeable but unstable state; 9 comments, 3 review comments)
  • Quality: 25/20→capped 20 (CI copilot check green, has AI review approvals, well-described PR)

Recommended action: fast_track — clean internal split of actionpins/agentdrain modules, approved by automated reviewers, no external behavior change; ready for expedited human sign-off.

Automated triage via PR Triage Agent.

Generated by 🔧 PR Triage Agent · auto · 45.9 AIC · ⌖ 2.89 AIC · ⊞ 7.8K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Quick triage nudge for this PR.

Please refresh the branch if GitHub can update it cleanly, address the maintainer-facing feedback below, and run the pr-finisher skill before handing this back.

Open review context (newest first):

  • github-actions review: add t.Parallel() to TestApplyContainerPinMapping_DeduplicatesInvalidWarnings
  • github-actions review: switch extractParams from []string{} to var params []string unless there is a reason to keep the allocation
  • github-actions review: add t.Parallel() to TestPinContextEmitOnce_InitializesAndDeduplicates
  • no failed checks were listed in the compact candidate snapshot

Branch refresh was requested.
Run: https://github.com/github/gh-aw/actions/runs/31363534572

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 13 AIC · ⌖ 6.68 AIC · ⊞ 8.5K ·
Comment /souschef to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Quick triage nudge for this PR.

Please refresh the branch if GitHub can update it cleanly, address the maintainer-facing feedback below, and run the pr-finisher skill before handing this back.

Open review context (newest first):

Branch refresh was requested.
Run: https://github.com/github/gh-aw/actions/runs/31369116288

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.2 AIC · ⌖ 6.75 AIC · ⊞ 8.5K ·
Comment /souschef to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Quick triage nudge for this PR.

Please refresh the branch if GitHub can update it cleanly, address the maintainer-facing feedback below, and run the pr-finisher skill before handing this back.

Open review context (newest first):

  • github-actions review: add t.Parallel() to TestPinContextEmitOnce_InitializesAndDeduplicates
  • github-actions review: switch extractParams from []string{} to var params []string unless there is a reason to keep the allocation
  • github-actions review: add t.Parallel() to TestApplyContainerPinMapping_DeduplicatesInvalidWarnings
  • no failed checks were listed in the compact candidate snapshot

Branch refresh was requested.
Run: https://github.com/github/gh-aw/actions/runs/31375792022

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 17.8 AIC · ⌖ 5.46 AIC · ⊞ 8.5K ·
Comment /souschef to run again

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

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Quick triage nudge for this PR.

Please refresh the branch if GitHub can update it cleanly, address the maintainer-facing feedback below, and run the pr-finisher skill before handing this b...

Addressed in cefdd5f.

  • Added t.Parallel() to TestPinContextEmitOnce_InitializesAndDeduplicates
  • Switched extractParams initialization to var params []string
  • Added t.Parallel() to TestApplyContainerPinMapping_DeduplicatesInvalidWarnings

Local validation completed with make fmt, make lint, make test-unit, make test, and make recompile.

@pelikhan
pelikhan merged commit 997623c into main Aug 10, 2026
29 checks passed
@pelikhan
pelikhan deleted the copilot/refactor-consolidate-warn-once branch August 10, 2026 11:04
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.

[refactor] Consolidate duplicated warn-once block in actionpins; split 595-line file and fix 3 agentdrain outliers

4 participants