mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-22 01:02:00 +00:00
探查失败不再伪装成"还没探查":把实情和下一步交给 agent
从 run 554a0f92 查出来的。那次问「userID=2 是谁」,9 次工具调用花掉 6 次、
前 29 秒没碰到一点真数据:
+ 2.1s db_schema → "还没有探查过结构,请在设置页里执行一次"
+ 4.9s db_schema ×7 个猜的表名 → "没有 user / users / member / …"
+ 7.7s SELECT 1 → 不信任前面的结果,先探一下连通性
+12.8s information_schema.tables ┐
+18.3s information_schema.tables ├ 自己把 schema 重建一遍
+21.5s information_schema.columns ┘
+29.2s 终于开始查真数据
根因:shop 的探查**失败过**(Lost connection to MySQL server during query),
但失败被存成了一个"成功但没表"的缓存,schema_synced_at 照常盖戳:
{"tables": {}, "total": 0,
"error": "OperationalError: (2013, 'Lost connection...')",
"available_schemas": ["prod_shop", "shop_dev", "toolsdb", …10 个]}
于是三处同时说假话:界面显示"结构未探查"、工具对 agent 说"还没有探查过"、
而那 10 个候选 schema 就躺在缓存里没人交出去。**用户明明点过探查,是超时了。**
**分清"还没探查"和"探查失败了"。** introspect 的结果加 failed 标记;
失败照样把缓存存下来(候选是下一步的线索),但不盖"已同步"的戳;
界面把红字和候选列出来;探查按钮的提示也分清是超时还是 schema 填错。
**给 agent 一个它做得到的下一步。** 以前那句"请在设置页里执行一次结构探查"
——agent 进不了设置页。现在换成实情 + 候选 schema + "不要猜表名,直接查
information_schema / sqlite_master"。那条自救路线 agent 最后也走通了,
只是自己摸索了三轮才找到,直接告诉它就行。
describe_table 同样:缓存空的时候说"数据源里没有 user"是在误导,真相是我们
什么都不知道。那次一口气问了 7 个表名,收到 7 条一模一样的
"没有 X。现有的对象:(还没探查过结构)",白花一整步。
顺带把逐表反射换成 SQLAlchemy 2.0 的 get_multi_*,但**别指望它治超时**:
实测 60 张表逐表 121 次往返、批量 122 次——反射缓存本来就把 get_columns 和
get_pk_constraint 合并了,而 MySQL 方言压根没实现 get_multi_*,落到基类还是
每表一次 SHOW CREATE TABLE。换它是因为这是 2.0 的正经接口、少三层
try/except,不是因为它快。shop 那次超时多半是偶发的,所以真正的对策
不在那儿,在"失败要如实记成失败"。
重新探查了一次 shop:153 张表、38 秒、成功。之前 agent 要花 6 次调用、
29 秒拼出来的东西,现在工具描述第一眼就给了。
验证:后端 269 passed(test_datasource.py 新增 4 条,守"失败不能被说成没探查过"
和"给 agent 的下一步它做得到");tsc 干净;三个 check 不回归。
This commit is contained in:
@@ -234,11 +234,15 @@ function SourceCard({ row, onChanged, onEdit }: {
|
||||
setBusy('introspect')
|
||||
try {
|
||||
const r = await api.datasources.introspect(row.id)
|
||||
toast(`探到 ${r.table_count} 个对象`, r.table_count ? 'ok' : 'error')
|
||||
if (!r.table_count) {
|
||||
// 大概率是 schema 没配对:只读账号名下往往什么都没有
|
||||
const s = await api.datasources.schema(row.id)
|
||||
toast(s.summary?.includes('schema') ? s.summary.slice(0, 120) : '没探到对象,检查 schema 配置', 'error')
|
||||
if (r.table_count) {
|
||||
toast(`探到 ${r.table_count} 个对象`, 'ok')
|
||||
} else if (r.schema_error) {
|
||||
// 真失败了。以前这里一律说"检查 schema 配置",而超时和填错 schema
|
||||
// 要做的事完全不同,卡片上那段红字写了实情,这里指过去
|
||||
toast(`探查失败:${r.schema_error.slice(0, 100)}`, 'error')
|
||||
} else {
|
||||
// 连得上、也没报错,就是这个 schema 下真的没有对象
|
||||
toast('这个库里没有对象,多半是 schema 填的不对——卡片上列了可选的', 'error')
|
||||
}
|
||||
await onChanged()
|
||||
} catch (e: any) {
|
||||
@@ -285,6 +289,19 @@ function SourceCard({ row, onChanged, onEdit }: {
|
||||
<div className="mt-1 text-[11px] text-dim">{row.description}</div>
|
||||
)}
|
||||
|
||||
{row.schema_error && (
|
||||
<div className="mt-1.5 rounded border px-2 py-1.5 text-[10.5px] leading-relaxed"
|
||||
style={{ borderColor: 'var(--err)', color: 'var(--err)' }}>
|
||||
上次探查失败:{row.schema_error}
|
||||
{!!row.available_schemas?.length && (
|
||||
<div className="mt-1 text-dim">
|
||||
这台服务器上可选的库:{row.available_schemas.slice(0, 10).join('、')}
|
||||
——当前连的是「{row.database || '未指定'}」,不对的话在「编辑」里改
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-1.5 flex flex-wrap items-center gap-2 text-[10.5px] text-faint">
|
||||
<span className="mono">
|
||||
{row.kind === 'sqlite' ? row.database : `${row.username ?? ''}@${row.host ?? ''}:${row.port ?? ''}`}
|
||||
@@ -294,6 +311,14 @@ function SourceCard({ row, onChanged, onEdit }: {
|
||||
<button className="chip hover:bg-hover" onClick={peek}>
|
||||
<Table2 size={9} className="mr-1 inline" />{row.table_count} 个对象
|
||||
</button>
|
||||
) : row.schema_error ? (
|
||||
// "还没探查"和"探查失败了"是两回事:前者点一下按钮就行,后者点了
|
||||
// 也没用。以前两者显示成同一句,于是用户点了探查、看到还是"未探查",
|
||||
// 而 agent 那边也被告知"还没探查过"——没有一处说的是真话
|
||||
<span className="chip" style={{ color: 'var(--err)', borderColor: 'var(--err)' }}
|
||||
title={row.schema_error}>
|
||||
探查失败
|
||||
</span>
|
||||
) : (
|
||||
<span className="chip" style={{ color: 'var(--warn)' }}>结构未探查</span>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user