mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-25 06:42:03 +00:00
口径卡给容器型 vars 输入另存完整值(value_artifact),供数字推演重算
卡里的输入对列表、字典只记「[12 项]」这样的大概,事后要排除几行、改一个数再算一遍,手里没有完整的值。
nodes.*、input.* 的完整值在那个节点封存的产出工件里,agent 字段能按出处从查询快照还原;vars 是谁写的、
写进去的是不是节点产出本身说不准,只能在口径卡算的那一刻存下。
- 此后容器型 vars.* 输入落一份 metric_input 工件 {path, value}(put_json,随运行封存),输入里记下 value_artifact;
id 写在内容寻址的指标集里,不另起台账条目
- 大过 4 MB 的不存,写失败也不存:口径卡照常算出来,只是这个输入以后推演不了
- 金样测试(改动之前的代码真跑出来的工件):只有标量输入的卡逐字节相同、工件 id 不变;带容器型 vars 输入的卡
去掉新键后和以前一字不差
This commit is contained in:
@@ -137,6 +137,13 @@ async def run_metrics(state: GraphState, ctx: NodeContext) -> dict[str, Any]:
|
||||
incomplete = {"incomplete": True, "incomplete_reason": _incomplete_reason(sources),
|
||||
"truncated_sources": sources}
|
||||
inputs = [_input_of(path, values[path], state, ctx, tctx) for path in paths]
|
||||
for path, item in zip(paths, inputs):
|
||||
# 容器型的 vars.* 输入(列表、字典)另存一份完整值:卡里只记了「[12 项]」这样的大概,事后推演
|
||||
# (engine/recompute.py)要拿完整的值重算。nodes.*、input.* 的完整值在那个节点封存的产出工件里,
|
||||
# agent 字段能按出处从查询快照还原,都不用另存;vars 是谁写的、写进去的是不是节点产出本身说不准,
|
||||
# 只能在这一刻存下。只给这种输入多一个键:没有容器型 vars 输入的卡和以前逐字节相同
|
||||
if _container_var(path, values[path]) and (stored := await _store_value(path, values[path], ctx)):
|
||||
item["value_artifact"] = stored
|
||||
sql_check: dict[str, Any] = {}
|
||||
if failed := _failed_queries(inputs, list(use.sources.values()), paths, tctx, checked):
|
||||
sql_check = {"sql_check_failed": True, "sql_check_reason": _sql_check_reason(failed),
|
||||
@@ -726,6 +733,32 @@ def _recompute(substituted: str, tctx: dict[str, Any], value: Any, decimals: int
|
||||
return again == value
|
||||
|
||||
|
||||
#: 另存的完整值最大多少字节(规范 JSON)。查询结果整份赋给变量时可能很大,每张卡都再存一份不值当:大过这个数就
|
||||
#: 不存,推演照实说当时没有保存完整值
|
||||
VALUE_ARTIFACT_MAX = 4 * 1024 * 1024
|
||||
|
||||
|
||||
def _container_var(path: str, value: Any) -> bool:
|
||||
head = _REF_HEAD.match(path)
|
||||
return isinstance(value, (list, dict)) and head is not None and head.group(1) == "vars"
|
||||
|
||||
|
||||
async def _store_value(path: str, value: Any, ctx: NodeContext) -> str | None:
|
||||
"""容器型 vars 输入的完整值落成 metric_input 工件:{path, value}。它的 id 记在指标集里,指标集内容寻址、
|
||||
在封存范围内,完整值也就随运行封存,不另起台账条目。存不下(太大、写失败)就不存:口径卡照常算出来,
|
||||
只是这个输入以后推演不了。"""
|
||||
from app.core.artifact_store import canonical_json, put_json
|
||||
|
||||
content = {"path": path, "value": value}
|
||||
try:
|
||||
if len(canonical_json(content).encode()) > VALUE_ARTIFACT_MAX:
|
||||
return None
|
||||
return await put_json(content, kind="metric_input", run_id=ctx.run.run_id, node_id=ctx.node.id,
|
||||
meta={"path": path})
|
||||
except Exception: # noqa: BLE001 - 完整值存不下不该毁掉口径卡
|
||||
return None
|
||||
|
||||
|
||||
async def _store(card: dict[str, Any], caliber: str, version: str, ctx: NodeContext) -> str | None:
|
||||
"""整张卡落成 metric_set 工件。写失败不毁掉运行,只是这张卡没法被引用。"""
|
||||
from app.core.artifact_store import put_json
|
||||
|
||||
Reference in New Issue
Block a user