Skip to content

feat(workflow): invalid variable check - #7608

Open
Nixieboluo wants to merge 21 commits into
labring:mainfrom
Nixieboluo:feat/global-var-check
Open

feat(workflow): invalid variable check#7608
Nixieboluo wants to merge 21 commits into
labring:mainfrom
Nixieboluo:feat/global-var-check

Conversation

@Nixieboluo

@Nixieboluo Nixieboluo commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Context

Workflow references can become invalid after global variables, node outputs, types, connections, or catchError settings change. Existing cleanup may remove these references and cause data loss.

Description

  • Add unified workflow reference validation.
  • Classify issues as invalid_reference, invalid_reference_type, and unreachable_reference.
  • Preserve original references until users fix or remove them.
  • Trigger workflow rechecks after graph, variable, output, type, and catchError changes.
  • Validate nested references in IfElse and VariableUpdate.
  • Display invalid references and reasons in reference controls and related workflow nodes.
  • Add reference snapshots for historical source and output labels.
  • Block publish and debug when error-level reference issues remain.
  • Share the validation logic between Agent V1 and V2.

Changes in the codebase

  • Added referenceCheck.ts with reference status and type compatibility checks.
  • Extended workflowCheck.ts with reference issue classification and field-level issues.
  • Updated workflow action and utility contexts to trigger rechecks and preserve snapshots.
  • Removed save-time filtering of unavailable references.
  • Added reference snapshot types, legacy migration cleanup, and schema compatibility.
  • Updated Reference, VariableUpdate, IfElse, DatasetConcat, plugin output, and dynamic input components.
  • Preserved folded node state during workflow serialization and restoration.
  • Added localized messages and expanded migration, serialization, and workflow validation tests.

Additional information

  • References are identified by node/output IDs or global variable keys.
  • Labels are used for display only; references are not automatically remapped.
  • Prompt editor references retain their original text.
  • Existing structural workflow checks keep their current responsibilities.

Signed-off-by: Nixieboluo me@sagirii.me

Signed-off-by: Nixieboluo <me@sagirii.me>
共享类型兼容谓词判定引用类型不兼容,选择器按列表自行区分删除/类型失效原因,新增类型问题聚合 Toast。
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

Admin Preview Image Ready!

ghcr.io/labring/fastgpt-pr:admin_425fc867a1fb74e9b9fb30ce3b4d494771d9165c

🕒 Time: 2026-09-03 10:51:14 (UTC+8)

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 32.24% 3165 / 9814
🔵 Statements 32.15% 3339 / 10384
🔵 Functions 26.96% 637 / 2362
🔵 Branches 26.6% 1542 / 5795
File CoverageNo changed files found.
Generated in workflow #2891 for commit 425fc86 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

Build and publish successful - Preview fastgpt Image:

ghcr.io/labring/fastgpt-pr:fastgpt_425fc867a1fb74e9b9fb30ce3b4d494771d9165c

🕒 Time: 2026-09-03 10:54:13 (UTC+8)

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

Docs preview deployed

🔗 👀 Click here to visit preview

ghcr.io/labring/fastgpt-docs-pr:425fc867a1fb74e9b9fb30ce3b4d494771d9165c

🕒 Time: 2026-09-03 10:48:14 (UTC+8)

Signed-off-by: Nixieboluo <me@sagirii.me>
Preserve invalid references for editor recovery while excluding\nunavailable values from runtime HTTP requests.

@c121914yu c121914yu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这版需要调整以下问题:

  1. 引用校验必须前后端同源。 当前发布阻断主要在前端,直接调用发布 API 可以绕过。建议将不依赖 React、i18n 的纯校验逻辑下沉到共享层,前端现有错误检查和后端发布接口调用同一个实现,后端作为最终兜底,不能分别复制一套规则。

  2. Reference 校验应合并进现有工作流错误检查,不要建立独立检查链路。 请移除每 10 秒执行一次的全量扫描以及 reference 专用调度。节点、边和配置变化时,跟随现有错误检查一起执行;普通配置变化可检查当前节点,结构变化可防抖全量检查;调试和发布时同步执行最终全量检查。

  3. 避免编辑器、发布和运行期各自解释 reference。 引用结构、来源存在性、可达性、输出可选性和类型兼容规则应共享。HTTP 运行期只应额外判断当前引用是否实际产生了值,避免三套逻辑继续漂移。

  4. 补齐容器节点场景。 当前来源范围计算在 LoopRun 等嵌套工作流中可能把合法的子节点引用判为 unreachable_reference。选择器、错误检查和运行期必须使用一致的容器拓扑规则,并补充 Loop、Parallel、嵌套容器测试。

  5. 明确并补齐 referenceSnapshots 生命周期。 Snapshot 只应作为 [nodeId, outputId] 对应的历史展示名称,不参与校验和运行。目前主要在选择器操作时生成,历史工作流没有回填,代码直接修改 reference 或节点/输出改名时也不保证同步。需要明确它是选择时名称还是最后可解析名称,并集中维护 reference 与 snapshot 的一致性。

  6. 修复国际化硬编码。 IfElse 引用错误信息中的“变量/值”直接使用了中文,会混入英文等语言界面,应改用 i18n key。

建议至少补充以下验证:发布 API 无法绕过引用校验、前后端对同一工作流返回一致的问题码、Loop/容器引用、历史无 snapshot 数据,以及 reference 与 snapshot 的同步更新。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

补充注释

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥会动到后端的

return listItem.children?.some((v) => v.value === item[1]);
});
onSelect(validList);
// 保留当前列表中已失效的引用,交给上层展示并在用户删除时移除。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可能会引入其他组件的风险

/>
</MenuList>
</Menu>
{rightContent && (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要绝对定位吧,会覆盖在正常组件上方么

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants