Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

mcp: a transcript's messages are not slimmed to their ids (#1426)

justrach38c9ea083a7b
diff --git a/src/mcp_shapes.zig b/src/mcp_shapes.zig
index 410329ef..dfec3f93 100644
--- a/src/mcp_shapes.zig
+++ b/src/mcp_shapes.zig
@@ -494,7 +494,9 @@ fn authorName(item: Value) ?[]const u8 {
}
fn slimIdentity(alloc: Allocator, items: []const Value) ?[]u8 {
- if (!hasIdentity(items[0].object)) return null;
+ // #1426: a row known only by an opaque id (a transcript message) is all
+ // content; a cut down to its ids would stand in for nothing readable.
+ if (!hasLabel(items[0].object) or items[0].object.get("role") != null) return null;
var aw: Io.Writer.Allocating = .init(alloc);
var s: std.json.Stringify = .{ .writer = &aw.writer };
s.beginArray() catch {
@@ -535,6 +537,11 @@ fn hasIdentity(obj: std.json.ObjectMap) bool {
return false;
}
+fn hasLabel(obj: std.json.ObjectMap) bool {
+ for (identity_keys[1..]) |k| if (obj.get(k) != null) return true;
+ return false;
+}
+
/// Splice stored shapes onto a load_tool_schemas / search RESULT. Never call
/// this from catalog render (ADR 0011 prefix must stay byte-stable).
pub fn annotate(gpa: Allocator, arena: Allocator, io: Io, cwd: ?[]const u8, text: []const u8) ![]const u8 {
diff --git a/src/mcp_shapes_tests.zig b/src/mcp_shapes_tests.zig
index cb436146..947f546d 100644
--- a/src/mcp_shapes_tests.zig
+++ b/src/mcp_shapes_tests.zig
@@ -227,3 +227,20 @@ test "a comment fold names the issue every row shares, and only then" {
try std.testing.expect(std.mem.indexOf(u8, mixed_fold, "issue") == null);
try std.testing.expect(std.mem.indexOf(u8, shapes.slim_rule, "\"issue\"") != null);
}
+
+test "a transcript's messages are never cut to their ids (#1426)" {
+ const gpa = std.testing.allocator;
+ const pad: [900]u8 = @splat('x');
+ const pad_s: []const u8 = &pad;
+ // One long message, and a window of several: both stay readable.
+ const one = try std.fmt.allocPrint(gpa, "{{\"chatId\":\"c1\",\"total\":1,\"messages\":[{{\"id\":\"m1\",\"role\":\"assistant\",\"text\":\"{s}\"}}]}}", .{pad_s});
+ defer gpa.free(one);
+ try std.testing.expect(shapes.slim(gpa, one) == null);
+ const many = try std.fmt.allocPrint(gpa, "{{\"messages\":[{{\"id\":\"m1\",\"role\":\"user\",\"text\":\"{s}\"}},{{\"id\":\"m2\",\"role\":\"assistant\",\"text\":\"done\"}}]}}", .{pad_s});
+ defer gpa.free(many);
+ try std.testing.expect(shapes.slim(gpa, many) == null);
+ // Rows known only by an opaque id are content too.
+ const bare = try std.fmt.allocPrint(gpa, "[{{\"id\":\"r1\",\"text\":\"{s}\"}}]", .{pad_s});
+ defer gpa.free(bare);
+ try std.testing.expect(shapes.slim(gpa, bare) == null);
+}