Skip to content

fix(session): accept legacy agentName JSON key when unmarshaling Message#3483

Merged
Sayt-0 merged 2 commits into
docker:mainfrom
dgageot:fix/session-agent-name-compat
Jul 6, 2026
Merged

fix(session): accept legacy agentName JSON key when unmarshaling Message#3483
Sayt-0 merged 2 commits into
docker:mainfrom
dgageot:fix/session-agent-name-compat

Conversation

@dgageot

@dgageot dgageot commented Jul 6, 2026

Copy link
Copy Markdown
Member

PR #3471 renamed the JSON tag on session.Message.AgentName from agentName to agent_name. However, contrary to that PR's description, Go's encoding/json does not perform case-insensitive matching between agentName and a field tagged agent_name — the two differ by more than case. As a result, any previously exported session files or evaluation JSON documents that used the old key silently dropped the agent name on load.

This PR adds a compatibility UnmarshalJSON on session.Message that accepts both agentName and agent_name. The new canonical agent_name key wins when both are present; decoding is done through a pointer-aliased struct to preserve the stock null-handling and field-merging semantics without recursion. Marshaling is unchanged and still emits only agent_name. Unit tests cover the legacy key, the new key, both keys present at once, and a realistic end-to-end legacy session document. The evaluation docs example is updated to the canonical key.

No breaking changes. Existing sessions written with agent_name are unaffected; sessions written with the old agentName key now round-trip correctly.

dgageot added 2 commits July 6, 2026 10:31
Adds a compatibility UnmarshalJSON so session/eval JSON exported before
the agent_name tag rename (PR docker#3471) still loads the agent name.

Assisted-By: Claude
…haller

Decode through a pointer alias so null and partial decodes preserve stock
encoding/json merge semantics. Document the empty-vs-absent precedence
trade-off. Add null, empty-current-key, and end-to-end legacy session tests.
Update the evaluation docs example to the canonical agent_name key.

Assisted-By: Claude
@dgageot dgageot requested a review from a team as a code owner July 6, 2026 08:41

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

The UnmarshalJSON implementation is correct and well-structured. The pointer-aliased type alias technique (type message Message + embedded *message) properly avoids infinite recursion while populating all Message fields in-place during unmarshal. The fallback logic (if m.AgentName == "") correctly handles both absent and explicitly-empty agent_name values. No nil-pointer risks are introduced — the *message pointer is always initialized before unmarshal. The design decision to treat empty and absent agent_name equivalently is intentional and clearly documented in the comment.

No bugs found in the introduced code.

@Sayt-0 Sayt-0 merged commit 3655974 into docker:main Jul 6, 2026
14 of 15 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.

3 participants