Repository navigation
[v2] Fix the Loop variable catalog, name refused publishes, and free the iteration ports - #436
Conversation
The engine publishes only a Loop's named outputs to the outer scope (as
desktop loop_round.rs exit_outputs does), resolves its loop variables only
inside the body, and never assigns a body's round Start. Publication still
declared `{loop}.output` and checked only that a producer was visible, so a
graph saved with `loop-1.output` or `loop-1-start.input` published fine and
failed at runtime as "unassigned".
Publication now rejects such selector, template and aggregator references as
invalid_loop_reference on the consuming node, and the static catalog no
longer declares `{loop}.output`. This is stricter than desktop, recorded in
the README.
Refs ora-space/circus#1388
…ble catalog
The editor catalog offered `{loop}.output` to consumers after a Loop and only
the round Start's `input` inside it; the engine assigns neither, so every
workflow configured from the picker failed at runtime. Following the owner's
decision (fix the catalog, not the engine), Loops now work the way Iteration
already does: outer consumers see the Loop's named `loopConfig.outputs`
(typed `any`, as the backend declares them, so aggregator typing agrees);
body members see the loop variables, their in-body upstream, and what the
Loop itself sees (e.g. `start.input`); the round Start contributes nothing.
Desktop shares this catalog (packages/workflow-mock/src/variable-catalog.ts)
and the same bug; it is left for the desktop comparison.
Refs ora-space/circus#1388
A refused publish closed the dialog and left only the list-level "工作流图无法 解析,请检查后再保存。", which spoke of saving and named nothing. v2-server now returns the domain's node, field and reason as the params of 400 workflow_run_graph_parse (read through a FaultParams method so the HTTP layer still does not import the domain). The publish dialog stays open while publishing and, on failure, says the publish was rejected, names the node by its title and the field in the author's terms, and shows the server's reason; other refusals keep their own message under a 发布失败 prefix. Refs ora-space/circus#1388
…e dot The iteration header is raised (z-20) above its region, and the frame's input and output ports sat beneath it, so the inner half of each port's hit area belonged to the header: pressing there dragged the frame instead of starting a connection. The ports now stack above the header. The Loop container renders its ports after an unraised header and was not affected. The new e2e spec hit-tests both containers' ports across the dot, drags a connection from the inner half, and publishes a stale `loop.output` graph to check the refusal names the node in the dialog. Refs ora-space/circus#1388
zhangxinhao
left a comment
There was a problem hiding this comment.
需要修改(61429bd)
@EricWvi 我看了这个 PR,理解它是要让 Loop 变量选择器与执行语义一致,在发布对话框里点明被拒的节点和字段,并让迭代端口的整个圆点都能拖线。有 3 处合并前需要改,其余都是建议。
合并前需要修正三处 Loop 校验回归。新规则会拒绝原本可执行的轮次 Start 默认值、与 Loop 节点同前缀的全局变量,以及使用显式命名输出 output 的部分工作流。前端相关单测通过,发布接口测试因缺少数据库配置而跳过。
- ❗ P1-1(合并前需要改):保留显式命名输出 output 的类型(见行内)
- ❗ P1-2(合并前需要改):按完整变量名识别全局声明(见行内)
- ❗ P1-3(合并前需要改):保留轮次 Start 已赋默认值的引用(见行内)
- 💬 其他建议:P2-1 发布请求进行中仍能关闭对话框;P2-2 聚合器会列出发布不接受的循环变量;P2-3 校验 Loop 自身配置里的无效引用
- 测试:
go test -race ./internal/workflow通过;npm test -- src/lib/workflows/mock/variable-catalog.test.ts src/features/workflows/editor/workflow-publish-error.test.ts src/features/workflows/page.test.tsx通过;go test -race -v ./internal/server -run '^TestWorkflow(PublishRefusalNamesTheNode|AnalysisAndPublishValidation)$'没跑(在 v2-server 中尝试运行,两个发布接口用例均因未设置 TEST_DATABASE_URL 而跳过。);没跑全量和 e2e。
涉及对外 API/协议,建议 owner 再看一眼。
P1 改完后我会再看一轮;其余都是建议,怎么处理由你决定。
自动检视 · 基于 61429bd · 第 1 轮(全量)
| // A Loop publishes only its named outputs (below), never an `output`. | ||
| case "condition", "iteration", "aggregator", "loop": |
There was a problem hiding this comment.
P1-1(合并前需要改) loopConfig.outputs 可以显式将一个字符串结果命名为 output,运行时的 NewPool 仍会把这个键声明为 string。我验证了把显式的 loop.output 和 start.input 一起作为 Aggregator 候选时,merge-base 能解析,当前版本却因 any 和 string 不一致而拒绝,已发布的图也会在重新解析时受影响。建议保留这个显式输出的现有类型,前端目录也使用同一类型。
| // A Loop publishes only its named outputs (below), never an `output`. | |
| case "condition", "iteration", "aggregator", "loop": | |
| case "condition", "iteration", "aggregator": | |
| case "loop": | |
| // NewPool retains the legacy string type when a Loop explicitly names an export "output". | |
| cfg, _ := (Node{data: n.data}).loopConfig() | |
| for _, output := range cfg.Outputs { | |
| if output.Name == "output" { | |
| declare(n, output.Name, "string") | |
| } | |
| } |
可直接采纳这条修改。
| check := func(n *node, field string, parts []string) error { | ||
| producer := d.byID[parts[0]] |
There was a problem hiding this comment.
P1-2(合并前需要改) 这里先按前缀找节点,会把合法的全局变量误当成 Loop 变量。比如节点 ID 为 loop,全局变量 loop.label 初值为 hello,循环体 Agent 的 {{#loop.label#}} 在 merge-base 可以解析,loopPool 也会继承该值。当前版本会在发布和快照启动时都拒绝这张图。建议在按节点分类前,先用根变量全名匹配已校验的全局声明。
| check := func(n *node, field string, parts []string) error { | |
| producer := d.byID[parts[0]] | |
| globals, _ := validateGlobals(d.raw, true) // buildScopes already validated the declarations. | |
| check := func(n *node, field string, parts []string) error { | |
| if len(parts) < 2 || globals[qualified(parts)] != "" { | |
| return nil | |
| } | |
| producer := d.byID[parts[0]] |
可直接采纳这条修改。
| if producer.kind == "start" && producer.container { | ||
| return invalid("invalid_loop_reference", n.id, field, | ||
| "round Start "+producer.id+" assigns no variables; "+selected+" is never set, read the Loop's variables instead") | ||
| } |
There was a problem hiding this comment.
P1-3(合并前需要改) 轮次 Start 的普通 input 没有赋值,但 loopPool 会通过 NewPool(body) 将带默认值的输入写入每轮变量池。我用现有 Loop fixture 验证了 entry.topic 带字符串默认值时,merge-base 能解析并读到该值,当前版本却会拒绝引用它的 Agent。启动已发布的快照同样走这段校验。建议保留带默认值的声明,前端目录也按同一规则过滤。
| if producer.kind == "start" && producer.container { | |
| return invalid("invalid_loop_reference", n.id, field, | |
| "round Start "+producer.id+" assigns no variables; "+selected+" is never set, read the Loop's variables instead") | |
| } | |
| if producer.kind == "start" && producer.container { | |
| for _, variable := range (Node{data: producer.data}).StartVariables() { | |
| if variable.Name == parts[1] && variable.Value != nil { | |
| return nil | |
| } | |
| } | |
| return invalid("invalid_loop_reference", n.id, field, | |
| "round Start "+producer.id+" has no default value for "+selected+"; read the Loop's variables instead") | |
| } |
可直接采纳这条修改。
| <AlertDialogCancel>{t("common.cancel")}</AlertDialogCancel> | ||
| <AlertDialogAction onClick={() => void confirmPublish()}> | ||
| <AlertDialogAction | ||
| disabled={publishWorkflowMutation.isPending} |
There was a problem hiding this comment.
P2-1(建议) 等待发布时还能点取消或按 Esc,关闭也不会取消请求。若请求随后被拒,错误只写进已经隐藏的对话框,下次打开又会清除它。建议在请求期间同时禁用取消按钮,并在 AlertDialog 的 onOpenChange 拦住关闭请求,等发布结果返回再恢复交互。
| if (consumerLoopId === node.id) { | ||
| for (const variable of config?.variables ?? []) { | ||
| entries.push(nodeVariable(node, variable.name, variable.valueType)); | ||
| } | ||
| return; |
There was a problem hiding this comment.
P2-2(建议) Loop 体内的聚合器也直接使用这份目录,所以现在能选到 loop.draft 或继承来的 start.input。后端用循环体自己的 scope.validateDeclarations 校验聚合候选,该声明表里没有这些继承变量。我用只有 loop.draft 一个候选的图验证了发布会报 selector is not declared。建议先让聚合器候选过滤遵循当前声明表,并保留 Agent 和 Condition 的可见范围。
| return nil | ||
| } | ||
| for _, n := range d.nodes { | ||
| if !d.active[n.id] || n.kind == "loop" { |
There was a problem hiding this comment.
P2-3(建议) 这里跳过了整个 Loop 节点,但 validateLoopBindings 只检查配置引用的生产者是否在作用域内。把现有 fixture 的 loopConfig.outputs[0].variableSelector 改为 ['entry', 'input'] 仍能发布,等循环完成读取输出时才会失败。建议按初始值和轮次内配置分别校验,前者按外层作用域判断,反馈、退出条件和输出按轮次作用域判断。
The reference check refuses `{loop}.output` before scope typing runs, so
reverting the declarations.go change went unnoticed. declarations() now
returns the static catalog it builds, and an internal test reads it
directly: a Loop declares its named outputs (typed any) and no `output`.
Refs ora-space/circus#1388
invalid_loop_reference skipped Loop nodes, so `until` or `outputs` reading the round Start, or a second Loop whose `initial` read `loopA.output`, still published and failed at run time. A Loop's `initial` is now checked as an outer reference (named outputs only, never the Loop itself), and its `feedback`, `until` and `outputs` as round-pool references (its loop variables, never its named outputs); the round Start is always refused. An aggregator inside a Loop body is typed against the body's own declarations, so its candidates must come from the body or be globals; it is refused with that reason rather than "selector is not declared". A global whose name starts with a Loop or round Start ID resolves as the global and is no longer refused. Templates now carry the field they came from (agentConfig.prompt, cases, loopConfig.until) instead of a generic "template", so the editor can name a Condition's comparison value correctly. Refs ora-space/circus#1388
…ip by containerId Publication types an aggregator inside a Loop body against the body's own declarations, but the catalog offered it the loop variables and the Loop's upstream, which publish then refused. Such an aggregator now sees only globals and its in-body upstream products. Loop membership is now `data.containerId` everywhere in the catalog and the Loop panel, matching the backend, which refuses a Loop member without it; Iteration membership stays `parentId`. Refs ora-space/circus#1388
…nce was written Cancel or Escape while a publish was pending closed the dialog, and a later refusal was then shown nowhere. The dialog now stays open until the publish settles; a ref guards against a second submit in the same tick, and tests cover both. Refusal fields follow the server's new template sources: an Agent prompt reads 提示词变量, a Condition value 分支条件, and a Loop's initial value, next-round value, end condition and outputs are named as such. Refs ora-space/circus#1388
zhangxinhao
left a comment
There was a problem hiding this comment.
需要修改(0196e37)
@EricWvi 我看了这个 PR,理解它是要让 Loop 变量选择器与执行语义一致,在发布对话框里指出被拒绝的节点和字段,并让迭代端口的整个圆点都能拖线。这是第 2 轮,我看了 61429bd 之后的改动。有 1 处合并前需要改,其余都是建议。
合并前需要修正 Loop 结束条件的兼容性回归,避免原本能运行的已发布快照在启动时被拒绝。导入自动发布期间,手动按 Enter 也会发出第二个发布请求。
- ❗ P1-4(合并前需要改):保留检查未赋值的 Loop 结束条件(见行内)
- 🔧 2 处小改已写成建议(P2-4、P2-5):见行内 suggestion,可以一键采纳,也可以不改或留到以后。
- ✅ 上轮的 P1-2、P2-2、P2-3 已处理,谢谢。
- ⏳ 上轮还没处理的:P1-1、P1-3、P2-1(仍是建议,不影响合并)。
- 测试:
go test -race ./internal/workflow通过;go test -race -v ./internal/server -run '^TestWorkflowPublishRefusalNamesTheNode$'没跑(测试因未配置TEST_DATABASE_URL跳过。);npm test -- src/lib/workflows/mock/variable-catalog.test.ts src/features/workflows/editor/workflow-publish-error.test.ts src/features/workflows/page.test.tsx通过;没跑全量和 e2e。
涉及对外 API/协议,建议 owner 再看一眼。
P1 改完后我会再看一轮;其余都是建议,怎么处理由你决定。
自动检视 · 基于 0196e37 · 第 2 轮(增量)
| } | ||
| for _, clause := range cfg.until { | ||
| for _, rule := range clause.rules { | ||
| if err := check(loop, loop.id, "loopConfig.until", rule.selector); err != nil { |
There was a problem hiding this comment.
P1-4(合并前需要改) 这里把结束条件的左侧选择器当成必须取到值的引用。轮次池会声明 entry.input,即使它没有值,not_exists 和 empty 也能正常求值。我用同一张图验证了上轮版本能启动并结束循环,当前版本却在解析快照时返回 invalid_loop_reference。建议按运算符区分读取值和检查赋值状态,继续拒绝未声明的变量,并单独校验比较值里的模板。
| /** Publishes the current draft as an immutable snapshot with an optional version name. */ | ||
| async function confirmPublish(): Promise<void> { | ||
| if (workflow === null) { | ||
| if (workflow === null || publishingRef.current) { |
There was a problem hiding this comment.
P2-4(建议) 导入后自动发布也使用 publishWorkflowMutation,该路径没有设置 publishingRef。我让自动发布请求保持进行中,打开手动发布对话框,看到发布按钮已禁用,但在版本名输入框按 Enter 仍发出了第二个 POST /publish,可能生成额外版本。建议保留 isPending 检查,并用 ref 兜住手动提交同一拍的重复触发。
| if (workflow === null || publishingRef.current) { | |
| if (workflow === null || publishingRef.current || publishWorkflowMutation.isPending) { |
可直接采纳,也可以不改。
| } | ||
| } | ||
| } | ||
| for _, template := range loop.templates { |
There was a problem hiding this comment.
P2-5(建议) validateNode 会收集 Loop 节点上保留下来的 agentConfig.prompt,而 Loop 执行时不会读取这个字段。我在能正常结束的 Loop 上加了一个含 {{#entry.input#}} 的遗留提示词,上轮版本仍能运行,当前版本会拒绝发布,还会指向 Loop 面板里没有的提示词字段。建议这里只检查结束条件里的模板。
| for _, template := range loop.templates { | |
| for _, template := range loop.templates { | |
| if template.field != "loopConfig.until" { | |
| continue | |
| } |
可直接采纳,也可以不改。
修复 #844 S4 验收遗留的三个工作流编辑器问题
v2,不涉及 specs。只改
frontend-v2/和v2-server/。1. Loop 的变量选择器和引擎对不上(按 owner 结论改编辑器目录,不改引擎)
loopConfig.outputs,类型any,与服务端声明一致),不再有{loop}.output;循环内成员看到循环变量、本循环内上游,以及 Loop 能看到的上游变量(如start.input);轮次 Start 不再提供变量。invalid_loop_reference:循环外引用命名输出以外的变量、循环内引用循环变量以外的 Loop 变量、引用轮次 Start 的变量,一律在发布时拒绝并指向引用它的节点(选择器、提示词模板、聚合候选)。已存的loop.output旧图会在发布时说清楚,不再拖到运行时失败。比 desktop 严,已写进 README 的差异说明。packages/workflow-mock/src/variable-catalog.ts有同样的问题,留给 desktop 对照时处理。2. 发布被拒的提示
400 workflow_run_graph_parse的params带上nodeId、field、reason。3. 迭代节点的端口被标题栏挡住
z-20)盖住了输入、输出端口内侧一半的命中区,按在那里会拖动整个框。端口改为叠在标题栏之上。Loop 容器不受影响。测试
tsc -b、oxlint、vitest 1130/1130、build;新增变量目录 Loop 用例、workflow-publish-error.test.ts、页面发布被拒用例。go test -race ./...全部通过;新增loop_references_test.go、TestWorkflowPublishRefusalNamesTheNode。workflow-container-editor.spec.ts(端口命中测试与拖线、旧图发布被拒),在 main 上失败、本分支通过。截图
(修复前 / 修复后:选择器 ×2、发布被拒 ×2、迭代端口拖线)
Refs ora-space/circus#1388