59 lines
3.3 KiB
Markdown
59 lines
3.3 KiB
Markdown
# 诊断运行表:diagnosis_run
|
||
|
||
**状态**:当前诊断运行主表
|
||
**来源**:`V011__add_session_run_isolation.sql`、`DiagnosisRun`
|
||
|
||
## 定位
|
||
|
||
`diagnosis_run` 表示一次 `/api/chat` 应用执行。`run_id` 是运行级边界,SSE、Trace、AgentStep 与 ToolInvocation 必须按 metadata 返回的 exact `run_id` 绑定。
|
||
|
||
## 字段
|
||
|
||
| 字段 | 类型 | 必填 | 说明 |
|
||
|---|---|---|---|
|
||
| `id` | BIGINT | 是 | 自增主键 |
|
||
| `run_id` | VARCHAR(64) | 是 | 运行唯一 ID,格式为 `run-` + UUID |
|
||
| `session_id` | VARCHAR(64) | 是 | 所属 `chat_session.session_id` |
|
||
| `query` | TEXT | 是 | 本次 Chat 用户问题 |
|
||
| `status` | VARCHAR(16) | 否 | `PENDING`、`RUNNING`、`SUCCESS`、`FALLBACK`、`FAILED` 或 `CANCELLED` |
|
||
| `agent_flow` | VARCHAR(32) | 否 | 历史兼容字段;当前公开执行统一来自 Chat Harness |
|
||
| `answer` | LONGTEXT | 否 | 安全发布的最终文本兼容字段 |
|
||
| `intent` | VARCHAR(32) | 否 | `SYSTEM_CHAT`、`KNOWLEDGE_QUERY` 或 `DIAGNOSIS` |
|
||
| `release_outcome` | VARCHAR(16) | 否 | `SUCCESS`、`FALLBACK`、`FAILED` 或 `CANCELLED` |
|
||
| `published_result` | JSON | 否 | Release Policy 允许发布的结构化安全结果 |
|
||
| `self_evaluation` | JSON | 否 | 历史兼容字段;当前 Harness 不写入旧 verifier/AiOps 结构 |
|
||
| `feedback` | VARCHAR(16) | 否 | 本次运行的用户反馈 |
|
||
| `total_duration_ms` | INT | 否 | 本次运行总耗时 |
|
||
| `total_token_count` | INT | 否 | 本次运行 Token 消耗 |
|
||
| `step_count` | INT | 否 | 本次运行的 Agent 步骤数 |
|
||
| `tool_call_count` | INT | 否 | 本次运行的工具调用数 |
|
||
| `created_at` | DATETIME | 是 | 创建时间 |
|
||
| `updated_at` | DATETIME | 是 | 更新时间 |
|
||
|
||
## 索引
|
||
|
||
| 索引 | 字段 | 用途 |
|
||
|---|---|---|
|
||
| `run_id` unique | `run_id` | 运行唯一约束 |
|
||
| `idx_diagnosis_run_session_created` | `session_id, created_at, id` | session 下最新运行解析和运行列表 |
|
||
| `idx_diagnosis_run_session_run` | `session_id, run_id` | exact trace / feedback ownership 校验 |
|
||
| `idx_diagnosis_run_status` | `status` | 状态筛选 |
|
||
| `idx_diagnosis_run_agent_flow` | `agent_flow` | 历史兼容筛选 |
|
||
|
||
## 关系
|
||
|
||
- `diagnosis_run.session_id` 逻辑关联 `chat_session.session_id`。
|
||
- `agent_step.run_id` 逻辑关联 `diagnosis_run.run_id`。
|
||
- `tool_invocation.run_id` 逻辑关联 `diagnosis_run.run_id`。
|
||
- `diagnosis_trace_event.run_id` 逻辑关联 `diagnosis_run.run_id`,形成统一生命周期 Timeline。
|
||
- `agent_reasoning_audit.run_id` 逻辑关联 `diagnosis_run.run_id`,但只能通过独立敏感审计读路径查询。
|
||
- 新的自动案例沉淀使用 `case_library.diagnosis_id = diagnosis_run.run_id`。
|
||
|
||
## 注意点
|
||
|
||
- `GET /api/diagnosis/{sessionId}/trace` 未带 `runId` 时只为兼容解析 latest run;新 demo 和新客户端应传 `runId`。
|
||
- latest run 排序使用 `created_at DESC, id DESC`,避免 feedback 或自评估更新 `updated_at` 后改变回放目标。
|
||
- 历史 `diagnosis_session` 会被迁移成兼容 run,但旧混合数据不能被还原成真实多轮边界。
|
||
- 当前诊断发布结果以 `release_outcome + published_result` 为准,不得从旧 self-evaluation 推断 Release Policy 结果。
|
||
- `diagnosis_run` 不保存 reasoning 原文;普通 Run/Trace 查询也不得通过聚合将其带出。
|