diff options
| author | t <t@tjp.lol> | 2026-06-18 14:15:55 -0600 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-06-18 14:16:24 -0600 |
| commit | 270cd00129551647e7c764a13836e03e0b2dc4e2 (patch) | |
| tree | f939bbf999dd67d996b4025b03dbfe4abd30b9f4 /libpanto/src/turn_persist.zig | |
| parent | 7c2d8825660f73198149c0b2ce26166b16ba3532 (diff) | |
preserve signature origins across compactions
Diffstat (limited to 'libpanto/src/turn_persist.zig')
| -rw-r--r-- | libpanto/src/turn_persist.zig | 18 |
1 files changed, 13 insertions, 5 deletions
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 { |
