Skip to content

Commit 4242c77

Browse files
authored
fix: Infinite loop increases maximum loop count limit (#4088)
1 parent 9b00b85 commit 4242c77

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

apps/application/flow/step_node/loop_node/impl/base_loop_node.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
from application.flow.tools import Reasoning
1616
from application.models import ChatRecord
1717
from common.handle.impl.response.loop_to_response import LoopToResponse
18+
from maxkb.const import CONFIG
19+
from django.utils.translation import gettext as _
20+
21+
max_loop_count = (CONFIG.get("MAX_LOOP_COUNT") or 1000)
1822

1923

2024
def _is_interrupt_exec(node, node_variable: Dict, workflow_variable: Dict):
@@ -127,6 +131,7 @@ def loop(workflow_manage_new_instance, node: INode, generate_loop):
127131
current_index = node.context.get("current_index") or 0
128132
node_params = node.node_params
129133
start_node_id = node_params.get('child_node', {}).get('runtime_node_id')
134+
loop_type = node_params.get('loop_type')
130135
start_node_data = None
131136
chat_record = None
132137
child_node = None
@@ -138,6 +143,8 @@ def loop(workflow_manage_new_instance, node: INode, generate_loop):
138143
details=loop_node_data[current_index])
139144

140145
for item, index in generate_loop(current_index):
146+
if 0 < max_loop_count <= index - current_index and loop_type == 'LOOP':
147+
raise Exception(_('Exceeding the maximum number of cycles'))
141148
"""
142149
指定次数循环
143150
@return:

installer/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ENV MAXKB_VERSION="${DOCKER_IMAGE_TAG} (build at ${BUILD_AT}, commit: ${GITHUB_C
4444
MAXKB_LOCAL_MODEL_HOST=127.0.0.1 \
4545
MAXKB_LOCAL_MODEL_PORT=11636 \
4646
MAXKB_LOCAL_MODEL_PROTOCOL=http \
47+
MAXKB_MAX_LOOP_COUNT=1000 \
4748
PIP_TARGET=/opt/maxkb/python-packages
4849

4950

ui/src/workflow/common/validate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ export class WorkFlowInstance {
8585
const base_node_list = this.nodes.filter((item) => item.id === WorkflowType.Base)
8686
return base_node_list[0]
8787
}
88-
extis_break_node() {
89-
return this.nodes.some((item) => item.id === WorkflowType.LoopBreakNode)
88+
exist_break_node() {
89+
return this.nodes.some((item) => item.type === WorkflowType.LoopBreakNode)
9090
}
9191
/**
9292
* 校验工作流

ui/src/workflow/nodes/loop-body-node/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const validate = () => {
2626
const loop_node = props.nodeModel.graphModel.getNodeModelById(loop_node_id)
2727
try {
2828
workflow.is_loop_valid()
29-
if (loop_node.properties.node_data.loop_type == 'LOOP' && !workflow.extis_break_node()) {
29+
if (loop_node.properties.node_data.loop_type == 'LOOP' && !workflow.exist_break_node()) {
3030
return Promise.reject({
3131
node: loop_node,
3232
errMessage: t('views.applicationWorkflow.validate.loopNodeBreakNodeRequired'),

0 commit comments

Comments
 (0)