Skip to content

agentdrain: AnomalyReport.IsNewTemplate and NewClusterCreated are always set identically — remove the duplicate field #30759

@github-actions

Description

@github-actions

Problem

In pkg/agentdrain/types.go, the AnomalyReport struct has two fields with nearly identical documentation that are always assigned the same value:

// types.go:59 — "IsNewTemplate is true when the log line created a new cluster"
IsNewTemplate bool
// types.go:65 — "NewClusterCreated is true when this event produced a brand-new cluster"
NewClusterCreated bool

In pkg/agentdrain/anomaly.go:31-33, both fields are set to the same variable:

report := &AnomalyReport{
    IsNewTemplate:     isNew,
    NewClusterCreated: isNew,  // Always identical to IsNewTemplate
    ...
}

Verified via Serena LSP (find_referencing_symbols):

  • NewClusterCreated is only set in one place (anomaly.go:32) and is only checked in tests
  • IsNewTemplate is used in scoring logic, logging, buildReason(), and tests
  • buildReason() checks IsNewTemplate but not NewClusterCreated
  • The debug log at anomaly.go:62 prints IsNewTemplate but omits NewClusterCreated

Impact

  • Severity: Medium
  • Affected files: pkg/agentdrain/types.go, pkg/agentdrain/anomaly.go, pkg/agentdrain/anomaly_test.go, pkg/agentdrain/miner_test.go, pkg/agentdrain/spec_test.go
  • Risk: API confusion — consumers of AnomalyReport cannot know which field to read. The redundant field makes the struct harder to reason about and wastes space. The near-identical documentation masks the problem.

Recommendation

If IsNewTemplate and NewClusterCreated are truly always synonymous, remove NewClusterCreated and update all consumers to use IsNewTemplate:

// types.go — remove NewClusterCreated field
type AnomalyReport struct {
    // IsNewTemplate is true when the log line produced a brand-new log cluster.
    IsNewTemplate bool
    LowSimilarity bool
    RareCluster   bool
    AnomalyScore  float64
    Reason        string
}

If the two fields were intended to capture distinct concepts (e.g., IsNewTemplate = the input was new, NewClusterCreated = a persistent cluster was actually persisted), clarify the documentation and ensure they are set independently.

Validation

  • Use serena find_referencing_symbols to locate all NewClusterCreated usages
  • Remove the field and fix all compilation errors
  • Update tests in anomaly_test.go and miner_test.go
  • Confirm buildReason() and scoring logic still cover all intended cases

Estimated Effort: Small


Found by Sergo — Serena Go static analysis (LSP-confirmed), run 2026-05-07

Generated by Sergo - Serena Go Expert · ● 578.5K ·

  • expires on May 14, 2026, 4:59 AM UTC

Metadata

Metadata

Labels

cookieIssue Monster Loves Cookies!sergo

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions