From 270cd00129551647e7c764a13836e03e0b2dc4e2 Mon Sep 17 00:00:00 2001 From: t Date: Thu, 18 Jun 2026 14:15:55 -0600 Subject: preserve signature origins across compactions --- libpanto/src/turn_persist.zig | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'libpanto/src/turn_persist.zig') diff --git a/libpanto/src/turn_persist.zig b/libpanto/src/turn_persist.zig index 0147fbd..1dacfec 100644 --- a/libpanto/src/turn_persist.zig +++ b/libpanto/src/turn_persist.zig @@ -41,7 +41,7 @@ const Session = session_store.Session; pub fn persistTurn( alloc: Allocator, session: *Session, - conv: *const conversation.Conversation, + conv: *conversation.Conversation, start_index: usize, identity: WireIdentity, tools: []const ToolDecl, @@ -52,14 +52,22 @@ pub fn persistTurn( const all_messages = conv.messages.items; var i = start_index; while (i < all_messages.len) : (i += 1) { - const msg = all_messages[i]; + const msg = &all_messages[i]; if (msg.role == .assistant and hasToolUseWithoutFollowingResults(conv, i)) { continue; } + // Stamp the producing identity once, on first persist. A message that + // already carries one (e.g. a kept-verbatim turn carried through + // compaction, or one rebuilt from disk) keeps it — only the messages + // freshly produced under `identity` are stamped now. This is what + // makes the stamp survive a later compaction onto a different model. + if (msg.identity == null) { + msg.identity = try conversation.dupeWireIdentity(alloc, identity); + } try batch.append(alloc, .{ - .message = msg, + .message = msg.*, .usage = msg.usage, - .identity = identity, + .identity = msg.identity.?, .conversation = all_messages, .tools_available = tools, }); @@ -75,7 +83,7 @@ pub fn persistTurn( pub fn persistCompaction( alloc: Allocator, session: *Session, - conv: *const conversation.Conversation, + conv: *conversation.Conversation, identity: WireIdentity, tools: []const ToolDecl, ) !void { -- cgit v1.3