Files
2026-10-16 12:55:18 +03:00

41 lines
3.4 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Тайминг обработки запроса в чате ассистента: от сообщения в Slack до ответа в Slack, по этапам (диагностика медленных ответов).
create table chat_timing (
id uuid primary key default gen_random_uuid(),
created_at timestamptz not null default now(),
manager_person_id uuid references construction_manager(person_id),
channel_id text,
kind text not null check (kind in ('message', 'event')),
agent_version text not null check (agent_version in ('classic', 'live')),
status text not null check (status in ('ok', 'failed')),
error text,
message_ts text,
message_at timestamptz, -- время первого сообщения пакета в Slack (из ts)
received_at timestamptz, -- когда сообщение принято сервисом (журнал slack_message_log)
started_at timestamptz not null, -- начало обработки пакета (после ожидания debounce)
reply_slack_ts text, -- ts ответа ассистента, полученный от Slack
reply_at timestamptz, -- время ответа в Slack (из reply_slack_ts)
slack_in_ms integer, -- Slack -> сервис (received_at - message_at)
debounce_ms integer, -- ожидание накопления сообщений (started_at - received_at)
inputs_ms integer, -- история напоминаний и вложения (скачивание)
drive_ms integer, -- выгрузка исходников в Drive
prompt_ms integer, -- сборка промта (запросы к БД, текст)
prompt_chars integer,
queue_ms integer, -- ожидание очереди менеджера и пула агентов
start_ms integer, -- старт процесса агента и прогрев (live; для classic не измеряется отдельно)
model_ms integer, -- от отправки промта до результата (все попытки)
api_ms integer, -- время запросов к API модели по данным claude
first_event_ms integer, -- до первого события хода (live)
tool_calls integer,
num_turns integer,
attempts integer, -- вызовов модели (повторы "исправь формат")
cost_usd numeric(10, 4),
post_ms integer, -- сохранение памяти, проблем, истории
publish_ms integer, -- отправка ответа в Slack (с озвучиванием)
final_ms integer, -- повторная выгрузка в Drive после ответа
processing_ms integer, -- вся обработка пакета (started_at -> конец)
total_ms integer, -- от сообщения в Slack до ответа в Slack (message_at -> reply_at)
steps jsonb -- подробности: вызовы модели с таймингом
);
create index chat_timing_manager_idx on chat_timing (manager_person_id, created_at desc);
alter table chat_timing enable row level security;