mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-24 13:52:12 +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:
@@ -10,6 +10,7 @@ from collections.abc import Iterator
|
||||
from contextlib import contextmanager
|
||||
from contextvars import ContextVar
|
||||
from dataclasses import dataclass, field
|
||||
from decimal import Decimal
|
||||
from typing import Any, Callable
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
@@ -36,6 +37,8 @@ def resolve_path(ctx: dict[str, Any], path: str) -> Any:
|
||||
if isinstance(cur, dict):
|
||||
cur = cur.get(name)
|
||||
else:
|
||||
if name.startswith("_"):
|
||||
return None
|
||||
cur = getattr(cur, name, None)
|
||||
if cur is None:
|
||||
return None
|
||||
@@ -65,11 +68,24 @@ _FILTERS = {
|
||||
}
|
||||
|
||||
|
||||
def _format_decimal(value: Decimal) -> str:
|
||||
if not value.is_finite():
|
||||
return str(value)
|
||||
text = str(value)
|
||||
if "e" in text or "E" in text:
|
||||
exp = value.as_tuple().exponent
|
||||
if isinstance(exp, int) and abs(exp) <= 100:
|
||||
return format(value, "f")
|
||||
return text
|
||||
|
||||
|
||||
def _stringify(value: Any) -> str:
|
||||
if value is None:
|
||||
return ""
|
||||
if isinstance(value, str):
|
||||
return value
|
||||
if isinstance(value, Decimal):
|
||||
return _format_decimal(value)
|
||||
if isinstance(value, (dict, list, tuple)):
|
||||
return json.dumps(value, ensure_ascii=False, default=str)
|
||||
return str(value)
|
||||
@@ -223,6 +239,7 @@ class ExpressionError(ValueError):
|
||||
# 一条画布上的分支条件就能把整个后端冻死。
|
||||
_MAX_POW_EXPONENT = 1024
|
||||
_MAX_POW_BASE = 1e15
|
||||
_MAX_SEQ_REPEAT = 1_000_000
|
||||
|
||||
|
||||
def _safe_pow(base: Any, exponent: Any) -> Any:
|
||||
@@ -237,10 +254,22 @@ def _safe_pow(base: Any, exponent: Any) -> Any:
|
||||
return operator.pow(base, exponent)
|
||||
|
||||
|
||||
def _safe_mul(a: Any, b: Any) -> Any:
|
||||
"""带上界的乘法:序列重复('x' * 10**9、[0] * 10**8)超界直接报错,防止在事件循环里把内存撑爆。"""
|
||||
seq_types = (str, bytes, bytearray, list, tuple, TruncatedRows)
|
||||
if isinstance(a, seq_types) and isinstance(b, int):
|
||||
if len(a) * max(0, b) > _MAX_SEQ_REPEAT:
|
||||
raise ExpressionError(f"序列重复长度超过上限 {_MAX_SEQ_REPEAT}")
|
||||
elif isinstance(b, seq_types) and isinstance(a, int):
|
||||
if len(b) * max(0, a) > _MAX_SEQ_REPEAT:
|
||||
raise ExpressionError(f"序列重复长度超过上限 {_MAX_SEQ_REPEAT}")
|
||||
return operator.mul(a, b)
|
||||
|
||||
|
||||
_BIN_OPS = {
|
||||
ast.Add: operator.add,
|
||||
ast.Sub: operator.sub,
|
||||
ast.Mult: operator.mul,
|
||||
ast.Mult: _safe_mul,
|
||||
ast.Div: operator.truediv,
|
||||
ast.FloorDiv: operator.floordiv,
|
||||
ast.Mod: operator.mod,
|
||||
|
||||
Reference in New Issue
Block a user