Avoid decoding full tool results when forking conversations
This commit is contained in:
@@ -171,7 +171,7 @@ func (m *Manager) fork(ctx context.Context, src api.Task, project api.Project, n
|
||||
if srcSess.Vendor == api.Antigravity {
|
||||
return api.Task{}, "", fmt.Errorf("%w: snapshot %d of task %s is from an Antigravity session, and agy can't fork a conversation", ErrConflict, n, src.Id)
|
||||
}
|
||||
events, err := m.store.TaskEvents(ctx, src.Id, 0, -1)
|
||||
events, err := m.store.ForkEvents(ctx, src.Id, srcSess.Id)
|
||||
if err != nil {
|
||||
return api.Task{}, "", err
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func (m *Manager) Continue(ctx context.Context, srcSess api.AgentSession, src ap
|
||||
return m.store.GetTask(ctx, prior.TaskId)
|
||||
}
|
||||
|
||||
events, err := m.store.TaskEvents(ctx, src.Id, 0, -1)
|
||||
events, err := m.store.ForkEvents(ctx, src.Id, srcSess.Id)
|
||||
if err != nil {
|
||||
return api.Task{}, err
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user