Skip to content

Fix Agents.UnmarshalYAML to reject unknown fields#1684

Merged
dgageot merged 1 commit intodocker:mainfrom
simonferquel:fix/agents-strict-unmarshal
Feb 10, 2026
Merged

Fix Agents.UnmarshalYAML to reject unknown fields#1684
dgageot merged 1 commit intodocker:mainfrom
simonferquel:fix/agents-strict-unmarshal

Conversation

@simonferquel
Copy link
Contributor

Problem

latest.Parse() and v4.Parse() call yaml.UnmarshalWithOptions(data, &cfg, yaml.Strict()) to reject unknown fields. However, Agents.UnmarshalYAML re-marshals each agent value to bytes and calls plain yaml.Unmarshal, which does not enforce strict field validation. Unknown fields in agent blocks are silently ignored.

For example, writing instructions (plural) instead of the correct instruction (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) to yaml.UnmarshalWithOptions(valueBytes, &agent, yaml.DisallowUnknownField()) in both latest/types.go and v4/types.go.

Tests

Added tests to both latest/types_test.go and v4/types_test.go:

  • TestAgents_UnmarshalYAML_RejectsUnknownFields — verifies instructions (plural) is rejected
  • TestAgents_UnmarshalYAML_AcceptsValidConfig — verifies instruction (singular) still works

All existing tests pass, including the full TestParseExamples suite that validates all example YAML configs.

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
@simonferquel simonferquel requested a review from a team as a code owner February 10, 2026 15:24
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

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

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 dgageot merged commit 1a8e453 into docker:main Feb 10, 2026
8 checks passed
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.

Agents.UnmarshalYAML silently drops unknown fields despite yaml.Strict() in Parse

2 participants