-
Notifications
You must be signed in to change notification settings - Fork 1.3k
refactor(core): drop unused role parameter from message #3045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,7 +72,6 @@ public AssistantMessage(List<ContentBlock> blocks) { | |
| private AssistantMessage( | ||
| @JsonProperty("id") String id, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Warning] Removing this parameter does change deserialization behaviour, because With the parameter gone, Two consequences worth locking down with a wire-compat test before merge:
A test that deserializes each subtype from JSON with a correct |
||
| @JsonProperty("name") String name, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dropping |
||
| @JsonProperty("role") MsgRole role, | ||
| @JsonProperty("content") List<ContentBlock> content, | ||
| @JsonProperty("metadata") Map<String, Object> metadata, | ||
| @JsonProperty("timestamp") String timestamp, | ||
|
|
@@ -167,8 +166,7 @@ public Builder generateReason(GenerateReason reason) { | |
|
|
||
| @Override | ||
| public AssistantMessage build() { | ||
| return new AssistantMessage( | ||
| id, name, MsgRole.ASSISTANT, content, metadata, timestamp, usage); | ||
| return new AssistantMessage(id, name, content, metadata, timestamp, usage); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,7 +77,6 @@ public ToolResultMessage(List<ToolResultBlock> results) { | |
| private ToolResultMessage( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two process points: (1) the PR title says
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Title has been rewritten |
||
| @JsonProperty("id") String id, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Info] Same
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Info] Same |
||
| @JsonProperty("name") String name, | ||
| @JsonProperty("role") MsgRole role, | ||
| @JsonProperty("content") List<ContentBlock> content, | ||
| @JsonProperty("metadata") Map<String, Object> metadata, | ||
| @JsonProperty("timestamp") String timestamp, | ||
|
|
@@ -215,7 +214,7 @@ public Builder generateReason(GenerateReason reason) { | |
| @Override | ||
| public ToolResultMessage build() { | ||
| return new ToolResultMessage( | ||
| id, name, MsgRole.TOOL, List.copyOf(content), metadata, timestamp, usage); | ||
| id, name, List.copyOf(content), metadata, timestamp, usage); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Warning] Removing this parameter does change deserialization behaviour, because
Msgdeclares@JsonTypeInfo(..., visible = true)— therolevalue from JSON is actively forwarded to the subtype creator rather than consumed only as the type discriminator.With the parameter gone,
roleis no longer bindable by this creator, so it is dropped as an unknown property. That is tolerated only becauseMsgcarries@JsonIgnoreProperties(ignoreUnknown = true)and that annotation is@Inherited. So the code compiles and round-trips today, but the cleanup now depends on an inherited annotation on the base class that nothing in this file enforces: ifignoreUnknownwere ever narrowed, deserializing these four subtypes would start failing withUnrecognizedPropertyException.Two consequences worth locking down with a wire-compat test before merge:
roleis absent or whose value does not match the resolved subtype is now silently overridden by the hardcoded constant (e.g. anASSISTANTpayload always yieldsMsgRole.ASSISTANT). That is the intent, but it is an implicit guarantee.Msg.validateRoleContent(role, content)now always sees the hardcoded role, so a mismatched stored payload can no longer be detected at all.A test that deserializes each subtype from JSON with a correct
role, a mismatchedrole, and a missingrole, asserting the resultinggetRole()and that no exception is thrown, would make the invariant explicit and independent of the base-class annotation.