mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-23 21:02:01 +00:00
全栈安全加固、性能提速与架构演进:连接池与沙箱止血、双路混合检索、多版本归档及前端分包治理
- 第一批(安全加固与生命周期止血):隔离测试宿主机密钥与 .env 泄漏;修复 SQLite 取消查询挂死、:memory: 连接池报错与 EngineCache 世代竞态;补齐运行与评测删除时的 Checkpointer 线程、Artifact 磁盘文件与无主附件回收;加固三套沙箱路径越界、进程组清理与 Seatbelt 数据目录隔离,封堵 SSRF IPv4-mapped IPv6 元数据绕过与响应体 OOM;修复推理模型多轮 reasoning_content、结构化输出 Token 漏计与缓存折扣计费 - 第二批(数据库/集群/问数提速与首屏分包):补齐核心表索引与 SQLite WAL 调优,列表接口按需 defer 大列,收敛启动扫描并打通跨进程 slot 槽位唤醒;优化跨源全局选表、哈希桶数字绑定、流式 CSV 导入及多方言分析算子;剥离首屏静态引入的 @xyflow/react 与全局样式(首屏主包降至 461.59 kB),补充流式 rAF 攒批、Store 精细订阅与表单无障碍绑定 - 第三批(架构演进与工程自动化闭环):记录库超挂接阈值历史版本自动增量归档至单库多表(解除 SQLite 10 库 ATTACH 硬上限);重构知识库为词面 BM25 与全集合归一化向量矩阵真·双路独立召回并支持游标分批重建;升级多方言感知 SQL 模板词法分析(E'...' / $$...$$ / q'[...]' / # / 嵌套注释)与 Decimal / bool / NaN 参数校验,消除 ledger 层对 api 路由层的反向依赖;拆分 3101 行 CaliberDrafts 页面为 7 个领域子模块,消除检查脚本本机路径硬编码并新增 GitHub Actions CI 门禁与三批回归测试套件
This commit is contained in:
+17
-101
@@ -149,8 +149,6 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
SCHEMA = "agentlab.evidence/1"
|
||||
|
||||
RUN_NOT_FOUND = "run_not_found"
|
||||
REPORT_NOT_FOUND = "evidence_report_not_found"
|
||||
SEGMENT_NOT_FOUND = "evidence_segment_not_found"
|
||||
DOC_MISSING = "evidence_doc_missing"
|
||||
DOC_TAMPERED = "evidence_doc_tampered"
|
||||
@@ -159,17 +157,26 @@ LEGACY_NOTE = "旧版出具:按数值匹配,不是显式引用。同一个
|
||||
NONE_NOTE = "本次运行没有报告文档,也没有出具契约,没有可展示的证据"
|
||||
NO_DOC_NOTE = "本次运行的出具契约采用引用模式核对,但报告没有产出可核对的文档"
|
||||
|
||||
from app.engine.evidence_reader import Sealed as _Sealed, metric_cards as _sealed_cards, read_sealed
|
||||
from app.engine.evidence_reader import (
|
||||
MASKED,
|
||||
REPORT_NOT_FOUND,
|
||||
RUN_NOT_FOUND,
|
||||
Report as _Report,
|
||||
Sealed as _Sealed,
|
||||
ShownText as _Shown,
|
||||
choose_report as _choose,
|
||||
load_sealed,
|
||||
metric_cards as _sealed_cards,
|
||||
output_evidence as _output_evidence,
|
||||
read_sealed,
|
||||
reports_of as _reports,
|
||||
)
|
||||
|
||||
|
||||
async def _sealed(run_id: str) -> _Sealed:
|
||||
try:
|
||||
return await read_sealed(run_id)
|
||||
except LookupError:
|
||||
raise CodedHTTPException(404, "运行记录不存在", RUN_NOT_FOUND) from None
|
||||
return await load_sealed(run_id)
|
||||
|
||||
|
||||
MASKED = "已遮罩"
|
||||
#: 面板底下的遮罩说明。遮的列可能是遮罩列本身,也可能是 SQL 里给它起了别名、套了函数得来的结果列(c.phone AS tel)
|
||||
MASK_NOTE = "这些列取自数据源中设置了遮罩的列,面板上不显示原值。遮罩只减少暴露,不是安全边界"
|
||||
#: 遮没遮核对不了、不显示的值(指标步骤的值、推演的原值):和「已遮罩」分开,读的人不该以为这里设了遮罩
|
||||
@@ -198,66 +205,10 @@ MISSING_RETRIEVAL = "无法读取检索快照,或其中没有这条命中"
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# 报告文档
|
||||
# 报告文档(Report / reports_of / output_evidence 定义在 app/engine/evidence_reader.py)
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
|
||||
@dataclass
|
||||
class _Report:
|
||||
node_id: str
|
||||
doc_artifact: str
|
||||
ok: bool | None
|
||||
repairs: int | None
|
||||
stats: dict[str, Any] | None
|
||||
doc: dict[str, Any] | None
|
||||
#: True 取回并复验通过;False 内容和哈希对不上(或者不是这次运行这个节点写的);None 文件不在了
|
||||
hash_ok: bool | None
|
||||
fields: list[str]
|
||||
#: 写这份报告时的结论句策略(report.checked 里记的,升级前的运行没有)
|
||||
claims: str | None = None
|
||||
|
||||
|
||||
def _reports(sealed: _Sealed, *, nested: bool = False) -> list[_Report]:
|
||||
"""封存范围内每个报告节点最后一次的自查结果,按第一次出现的顺序。
|
||||
|
||||
默认只认这次运行的图上的报告节点:子工作流里的报告(节点 id「子工作流节点 id/…」,子图的事件和父运行在同一个流里)
|
||||
是子工作流那一步内部的东西,父图的答案是子工作流出口的值,不是那份报告本身——证据图、取答案的评测、按成果挑报告
|
||||
(_choose)都按父图自己的认。nested 为真时连子工作流里的一起给(按 ?report=sub/write 点开它们)。可验证报告另按全部
|
||||
report.checked 核对(bundle/build._report_events:自查过的文档一份都不能少)。"""
|
||||
latest: dict[str, dict[str, Any]] = {}
|
||||
for _, etype, node_id, data in sealed.events:
|
||||
if etype == "report.checked" and node_id and isinstance(data, dict) and data.get("doc_artifact") \
|
||||
and (nested or "/" not in node_id):
|
||||
latest[node_id] = data
|
||||
evidence = _output_evidence(sealed)
|
||||
out = []
|
||||
for node_id, data in latest.items():
|
||||
artifact = str(data["doc_artifact"])
|
||||
try:
|
||||
doc = load(artifact)
|
||||
hash_ok: bool | None = True if doc is not None else None
|
||||
except ValueError:
|
||||
doc, hash_ok = None, False
|
||||
# 文档要真是这次运行里这个节点写的:内容寻址只保证没被改,不保证没被张冠李戴
|
||||
if isinstance(doc, dict) and (doc.get("node_id") != node_id or doc.get("run_id") != sealed.run_id):
|
||||
doc, hash_ok = None, False
|
||||
fields = [f for r in evidence if r.get("report_node") == node_id and r.get("doc_artifact") == artifact
|
||||
for f in r.get("fields") or []]
|
||||
out.append(_Report(node_id=node_id, doc_artifact=artifact, ok=data.get("ok"), repairs=data.get("repairs"),
|
||||
stats=(doc or {}).get("stats") or data.get("stats"),
|
||||
doc=doc if isinstance(doc, dict) else None, hash_ok=hash_ok, fields=fields,
|
||||
claims=data.get("claims") if isinstance(data.get("claims"), str) else None))
|
||||
return out
|
||||
|
||||
|
||||
def _output_evidence(sealed: _Sealed) -> list[dict[str, Any]]:
|
||||
output = sealed.payload_of(sealed.nodes_of("output")) or {}
|
||||
primary = output.get("_evidence")
|
||||
if not isinstance(primary, dict):
|
||||
return []
|
||||
return [primary, *[r for r in primary.get("others") or [] if isinstance(r, dict)]]
|
||||
|
||||
|
||||
def _input_payloads(sealed: _Sealed) -> dict[str, Any]:
|
||||
return sealed.payload_of(sealed.nodes_of("input")) or {}
|
||||
|
||||
@@ -830,16 +781,6 @@ def _named_reports(sealed: _Sealed, wanted: str | None) -> list[_Report]:
|
||||
return _reports(sealed, nested=bool(wanted) and "/" in str(wanted))
|
||||
|
||||
|
||||
def _choose(reports: list[_Report], wanted: str | None, sealed: _Sealed) -> _Report:
|
||||
if wanted:
|
||||
chosen = next((r for r in reports if r.node_id == wanted), None)
|
||||
if chosen is None:
|
||||
raise CodedHTTPException(404, "本次运行中没有所选报告撰写节点的文档", REPORT_NOT_FOUND)
|
||||
return chosen
|
||||
primary = next(iter(_output_evidence(sealed)), {})
|
||||
return next((r for r in reports if r.node_id == primary.get("report_node")), reports[0])
|
||||
|
||||
|
||||
async def _chain(seg: dict[str, Any], doc: dict[str, Any], sealed: _Sealed,
|
||||
report_node: str) -> list[dict[str, Any]]:
|
||||
cite = seg.get("cite") or {}
|
||||
@@ -2977,32 +2918,7 @@ def _no_data_view(snap: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
if isinstance(item, dict) and isinstance(item.get("message"), str)]
|
||||
|
||||
|
||||
class _Shown:
|
||||
"""查询步骤上要展示的 SQL、合并 SQL、SQL 检查的片段、合并警告:里面写着的遮罩值(secrets,这次运行查到过的,
|
||||
masking._Secrets)换成「已遮罩」,换了写法的长号码也认。secrets 为 None 时原样交回。changed:换过东西,查询步骤
|
||||
底下要说清这只是展示时遮的。"""
|
||||
|
||||
def __init__(self, secrets: Any) -> None:
|
||||
self._secrets = secrets
|
||||
self.changed = False
|
||||
|
||||
def text(self, value: Any) -> Any:
|
||||
if self._secrets is None or not isinstance(value, str) or not value:
|
||||
return value
|
||||
out = self._secrets.scrub(value, loose=True)
|
||||
self.changed = self.changed or out != value
|
||||
return out
|
||||
|
||||
def checks(self, checks: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
return [{**c, **{k: self.text(c[k]) for k in ("message", "sql_excerpt") if isinstance(c.get(k), str)}}
|
||||
for c in checks]
|
||||
|
||||
def merge(self, view: dict[str, Any]) -> dict[str, Any]:
|
||||
view["sql"] = self.text(view.get("sql"))
|
||||
view["warnings"] = [{**w, "message": self.text(w.get("message"))} for w in view.get("warnings") or []]
|
||||
view["inputs"] = [{**i, **({"checks": self.checks(i["checks"])} if i.get("checks") else {})}
|
||||
for i in view.get("inputs") or []]
|
||||
return view
|
||||
# _Shown 定义在 app.engine.evidence_reader.ShownText 并在上方导入为 _Shown
|
||||
|
||||
|
||||
def _has_values(snap: dict[str, Any]) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user