[PR #27509] feat: add a stop run button to the published app UI #31783

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

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

State: closed
Merged: Yes


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

Fixes: #27332

Before After
The workflow stop API existed, but there was no way for users to stop a running generation in the published app. Added a “Stop Run” button to the shared app UI, letting end users stop ongoing runs directly.

web/service/share.ts

  • Added an optional getAbortController callback to sendCompletionMessage, exposing the SSE AbortController so the UI can cancel completion streams.

web/app/components/share/text-generation/result/index.tsx

  • Track the current task ID, stop state, and AbortController; call the appropriate stop API (workflow/chat) and abort the stream when the user requests a stop.
  • Introduced onRunControlChange to hand the stop handler up to the Run Once form and a hideInlineStopButton flag to hide the in-panel button when the form owns it.
  • When a workflow run finishes with status stopped, mark all traced nodes as Stopped and reset local state / callbacks.

web/app/components/share/text-generation/index.tsx

  • Added a shared runControl state that stores the current stop handler; pass it down to RunOnce and hide the inline stop button while single runs are active.
  • Reset runControl when switching to batch mode.

web/app/components/share/text-generation/run-once/index.tsx

  • Converted the Execute button into a toggle: idle state shows the blue "Execute" submit button, running state shows a grey "Stop Run" button (with spinner while stopping) that invokes the shared handler.

web/i18n/en-US/share.ts

  • Added the translation key stopRun: 'Stop Run' for the new button label.

Tests

pnpm run test result are below.

Overall Status

  • Test Suites: 69 passed (100% success rate)
  • Test Cases: 645 passed
  • Snapshots: 6 passed
  • Execution Time: 13.828 seconds
  • Status: All tests passed successfully

Coverage Metrics

  • Statements: 72.93% (23592/32347)
  • Branches: 82.57% (782/947)
  • Functions: 23.05% (175/759)
  • Lines: 72.93% (23592/32347)

Screenshots

Before After

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/27509 **State:** closed **Merged:** Yes --- > [!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 Fixes: #27332 | Before | After | |--------|--------| | The workflow stop API existed, but there was no way for users to stop a running generation in the published app. | Added a **“Stop Run”** button to the **shared app UI**, letting end users stop ongoing runs directly. | ### web/service/share.ts - Added an optional getAbortController callback to sendCompletionMessage, exposing the SSE AbortController so the UI can cancel completion streams. ### web/app/components/share/text-generation/result/index.tsx - Track the current task ID, stop state, and AbortController; call the appropriate stop API (workflow/chat) and abort the stream when the user requests a stop. - Introduced onRunControlChange to hand the stop handler up to the Run Once form and a hideInlineStopButton flag to hide the in-panel button when the form owns it. - When a workflow run finishes with status stopped, mark all traced nodes as Stopped and reset local state / callbacks. ### web/app/components/share/text-generation/index.tsx - Added a shared runControl state that stores the current stop handler; pass it down to RunOnce and hide the inline stop button while single runs are active. - Reset runControl when switching to batch mode. ### web/app/components/share/text-generation/run-once/index.tsx - Converted the Execute button into a toggle: idle state shows the blue "Execute" submit button, running state shows a grey "Stop Run" button (with spinner while stopping) that invokes the shared handler. ### web/i18n/en-US/share.ts - Added the translation key stopRun: 'Stop Run' for the new button label. <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> ## Tests `pnpm run test` result are below. #### Overall Status - **Test Suites**: 69 passed (100% success rate) - **Test Cases**: 645 passed - **Snapshots**: 6 passed - **Execution Time**: 13.828 seconds - **Status**: ✅ All tests passed successfully #### Coverage Metrics - **Statements**: 72.93% (23592/32347) - **Branches**: 82.57% (782/947) - **Functions**: 23.05% (175/759) - **Lines**: 72.93% (23592/32347) ## Screenshots | Before | After | |--------|-------| | <img src="https://github.com/user-attachments/assets/43ca6332-1e66-4bd7-beec-f9f37f7f5f52" width="900" /> | <img src="https://github.com/user-attachments/assets/34afba21-8b2e-4003-a074-8c86a1d927b2" width="900" /><br><img src="https://github.com/user-attachments/assets/fd4cb2d7-8b29-4c5c-84d3-f21d7e45bda0" width="900" /> | ## 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:50:07 -05:00
yindo closed this issue 2026-02-21 20:50:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31783