Retry failed sends with their send_id until the server confirms them
This commit is contained in:
@@ -0,0 +1 @@
|
||||
CREATE INDEX events_send_id ON events(json_extract(payload, '$.send_id')) WHERE kind IN ('user.queued', 'user.message');
|
||||
@@ -1356,6 +1356,16 @@ func (s *Store) SessionStarted(ctx context.Context, sessionID string) (bool, err
|
||||
return started, err
|
||||
}
|
||||
|
||||
func (s *Store) UnusedSession(ctx context.Context, taskID, member string) (string, bool, error) {
|
||||
id := ""
|
||||
err := s.db.QueryRowContext(ctx, `SELECT id FROM agent_sessions WHERE task_id = ? AND member = ? AND role = ? AND state = ? AND started = 0 AND pending = 0 LIMIT 1`,
|
||||
taskID, member, string(api.Implementer), string(api.AgentSessionStateIdle)).Scan(&id)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return "", false, nil
|
||||
}
|
||||
return id, err == nil, err
|
||||
}
|
||||
|
||||
func (s *Store) SessionPending(ctx context.Context, sessionID string) (bool, error) {
|
||||
pending := false
|
||||
err := s.db.QueryRowContext(ctx, `SELECT pending FROM agent_sessions WHERE id = ?`, sessionID).Scan(&pending)
|
||||
|
||||
@@ -45,6 +45,22 @@ func (s *Store) AddTaskInput(ctx context.Context, in TaskInput, projectID, sessi
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Store) SendSession(ctx context.Context, sendID string) (string, bool, error) {
|
||||
sessionID := sql.NullString{}
|
||||
err := s.db.QueryRowContext(ctx, `SELECT agent_session_id FROM events WHERE kind IN ('user.queued', 'user.message') AND json_extract(payload, '$.send_id') = ? LIMIT 1`, sendID).Scan(&sessionID)
|
||||
if err == nil {
|
||||
return sessionID.String, true, nil
|
||||
}
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
return "", false, err
|
||||
}
|
||||
err = s.db.QueryRowContext(ctx, `SELECT 1 FROM lead_inputs WHERE send_id = ? LIMIT 1`, sendID).Scan(new(int))
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return "", false, nil
|
||||
}
|
||||
return "", err == nil, err
|
||||
}
|
||||
|
||||
func (s *Store) WithdrawTaskInput(ctx context.Context, taskID string, id int64, projectID, actor string) (string, error) {
|
||||
sessionID := ""
|
||||
err := s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
|
||||
Reference in New Issue
Block a user