mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-26 07:51:59 +00:00
子工作流的证据交回父图(后端):子图每一步进同一个运行、台账和口径卡交回、出口字段带出处、父图跨子图往下追
调查时发现:run_subgraph 只设了节点 id 前缀(node_prefix)没用上,子图在父节点里用 ainvoke 跑,LangGraph 不把它的 custom 事件交给父图的流——子图里每一步在运行的事件里一条都没有,时间线看不到、封存也不含它查过的数。「事件本来就在同一个 运行里」此前并不成立(docs/design/orchestration-round/00-总方案.md §2)。 - engine/context + nodes/multi:子图拿到父运行的写入口(STREAM_KEY)和前缀(PREFIX_KEY),子图里的节点经它发事件,节点 id 「子工作流节点 id/…」,嵌套的一层层接上;工件按这次运行里的 id 记。子图里报的错(含被驳回)交回时节点 id 换成这一层的、 名字接上子工作流(runner 的 run.failed / run.cancelled 写「子工作流 › 那一步」),不再和父图里同名的节点混在一起 - nodes/multi:子图的台账条目加前缀并进父图 evidence(父图报告的目录据此收进子图里的查询和口径卡);子图口径卡的产出以 「子工作流节点 id/卡」进父图 nodes;出口每个字段按出口模板认出处(模板整串就是一个取值链、渲染出来正是那个值的才认, 同口径卡认输入的那一套),出自子图运行输入的按子工作流节点的「输入」模板再往父图追一层,追不到的记 subgraph_input - engine/compiler:子工作流节点自己的 node.finished 不再重记交回来的台账条目(子图那几步自己的 node.finished 已经带着) - nodes/metrics:父图口径卡读 nodes.<子图>.output.<字段>(或 assign_to 变量的字段)时接上那个字段的出处,另记 subgraph、 field;经子图出口转抄子图口径卡的指标照样带上不完整、存疑;cell(nodes.<子图>.output.<原样交出的查询结果>, …) 按台账 认出子图里的那份快照 - engine/lineage:静态认法跨子图往下追(出口模板 → 子图里接着认;子图的运行输入按「输入」模板回父图认;最多 3 层), 和运行时同一套;whole_ref 是两边共用的「整串一个取值链」判断。lint_process.load_subgraphs 往下读嵌套的子工作流, subgraph_spec 给静态认法取图;没读好放进来的照旧停在子工作流节点 - nodes/report:报告收证据的范围加上上游子工作流交回来的(evidence_from 写了子工作流节点的一并算) - nodes/io:指标出具的缺口里,停在子图里的说停在那个子工作流(和静态检查同一句) - api/evidence:卡上记的节点 id 按卡所在那一层认(_scoped:子图里的卡写子图里的 id),转抄、输入、追不到的那几步一路给到 子图里的那一格;子图里的节点按 node.started 记的名字接成「子工作流 › 节点」(node_label、subgraph_label);双盲复算条目 里的卡 id 同样换成这次运行里的 - apps/resolve:实例进度不单列子图里的步骤 - 口径账本的 use_caliber 不改;比对读封存的查询,子图里的查询如今在封存范围里,照常认得出 测试:test_subgraph_evidence(子图每一步进运行、报错点名子图里那一步、实例进度、父图口径卡跨子图追到查询格并完整出具、 子图里追不到的父图降档、不是整串取值链的停在子工作流、运行输入往父图追、嵌套两层、静态检查与运行时一致(含两层和输入 模板)、父图报告引用子图里的查询和口径卡并一路点到那一格、封存与可验证报告、子图里的遮罩照父图的运行)。去掉「交写入口」 回跑,五条失败(快照不在封存范围里)。后端全量 14472 通过
This commit is contained in:
+64
-16
@@ -209,6 +209,9 @@ class _Sealed:
|
||||
#: 按需裁判的判定(evidence.judged 事件),按先后:(seq, 节点, 载荷)。不管落在封存前后都收——
|
||||
#: 失败后接着跑的运行会把早先追加的判定封进新的清单里,它仍然是按需裁判的批注
|
||||
judged: list[tuple[int, str | None, dict[str, Any]]] = field(default_factory=list)
|
||||
#: 节点 id → node.started 上记的名字、类型。子工作流里的节点(「子工作流节点 id/…」)不在这次运行的图上,名字从这里取
|
||||
labels: dict[str, str] = field(default_factory=dict)
|
||||
types: dict[str, str] = field(default_factory=dict)
|
||||
|
||||
@property
|
||||
def sealed(self) -> bool:
|
||||
@@ -273,6 +276,11 @@ async def _sealed(run_id: str) -> _Sealed:
|
||||
out.retrievals.setdefault(str(data["artifact"]), {"node_id": node_id, "source": data.get("collection")})
|
||||
elif etype == "caliber.upgrade":
|
||||
out.upgrades[node_id] = data
|
||||
elif etype == "node.started":
|
||||
if isinstance(data.get("label"), str) and data["label"]:
|
||||
out.labels.setdefault(node_id, data["label"])
|
||||
if isinstance(data.get("node_type"), str) and data["node_type"]:
|
||||
out.types.setdefault(node_id, data["node_type"])
|
||||
if etype != "node.finished":
|
||||
continue
|
||||
if data.get("artifact"):
|
||||
@@ -280,7 +288,9 @@ async def _sealed(run_id: str) -> _Sealed:
|
||||
for entry in data.get("evidence") or []:
|
||||
if isinstance(entry, dict) and entry.get("artifact"):
|
||||
out.ledger.add((node_id, entry["artifact"]))
|
||||
out.entries.append({**entry, "node_id": node_id})
|
||||
# 条目里另记的节点 id(双盲复算复算的口径卡)是那个节点所在那一层图里的 id:换成这次运行里的
|
||||
out.entries.append({**entry, "node_id": node_id,
|
||||
**({"card": _scoped(node_id, entry["card"])} if entry.get("card") else {})})
|
||||
artifact = str(entry["artifact"])
|
||||
if entry.get("kind") == "query":
|
||||
out.queries[artifact] = {
|
||||
@@ -975,20 +985,21 @@ async def _metric_chain(seg: dict[str, Any], cite: dict[str, Any], entry: dict[s
|
||||
# 期 4:这个指标做没做过双盲复算、结果如何。没有双盲复算复核过这份指标集时没有这个键,老运行一字不差
|
||||
if checked := _dual_check_of(sealed, str(entry.get("node_id") or ""), artifact, metric_id, metric):
|
||||
step["dual_check"] = checked
|
||||
card_node = str(entry.get("node_id") or "")
|
||||
if metric is not None and metric.get("inputs"):
|
||||
# 输入追没追到原始数据(engine/lineage.py):和「有出处」(确定性复算一致)是两件事,面板分开说。追不到的照实说
|
||||
# 出处追到哪个节点为止;卡上没有输入(常量)的没有可追的,不给这个键
|
||||
step["untraced"] = _untraced_steps(metric, sealed)
|
||||
step["untraced"] = _untraced_steps(metric, sealed, card_node)
|
||||
catalog = doc.get("catalog") or {}
|
||||
inputs: list[dict[str, Any]] = []
|
||||
#: 输入指到的查询快照 → 被引用的格;同一份快照只给一个查询步骤,格合在一起高亮
|
||||
wanted: dict[str, list[tuple[Any, Any]]] = {}
|
||||
held, word = await _metric_masks(metric or {}, str(entry.get("node_id") or ""), artifact, sealed, masks, card=card)
|
||||
for item in (metric or {}).get("inputs") or []:
|
||||
one = {"step": "input", **item}
|
||||
one = {"step": "input", **item, **_scoped_ids(item, card_node, sealed)}
|
||||
if item.get("through"):
|
||||
# 穿过原样解析查询结果的整形节点按位置取的格:面板写明经过的是哪个节点(图里的名字)
|
||||
one["through_label"] = _node_label(sealed, item["through"])
|
||||
one["through_label"] = _node_label(sealed, one["through"])
|
||||
artifact_of = item.get("artifact")
|
||||
if artifact_of and item.get("via") in ("tool_cell", "agent_field"):
|
||||
one["query"] = _query_alias(catalog, artifact_of)
|
||||
@@ -999,7 +1010,8 @@ async def _metric_chain(seg: dict[str, Any], cite: dict[str, Any], entry: dict[s
|
||||
one = _withheld(one, found)
|
||||
inputs.append(one)
|
||||
# 转抄另一张口径卡的指标(对账卡、召回卡的「口径」那一项):跨卡往下追,接上那个指标自己的一段出处,一直到查询格子
|
||||
upstream = await _upstream_steps(metric or {}, sealed, masks, catalog, wanted, {(artifact, str(metric_id))})
|
||||
upstream = await _upstream_steps(metric or {}, sealed, masks, catalog, wanted, {(artifact, str(metric_id))},
|
||||
card_node=card_node)
|
||||
if withheld := {path: _held_word(found) for path, found in held.items() if found.kind != "table"}:
|
||||
# 代入式里那几处同样写「已遮罩」(遮没遮核对不了的写「无法核对」):不然标签里遮着、代入式里亮着,同一个值换个
|
||||
# 地方照样看得到。整份结果当输入的不换:代入式里本来就只留着它的路径
|
||||
@@ -1015,7 +1027,7 @@ async def _metric_chain(seg: dict[str, Any], cite: dict[str, Any], entry: dict[s
|
||||
|
||||
async def _upstream_steps(metric: dict[str, Any], sealed: _Sealed, masks: "_Masks", catalog: dict[str, Any],
|
||||
wanted: dict[str, list[tuple[Any, Any]]], seen: set[tuple[str, str]],
|
||||
depth: int = 1) -> list[dict[str, Any]]:
|
||||
depth: int = 1, *, card_node: str = "") -> list[dict[str, Any]]:
|
||||
"""指标的输入里转抄另一张口径卡的指标的(nodes.<卡>.metrics[i].value,卡上记着 upstream),每个接一步 upstream:那张
|
||||
卡的那个指标(名字、值、式子、代入式、核对状态,取值按同一套遮罩),它自己的输入(同指标步骤的输入;落在查询快照上的
|
||||
并进 wanted,后面照常给查询步骤),追没追到原始数据。转抄的转抄一层层接着追(防环:同一个指标只接一次;最多
|
||||
@@ -1033,7 +1045,8 @@ async def _upstream_steps(metric: dict[str, Any], sealed: _Sealed, masks: "_Mask
|
||||
if (artifact, metric_id) in seen:
|
||||
continue
|
||||
seen.add((artifact, metric_id))
|
||||
node = str(item.get("node_id") or "")
|
||||
# 卡上记的是卡所在那一层图里的 id(子工作流里的卡转抄同一张子图里的卡;经子工作流出口转抄的已经是这一层的)
|
||||
node = str(_scoped(card_node, item.get("node_id")) or "")
|
||||
card, hash_ok = _load_card(artifact)
|
||||
found = _metric_in(card, metric_id)
|
||||
step: dict[str, Any] = {
|
||||
@@ -1060,7 +1073,7 @@ async def _upstream_steps(metric: dict[str, Any], sealed: _Sealed, masks: "_Mask
|
||||
if found.get("incomplete") else {}),
|
||||
**({"sql_check_failed": True, "sql_check_reason": found.get("sql_check_reason") or ""}
|
||||
if found.get("sql_check_failed") else {}),
|
||||
"untraced": _untraced_steps(found, sealed),
|
||||
"untraced": _untraced_steps(found, sealed, node),
|
||||
})
|
||||
if withheld := {path: _held_word(h) for path, h in held.items() if h.kind != "table"}:
|
||||
step["substituted"] = recompute.substituted_without(found, withheld)
|
||||
@@ -1068,7 +1081,7 @@ async def _upstream_steps(metric: dict[str, Any], sealed: _Sealed, masks: "_Mask
|
||||
for sub in found.get("inputs") or []:
|
||||
if not isinstance(sub, dict):
|
||||
continue
|
||||
one = {"step": "input", **sub}
|
||||
one = {"step": "input", **sub, **_scoped_ids(sub, node, sealed)}
|
||||
if sub.get("artifact") and sub.get("via") in SNAPSHOT_VIAS:
|
||||
one["query"] = _query_alias(catalog, sub["artifact"])
|
||||
if cell := _input_cell(sub, catalog):
|
||||
@@ -1079,27 +1092,60 @@ async def _upstream_steps(metric: dict[str, Any], sealed: _Sealed, masks: "_Mask
|
||||
inputs.append(one)
|
||||
step["inputs"] = inputs
|
||||
out.append(step)
|
||||
out += await _upstream_steps(found, sealed, masks, catalog, wanted, seen, depth + 1)
|
||||
out += await _upstream_steps(found, sealed, masks, catalog, wanted, seen, depth + 1, card_node=node)
|
||||
return out
|
||||
|
||||
|
||||
def _scoped(card_node: Any, node_id: Any) -> Any:
|
||||
"""口径卡上记的节点 id(输入来自哪个节点、穿过的整形节点、转抄的卡)是卡所在那一层图里的 id:子工作流里的卡
|
||||
(节点 id「子工作流节点 id/卡」)记的是子图里的 id,换成这次运行里的(接上同一个前缀)。最外层的卡原样;经子工作流
|
||||
出口接上的出处(multi.run_subgraph 记的)已经是卡这一层的 id,同样接上卡的前缀就对了。"""
|
||||
card = str(card_node or "")
|
||||
if not isinstance(node_id, str) or not node_id or "/" not in card:
|
||||
return node_id
|
||||
return f"{card.rsplit('/', 1)[0]}/{node_id}"
|
||||
|
||||
|
||||
def _scoped_ids(item: dict[str, Any], card_node: str, sealed: _Sealed) -> dict[str, Any]:
|
||||
"""输入步骤上的节点 id 换成这次运行里的(_scoped);落在子工作流里的另给图上的名字(node_label、subgraph_label:
|
||||
「子工作流 › 节点」),画布、记录页认不出这个 id 时照它写。最外层的输入不多带键,和以前一字不差。"""
|
||||
out: dict[str, Any] = {}
|
||||
for key in ("node_id", "through", "subgraph"):
|
||||
if isinstance(item.get(key), str) and item[key]:
|
||||
out[key] = _scoped(card_node, item[key])
|
||||
if "/" in str(out.get("node_id") or ""):
|
||||
out["node_label"] = _node_label(sealed, out["node_id"])
|
||||
if out.get("subgraph"):
|
||||
out["subgraph_label"] = _node_label(sealed, out["subgraph"])
|
||||
return out
|
||||
|
||||
|
||||
def _node_label(sealed: _Sealed, node_id: Any) -> str:
|
||||
"""封存的图里这个节点的名字,没有名字的写 id。"""
|
||||
"""封存的图里这个节点的名字,没有名字的写 id。子工作流里的节点(「子工作流节点 id/…」)不在图上,按 node.started 记的
|
||||
名字一层层接上:「子工作流 › 节点」。"""
|
||||
node = next((n for n in (sealed.graph or {}).get("nodes") or [] if isinstance(n, dict) and n.get("id") == node_id), {})
|
||||
return str((node.get("data") or {}).get("label") or node_id or "")
|
||||
if node or not isinstance(node_id, str) or "/" not in node_id:
|
||||
return str((node.get("data") or {}).get("label") or node_id or "")
|
||||
parts = node_id.split("/")
|
||||
names = [_node_label(sealed, parts[0])]
|
||||
for i in range(2, len(parts) + 1):
|
||||
here = "/".join(parts[:i])
|
||||
names.append(sealed.labels.get(here) or parts[i - 1])
|
||||
return " › ".join(names)
|
||||
|
||||
|
||||
def _untraced_steps(metric: dict[str, Any], sealed: _Sealed) -> list[dict[str, Any]]:
|
||||
def _untraced_steps(metric: dict[str, Any], sealed: _Sealed, card_node: str = "") -> list[dict[str, Any]]:
|
||||
"""指标的输入里追不到原始数据的:[{path, node_id, label, type}],label 是封存的图里那个节点的名字、type 是节点类型
|
||||
(面板按它写「数据整形」「沙箱代码」)。认不出是哪个节点的,node_id、label 为 None。"""
|
||||
(面板按它写「数据整形」「沙箱代码」)。认不出是哪个节点的,node_id、label 为 None。节点 id 按卡所在那一层认
|
||||
(_scoped)。"""
|
||||
nodes = {n.get("id"): n for n in (sealed.graph or {}).get("nodes") or [] if isinstance(n, dict)}
|
||||
out = []
|
||||
for item in untraced(metric.get("inputs") or []):
|
||||
node_id = item.get("node_id")
|
||||
node_id = _scoped(card_node, item.get("node_id"))
|
||||
node = nodes.get(node_id) or {}
|
||||
out.append({"path": item.get("path"), "node_id": node_id,
|
||||
"label": _node_label(sealed, node_id) if node_id else None,
|
||||
"type": node.get("type") or None})
|
||||
"type": node.get("type") or sealed.types.get(str(node_id or "")) or None})
|
||||
return out
|
||||
|
||||
|
||||
@@ -1495,6 +1541,8 @@ class _InputMasks:
|
||||
return None, True
|
||||
|
||||
def _output(self, node_id: Any) -> Any:
|
||||
# 卡的取值链里写的是卡所在那一层图里的 id(子工作流里的卡写子图里的 id),换成这次运行里的再找
|
||||
node_id = _scoped(self._card, node_id)
|
||||
if self._given is not None:
|
||||
return self._given(node_id)
|
||||
if self._outputs is None:
|
||||
|
||||
Reference in New Issue
Block a user