Skip to content

Report validation error for duplicate action names#1528

Merged
poutsma merged 1 commit intoembabel:mainfrom
poutsma:gh-1304
Mar 24, 2026
Merged

Report validation error for duplicate action names#1528
poutsma merged 1 commit intoembabel:mainfrom
poutsma:gh-1304

Conversation

@poutsma
Copy link
Copy Markdown
Contributor

@poutsma poutsma commented Mar 23, 2026

This PR ensures that actions names only occur once, and reports a validation error otherwise.

Closes: gh-1304

This commit ensures that actions names only occur once, and reports a
validation error otherwise.

Closes: embabelgh-1304
Signed-off-by: Arjen Poutsma <poutsma@mac.com>
Copy link
Copy Markdown
Contributor

@igordayen igordayen left a comment

Choose a reason for hiding this comment

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

minor comment to consider in future. looks good

)
}

// Check for duplicate action names
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.

at some point for documentation purposes perhaps collect all error codes / maintain enum for ValidationError.code:

./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/GoapPathToCompletionValidator.kt:import com.embabel.common.core.validation.ValidationError
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/GoapPathToCompletionValidator.kt:        val errors = mutableListOf<ValidationError>()
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/GoapPathToCompletionValidator.kt:    ): ValidationError =
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/GoapPathToCompletionValidator.kt:        ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt:import com.embabel.common.core.validation.ValidationError
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt:                val error = ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt:        val errors = mutableListOf<ValidationError>()
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt:                ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt:                ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt:                    ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt:                    ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/core/hitl/FormBindingRequest.kt:interface ValidationError
./embabel-agent-api/src/main/kotlin/com/embabel/agent/core/hitl/FormBindingRequest.kt:    val validationErrors: List<ValidationError> = emptyList(),
./embabel-agent-api/src/main/kotlin/com/embabel/common/core/validation/ValidationResult.kt:    val errors: List<ValidationError>,
./embabel-agent-api/src/main/kotlin/com/embabel/common/core/validation/ValidationError.kt:data class ValidationError  @JvmOverloads constructor(

Copy link
Copy Markdown
Contributor

@alexheifetz alexheifetz left a comment

Choose a reason for hiding this comment

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

Very nice fix — groupBy { it.name }.filter { it.value.size > 1 } is the right idiom and the validator is the right layer.

Two minor things:

  • Agreeing with @igordayen on typed error codes — the raw string in the test assertion is a silent typo risk.
  • The error message could include the declaring class of each duplicate so the developer knows where to look, not just that a collision exists.

@poutsma
Copy link
Copy Markdown
Contributor Author

poutsma commented Mar 24, 2026

  • Agreeing with @igordayen on typed error codes — the raw string in the test assertion is a silent typo risk.

Sounds good, I will create a follow-up issue for that.

  • The error message could include the declaring class of each duplicate so the developer knows where to look, not just that a collision exists.

The action name is used in the message, and will be the fully qualified method name when using annotations. For instance, for the unit test it's com.embabel.agent.api.annotation.support.AgentWithDuplicateActionNames.respond.

@poutsma
Copy link
Copy Markdown
Contributor Author

poutsma commented Mar 24, 2026

I have created #1533 to collect all validation error codes.

@poutsma poutsma merged commit 738f5bc into embabel:main Mar 24, 2026
7 checks passed
@poutsma poutsma deleted the gh-1304 branch March 24, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Actions with the same name can cause unpredictable behaviour

3 participants