Fix Agents.UnmarshalYAML to reject unknown fields#1684
Merged
dgageot merged 1 commit intodocker:mainfrom Feb 10, 2026
Merged
Conversation
Agents.UnmarshalYAML re-marshals each agent value to bytes and calls yaml.Unmarshal to parse it into AgentConfig. This plain Unmarshal call does not enforce strict field validation, so unknown fields like 'instructions' (instead of 'instruction') are silently ignored — even though Parse() uses yaml.Strict() at the top level. Switch to yaml.UnmarshalWithOptions with DisallowUnknownField so that the strictness is propagated into agent blocks. Fixes docker#1683 Assisted-By: cagent
There was a problem hiding this comment.
Review Summary
✅ No issues found
The changes correctly implement strict YAML field validation by replacing yaml.Unmarshal() with yaml.UnmarshalWithOptions() using the yaml.DisallowUnknownField() option. This will properly reject typos like "instructions" instead of silently ignoring them.
Changes reviewed:
- ✅
pkg/config/latest/types.go: Correct implementation with proper error handling - ✅
pkg/config/v4/types.go: Correct implementation with proper error handling - ✅ Tests added to validate both rejection of unknown fields and acceptance of valid configs
The implementation is minimal, focused, and addresses the issue described in #1683.
dgageot
approved these changes
Feb 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
latest.Parse()andv4.Parse()callyaml.UnmarshalWithOptions(data, &cfg, yaml.Strict())to reject unknown fields. However,Agents.UnmarshalYAMLre-marshals each agent value to bytes and calls plainyaml.Unmarshal, which does not enforce strict field validation. Unknown fields in agent blocks are silently ignored.For example, writing
instructions(plural) instead of the correctinstruction(singular) produces no error, but the instruction is completely lost — the agent runs with no instructions at all.Fixes #1683
Fix
Change
yaml.Unmarshal(valueBytes, &agent)toyaml.UnmarshalWithOptions(valueBytes, &agent, yaml.DisallowUnknownField())in bothlatest/types.goandv4/types.go.Tests
Added tests to both
latest/types_test.goandv4/types_test.go:TestAgents_UnmarshalYAML_RejectsUnknownFields— verifiesinstructions(plural) is rejectedTestAgents_UnmarshalYAML_AcceptsValidConfig— verifiesinstruction(singular) still worksAll existing tests pass, including the full
TestParseExamplessuite that validates all example YAML configs.