Avoid decoding full tool results when forking conversations

This commit is contained in:
Ian Gulliver
2026-10-23 06:46:25 -07:00
parent d6494de33b
commit de9a830cc6
2 changed files with 18 additions and 2 deletions
+16
View File
@@ -973,6 +973,22 @@ func (s *Store) TaskEvents(ctx context.Context, taskID string, after int64, limi
return scanEvents(rows)
}
// ForkEvents returns only the payload fields needed to find a safe conversation boundary.
// Tool results can contain large captures that would otherwise be decoded just to discard them.
func (s *Store) ForkEvents(ctx context.Context, taskID, sessionID string) ([]api.Event, error) {
rows, err := s.db.QueryContext(ctx, `
SELECT seq, kind, project_id, task_id, agent_session_id, owner, actor,
json_object('vendor_uuid', json_extract(payload, '$.vendor_uuid'),
'id', json_extract(payload, '$.id'), 'tool_use_id', json_extract(payload, '$.tool_use_id')),
created_at
FROM events WHERE task_id = ? AND agent_session_id = ? ORDER BY seq
`, taskID, sessionID)
if err != nil {
return nil, err
}
return scanEvents(rows)
}
func (s *Store) TranscriptEvents(ctx context.Context, taskID string, after int64, limit int) ([]api.Event, error) {
query := "SELECT " + eventColumns + " FROM events WHERE task_id = ? AND seq > ?"
args := []any{taskID, after}