fix(session): accept legacy agentName JSON key when unmarshaling Message#3483
Merged
Conversation
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
docker-agent
reviewed
Jul 6, 2026
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
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
approved these changes
Jul 6, 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.
PR #3471 renamed the JSON tag on
session.Message.AgentNamefromagentNametoagent_name. However, contrary to that PR's description, Go'sencoding/jsondoes not perform case-insensitive matching betweenagentNameand a field taggedagent_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
UnmarshalJSONonsession.Messagethat accepts bothagentNameandagent_name. The new canonicalagent_namekey 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 onlyagent_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_nameare unaffected; sessions written with the oldagentNamekey now round-trip correctly.