[PR #30462] Feat/hitl #32829

Closed
opened 2026-02-21 20:52:09 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/30462

State: closed
Merged: No


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

本PR实现了 Human-in-the-Loop (HITL) 工作流暂停/恢复功能,允许工作流在 HumanInputNode 节点暂停,等待用户审批或拒绝后继续执行。

核心特性

  • 工作流暂停:工作流可在 HumanInputNode 处暂停,等待人工决策
  • 双模式恢复
    • Signal 模式:内存信号机制,用于 SSE 连接场景(调试器模式)
    • Celery 模式:异步任务恢复,用于后台处理
  • 多节点支持:支持连续多个 HumanInputNode 的暂停/恢复
  • 权限控制:用户只能恢复自己触发的工作流

新增 API 端点

  • POST /apps/{app_id}/workflow-runs/{run_id}/resume - 恢复暂停的工作流
  • GET /apps/{app_id}/workflow-runs/{run_id}/pause-info - 获取暂停信息
  • Service API 同步提供相应端点

主要变更

  • 新增核心文件
    • api/core/app/apps/workflow/resume_signal.py - 内存信号机制
    • api/core/app/apps/workflow/workflow_resumption_service.py - 统一恢复服务
    • api/core/app/layers/pause_state_persist_layer.py - 暂停状态持久化层
  • 节点增强:重构 HumanInputNode,优化暂停/恢复逻辑
  • 新增事件QueueWorkflowPausedEventWorkflowPausedStreamResponseWorkflowResumedStreamResponse
  • 数据库迁移workflow_pauses 表新增恢复追踪字段和索引

向后兼容性

所有变更均向后兼容 - 现有工作流继续正常运行。暂停/恢复逻辑仅在工作流到达 HumanInputNode 时激活。

Screenshots

WX20260102-165055@2x WX20260102-165043@2x WX20260102-165028@2x WX20260102-165018@2x WX20260102-165004@2x WX20260102-164940@2x WX20260102-164833@2x

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/30462 **State:** closed **Merged:** No --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary 本PR实现了 **Human-in-the-Loop (HITL) 工作流暂停/恢复功能**,允许工作流在 `HumanInputNode` 节点暂停,等待用户审批或拒绝后继续执行。 ### 核心特性 - **工作流暂停**:工作流可在 `HumanInputNode` 处暂停,等待人工决策 - **双模式恢复**: - **Signal 模式**:内存信号机制,用于 SSE 连接场景(调试器模式) - **Celery 模式**:异步任务恢复,用于后台处理 - **多节点支持**:支持连续多个 `HumanInputNode` 的暂停/恢复 - **权限控制**:用户只能恢复自己触发的工作流 ### 新增 API 端点 - `POST /apps/{app_id}/workflow-runs/{run_id}/resume` - 恢复暂停的工作流 - `GET /apps/{app_id}/workflow-runs/{run_id}/pause-info` - 获取暂停信息 - Service API 同步提供相应端点 ### 主要变更 - **新增核心文件**: - `api/core/app/apps/workflow/resume_signal.py` - 内存信号机制 - `api/core/app/apps/workflow/workflow_resumption_service.py` - 统一恢复服务 - `api/core/app/layers/pause_state_persist_layer.py` - 暂停状态持久化层 - **节点增强**:重构 `HumanInputNode`,优化暂停/恢复逻辑 - **新增事件**:`QueueWorkflowPausedEvent`、`WorkflowPausedStreamResponse`、`WorkflowResumedStreamResponse` - **数据库迁移**:`workflow_pauses` 表新增恢复追踪字段和索引 ### 向后兼容性 ✅ 所有变更均**向后兼容** - 现有工作流继续正常运行。暂停/恢复逻辑仅在工作流到达 `HumanInputNode` 时激活。 ## Screenshots <img width="3678" height="1802" alt="WX20260102-165055@2x" src="https://github.com/user-attachments/assets/31d6a040-8a5c-4caf-a0d3-7edae53558ff" /> <img width="3698" height="2008" alt="WX20260102-165043@2x" src="https://github.com/user-attachments/assets/df03cad6-337f-4b43-ad56-2e7140fff74e" /> <img width="3690" height="2018" alt="WX20260102-165028@2x" src="https://github.com/user-attachments/assets/60b094f5-3120-47ca-994d-a05f6a7854bd" /> <img width="3698" height="2096" alt="WX20260102-165018@2x" src="https://github.com/user-attachments/assets/c89230f6-3782-4733-b7a9-08eb710721c3" /> <img width="3702" height="2012" alt="WX20260102-165004@2x" src="https://github.com/user-attachments/assets/1696d490-5753-41cc-b538-953ba979b14a" /> <img width="3708" height="2114" alt="WX20260102-164940@2x" src="https://github.com/user-attachments/assets/74683fbf-e77b-4fd1-98af-5fd7a44b0ed7" /> <img width="3686" height="2008" alt="WX20260102-164833@2x" src="https://github.com/user-attachments/assets/e88613cd-55fe-4a62-b81d-b4831f4ce942" /> ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:52:09 -05:00
yindo closed this issue 2026-02-21 20:52:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32829