Skip to content

fix(inspection): deduplicate feature tasks by SelectionPriority in SetInspectionType - #884

Merged
kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-szvukwllvzpl
Aug 13, 2026
Merged

kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-szvukwllvzpl

Conversation

@kyasbal

@kyasbal kyasbal commented Aug 13, 2026

Copy link
Copy Markdown
Member

Problem

When multiple compatible task implementations share the same TaskRef (e.g. a generic parser task vs. a platform-specialized parser task), the final task graph only ever selects a single implementation based on SelectionPriority.
However, during inspection creation (SetInspectionType), all compatible implementations were registered into availableTasks and exposed in FeatureList(). This caused tasks that would never actually be included in the final task graph to appear in the feature selection UI, making feature toggling for those tasks confusing and ineffective.

Solution

  • Upfront Task Deduplication: Deduplicate compatible tasks in SetInspectionType (pkg/core/inspection/runner.go) by selecting only the implementation with the highest coretask.LabelKeyTaskSelectionPriority per TaskRef (tie-breaking deterministically by implementation ID string).
  • GraphResolver Simplification: Since availableTasks is now guaranteed to have unique TaskRefs upfront, removed the redundant runtime priority sorting in GraphResolver (pkg/core/task/graphresolver.go) and optimized task lookup via slices.BinarySearchFunc over pre-sorted tasks.

Key Changes

  • pkg/core/inspection/runner.go: Added deduplicateTasksByPriority and invoked it in SetInspectionType immediately after compatibility filtering.
  • pkg/core/task/graphresolver.go: Pre-sorted availableTasks in GraphResolver.Resolve and replaced findHighestPriorityUntypedTaskForTaskReference with binary search in findUntypedTaskForTaskReference.
  • pkg/core/inspection/runner_test.go: Added TestDeduplicateTasksByPriority and TestSetInspectionType_SelectionPriority to verify feature list and task deduplication behavior.
  • pkg/core/task/graphresolver_test.go: Updated unit tests to match binary search lookup.

Verification

  • make build-go passed.
  • make test-go passed.
  • make lint-go passed.
  • make pre-commit passed.
@kyasbal kyasbal added the type:bug Something isn't working as expected label Aug 13, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces task deduplication by priority in the inspection runner and optimizes task resolution in the graph resolver by pre-sorting available tasks and using binary search. The reviewer feedback highlights that the deduplication logic contains non-determinism due to map iteration and suggests a deterministic O(N) alternative. Additionally, the reviewer advises against the binary search optimization in the graph resolver, as it is a premature optimization that breaks the resolver's ability to handle multiple task implementations and select the highest priority one, which also led to the unauthorized removal of existing test cases in violation of the repository style guide.

Comment thread pkg/core/inspection/runner.go Resolved
Comment thread pkg/core/task/graphresolver.go Resolved
Comment thread pkg/core/task/graphresolver.go Resolved
Comment thread pkg/core/task/graphresolver_test.go Resolved
…tInspectionType

Previously, when multiple compatible tasks shared the same TaskRef (e.g. generic vs. platform-specialized implementations), all implementations were exposed in FeatureList() and availableTasks during inspection setup. However, the task graph resolver would ultimately only select the single highest-priority implementation via SelectionPriority, making the presence of duplicate implementations in feature selection misleading and ineffective.

This fix:
- Deduplicates compatible tasks in SetInspectionType by selecting the implementation with the highest SelectionPriority per TaskRef.
- Simplifies GraphResolver to find tasks via binary search over pre-sorted availableTasks, since deduplication is now guaranteed upfront.
- Adds unit tests to verify feature list deduplication and GraphResolver dependency resolution.
@kyasbal
kyasbal force-pushed the push-szvukwllvzpl branch from 7c21301 to a4059cf Compare August 13, 2026 10:12
@kyasbal
kyasbal marked this pull request as ready for review August 13, 2026 13:50
@kyasbal
kyasbal merged commit c35c497 into GoogleCloudPlatform:main Aug 13, 2026
16 checks passed
@kyasbal
kyasbal deleted the push-szvukwllvzpl branch August 13, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Something isn't working as expected

1 participant