Skip to content

Commit 500d11e

Browse files
belaltaher8Copilot
andcommitted
rust: use IndexMap for tool metadata to serialize deterministically
HashMap serializes keys in a randomized order, unlike the sibling `parameters` field (IndexMap) and the other SDKs (nodejs/python insertion order, Go sorted). Switch the tool `metadata` bag to IndexMap<String, Value> so key order is deterministic and consistent, avoiding non-reproducible wire output. No new dependency; indexmap is already used by this struct. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bf2bf0dd-ec9f-42f5-a6e1-4f2a9e562d5f
1 parent 2a5b8b3 commit 500d11e

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

rust/src/types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ pub struct Tool {
356356
/// Keys are namespaced and not part of the stable public API; values are
357357
/// not interpreted and may be recognized to inform host-specific behavior.
358358
/// Unknown keys are preserved and round-tripped untouched.
359-
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
360-
pub metadata: HashMap<String, Value>,
359+
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
360+
pub metadata: IndexMap<String, Value>,
361361
/// Optional runtime implementation. When `Some`, the SDK dispatches
362362
/// matching `external_tool.requested` broadcasts to this handler.
363363
/// When `None`, the tool is declaration-only.
@@ -479,7 +479,7 @@ impl Tool {
479479

480480
/// Set opaque, host-defined metadata for the tool. Keys are namespaced and
481481
/// not part of the stable public API. Replaces any previously-set metadata.
482-
pub fn with_metadata(mut self, metadata: HashMap<String, Value>) -> Self {
482+
pub fn with_metadata(mut self, metadata: IndexMap<String, Value>) -> Self {
483483
self.metadata = metadata;
484484
self
485485
}
@@ -5460,9 +5460,9 @@ mod tests {
54605460

54615461
#[test]
54625462
fn tool_metadata_serialization() {
5463-
use std::collections::HashMap;
5463+
use indexmap::IndexMap;
54645464

5465-
let mut metadata = HashMap::new();
5465+
let mut metadata = IndexMap::new();
54665466
metadata.insert(
54675467
"github.com/copilot:safeForTelemetry".to_string(),
54685468
json!({ "name": true, "inputsNames": false }),

0 commit comments

Comments
 (0)